我需要在地图上为我拥有的数据添加标记。
在思考过程中,我浏览了.contains()
,我可以将自定义数据附加到地图上。现在,需要显示地图视口中存在的要素的属性。我无法遍历所有项目并检查<td><?php echo remove_junk(ucwords($a_customers['id']))?></td>
<td><?php echo remove_junk(ucwords($a_customers['name']))?></td>
<td><?php echo remove_junk(ucwords($a_customers['company']))?></td>
<td><?php echo remove_junk(ucwords($a_customers['address']))?></td>
<td><?php echo remove_junk(ucwords($a_customers['city']))?></td>
<td><?php echo remove_junk(ucwords($a_customers['state']))?></td>
<td><?php echo remove_junk(ucwords($a_customers['country']))?></td>
<td><?php echo remove_junk(ucwords($a_customers['phone']))?></td>
<td><?php echo remove_junk(ucwords($a_customers['email']))?></td>
,我有大量数据。是否有默认的google方式来获取地图视口中存在的要素的属性?
答案 0 :(得分:0)
伪代码
pointsWithinPolygon
函数addGeoJson
bounds_changed
事件中冲洗并重复实际代码
/*
You'd load your own geojson like so:
const points = turf.featureCollection(geojsonObject.features)
*/
// random 1M points as a demo
const points = turf.randomPoint(1e6, {
bbox: [-180, -90, 180, 90]
});
const {
west,
south,
east,
north
} = map.getBounds().toJSON();
// extent in minX, minY, maxX, maxY order
const viewport_as_polygon = turf.bboxPolygon([west, south, east, north])
const points_within = turf.pointsWithinPolygon(points, viewport_as_polygon)
注意:由于直到调用addGeoJSON
为止,这些都不会与DOM交互,因此它比为每个要素生成标记然后隐藏/修改视口之外的透明度的速度要快。