There are two constraining issues here.
- The first is has to do with rendering geometries that cross the 180th meridian. When a geometry does this, it is actually rendered on two separate globes in maps that support "wrap around". To handle this, longitude values that are on the "next globe" will be offset by 360 degrees. Mathematically, these longitude values are still value since two longitude values that are offset by 360 degrees represent the same location when normalized. However, not all libraries support doing calculations like this.
- Turf.js does spatial calculations based on GeoJSON. The GeoJSON specification does not allow geometries to cross the 180th Meridian (https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.9) and requires the geometries to be cut into two. The
booleanPointInPolygon
function in this case does not support longitude values outside the -180/180 range, however, theturf.pointsWithinPolygon
function does handle this.
To resolve your issue you can do one of the following:
- Loop through the coordinates and normalize the longitude value to get it into the -180/180 range. There is a helper method for this in the
atlas.math.normalizeLongitude
https://learn.microsoft.com/en-us/javascript/api/azure-maps-control/atlas.math?view=azure-maps-typescript-latest#azure-maps-control-atlas-math-normalizelongitude - You can split the polygon ring into two along the 180th meridian and create a multipolygon. The
atlas.math.getPathSplitByAntimeridian
function can help with this. https://learn.microsoft.com/en-us/javascript/api/azure-maps-control/atlas.math?view=azure-maps-typescript-latest#azure-maps-control-atlas-math-getpathsplitbyantimeridian - You can use the
turf.pointsWithinPolygon
function instead. This would likely be the easiest. Here is a full code sample for this: https://samples.azuremaps.com/?search=draw&sample=select-data-in-drawn-polygon-area