i need to hand the latlng coordinates from my phpPostGIS-served geoJSONLayer as an array over to a new added HeatMap Layer. L.geoJSON has an build-in option: coordsToLatLng( coords )" and a static method for that: coordsToLatLngs( coords, levelsDeep?, reverse? ). I don´t get any errors, but the heat map does´t show up. If i build a new L.heatLayer(coord).addTo(map); outside the function, it works… Does anyone have an idea? This is what i have so far:
$.getJSON("postgis_geojson.php?geotable=shops&geomfield=the_geom", function(data) {
L.geoJson(data, {
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, geojsonMarkerOptions);
},
onEachFeature: function (feature, layer) {
popupOptions = {maxWidth: 200};
layer.bindPopup(feature.properties.popupContent);
},
coordsToLatLng: function (coords) {
return new L.heatLayer(coords);
}
}).addTo(map);
});
Answer
In OnEachFeature you can find the coordinates in feature.geometry.coordinates. so
coords = []; //define an array to store coordinates
onEachFeature: function (feature, layer) {
popupOptions = {maxWidth: 200};
layer.bindPopup(feature.properties.popupContent);
coords.push(feature.geometry.coordinates);
}
Now you can use the array coords in L.heatLayer
No comments:
Post a Comment