有没有办法,现在如何使用Leaflet对多边形进行z索引?我可以在启动地图时使用,但是在向现有地图添加新多边形时,我需要根据其区域将新多边形分类到现有多边形中 - 因此较大的多边形不会与小地图重叠。我找到了这个解决方案:
但当我的地图包含更多功能时,它的速度很慢。有什么想法吗?
答案 0 :(得分:0)
我不知道这个答案的表现,但你可以尝试一下:
GeoJSON Layer Order In Leaflet 0.7.5
主要代码是:
// To be called after adding a geoJsonLayer to the map.
function assignZindex(geoJsonLayer) {
geoJsonLayer.eachLayer(function (layer) {
layer._container.zIndex = layer.options.zIndex;
});
}
// To be called after assignZindex().
function reOrderVectorLayers() {
var root = map._pathRoot,
child = root.firstChild,
next;
while (child) {
next = child.nextSibling;
if (!next) {
break;
}
if (next.zIndex < child.zIndex) {
root.insertBefore(next, child);
if (next === root.firstChild) {
continue;
}
child = next.previousSibling;
continue;
}
child = next;
}
}
它假设zIndex
属性是在每个向量(多边形)图层的options
中定义的数字。
如该问题的评论中所述,如果您使用Leaflet 1.x,您现在可以创建自己的窗格,您可以通过CSS z-index订购,并将每个矢量图层插入指定的窗格中。