使用http://leafletjs.com/examples/layers-control.html示例中的框架我替换了行:
var cities = new L.LayerGroup();
L.marker([39.61, -105.02]).bindPopup('This is Littleton, CO.').addTo(cities),
L.marker([39.74, -104.99]).bindPopup('This is Denver, CO.').addTo(cities),
L.marker([39.73, -104.8]).bindPopup('This is Aurora, CO.').addTo(cities),
L.marker([39.77, -105.23]).bindPopup('This is Golden, CO.').addTo(cities);
有:
var cities = new L.LayerGroup();
$.getJSON("cvs.geojson",function(data){
var cvsIcon = L.icon({
iconUrl: 'CVS.svg',
iconSize: [45, 45]
});
L.geoJson(data, {
pointToLayer: function(feature, latlng) {
var marker = L.marker(latlng, {icon: cvsIcon});
marker.bindPopup(feature.properties.Address);
return marker;
}
}).addTo(cities);
});
代码的其余部分与示例相同,因此我非常确定我是如何加载数据的,或者geojson如何传递给"城市"变量。 cvs.geojson和CVS.svg文件都与index.html文件位于同一文件夹中。我对javascript和传单很新,任何帮助都将不胜感激。