Skip to content

Commit

Permalink
[UPD] Splitter tolerance #1073
Browse files Browse the repository at this point in the history
  • Loading branch information
Viglino committed Jun 20, 2024
1 parent a893c9f commit 58589bb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 8 additions & 2 deletions examples/interaction/map.interaction.splitter.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ <h2>Options:</h2>
var map = new ol.Map({
target: 'map',
view: new ol.View({
/** /
zoom: 5,
center: [261720, 5951081]
center: [261720, 5951081],
/*/
zoom: 15,
center: [0, 48],
projection: 'EPSG:4326'
/**/
}),
layers: layers
});
Expand All @@ -97,7 +103,7 @@ <h2>Options:</h2>
vector.getSource().addFeature(new ol.Feature(new ol.geom.Point([261720, 5951081])));

// Add splitter before other interaction
var splitter = new ol.interaction.Splitter({ source: vector.getSource(), tolerance: 0.001 });
var splitter = new ol.interaction.Splitter({ source: vector.getSource(), tolerance: 1e-8 });
map.addInteraction(splitter);

// Add interactions to modify features
Expand Down
11 changes: 7 additions & 4 deletions src/interaction/Splitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import '../geom/LineStringSplitAt.js'
* @param {ol_Collection.<ol.Feature>} options.triggerFeatures Any newly created or modified features from this collection will be used to split features on the target source (replace triggerSource).
* @param {function|undefined} options.filter a filter that takes a feature and return true if the feature is eligible for splitting, default always split.
* @param {function|undefined} options.tolerance Distance between the calculated intersection and a vertex on the source geometry below which the existing vertex will be used for the split. Default is 1e-3.
* @param {function|undefined} options.alignTolerance Tolerance to check allignment. Default is 1e-3.
* @todo verify auto intersection on features that split.
*/
var ol_interaction_Splitter = class olinteractionSplitter extends ol_interaction_Interaction {
Expand Down Expand Up @@ -68,8 +69,10 @@ var ol_interaction_Splitter = class olinteractionSplitter extends ol_interaction
this.source_.on("removefeature", this.onRemoveFeature.bind(this))
}

// Split tolerance between the calculated intersection and the geometry
// Node tolerance to snap
this.tolerance_ = options.tolerance || 1e-3
// Split tolerance between the calculated intersection and the geometry
this.tolerance2_ = options.alignTolerance || options.tolerance || 1e-3

// Get all features candidate
this.filterSplit_ = options.filter || function () { return true }
Expand Down Expand Up @@ -186,7 +189,7 @@ var ol_interaction_Splitter = class olinteractionSplitter extends ol_interaction
var p = this.intersectSegs(seg, [c2[j], c2[j + 1]])
if (p) {
split.push(p)
g = f.getGeometry().splitAt(p, this.tolerance_)
g = f.getGeometry().splitAt(p, this.tolerance2_)
if (g && g.length > 1) {
found = f
return true
Expand All @@ -203,7 +206,7 @@ var ol_interaction_Splitter = class olinteractionSplitter extends ol_interaction
extent = ol_extent_buffer(ol_extent_boundingExtent(seg), this.tolerance_ /*0.01*/)
this.source_.forEachFeatureIntersectingExtent(extent, function(f) {
if (f.getGeometry().splitAt) {
var g = f.getGeometry().splitAt(c[0], this.tolerance_)
var g = f.getGeometry().splitAt(c[0], this.tolerance2_)
if (g.length > 1) {
this.source_.removeFeature(f)
for (k = 0; k < g.length; k++) {
Expand Down Expand Up @@ -251,7 +254,7 @@ var ol_interaction_Splitter = class olinteractionSplitter extends ol_interaction
// Split original
var splitOriginal = false
if (split.length) {
var result = feature.getGeometry().splitAt(split, this.tolerance_)
var result = feature.getGeometry().splitAt(split, this.tolerance2_)
if (result.length > 1) {
for (k = 0; k < result.length; k++) {
f2 = feature.clone()
Expand Down

0 comments on commit 58589bb

Please sign in to comment.