首页 > 解决方案 > 如果使用 Leaflet.markercluster,Leaflet VectorGrid 交互性将不起作用

问题描述

我正在尝试将 Leaflet VectorGrid交互选项用于单击和鼠标事件:

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

我创建了一个代码沙盒

如果您发表评论map.addLayer(mcg);,则交互性有效。

标签: javascriptleafletleaflet.markercluster

解决方案


传单贡献者的回答:

您正在遭受 github.com/Leaflet/Leaflet/issues/4135 的困扰 - 将 preferCanvas 设置为 false 可以解决该问题。问题不是 vectorgrid 与 markercluster 的交互,而是 L.Canvas 中的矢量特征(markercluster 多边形)与任何其他交互层(vectorgrid 瓦片)


推荐阅读