I am looking to merge at least 2 JSON layers to allow all their markers to be searchable within a specified radius after clicking.
There are two files defined in the code as follows:
var url = "Peterborough.json";
var url2 = "Test.json";
The implementation can be found in the example linked below:
up to where we need to set the SelectPoints(lat,lon)
function.
Afterwards, I attempted something like this:
https://i.sstatic.net/MJ6q3.png
function SelectPoints(lat,lon){
var dist = document.getElementById("miles").value;
xy = [lat,lon]; //center point of circle
var theRadius = parseInt(dist) * 1609.34 //1609.34 meters in a mile
//dist is a string so it's convered to an Interger.
selPts.length =0; //Reset the array if selecting new points
job.eachLayer(function (layer) {
// Lat, long of current point as it loops through.
layer_lat_long = layer.getLatLng();
// Distance from our circle marker To current point in meters
distance_from_centerPoint = layer_lat_long.distanceTo(xy);
// See if meters is within radius, add the to array
if (distance_from_centerPoint <= theRadius) {
selPts.push(layer.feature);
}
job2.eachLayer(function (layer) {
// Lat, long of current point as it loops through.
layer_lat_long = layer.getLatLng();
// Distance from our circle marker To current point in meters
distance_from_centerPoint = layer_lat_long.distanceTo(xy);
// See if meters is within radius, add the to array
if (distance_from_centerPoint <= theRadius) {
selPts.push(layer.feature);
}
});
However, instead of the desired result, I ended up with a blank space (even the map disappears).
What could be causing this issue?
I have read about the iteration of this function here:
Leaflet eachLayer function does not iterate through all Layers
but it hasn't provided a clear solution for me.
I want both of these layers to be selectable after clicking the marker instead of just one.
When I try to use the second JSON file as a layer and replicate the
$.getJSON(url2, function(data) {
code, I can see everything on the map clearly, but they are not selected upon clicking.
Is there a way to address this issue and make both layers eligible for selection?