Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从某个半径内的多个JSON层中选择标记_Javascript_Json_Leaflet - Fatal编程技术网

Javascript 从某个半径内的多个JSON层中选择标记

Javascript 从某个半径内的多个JSON层中选择标记,javascript,json,leaflet,Javascript,Json,Leaflet,我想结合至少2个json层,以便在单击后在一定半径内对其所有标记进行研究 有两个文件,其代码如下所示: var url = "Peterborough.json"; var url2 = "Test.json"; job.eachLayer(function (layer) { // Lat, long of current point as it loops through. layer_lat_long = layer.getLatLng(); // Dista

我想结合至少2个json层,以便在单击后在一定半径内对其所有标记进行研究

有两个文件,其代码如下所示:

var url = "Peterborough.json";
var url2 = "Test.json";
 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);  
    }
  })
然后,此链接下的示例中的代码如下所示:

现在,我们必须设置
SelectPoints(lat,lon)
功能

后来我做了这样的事情:

var url = "Peterborough.json";
var url2 = "Test.json";
 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);  
    }
  })

代码,然后我可以在地图上清楚地看到所有内容,但单击后它们不会被选中


可以澄清一下吗?

看起来好像是我把
放进去的在错误的位置

代码应该如下所示:

var url = "Peterborough.json";
var url2 = "Test.json";
 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);  
    }
  })
job.eachLayer(函数(层){
//Lat,循环通过时当前点的长度。
layer_lat_long=layer.getLatLng();
//从圆标记到当前点的距离(米)
距离中心点的距离=层平面长距离(xy);
//查看米是否在半径范围内,将其添加到阵列
if(从中心点到中心点的距离