如何使用半径和纬度过滤地图框特征

我在mapbox Studio上有一个图层,其中包含在地图上绘制的所有邮政编码,并且我正在使用访问键和图层ID对其进行访问,

我只想过滤半径内的邮政编码(标记)

jing35711 回答:如何使用半径和纬度过滤地图框特征

草皮提供了pointsWithinPolygon()功能,可帮助您找到圆内的任何点。这是一个示例:

*s[1]
a2
mapboxgl.accessToken = 'pk.eyJ1IjoicGFybmRlcHUiLCJhIjoiY2l6dXZ5OXVkMDByZDMycXI2NGgyOGdyNiJ9.jyTchGQ8N1gjPdra98qRYg';

var map = new mapboxgl.Map({
  container: 'map',style: 'mapbox://styles/mapbox/light-v10',center: [-46.6062,-23.5513],zoom: 11
});

map.on('load',function () {

  // List of your marker locations
  var points = turf.points([
      [-46.6318,-23.5523],[-46.6246,-23.5325],[-46.6062,[-46.663,-23.554],[-46.643,-23.557]
  ]);

  // Create circle with radius
  var center = [-46.6062,-23.5513];
  var radius = 3;
  var options = {steps: 10,units: 'kilometers',properties: {foo: 'bar'}};
  var circle = turf.circle(center,radius,options);

  // Find point within circle
  var markerWithin = turf.pointsWithinPolygon(points,circle);

  console.log("Found: " + markerWithin.features.length + " points");
  
  // Draw circle polygon
  map.addLayer({
    'id': 'circle','type': 'fill','source': {
      'type': 'geojson','data': circle
    },'layout': {},'paint': {
      'fill-color': '#525252','fill-opacity': 0.2
    }
  });
  
  // Draw all points 
  map.addLayer({
    'id': 'points','type': 'circle','data': points
    },'paint': {
      'circle-radius': 5,'circle-color': 'red','circle-opacity': 1
    }
  });
  
  // Draw marker with in circle
  markerWithin.features.forEach(function(marker) {
    // Create marker
    new mapboxgl.Marker()
      .setLngLat(marker.geometry.coordinates)
      .addTo(map);
  });
});

本文链接:https://www.f2er.com/2982331.html

大家都在问