ol 10.6.2-dev.1753992384159 → 10.6.2-dev.1753992411402
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ol.js +1 -1
- package/dist/ol.js.map +1 -1
- package/interaction/Draw.d.ts +3 -62
- package/interaction/Draw.d.ts.map +1 -1
- package/interaction/Draw.js +12 -387
- package/interaction/Modify.d.ts +93 -59
- package/interaction/Modify.d.ts.map +1 -1
- package/interaction/Modify.js +486 -94
- package/interaction/tracing.d.ts +103 -0
- package/interaction/tracing.d.ts.map +1 -0
- package/interaction/tracing.js +409 -0
- package/package.json +1 -1
- package/util.js +1 -1
package/interaction/Draw.d.ts
CHANGED
|
@@ -165,10 +165,7 @@ export type Options = {
|
|
|
165
165
|
* Coordinate type when drawing points.
|
|
166
166
|
*/
|
|
167
167
|
export type PointCoordType = import("../coordinate.js").Coordinate;
|
|
168
|
-
|
|
169
|
-
* Coordinate type when drawing lines.
|
|
170
|
-
*/
|
|
171
|
-
export type LineCoordType = Array<import("../coordinate.js").Coordinate>;
|
|
168
|
+
export type LineCoordType = import("./tracing.js").LineCoordType;
|
|
172
169
|
/**
|
|
173
170
|
* Coordinate type when drawing polygons.
|
|
174
171
|
*/
|
|
@@ -177,44 +174,8 @@ export type PolyCoordType = Array<Array<import("../coordinate.js").Coordinate>>;
|
|
|
177
174
|
* Types used for drawing coordinates.
|
|
178
175
|
*/
|
|
179
176
|
export type SketchCoordType = PointCoordType | LineCoordType | PolyCoordType;
|
|
180
|
-
export type TraceState =
|
|
181
|
-
|
|
182
|
-
* Tracing active.
|
|
183
|
-
*/
|
|
184
|
-
active: boolean;
|
|
185
|
-
/**
|
|
186
|
-
* The initially clicked pixel location.
|
|
187
|
-
*/
|
|
188
|
-
startPx?: import("../pixel.js").Pixel | undefined;
|
|
189
|
-
/**
|
|
190
|
-
* Targets available for tracing.
|
|
191
|
-
*/
|
|
192
|
-
targets?: TraceTarget[] | undefined;
|
|
193
|
-
/**
|
|
194
|
-
* The index of the currently traced target. A value of -1 indicates
|
|
195
|
-
* that no trace target is active.
|
|
196
|
-
*/
|
|
197
|
-
targetIndex?: number | undefined;
|
|
198
|
-
};
|
|
199
|
-
export type TraceTarget = {
|
|
200
|
-
/**
|
|
201
|
-
* Target coordinates.
|
|
202
|
-
*/
|
|
203
|
-
coordinates: Array<import("../coordinate.js").Coordinate>;
|
|
204
|
-
/**
|
|
205
|
-
* The target coordinates are a linear ring.
|
|
206
|
-
*/
|
|
207
|
-
ring: boolean;
|
|
208
|
-
/**
|
|
209
|
-
* The index of first traced coordinate. A fractional index represents an
|
|
210
|
-
* edge intersection. Index values for rings will wrap (may be negative or larger than coordinates length).
|
|
211
|
-
*/
|
|
212
|
-
startIndex: number;
|
|
213
|
-
/**
|
|
214
|
-
* The index of last traced coordinate. Details from startIndex also apply here.
|
|
215
|
-
*/
|
|
216
|
-
endIndex: number;
|
|
217
|
-
};
|
|
177
|
+
export type TraceState = import("./tracing.js").TraceState;
|
|
178
|
+
export type TraceTarget = import("./tracing.js").TraceTarget;
|
|
218
179
|
/**
|
|
219
180
|
* Function that takes an array of coordinates and an optional existing geometry
|
|
220
181
|
* and a projection as arguments, and returns a geometry. The optional existing
|
|
@@ -227,26 +188,6 @@ export type GeometryFunction = (arg0: SketchCoordType, arg1: import("../geom/Sim
|
|
|
227
188
|
* cousins.
|
|
228
189
|
*/
|
|
229
190
|
export type Mode = "Point" | "LineString" | "Polygon" | "Circle";
|
|
230
|
-
export type TraceTargetUpdateInfo = {
|
|
231
|
-
/**
|
|
232
|
-
* The new target index.
|
|
233
|
-
*/
|
|
234
|
-
index: number;
|
|
235
|
-
/**
|
|
236
|
-
* The new segment end index.
|
|
237
|
-
*/
|
|
238
|
-
endIndex: number;
|
|
239
|
-
};
|
|
240
|
-
export type PointSegmentRelationship = {
|
|
241
|
-
/**
|
|
242
|
-
* The closest point expressed as a fraction along the segment length.
|
|
243
|
-
*/
|
|
244
|
-
along: number;
|
|
245
|
-
/**
|
|
246
|
-
* The squared distance of the point to the segment.
|
|
247
|
-
*/
|
|
248
|
-
squaredDistance: number;
|
|
249
|
-
};
|
|
250
191
|
/**
|
|
251
192
|
* *
|
|
252
193
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Draw.d.ts","sourceRoot":"","sources":["Draw.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Draw.d.ts","sourceRoot":"","sources":["Draw.js"],"names":[],"mappings":"AA0+CA;;;;;;;;;;;;GAYG;AACH,6CATW,MAAM,UAEN,MAAM,GAIL,gBAAgB,CAmC3B;AAED;;;;;;GAMG;AACH,6BAHY,gBAAgB,CAiC3B;AA54CD;;;;GAIG;AACH;IACE;;;OAGG;IACH,kBAHW,aAAa,WACb,OAAO,EAWjB;IANC;;;;OAIG;IACH,SAHU,OAAO,CAGK;CAEzB;;;;;;;UArJa,OAAO,qBAAqB,EAAE,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAoEnC,OAAO,kBAAkB,EAAE,UAAU;4BAIrC,OAAO,cAAc,EAAE,aAAa;;;;4BAKpC,KAAK,CAAC,KAAK,CAAC,OAAO,kBAAkB,EAAE,UAAU,CAAC,CAAC;;;;8BAKnD,cAAc,GAAC,aAAa,GAAC,aAAa;yBAGzC,OAAO,cAAc,EAAE,UAAU;0BAEjC,OAAO,cAAc,EAAE,WAAW;;;;;;;+BAOnC,CAAS,IAAgB,EAAf,eAAe,EAAE,IAA2C,EAA3C,OAAO,2BAA2B,EAAE,OAAO,EAClF,IAA6C,EAA7C,OAAa,uBAAuB,EAAE,OAAO,KAC7C,OAAa,2BAA2B,EAAE,OAAO;;;;;mBAIrC,OAAO,GAAG,YAAY,GAAG,SAAS,GAAG,QAAQ;;;;4BAoD7C,MAAM,IACN,OA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OAAO,CAgDlB;IAED;;;;OAIG;IACH,2BA2BC;IAED;;;;;;OAMG;IACH,kBA8CC;IAED;;;OAGG;IACH,mCAQC;IAED;;;OAGG;IACH,wCAmBC;IAED;;;;OAIG;IACH,sBAgCC;IAED;;;;OAIG;IACH,uBAwCC;IAED;;;;;OAKG;IACH,sBAuCC;IAED;;OAEG;IACH,qBAFW,MAAM,QA8ChB;IAED;;;;OAIG;IACH,wBAEC;IAED;;;;;;OAMG;IACH,iBAHY,OAAO,CAAC,OAAO,2BAA2B,EAAE,OAAO,CAAC,GAAC,IAAI,CAgDpE;IAED;;;;OAIG;IACH,sBASC;IAED;;;OAGG;IACH,qBAKC;IAED;;;;;;;;OAQG;IACH,+BAJY,aAAa,QAuCxB;IAED;;;;;;;;;;;OAWG;IACH,gBAHY,OAAO,CAAC,UAAU,CAAC,QAgB9B;IAED;;;OAGG;IACH,8BAcC;IAED;;OAEG;IACH,qBAOC;CACF;yBA17CwB,qBAAqB;+BAEf,cAAc;wBAJrB,oBAAoB;uBAPrB,uBAAuB"}
|
package/interaction/Draw.js
CHANGED
|
@@ -25,7 +25,6 @@ import {
|
|
|
25
25
|
} from '../extent.js';
|
|
26
26
|
import {FALSE, TRUE} from '../functions.js';
|
|
27
27
|
import Circle from '../geom/Circle.js';
|
|
28
|
-
import GeometryCollection from '../geom/GeometryCollection.js';
|
|
29
28
|
import LineString from '../geom/LineString.js';
|
|
30
29
|
import MultiLineString from '../geom/MultiLineString.js';
|
|
31
30
|
import MultiPoint from '../geom/MultiPoint.js';
|
|
@@ -34,12 +33,17 @@ import Point from '../geom/Point.js';
|
|
|
34
33
|
import Polygon, {fromCircle, makeRegular} from '../geom/Polygon.js';
|
|
35
34
|
import {getStrideForLayout} from '../geom/SimpleGeometry.js';
|
|
36
35
|
import VectorLayer from '../layer/Vector.js';
|
|
37
|
-
import {clamp, squaredDistance, toFixed} from '../math.js';
|
|
38
36
|
import {fromUserCoordinate, getUserProjection} from '../proj.js';
|
|
39
37
|
import VectorSource from '../source/Vector.js';
|
|
40
38
|
import {createEditingStyle} from '../style/Style.js';
|
|
41
39
|
import PointerInteraction from './Pointer.js';
|
|
42
40
|
import InteractionProperty from './Property.js';
|
|
41
|
+
import {
|
|
42
|
+
getCoordinate,
|
|
43
|
+
getTraceTargetUpdate,
|
|
44
|
+
getTraceTargets,
|
|
45
|
+
interpolateCoordinate,
|
|
46
|
+
} from './tracing.js';
|
|
43
47
|
|
|
44
48
|
/**
|
|
45
49
|
* @typedef {Object} Options
|
|
@@ -115,8 +119,7 @@ import InteractionProperty from './Property.js';
|
|
|
115
119
|
*/
|
|
116
120
|
|
|
117
121
|
/**
|
|
118
|
-
*
|
|
119
|
-
* @typedef {Array<import("../coordinate.js").Coordinate>} LineCoordType
|
|
122
|
+
* @typedef {import('./tracing.js').LineCoordType} LineCoordType
|
|
120
123
|
*/
|
|
121
124
|
|
|
122
125
|
/**
|
|
@@ -129,23 +132,9 @@ import InteractionProperty from './Property.js';
|
|
|
129
132
|
* @typedef {PointCoordType|LineCoordType|PolyCoordType} SketchCoordType
|
|
130
133
|
*/
|
|
131
134
|
|
|
132
|
-
/**
|
|
133
|
-
* @typedef {Object} TraceState
|
|
134
|
-
* @property {boolean} active Tracing active.
|
|
135
|
-
* @property {import("../pixel.js").Pixel} [startPx] The initially clicked pixel location.
|
|
136
|
-
* @property {Array<TraceTarget>} [targets] Targets available for tracing.
|
|
137
|
-
* @property {number} [targetIndex] The index of the currently traced target. A value of -1 indicates
|
|
138
|
-
* that no trace target is active.
|
|
139
|
-
*/
|
|
135
|
+
/** @typedef {import('./tracing.js').TraceState} TraceState */
|
|
140
136
|
|
|
141
|
-
/**
|
|
142
|
-
* @typedef {Object} TraceTarget
|
|
143
|
-
* @property {Array<import("../coordinate.js").Coordinate>} coordinates Target coordinates.
|
|
144
|
-
* @property {boolean} ring The target coordinates are a linear ring.
|
|
145
|
-
* @property {number} startIndex The index of first traced coordinate. A fractional index represents an
|
|
146
|
-
* edge intersection. Index values for rings will wrap (may be negative or larger than coordinates length).
|
|
147
|
-
* @property {number} endIndex The index of last traced coordinate. Details from startIndex also apply here.
|
|
148
|
-
*/
|
|
137
|
+
/** @typedef {import('./tracing.js').TraceTarget} TraceTarget */
|
|
149
138
|
|
|
150
139
|
/**
|
|
151
140
|
* Function that takes an array of coordinates and an optional existing geometry
|
|
@@ -209,371 +198,6 @@ export class DrawEvent extends Event {
|
|
|
209
198
|
}
|
|
210
199
|
}
|
|
211
200
|
|
|
212
|
-
/**
|
|
213
|
-
* @param {import("../coordinate.js").Coordinate} coordinate The coordinate.
|
|
214
|
-
* @param {Array<Feature>} features The candidate features.
|
|
215
|
-
* @return {Array<TraceTarget>} The trace targets.
|
|
216
|
-
*/
|
|
217
|
-
function getTraceTargets(coordinate, features) {
|
|
218
|
-
/**
|
|
219
|
-
* @type {Array<TraceTarget>}
|
|
220
|
-
*/
|
|
221
|
-
const targets = [];
|
|
222
|
-
|
|
223
|
-
for (let i = 0; i < features.length; ++i) {
|
|
224
|
-
const feature = features[i];
|
|
225
|
-
const geometry = feature.getGeometry();
|
|
226
|
-
appendGeometryTraceTargets(coordinate, geometry, targets);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return targets;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* @param {import("../coordinate.js").Coordinate} a One coordinate.
|
|
234
|
-
* @param {import("../coordinate.js").Coordinate} b Another coordinate.
|
|
235
|
-
* @return {number} The squared distance between the two coordinates.
|
|
236
|
-
*/
|
|
237
|
-
function getSquaredDistance(a, b) {
|
|
238
|
-
return squaredDistance(a[0], a[1], b[0], b[1]);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* @param {LineCoordType} coordinates The ring coordinates.
|
|
243
|
-
* @param {number} index The index. May be wrapped.
|
|
244
|
-
* @return {import("../coordinate.js").Coordinate} The coordinate.
|
|
245
|
-
*/
|
|
246
|
-
function getCoordinate(coordinates, index) {
|
|
247
|
-
const count = coordinates.length;
|
|
248
|
-
if (index < 0) {
|
|
249
|
-
return coordinates[index + count];
|
|
250
|
-
}
|
|
251
|
-
if (index >= count) {
|
|
252
|
-
return coordinates[index - count];
|
|
253
|
-
}
|
|
254
|
-
return coordinates[index];
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Get the cumulative squared distance along a ring path. The end index index may be "wrapped" and it may
|
|
259
|
-
* be less than the start index to indicate the direction of travel. The start and end index may have
|
|
260
|
-
* a fractional part to indicate a point between two coordinates.
|
|
261
|
-
* @param {LineCoordType} coordinates Ring coordinates.
|
|
262
|
-
* @param {number} startIndex The start index.
|
|
263
|
-
* @param {number} endIndex The end index.
|
|
264
|
-
* @return {number} The cumulative squared distance along the ring path.
|
|
265
|
-
*/
|
|
266
|
-
function getCumulativeSquaredDistance(coordinates, startIndex, endIndex) {
|
|
267
|
-
let lowIndex, highIndex;
|
|
268
|
-
if (startIndex < endIndex) {
|
|
269
|
-
lowIndex = startIndex;
|
|
270
|
-
highIndex = endIndex;
|
|
271
|
-
} else {
|
|
272
|
-
lowIndex = endIndex;
|
|
273
|
-
highIndex = startIndex;
|
|
274
|
-
}
|
|
275
|
-
const lowWholeIndex = Math.ceil(lowIndex);
|
|
276
|
-
const highWholeIndex = Math.floor(highIndex);
|
|
277
|
-
|
|
278
|
-
if (lowWholeIndex > highWholeIndex) {
|
|
279
|
-
// both start and end are on the same segment
|
|
280
|
-
const start = interpolateCoordinate(coordinates, lowIndex);
|
|
281
|
-
const end = interpolateCoordinate(coordinates, highIndex);
|
|
282
|
-
return getSquaredDistance(start, end);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
let sd = 0;
|
|
286
|
-
|
|
287
|
-
if (lowIndex < lowWholeIndex) {
|
|
288
|
-
const start = interpolateCoordinate(coordinates, lowIndex);
|
|
289
|
-
const end = getCoordinate(coordinates, lowWholeIndex);
|
|
290
|
-
sd += getSquaredDistance(start, end);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (highWholeIndex < highIndex) {
|
|
294
|
-
const start = getCoordinate(coordinates, highWholeIndex);
|
|
295
|
-
const end = interpolateCoordinate(coordinates, highIndex);
|
|
296
|
-
sd += getSquaredDistance(start, end);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
for (let i = lowWholeIndex; i < highWholeIndex - 1; ++i) {
|
|
300
|
-
const start = getCoordinate(coordinates, i);
|
|
301
|
-
const end = getCoordinate(coordinates, i + 1);
|
|
302
|
-
sd += getSquaredDistance(start, end);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
return sd;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* @param {import("../coordinate.js").Coordinate} coordinate The coordinate.
|
|
310
|
-
* @param {import("../geom/Geometry.js").default} geometry The candidate geometry.
|
|
311
|
-
* @param {Array<TraceTarget>} targets The trace targets.
|
|
312
|
-
*/
|
|
313
|
-
function appendGeometryTraceTargets(coordinate, geometry, targets) {
|
|
314
|
-
if (geometry instanceof LineString) {
|
|
315
|
-
appendTraceTarget(coordinate, geometry.getCoordinates(), false, targets);
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
if (geometry instanceof MultiLineString) {
|
|
319
|
-
const coordinates = geometry.getCoordinates();
|
|
320
|
-
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
|
|
321
|
-
appendTraceTarget(coordinate, coordinates[i], false, targets);
|
|
322
|
-
}
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
if (geometry instanceof Polygon) {
|
|
326
|
-
const coordinates = geometry.getCoordinates();
|
|
327
|
-
for (let i = 0, ii = coordinates.length; i < ii; ++i) {
|
|
328
|
-
appendTraceTarget(coordinate, coordinates[i], true, targets);
|
|
329
|
-
}
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
if (geometry instanceof MultiPolygon) {
|
|
333
|
-
const polys = geometry.getCoordinates();
|
|
334
|
-
for (let i = 0, ii = polys.length; i < ii; ++i) {
|
|
335
|
-
const coordinates = polys[i];
|
|
336
|
-
for (let j = 0, jj = coordinates.length; j < jj; ++j) {
|
|
337
|
-
appendTraceTarget(coordinate, coordinates[j], true, targets);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
if (geometry instanceof GeometryCollection) {
|
|
343
|
-
const geometries = geometry.getGeometries();
|
|
344
|
-
for (let i = 0; i < geometries.length; ++i) {
|
|
345
|
-
appendGeometryTraceTargets(coordinate, geometries[i], targets);
|
|
346
|
-
}
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
// other types cannot be traced
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* @typedef {Object} TraceTargetUpdateInfo
|
|
354
|
-
* @property {number} index The new target index.
|
|
355
|
-
* @property {number} endIndex The new segment end index.
|
|
356
|
-
*/
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* @type {TraceTargetUpdateInfo}
|
|
360
|
-
*/
|
|
361
|
-
const sharedUpdateInfo = {index: -1, endIndex: NaN};
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* @param {import("../coordinate.js").Coordinate} coordinate The coordinate.
|
|
365
|
-
* @param {TraceState} traceState The trace state.
|
|
366
|
-
* @param {import("../Map.js").default} map The map.
|
|
367
|
-
* @param {number} snapTolerance The snap tolerance.
|
|
368
|
-
* @return {TraceTargetUpdateInfo} Information about the new trace target. The returned
|
|
369
|
-
* object is reused between calls and must not be modified by the caller.
|
|
370
|
-
*/
|
|
371
|
-
function getTraceTargetUpdate(coordinate, traceState, map, snapTolerance) {
|
|
372
|
-
const x = coordinate[0];
|
|
373
|
-
const y = coordinate[1];
|
|
374
|
-
|
|
375
|
-
let closestTargetDistance = Infinity;
|
|
376
|
-
|
|
377
|
-
let newTargetIndex = -1;
|
|
378
|
-
let newEndIndex = NaN;
|
|
379
|
-
|
|
380
|
-
for (
|
|
381
|
-
let targetIndex = 0;
|
|
382
|
-
targetIndex < traceState.targets.length;
|
|
383
|
-
++targetIndex
|
|
384
|
-
) {
|
|
385
|
-
const target = traceState.targets[targetIndex];
|
|
386
|
-
const coordinates = target.coordinates;
|
|
387
|
-
|
|
388
|
-
let minSegmentDistance = Infinity;
|
|
389
|
-
let endIndex;
|
|
390
|
-
for (
|
|
391
|
-
let coordinateIndex = 0;
|
|
392
|
-
coordinateIndex < coordinates.length - 1;
|
|
393
|
-
++coordinateIndex
|
|
394
|
-
) {
|
|
395
|
-
const start = coordinates[coordinateIndex];
|
|
396
|
-
const end = coordinates[coordinateIndex + 1];
|
|
397
|
-
const rel = getPointSegmentRelationship(x, y, start, end);
|
|
398
|
-
if (rel.squaredDistance < minSegmentDistance) {
|
|
399
|
-
minSegmentDistance = rel.squaredDistance;
|
|
400
|
-
endIndex = coordinateIndex + rel.along;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
if (minSegmentDistance < closestTargetDistance) {
|
|
405
|
-
closestTargetDistance = minSegmentDistance;
|
|
406
|
-
if (target.ring && traceState.targetIndex === targetIndex) {
|
|
407
|
-
// same target, maintain the same trace direction
|
|
408
|
-
if (target.endIndex > target.startIndex) {
|
|
409
|
-
// forward trace
|
|
410
|
-
if (endIndex < target.startIndex) {
|
|
411
|
-
endIndex += coordinates.length;
|
|
412
|
-
}
|
|
413
|
-
} else if (target.endIndex < target.startIndex) {
|
|
414
|
-
// reverse trace
|
|
415
|
-
if (endIndex > target.startIndex) {
|
|
416
|
-
endIndex -= coordinates.length;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
newEndIndex = endIndex;
|
|
421
|
-
newTargetIndex = targetIndex;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
const newTarget = traceState.targets[newTargetIndex];
|
|
426
|
-
let considerBothDirections = newTarget.ring;
|
|
427
|
-
if (traceState.targetIndex === newTargetIndex && considerBothDirections) {
|
|
428
|
-
// only consider switching trace direction if close to the start
|
|
429
|
-
const newCoordinate = interpolateCoordinate(
|
|
430
|
-
newTarget.coordinates,
|
|
431
|
-
newEndIndex,
|
|
432
|
-
);
|
|
433
|
-
const pixel = map.getPixelFromCoordinate(newCoordinate);
|
|
434
|
-
if (distance(pixel, traceState.startPx) > snapTolerance) {
|
|
435
|
-
considerBothDirections = false;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
if (considerBothDirections) {
|
|
440
|
-
const coordinates = newTarget.coordinates;
|
|
441
|
-
const count = coordinates.length;
|
|
442
|
-
const startIndex = newTarget.startIndex;
|
|
443
|
-
const endIndex = newEndIndex;
|
|
444
|
-
if (startIndex < endIndex) {
|
|
445
|
-
const forwardDistance = getCumulativeSquaredDistance(
|
|
446
|
-
coordinates,
|
|
447
|
-
startIndex,
|
|
448
|
-
endIndex,
|
|
449
|
-
);
|
|
450
|
-
const reverseDistance = getCumulativeSquaredDistance(
|
|
451
|
-
coordinates,
|
|
452
|
-
startIndex,
|
|
453
|
-
endIndex - count,
|
|
454
|
-
);
|
|
455
|
-
if (reverseDistance < forwardDistance) {
|
|
456
|
-
newEndIndex -= count;
|
|
457
|
-
}
|
|
458
|
-
} else {
|
|
459
|
-
const reverseDistance = getCumulativeSquaredDistance(
|
|
460
|
-
coordinates,
|
|
461
|
-
startIndex,
|
|
462
|
-
endIndex,
|
|
463
|
-
);
|
|
464
|
-
const forwardDistance = getCumulativeSquaredDistance(
|
|
465
|
-
coordinates,
|
|
466
|
-
startIndex,
|
|
467
|
-
endIndex + count,
|
|
468
|
-
);
|
|
469
|
-
if (forwardDistance < reverseDistance) {
|
|
470
|
-
newEndIndex += count;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
sharedUpdateInfo.index = newTargetIndex;
|
|
476
|
-
sharedUpdateInfo.endIndex = newEndIndex;
|
|
477
|
-
return sharedUpdateInfo;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* @param {import("../coordinate.js").Coordinate} coordinate The clicked coordinate.
|
|
482
|
-
* @param {Array<import("../coordinate.js").Coordinate>} coordinates The geometry component coordinates.
|
|
483
|
-
* @param {boolean} ring The coordinates represent a linear ring.
|
|
484
|
-
* @param {Array<TraceTarget>} targets The trace targets.
|
|
485
|
-
*/
|
|
486
|
-
function appendTraceTarget(coordinate, coordinates, ring, targets) {
|
|
487
|
-
const x = coordinate[0];
|
|
488
|
-
const y = coordinate[1];
|
|
489
|
-
for (let i = 0, ii = coordinates.length - 1; i < ii; ++i) {
|
|
490
|
-
const start = coordinates[i];
|
|
491
|
-
const end = coordinates[i + 1];
|
|
492
|
-
const rel = getPointSegmentRelationship(x, y, start, end);
|
|
493
|
-
if (rel.squaredDistance === 0) {
|
|
494
|
-
const index = i + rel.along;
|
|
495
|
-
targets.push({
|
|
496
|
-
coordinates: coordinates,
|
|
497
|
-
ring: ring,
|
|
498
|
-
startIndex: index,
|
|
499
|
-
endIndex: index,
|
|
500
|
-
});
|
|
501
|
-
return;
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* @typedef {Object} PointSegmentRelationship
|
|
508
|
-
* @property {number} along The closest point expressed as a fraction along the segment length.
|
|
509
|
-
* @property {number} squaredDistance The squared distance of the point to the segment.
|
|
510
|
-
*/
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* @type {PointSegmentRelationship}
|
|
514
|
-
*/
|
|
515
|
-
const sharedRel = {along: 0, squaredDistance: 0};
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* @param {number} x The point x.
|
|
519
|
-
* @param {number} y The point y.
|
|
520
|
-
* @param {import("../coordinate.js").Coordinate} start The segment start.
|
|
521
|
-
* @param {import("../coordinate.js").Coordinate} end The segment end.
|
|
522
|
-
* @return {PointSegmentRelationship} The point segment relationship. The returned object is
|
|
523
|
-
* shared between calls and must not be modified by the caller.
|
|
524
|
-
*/
|
|
525
|
-
function getPointSegmentRelationship(x, y, start, end) {
|
|
526
|
-
const x1 = start[0];
|
|
527
|
-
const y1 = start[1];
|
|
528
|
-
const x2 = end[0];
|
|
529
|
-
const y2 = end[1];
|
|
530
|
-
const dx = x2 - x1;
|
|
531
|
-
const dy = y2 - y1;
|
|
532
|
-
let along = 0;
|
|
533
|
-
let px = x1;
|
|
534
|
-
let py = y1;
|
|
535
|
-
if (dx !== 0 || dy !== 0) {
|
|
536
|
-
along = clamp(((x - x1) * dx + (y - y1) * dy) / (dx * dx + dy * dy), 0, 1);
|
|
537
|
-
px += dx * along;
|
|
538
|
-
py += dy * along;
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
sharedRel.along = along;
|
|
542
|
-
sharedRel.squaredDistance = toFixed(squaredDistance(x, y, px, py), 10);
|
|
543
|
-
return sharedRel;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* @param {LineCoordType} coordinates The coordinates.
|
|
548
|
-
* @param {number} index The index. May be fractional and may wrap.
|
|
549
|
-
* @return {import("../coordinate.js").Coordinate} The interpolated coordinate.
|
|
550
|
-
*/
|
|
551
|
-
function interpolateCoordinate(coordinates, index) {
|
|
552
|
-
const count = coordinates.length;
|
|
553
|
-
|
|
554
|
-
let startIndex = Math.floor(index);
|
|
555
|
-
const along = index - startIndex;
|
|
556
|
-
if (startIndex >= count) {
|
|
557
|
-
startIndex -= count;
|
|
558
|
-
} else if (startIndex < 0) {
|
|
559
|
-
startIndex += count;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
let endIndex = startIndex + 1;
|
|
563
|
-
if (endIndex >= count) {
|
|
564
|
-
endIndex -= count;
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
const start = coordinates[startIndex];
|
|
568
|
-
const x0 = start[0];
|
|
569
|
-
const y0 = start[1];
|
|
570
|
-
const end = coordinates[endIndex];
|
|
571
|
-
const dx = end[0] - x0;
|
|
572
|
-
const dy = end[1] - y0;
|
|
573
|
-
|
|
574
|
-
return [x0 + dx * along, y0 + dy * along];
|
|
575
|
-
}
|
|
576
|
-
|
|
577
201
|
/***
|
|
578
202
|
* @template Return
|
|
579
203
|
* @typedef {import("../Observable").OnSignature<import("../Observable").EventTypes, import("../events/Event.js").default, Return> &
|
|
@@ -1136,7 +760,7 @@ class Draw extends PointerInteraction {
|
|
|
1136
760
|
if (targets.length) {
|
|
1137
761
|
this.traceState_ = {
|
|
1138
762
|
active: true,
|
|
1139
|
-
|
|
763
|
+
startCoord: event.coordinate.slice(),
|
|
1140
764
|
targets: targets,
|
|
1141
765
|
targetIndex: -1,
|
|
1142
766
|
};
|
|
@@ -1261,7 +885,8 @@ class Draw extends PointerInteraction {
|
|
|
1261
885
|
|
|
1262
886
|
if (traceState.targetIndex === -1) {
|
|
1263
887
|
// check if we are ready to pick a target
|
|
1264
|
-
|
|
888
|
+
const startPx = event.map.getPixelFromCoordinate(traceState.startCoord);
|
|
889
|
+
if (distance(startPx, event.pixel) < this.snapTolerance_) {
|
|
1265
890
|
return;
|
|
1266
891
|
}
|
|
1267
892
|
}
|