javascript - 如果使用 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);
,则交互性有效。
解决方案
传单贡献者的回答:
您正在遭受 github.com/Leaflet/Leaflet/issues/4135 的困扰 - 将 preferCanvas 设置为 false 可以解决该问题。问题不是 vectorgrid 与 markercluster 的交互,而是 L.Canvas 中的矢量特征(markercluster 多边形)与任何其他交互层(vectorgrid 瓦片)
推荐阅读
- scala - 在一些关于函数式编程的书籍中,实例方法委托给伴随对象中定义的二进制函数。背后有什么实际原因吗?
- google-apps-script - 谷歌应用脚本按条件隐藏列
- fetchxml - 如何在 Power Apps 门户中使用 Liquid 标签获取选项集的名称?
- vim - 为什么它会在简单函数中引发错误“E523:此处不允许”?
- c++ - 将 cin 转换为 argc argv 输入。使用命令行传递值的新手
- javascript - 调整窗口大小时调整画布大小 (JavaScript)
- javascript - 将文件从本地 Angular 文件夹上传到服务器
- google-cloud-platform - 无法启动或移动 VM 实例
- uml - 如何用 UML 表示计数器类型的实体?
- java - Java 和 Jconn4 对 Sybase 16.3 的支持