Open JokanJan opened 3 months ago
The issue is in the tolerance that is too low:
var splitter = new ol.interaction.Splitter({ source: vector.getSource(), tolerance: 0.001 });
The issue is in the tolerance that is too low:
var splitter = new ol.interaction.Splitter({ source: vector.getSource(), tolerance: 0.001 });
Hi bro.I copy the code of the example, change the view projection from 'default' to 'EPSG:4326', and the splitter didn't work again. This is part of the code I tested:
// The map
var map = new ol.Map({
target: "map",
view: new ol.View({
center: [121.2738842396899, 30.179885990299272],
// center: ol.proj.transform(
// [121.2738842396899, 30.179885990299272],
// "EPSG:4326",
// "EPSG:3857"
// ),
zoom: 20,
projection: "EPSG:4326",
}),
layers: layers,
});
...
// Add splitter before other interaction
var splitter = new ol.interaction.Splitter({
source: vector.getSource(),
tolerance: 0.001,
});
The tolerance must be set in the coord system. You have to adapt it to make it run.
The tolerance must be set in the coord system. You have to adapt it to make it run.
Yes I tried.And I read the code of ol-ext later,I saw the tolerance must less than the variable det (in file /src/interaction/Splitter.js function intersectSegs) and greater than the result Math.abs(d1 - d2) (in the file /src/geom/LineStringSplitAt.js).I log both result like this: For now, how can I find a number which greater than the result Math.abs(d1 - d2) and less than the variable det?
The issue is due to numeric instability on calculation.
I've pushed a new version with 2 tolerances: tolerance
and alignTolerance
so you can adjust it.
tolerance = alignTolerance = 1e-8
seems to work for me with EPSG:4326 but it may depends on the latitude.
The issue is due to numeric instability on calculation. I've pushed a new version with 2 tolerances:
tolerance
andalignTolerance
so you can adjust it.tolerance = alignTolerance = 1e-8
seems to work for me with EPSG:4326 but it may depends on the latitude.
Thanks.I tried adjusting tolerance and alignTolerance many times, but this function still doesn't work properly in the coordinates I set (sometimes it splits a line into multiple segments with shorter intervals). In this case, is there any good way to quickly help me complete the setting and adjustment of these two parameters so that this function can work properly?
To prevent digital instability you can round coordinates, here is an example that round coords to 1E10: https://codepen.io/viglino/pen/QWRmapz?editors=0010