terra-draw
terra-draw copied to clipboard
[Bug] Can't move or resize object across -180 or 180 longitude
Describe the bug Objects can't be moved or resized so that they cross -180 or 180 longitude.
Terra Draw npm version 1.2.0
To Reproduce Steps to reproduce the behavior:
- Go to demo website
- Draw a circle or a polygon
- Try to move or resize the object so that it crosses -180 or 180 longitude
Expected behavior The object should be able to be moved past -180 or 180 and resized to cross -180 or 180.
Screenshots
Hey @Hooterr - thanks for raising this, appreciate your interest.
Yes, regrettably this is a known issue. Unfortunately handling antimeridian crossings is tricky. I would need to check all the mapping libraries handle rendering geometries that cross the antimeridian, but if so in theory I think this could be fixed by handling all cases where the user can mutate Polygons/LineStrings to ensure antimerdians are handled correctly.
Is there a way to implement a custom drawing mode? I'm trying to do that but it seems that the library doesn't export classes needed for that e.g. TerraDrawBaseDrawMode?
Hey @Hooterr, please see this example https://github.com/JamesLMilner/terra-draw-route-snap-mode on how to make a custom mode. Long term it would be good to improve the documentation and make extension easier but hopefully this shows how to create a custom mode for now.
Also, it's not possible to digitize a polygon that crosses the antimeridian in Terra + Maplibre when the map projection is set to globe. It will create the polygon by wrapping it around the globe in the wrong direction (see image). In mercator projection, it works but can't be edited, as mentioned in this issue. Also, using addFeatures to add a polygon that crosses the antimeridian doesn't work because it doesn't accept coordinates that are >180 or <-180. Is there a way to prevent the default validation when using addFeatures()?
Thanks for the additional info @glaroc. I will at some point get some time to investigate this a little deeper and understand what can be better done to support cross antimeridian geometries. Different mapping libraries take different approaches to cross antimeridian geometries so we need to be careful with the approach.
To answer your question at the end, there is no way currently to prevent coordinates not within those bounds currently as iI think it could cause quite a lot mayhem internally unfortunately due to expecting them to be between that range. I think in theory if you have geometries that are outside this range you could normalise them outside Terra Draw before adding them? Appreciate this is an extra step however.
@JamesLMilner From my understanding, Maplibre allows coordinates outside -180, 180 to enable creating features that extend beyond the antimeridian. In fact, adding a polygon with Terra Draw in Maplibre with the mercator projection will create a feature with coordinates outside the allowed range, but it can't be moved or edited by Terra Draw. So, normalizing coordinates outside Terra Draw would help to display the feature in Maplibre.