0

I am working on an application in OpenLayers which allows users to draw polylines and modify them.

For sake of presentation when the user draws across the dateline, I have split the polyline into two halves and added it to map as a MultiPolyline (MultiLineString) in OpenLayers.

The problem is when the user tries to modify the point on the dateline, the line can be observed as split on the map to the user. Which should not happen. When a user tries to modify the point on the dateline, it should be seen as a complete line not split at any instance.

To see the problem draw a polyline across the dateline and try to modify the dateline point (180° longitude). Here is a link to my code dateline modify problem

output

I was thinking about adding a vertex from the point being modified to the point on the dateline, is there a way to do that?

Also, I have observed that not all the polylines on my map are modifiable. I don't know why. Please suggest me if I should refactor my code with a different approach.

BPDESILVA
  • 2,040
  • 5
  • 15
  • 35
capnam
  • 429
  • 9
  • 25
  • 1
    They all all modifiable but only in the world between -180 and +180, so you need to pan across the world instead of simply crossing the dateline onto the next world. If you didn't split the lines and let them go out of the -180 to +180 range you could edit the whole line in one place, but only on the side of the world where it was first drawn. – Mike Jul 02 '19 at 13:34
  • I didn't understand, are you suggesting not to use `constructRoutes()` and `SplitOverDateLine()` in my code? – capnam Jul 03 '19 at 06:43
  • Okay, I got it. – capnam Jul 03 '19 at 06:56
  • How can I calculate the combined extent of two worlds over which line crossing dateline is drawn? I want to limit the view extent to the user while modifying the line. – capnam Jul 03 '19 at 10:25
  • It's probably best to restrict the extent to 180 degrees either side of the center of the feature, so there is only one world (although that world won't be centered on Greenwich) `var lon = feature.getGeometry().getExtent().getCenter()[0]; var projExtent = map.getView().getProjection().getExtent(); var restrictedExtent = [projExtent[0] + lon, projExtent[1], projExtent[2] + lon, projExtent[3]];` – Mike Jul 03 '19 at 11:42

0 Answers0