ThinkGeo.com    |     Documentation    |     Premium Support

Drawing a line across the dateline in wrapping mode

As I mentioned in my other thread: Wrong longitude for mouse location across dateline , working with features crossing the dateline causes some issues.

I have a custom track overlay that is used as a measure tool. Basically, the user clicks, and a line is built between the clicks, showing the length of the line on the label. This works except when the line crosses the dateline when wrapping mode is enabled. If I fix the x,y values, the line being drawn goes backwords across the entire map once it crosses the dateline, instead of just drawing a short distance across the dateline.

If I DON’T fix the values, the line draws fine across the dateline, but I can’t use functions like .GetLength(), because the actual X values being produced are < -180 or > 180. This will throw an error.

What’s a good way to get around this?

When I say I’m “fixing” the lat/long values, I mean I’m using modulus to keep them in the correct range.

Hi Dan,

In your other post, you just convert the X between -180 and 180, I don’t know which function you used this conversion, but I think you should only want to use it when you try to shows coordinates for example shows the mouse coordinate.

But in basic level of map, it still should be the actually value, so you won’t met this problem you mentioned.

If you have to do that please show us the scenario, a sample should be welcome.

Regards,

Ethan

So the problem is getting the length of the line for my label.

  1. Using your GetLength function lets the user select the DistanceUnit to use.
  2. Your GetLength function fails if any of the Vertex X values are < -180 or > 180.

Let’s say I have two vertices making a line. (179, 30) which is just before the dateline, and (181, 30) which is just past the dateline.

If I were to do a line.GetLength() on the above line, it would fail because of the x value 181 for the second vertex., even though the trackline itself on the map would be drawing correctly.

Now, I could use my conversion formula to “fix” 181. This would turn it into -179. In this case, line.GetLength() wouldn’t be measuring the short distance of the line. It would instead be wrapping backwards across the map to -179.

Hi Dan,

We discussed about it, in fact this requirement is not reasonable, projection 4326 don’t allow a line cross dateline to calculate, which will cause the result is not correct even we remove the validation of longitude need between -180 and 180.

But we also can understand it in your scenario, so the solution is like this:

Under projection 4326, the earth is a standard ellipsoid. If we think the line is around earth, we think the formula should works:
(X, Y) to (X1, Y1) = (X+offset, Y) to (X1+offset, Y1)

Follow this way you can dynamic move the line background, and get its length, then shows the result.

Please notice, if your line cross 180 degree, the result should be invalid, please don’t allow user to draw a line like this.

Wish that’s helpful.

Regards,

Ethan

Ethan,

I don’t understand why the line crossing 180 degrees should be invalid. This appears to be a significant bug. I should be able to load from a database, or draw a line from 179 to -179 and it should draw the “short” way around the earth. 2 degrees of latitude, not the “long” way, same for polygons. Just a small check to make sure that the line being drawn isn’t longer than 180 degrees and if it is, draw the other way around the earth. This means that I cannot display vehicle tracks that cross the dateline for even a short amount of time without the track wrapping around the world improperly.

Chris.

Hi Chris,

It looks you misunderstand my reply, I just mentioned calculate the length cross 180 is invalid, because in earth it don’t have a longitude bigger than 180. If you walk from 179 to 2, under 4326 you tried to calculate its length it should be two parts, a line part from 179 to 180 and the other part from 0 to 2.

But the result is not exactly, so I suggest you translation the points when calculate (It won’t be display on map, just for calculate).

I think it don’t effect you draw the vehicle tracking lines, because you can draw the line by the points 179 and 182. And you can also calculate the length, just need to transfer it from calculate 176 to 179 for example.

Do you think it still have problem here?

Regards,

Ethan

Ethan,

I understand how to calculate the length properly now, but I still have a drawing/loading problem.
I require lines to always draw the shortest path around the earth, but can’t have invalid latitude values such as 182. I would like to draw a line from 179 to -179 and have it be the “short way” how can I make this happen?

Hi Chris,

It looks your scenario is you can make user track custom line, so I have a suggestion about it, do you think that’s possible to make your lines looks like this:

If the end pass wrap date line, you create a dotted line in other direction between -180 to 180 like this:

Because you can calculate the actually length between 179 to 181(Direction east) and you can also calculate the length between 179 to 1(Direction west), so you can compare them, if the direction west length shorter than direction east one, you just redraw the line like this:

I think this can make this function looks better, if you met any detail problem when implement that please let us know.

Regards,

Ethan