I am trying to add attributes to a layer. I have a select function that finds all points within 10 miles of a feature. If the point is within the radius distance I add it to an array and make another "Selected Set" out of it for a map and report. However they now want to sort the selected point based on distance from. How do I push this vale to the selected point?
var selPts = [];
function SelectPoints(lat,lon){
var dist = 10; //Get Radius distance
xy = [lat,lon]; //center point of circle
var theRadius = dist * 1609.34 //1609.34 meters in a mile
selPts.length =0; //Reset the array if selecting new points
sites.eachLayer(function (layer) {
// Lat, long of current point as it loops through.
layer_lat_long = layer.getLatLng();
// Distance from our marker To current point in meters
distance_from_centerPoint = layer_lat_long.distanceTo(xy);
// See if pt is within radius, add the to array
if (distance_from_centerPoint <= theRadius) {
selPts.push(layer.feature);
// how do I push distance_from_centerPoint into the feature properties?
}
});
Answer
Since I wanted to just add a distance field (dist), and I had the feature in my loop, I just added "layer.feature.properties.dist = my Distance Value" then when I pushed the layer.feature it went along.
sites.eachLayer(function (layer) {
// Lat, long of current point as it loops through.
layer_lat_long = layer.getLatLng();
// Distance from our marker To current point in meters
distance_from_centerPoint = layer_lat_long.distanceTo(xy);
// See if pt is within radius, add the to array
if (distance_from_centerPoint <= theRadius) {
layer.feature.properties.dist = (distance_from_centerPoint / 1609.34); //meters to miles
selPts.push(layer.feature);
}
});
No comments:
Post a Comment