I'm making a map using Leaflet, and populating the map with data from a GeoJSON file. I want to use the distanceTo
function, but it requires a latLng
object. Is there a way to convert
the GeoJSON's properties.geometry.coordinates
into latLng
?
I have an array of 31 coordinates, from using the push()
method on the onEachLayer
:
var coords = [];
onEachFeature : function(feature,layer) {
coords.push(feature.geometry.coordinates)
//console.log(coords)...
After running that, the coords array is populated with the array for each coordinate. Is there a way to 'convert' this array of arrays to a latLng
object so ditanceTo
can be used?
End goal is to run the latLng
objects through a loop using distanceTo
, so that each popup displays the distance from the center point.
var low = L.geoJson(hosp, {
pointToLayer: function(feature,latlng) {
return L.circleMarker(latlng, {
color: 'yellow',
weight: 2,
fillColor: 'green',
fillOpacity: .7,
radius:9
});
},
filter: function (feature, layer) {
if(feature.properties.DAILY_PAT <= '600'){
return feature;}
},
onEachFeature : function(feature,layer) {
coords.push(feature.geometry.coordinates)
//console.log(coords)
layer.on('click',function(){
layer.bindPopup("<b>Low Enrollement </b><br>"+"<b>School Name: </b>"
+ feature.properties.FACILITY_N+"<br><b># of Students: </b>"
+ feature.properties.DAILY_PAT).openPopup()
});
}
}).addTo(map);