如果使用 Leaflet.markercluster,Leaflet VectorGrid 交互性将不起作用
Leaflet VectorGrid interactivity doesn't work if Leaflet.markercluster is used
我正在尝试将 Leaflet VectorGrid interactivity 选项用于单击和鼠标事件:
const vectorGrid = L.vectorGrid.slicer(geoJsonDocument, {
rendererFactory: L.canvas.tile,
vectorTileLayerStyles: {
sliced: geoJSONStyle(false)
},
maxZoom: 22,
indexMaxZoom: 5, // max zoom in the initial tile index
interactive: true
});
vectorGrid.on("mouseover", function (e) {
console.log("mouseover");
});
vectorGrid.on("click", function (e) {
console.log("click");
});
但是,如果使用 Leaflet.markercluster
,交互性将不起作用。
我创建了一个codesandbox。
如果您发表评论 map.addLayer(mcg);
,互动效果很好。
传单贡献者的回答:
You're suffering from github.com/Leaflet/Leaflet/issues/4135 - setting
preferCanvas to false works around the issue. The problem is not
vectorgrid vs markercluster interactions, but rather vector features
in a L.Canvas (markercluster polygons) vs anything other interactive
layers (vectorgrid tiles
我正在尝试将 Leaflet VectorGrid interactivity 选项用于单击和鼠标事件:
const vectorGrid = L.vectorGrid.slicer(geoJsonDocument, {
rendererFactory: L.canvas.tile,
vectorTileLayerStyles: {
sliced: geoJSONStyle(false)
},
maxZoom: 22,
indexMaxZoom: 5, // max zoom in the initial tile index
interactive: true
});
vectorGrid.on("mouseover", function (e) {
console.log("mouseover");
});
vectorGrid.on("click", function (e) {
console.log("click");
});
但是,如果使用 Leaflet.markercluster
,交互性将不起作用。
我创建了一个codesandbox。
如果您发表评论 map.addLayer(mcg);
,互动效果很好。
传单贡献者的回答:
You're suffering from github.com/Leaflet/Leaflet/issues/4135 - setting preferCanvas to false works around the issue. The problem is not vectorgrid vs markercluster interactions, but rather vector features in a L.Canvas (markercluster polygons) vs anything other interactive layers (vectorgrid tiles