[英]can't change marker icons / colors in mapbox
I'm manipulating the mapbox marker radius example here: 我在这里操纵地图框标记半径示例:
https://www.mapbox.com/mapbox.js/example/v1.0.0/marker-radius-search/ https://www.mapbox.com/mapbox.js/example/v1.0.0/marker-radius-search/
to attempt to change the color / icon of the markers within a certain radius of a random point, but the colors aren't changing despite the properties being registered as changed. 尝试在随机点的某个半径内更改标记的颜色/图标,但尽管属性已注册为已更改,但颜色不会更改。 Here's my code: 这是我的代码:
clusterLayer = L.mapbox.featureLayer('examples.map-h61e8o8e').on('ready', function(e) {
clusterGroup = new L.MarkerClusterGroup({
showCoverageOnHover: false,
animateAddingMarkers: true
});
e.target.eachLayer(function(layer) {
clusterGroup.addLayer(layer);
layerArray.push(layer);
});
map.addLayer(clusterGroup);
});
window.setTimeout(eventFunction,eventTiming);
function eventFunction(){
clusterLayer.setFilter(affectMarker);
}
function affectMarker(feature) {
var fLat = feature.geometry.coordinates[1];
var fLng = feature.geometry.coordinates[0];
var fPt = L.latLng(fLat,fLng);
var dist = eventPt.distanceTo(fPt);
if (dist < eventRadius){
feature.properties['marker-color'] = eventColorNegative;
feature.properties['marker-symbol'] = 'danger';
}
}
Why doesn't this work? 为什么这不起作用? I've verified that it is returning valid points. 我已经确认它返回了有效点数。
Note also that the markers being used are MakiMarkers 另请注意,使用的标记是MakiMarkers
I found two ways to do this, though neither, I think, is as ideal as being able to do so with the code above. 我发现有两种方法可以做到这一点,尽管我认为这两种方法都不如上面的代码那样理想。 The first is, rather than to use setFilter
, use eachLayer
: 第一个是,而不是使用setFilter
,使用eachLayer
:
clusterLayer.eachLayer(affectMarker);
and then in the loop, use setIcon: 然后在循环中,使用setIcon:
layer.feature.properties['marker-color'] = eventColorNegative; layer.feature.properties['marker-symbol'] = 'danger'; layer.setIcon(L.mapbox.marker.icon(layer.feature.properties));
The other way is to first include the MakiMarkers extension (which I believe has been deprecated and rolled into Mapbox): 另一种方法是首先包括MakiMarkers扩展(我相信已被弃用并转入Mapbox):
https://github.com/jseppi/Leaflet.MakiMarkers https://github.com/jseppi/Leaflet.MakiMarkers
and then use this syntax: 然后使用以下语法:
layer.setIcon(L.MakiMarkers.icon({icon: "danger", color: eventColorNegative}));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.