Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splitter function can not be used when the length of the line segment is short #1073

Open
JokanJan opened this issue Jun 13, 2024 · 7 comments
Labels

Comments

@JokanJan
Copy link

PixPin_2024-06-13_18-14-28

Viglino added a commit that referenced this issue Jun 19, 2024
@Viglino
Copy link
Owner

Viglino commented Jun 19, 2024

The issue is in the tolerance that is too low:

var splitter = new ol.interaction.Splitter({ source: vector.getSource(), tolerance: 0.001 });

@Viglino Viglino added the bug label Jun 19, 2024
@jidixueqiao
Copy link

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,
      });

@Viglino
Copy link
Owner

Viglino commented Jun 20, 2024

The tolerance must be set in the coord system.
You have to adapt it to make it run.

@jidixueqiao
Copy link

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:
image
For now, how can I find a number which greater than the result Math.abs(d1 - d2) and less than the variable det?

Viglino added a commit that referenced this issue Jun 20, 2024
@Viglino
Copy link
Owner

Viglino commented Jun 20, 2024

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.

@jidixueqiao
Copy link

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.

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?

@Viglino
Copy link
Owner

Viglino commented Jun 21, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants