Leaflet 使用GeoJson数据更改传单地图中的标记
我用传单和GeoJSON构建了一个网络地图。我想更改标记,但是传单站点的示例对我没有帮助,因为它是用于本地文件的。你知道怎么改吗Leaflet 使用GeoJson数据更改传单地图中的标记,leaflet,geojson,Leaflet,Geojson,我用传单和GeoJSON构建了一个网络地图。我想更改标记,但是传单站点的示例对我没有帮助,因为它是用于本地文件的。你知道怎么改吗 $.getJSON("https://gist.githubusercontent.com/vassilaros/3791204ca226d5b236b4cd3106ef23cf/raw/PicnicSites.geojson", function(data) { addDataToMap(data, map); }); 及 我想把{icon:greenIcon}添
$.getJSON("https://gist.githubusercontent.com/vassilaros/3791204ca226d5b236b4cd3106ef23cf/raw/PicnicSites.geojson", function(data) { addDataToMap(data, map); });
及
我想把{icon:greenIcon}
添加到我的图层中。
我必须添加这行代码吗
EDIT2:
我要更改此标记:
只需使用pointToLayer函数
var MyIcon = L.icon({
iconUrl: 'leaf-green.png',
iconSize: [38, 95], // size of the icon
shadowSize: [50, 64], // size of the shadow
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
shadowAnchor: [4, 62], // the same for the shadow
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
L.geoJson(data ,{
pointToLayer: function(feature,latlng){
return L.marker(latlng,{icon: MyIcon});
}
}).addTo(map);
只需使用pointToLayer函数
var MyIcon = L.icon({
iconUrl: 'leaf-green.png',
iconSize: [38, 95], // size of the icon
shadowSize: [50, 64], // size of the shadow
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
shadowAnchor: [4, 62], // the same for the shadow
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
L.geoJson(data ,{
pointToLayer: function(feature,latlng){
return L.marker(latlng,{icon: MyIcon});
}
}).addTo(map);
你想用哪一点替换哪一点?可能重复的我认为你的json无效。你想用哪一点替换哪一点?可能重复的我认为你的json无效。poinToLayer可能是解决方案。我发现这个问题和我的问题很接近。点图层可能是解决方案。我发现这个问题和我的问题很接近。
var MyIcon = L.icon({
iconUrl: 'leaf-green.png',
iconSize: [38, 95], // size of the icon
shadowSize: [50, 64], // size of the shadow
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
shadowAnchor: [4, 62], // the same for the shadow
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
});
L.geoJson(data ,{
pointToLayer: function(feature,latlng){
return L.marker(latlng,{icon: MyIcon});
}
}).addTo(map);