0

I am developing a react-native-mapbox-gl app on Windows 10. I need to "round" GeoJSON points uploaded to the app so that they appear in the center of a house block. For example:

Figure 1: A marker is added on the northeaster corner of a block Figure 1: A marker is added on the northeaster corner of a block

Figure 2: The marker is "rounded" / "moved" to the geographical center of the block Figure 2: The marker is

Since it's unfeasible to manually create a GeoJSON geometry for every street there is, is there a way to achieve this?

4

1 回答 1

0

If you encode the boundaries of a particular block as a Polygon feature, you can then use Turf.js's centroid method to calculate the center of said polygon. This will return a coordinate that can be used for the location of the marker.

If you don't have the geographic bounds of these features, one option would be to use the Mapbox Tilequery API to query for all building features within a particular radius, and then create a LatLngBounds object containing these buildings to use as the Polygon defining the boundaries of the block.

于 2020-06-04T19:57:52.673 回答