Azure maps: Trying to draw direct line between two point at two corners of world

welcomenxj 1 Reputation point
2020-08-26T11:30:39.617+00:00

Am trying to plot direct line between "green arrow location"(right top corner) to "destination popup point". But it's moving all around world as shown in picture. Any suggestion? Please find image for reference.

Other lines whose points are not on world edges are working fine.

20482-screen-shot-2020-08-26-at-92105-pm.png

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

2 answers

Sort by: Most helpful
  1. AshokPeddakotla-MSFT 33,746 Reputation points
    2020-08-26T12:36:06.293+00:00

    @welcomenxj Welcome to Q&A forum!
    How exactly did you draw the line? Did you try from left to right?

    I just tried with the sample code available here: Draw Line and able to draw a line between the points you mentioned.

    20449-azuremapsline.png


  2. rbrundritt 18,061 Reputation points Microsoft Employee
    2020-09-03T06:18:04.477+00:00

    Managed to reproduce the issue and after talking with one of our architects I was reminded that the GeoJSON specification does not allow shapes to cross the antemeridian. I'm not a fan of this, luckily there are a few ways around this:

    Options 1:

    • Similar to above, but break the line into segments to minimize complexity and shift longitude values outside of the -180/180 range as needed. Then create a MultiLineString from the segments.
    • You end up with a line with coordinates outside of the standard range but should render any line back and forth over the antemeridian as needed.

    Option 2:

    • Leverage a library to split the line segments on the antemeridian and create a MultiLineString.
    • This method is a lot more work and and might not be as accurate, but should also work with any line.

    Here is a code sample showing all two options:

    EDIT: Site doesn't let me copy in code or attach the file, I've uploaded the code here: https://github.com/Azure-Samples/AzureMapsCodeSamples/blob/master/AzureMapsCodeSamples/Experimental/Lines%20that%20cross%20the%20Anetmeridian%20.html


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.