简体   繁体   English

在传单功能中显示一些圆形标记

[英]Bring to front some circle markers in leaflet feature

I have a feature in a Leaflet map made up of many circle markers ( L.circleMarker ). 我在由许多圆形标记( L.circleMarker )组成的Leaflet映射中有一个功能。 The markers are symbolized to show whether a picture was taken at that location. 标记被符号化以显示是否在该位置拍摄了照片。

What I would like to do is bring all the markers that do have a photo at that location to the top of the layer, similar to how a marker can be raised with a mouse-over (but without mouse-over in this case). 我想做的就是将在该位置确实有照片的所有标记移到图层的顶部,这与通过鼠标悬停(但在这种情况下没有鼠标悬停)可以抬起标记的方式类似。

Here is an illustration of the original version: 这是原始版本的说明:
在此处输入图片说明

And this is what I would like them to be: 这就是我希望他们成为的人:

在此处输入图片说明

I've considered having different layers for photos vs. no photos, but due to some functions in the map, it's preferable that they are in a single layer. 我考虑过将照片分为不同的图层,而不是没有照片,但是由于地图中的某些功能,最好将它们放在单个图层中。

Any ideas as to how this could be done with JavaScript and Leaflet? 关于如何使用JavaScript和Leaflet进行操作的任何想法?

In the style definition for the circle marker it's possible to specify the "map pane" to which the marker is rendered ( http://leafletjs.com/reference-1.0.3.html#map-pane). 在圆形标记的样式定义中,可以指定标记要呈现到的“地图窗格”( http://leafletjs.com/reference-1.0.3.html#map-pane)。 It seems like this is the only way to specify the zIndex of circleMarkers (regular markers have a zindexOffset option). 似乎这是指定circleMarkers的zIndex的唯一方法(常规标记具有zindexOffset选项)。

My code looks like this: 我的代码如下所示:

var style = {
radius: 1.75,
fillColor: "darkred",
color: "darkred",
pane: 'overlayPane'
};
var picStyle = {
    radius: 0.25,
    fillColor: "blue",
    color: "blue",
    pane: 'shadowPane'
};
var site2 = new L.geoJSON(valuesSite2, {
    onEachFeature: onEachFeature,
    pointToLayer: function (feature, latlng) {
        feature.properties.layer = "Site 2";
        onEachFeature: onEachFeature;
        if (<there is a picture>) {
            return L.circleMarker(latlng, picStyle)
        } else {
            return L.circleMarker(latlng, style);
        }
    }
}).addTo(map);

The result looks like: 结果如下:
在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM