Add external geojson to leaflet layer

谁都会走 提交于 2019-11-30 18:24:41

问题


I am new to leaflet and JavaScript. I was thinking I could use geocommons and GeoJSON to host data for a mapping project.

I found External GeoJSON and Leaflet: The Other Way(s). This tutorial on reading external GeoJSON using a leaflet plugin but I haven't been able to get it to get the points to render on my map. The map portion of the code renders fine but the GeoJSON won't appear.

var geojsonLayer = new L.GeoJSON.AJAX("http://geocommons.com/datasets/168923/features.json?lat=53.796&lon=-1.551&radius=3&callback=?", {onEachFeature:popUp});

function popUp(feature, layer) {
  layer.bindPopup(feature.properties.name);
}

geojsonLayer.addTo(myMap);

回答1:


Save the leaflet.ajax plugin as leaflet.ajax.min.js in the same folder as your html page, then call it by adding this line in between the <head> tags

<script src="leaflet.ajax.min"></script>


来源:https://stackoverflow.com/questions/20485723/add-external-geojson-to-leaflet-layer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!