Share via

Azure Maps: Shape Coordinates Exceeding Limits, Causing Filtering Issues

Nilesh Khonde 80 Reputation points
25 Feb 2025, 3:53 pm

Hi all,

I am using the Drawing Manager from the Azure Maps Sample Code to draw shapes on a map using freehand drawing.

I am trying to filter markers within the drawn shape using turf.booleanPointInPolygon. However, in some areas, the markers are not being filtered correctly. I have around 1,000 markers on the map, but after drawing a freehand shape, the markers within it are not being filtered as expected.

Upon debugging, I retrieved the shape data using:

var shapes = this.drawingManager.getSource().getShapes();

Screenshot_25-2-2025_191324_org5d8e7b47.crm.dynamics.com

Screenshot_25-2-2025_191249_org5d8e7b47.crm.dynamics.com Screenshot_25-2-2025_19817_devtools

I then passed these shapes to turf.booleanPointInPolygon. However, when inspecting the console output, I noticed that the coordinates of the shapes sometimes exceed valid latitude and longitude ranges (i.e., beyond 90, -90 for latitude and 180, -180 for longitude) sometimes It also exceeds 200 range.

This seems to be the reason why the filtering is failing. It’s quite strange, as I have encountered this issue before but never understood the cause.

Any help or insights would be greatly appreciated!

 

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
798 questions
{count} votes

Accepted answer
  1. rbrundritt 19,831 Reputation points Microsoft Employee
    25 Feb 2025, 6:06 pm

    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, the turf.pointsWithinPolygon function does handle this.

    To resolve your issue you can do one of the following:

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Sampath 925 Reputation points Microsoft External Staff
    3 Mar 2025, 6:43 am

    Hello @Anonymous Azure Maps follows the geospatial standard of "longitude, latitude" (similar to x,y). Note that the response is in GeoJSON format, which is an open geospatial standard format. Its specification requires the "longitude, latitude" format. Azure Maps may show coordinates that exceed the valid range (i.e., 180, -180 for longitude). As far as I know, this is not a bug but an intended feature of Azure Maps due to how it handles wrap-around at the 180th meridian.

    Hope this helps!

    If you found this answer helpful, please click Accept Answer and kindly upvote it/ Click on yes.

    accept

    If you have any further questions, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.