我试着非常详细地解决我的问题,但我却被叫去寻求帮助,所以我在这里会非常笼统。
我需要总结在 Mapbox 上绘制的多边形中每个位置的值。我实际上有插入绘制多边形工具的代码,也可以在地图上绘制多边形,它确实汇总了显示在地图左侧框上的多边形内每个位置的值。但是,该值是错误的,我不确定为什么。我对此束手无策。有人对此有任何线索吗?
我一直在阅读 stackoverlow 上的其他帖子,我得到的一般想法是,如果您遇到问题,您可以随时寻求帮助。如果你不想帮助我,因为我寻求帮助的方式或出于任何原因是错误的,那没关系。如果您需要查看我的代码,请告诉我,不,我不想被灌输,我真的很想了解我的代码有什么问题以及有人可以如何帮助我。
如果没有看到您的代码,很难提供具体的指导,但总的来说,您可以采取以下一些步骤来总结 Mapbox 中多边形中每个位置的值:
// Get the coordinates of the polygon
const polygon = map.getSource('draw')._data.features[0].geometry.coordinates[0];
// Loop through each point in the polygon
let total = 0;
for (let i = 0; i < polygon.length; i++) {
const point = polygon[i];
// Check if the point falls within the bounds of a location
const locations = getLocations();
for (let j = 0; j < locations.length; j++) {
const location = locations[j];
if (point[0] >= location.minLon && point[0] <= location.maxLon &&
point[1] >= location.minLat && point[1] <= location.maxLat) {
total += location.value;
}
}
}
// Display the total value for the polygon
document.getElementById('total').textContent = total;
在此示例中,
getLocations()
是一个函数,它返回表示地图上每个位置的对象数组。每个对象都应具有属性 minLon
、maxLon
、minLat
、maxLat
和 value
,它们代表位置的最小和最大经度和纬度值,以及它的值。