Leaflet 控制传单图标层上的zindex

Leaflet 控制传单图标层上的zindex,leaflet,Leaflet,在下面,我试图通过点击按钮将绿色圆圈带到前面。我怎样才能做到这一点 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" > <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-

在下面,我试图通过点击按钮将绿色圆圈带到前面。我怎样才能做到这一点

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" >
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
</head>
<body>
    <button onclick="ccsdf()">Click me</button>
    <div id="map" style="width: 100%; height: 90vh"></div>

<script>
    var map;
    var layer1;
    var layer2;

    function ccsdf() {
        layer1.bringToFront();    
    }

    $(document).ready(function(){
        map = L.map('map').setView([0, 0], 14);

        L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
            attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
        }).addTo(map);

        layer1 = L.geoJson({ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [ 0, 0.0005 ]}}]}, {
            pointToLayer: function (feature, latlng) {
                return L.marker(latlng, {icon: L.icon({ iconUrl: 'https://upload.wikimedia.org/wikipedia/commons/5/52/Small_red_circle.png' }) });
            }
        }).addTo(map);

        layer2 = L.geoJson({ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "Point", "coordinates": [ 0, 0 ]}}]}, {
            pointToLayer: function (feature, latlng) {
                return L.marker(latlng, {icon: L.icon({ iconUrl: 'https://upload.wikimedia.org/wikipedia/commons/e/e7/Blue_1.png' }) });
            }
        }).addTo(map);
    });
</script>
</body>
</html>

点击我
var映射;
var层1;
var层2;
函数ccsdf(){
第1层:布林托夫隆();
}
$(文档).ready(函数(){
map=L.map('map').setView([0,0],14);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png'{
属性:“©;贡献者”
}).addTo(地图);
layer1=L.geoJson({“类型”:“特征集合”,“特征”:[{“类型”:“特征”,“属性”:{},“几何体”:{“类型”:“点”,“坐标”:[0,0.0005]}}}){
pointToLayer:功能(特性、latlng){
返回L.marker(latlng,{icon:L.icon({iconUrl:'https://upload.wikimedia.org/wikipedia/commons/5/52/Small_red_circle.png' }) });
}
}).addTo(地图);
layer2=L.geoJson({“类型”:“特征集合”,“特征”:[{“类型”:“特征”,“属性”:{},“几何体”:{“类型”:“点”,“坐标”:[0,0]}}){
pointToLayer:功能(特性、latlng){
返回L.marker(latlng,{icon:L.icon({iconUrl:'https://upload.wikimedia.org/wikipedia/commons/e/e7/Blue_1.png' }) });
}
}).addTo(地图);
});
有什么想法吗

干杯

下面的文字是因为堆栈溢出需要我写更多:-)

欧洲东部地区的Lorem ipsum dolor sit amet。一种泰勒斯调味品亨德雷特·埃尼姆、福斯·维塔伊、利奥和福斯·莫里斯·洛雷姆·苏西比特权杖。弧度,非前庭悬吊,非大前庭悬吊,大前庭悬吊。Nascetur eleifend位于faucibus faucibus,nulla fringilla,mauris ultrices posuere,在

中,不清楚为什么在您的案例中似乎不起作用。这可能是因为它只适用于向量形状,而向量形状也有单独的标记,与标记相反

无论如何,您可以简单地使用将a应用于每个标记(如果您的组有许多层,您可能需要检查该层是否为
L.marker
)。您可以简单地使用来实现这一点

函数ccsdf(){
//第1层:布林托夫隆();
第1层。各层(功能(层){
层设置偏移量(1000);
});
}

Plunker上的演示:

此插件将实现以下功能:

使用:

var aMarker = L.marker([lat, lon], {
    icon: icon,
    title: title,
    forceZIndex: <Value> // This is forceZIndex value
})
到一天结束时,如果没有宣布forceZIndex选项,标记器将正常工作

var aMarker = L.marker([lat, lon], {
    icon: icon,
    title: title,
    forceZIndex: <Value> // This is forceZIndex value
})
aMarker.setForceZIndex(<New Value>)
aMarker.setForceZIndex(null);