Loading Json properties in a popup using leafletjs

المشرف العام

Administrator
طاقم الإدارة
I have a geojson file (tide_gauges.geojson)

{"type": "FeatureCollection","crs": { "type": "name", "properties": { "name": "urn:eek:gc:def:crs:OGC:1.3:CRS84" } },

"features": [{ "type": "Feature", "properties": { "NUMERO": "10569", "MAREGRAFO": "COCALZINHO", "FICHA": null }, "geometry": { "type": "Point", "coordinates": [ -4, -1 ] } },{ "type": "Feature", "properties": { "NUMERO": "50240", "MAREGRAFO": "PONTA DE PARANAPUA", "FICHA": null }, "geometry": { "type": "Point", "coordinates": [ -4, -2 ] } }...

I retrieved this Json file in a variable:

var estacoes = new L.geoJson();estacoes.addTo(map);$.ajax({dataType: "json",url: "geojson/tide_gauges.geojson",success: function(data) { $(data.features).each(function(key, data) { estacoes.addData(data); });}}).error(function() {});I am in need to set all the feature properties ("NUMERO","MAREGRAFO","FICHA",LATITUDE e LONGITUDE) in a popup that appears after a click over point feature on the map.

I tried the code bellow, but it is not enough:

var popupContent ="";for (var k in feature.properties) { var v = String(feature.properties[k]); popupContent += k + '->' + v ;Could someone give some tips on that, please?



أكثر...
 
أعلى