我有一个包含简单点功能geojson的URL,我将在我的网络地图中显示它。
{"type": "FeatureCollection", "crs": {"type": "name", "properties": {"name": "EPSG:4326"}}, "features": [{"type": "Feature", "properties": {"name": "WORK", "pk": "3"}, "geometry": {"type": "Point", "coordinates": [-74.66645479202272, 40.79366860930495]}}, {"type": "Feature", "properties": {"name": "Great Swamp", "pk": "5"}, "geometry": {"type": "Point", "coordinates": [-74.47975158691408, 40.71239442660529]}}, {"type": "Feature", "properties": {"name": "stupid abid", "pk": "1"}, "geometry": {"type": "Point", "coordinates": [-74.25096586314858, 40.64616085364607]}}, {"type": "Feature", "properties": {"name": "Rutland", "pk": "2"}, "geometry": {"type": "Point", "coordinates": [-72.97393798828126, 43.61022814178643]}}, {"type": "Feature", "properties": {"name": "Sota", "pk": "4"}, "geometry": {"type": "Point", "coordinates": [-94.52636718750001, 46.46813299215556]}}]}
在JS中
我简单地使用
var incidences = new L.GeoJSON.AJAX("http://127.0.0.1:8000/incidence_data/")
incidences.addTo(map);
并且它被正确地添加。
我知道有一个OneachFeature选项,它本质上是作为一个for循环遍历每个功能,但我想知道如何使用for循环来处理incdences变量并打印出每个名称。
for (var x in incidences.features)
console.log(incidences.features[x].properties.name);
什么都没有出现
控制台日志(事件)
e {urls: Array(1), ajaxParams: {â¦}, _layers: {â¦}, options: {â¦}, _events: {â¦}, â¦}
ajaxParams
:
{dataType: "json", callbackParam: "callback", local: false, middleware: Æ}
options
:
{}
urls
:
["http://127.0.0.1:8000/incidence_data/"]
_events
:
{data:loaded: Array(1), data:progress: Array(1)}
_firingCount
:
0
_initHooksCalled
:
true
_layers
:
{1334: e, 1336: e, 1337: e, 1338: e, 1339: e}
_leaflet_id
:
1335
__proto__
:
e