I am creating a tool to edit gps tracks using Mapbox GL Draw and I need to be able to display which segments of the track have been edited. Essentially, what I want to do is split a geojson Linestring feature into three separate features anytime a vertex is dragged.
For example, the line below is a single Linestring feature. When dragging the third vertex, I want the lines around it to change color to show it has been edited, while the two outer sections remain te same color.
Is there a way to do this in Mapbox GL Draw? Or a library that can help me do this?
Alternatively, is there a way to get the index of the two vertices around the one that was edited (vertex 2 and 4) so that I can use a script to manually refactor the single geojson feature into three separate ones?
I see there is a split line mode, but I can't ask my client to cut the line anytime they want to make edits. This app will be used by people with different levels of computer literacy, so I want to make the line editing as easy as possible.
I also saw there is a getSelectedPoints()
method in Draw, but that only returns the point and doesn't give me the index or other information I can use to find the coordinates that need to be split in the feature's geometry. I could use the point coordinates to search for the appropriate coordinate in the geometry, but that assumes there won't be two points with the same coordinate, which I can't guarantee.