ol 10.6.2-dev.1752510546973 → 10.6.2-dev.1752570595686
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/Extent.d.ts +32 -2
- package/interaction/Extent.d.ts.map +1 -1
- package/interaction/Extent.js +91 -14
- package/package.json +1 -1
- package/util.js +1 -1
package/interaction/Extent.d.ts
CHANGED
|
@@ -24,6 +24,17 @@ export type Options = {
|
|
|
24
24
|
* Default is {@link module :ol/events/condition.always}.
|
|
25
25
|
*/
|
|
26
26
|
condition?: import("../events/condition.js").Condition | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* A function that
|
|
29
|
+
* takes a {@link module :ol/MapBrowserEvent~MapBrowserEvent} and returns a
|
|
30
|
+
* boolean to indicate whether that event should be handled to create a new extent.
|
|
31
|
+
* If `null`, the `condition` will also be used as `createCondition`.
|
|
32
|
+
*/
|
|
33
|
+
createCondition?: import("../events/condition.js").Condition | null | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* An extent can be dragged.
|
|
36
|
+
*/
|
|
37
|
+
drag?: boolean | undefined;
|
|
27
38
|
/**
|
|
28
39
|
* Initial extent. Defaults to no
|
|
29
40
|
* initial extent.
|
|
@@ -72,7 +83,8 @@ import Event from '../events/Event.js';
|
|
|
72
83
|
* @classdesc
|
|
73
84
|
* Allows the user to draw a vector box by clicking and dragging on the map.
|
|
74
85
|
* Once drawn, the vector box can be modified by dragging its vertices or edges.
|
|
75
|
-
*
|
|
86
|
+
* The interaction can also be configured with an initial extent and a `createCondition`
|
|
87
|
+
* to prevent the creation of a new extent on `pointerdown`, if desired.
|
|
76
88
|
*
|
|
77
89
|
* @fires ExtentEvent
|
|
78
90
|
* @api
|
|
@@ -100,6 +112,16 @@ declare class Extent extends PointerInteraction {
|
|
|
100
112
|
* @private
|
|
101
113
|
*/
|
|
102
114
|
private condition_;
|
|
115
|
+
/**
|
|
116
|
+
* @type {import("../events/condition.js").Condition}
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
private createCondition_;
|
|
120
|
+
/**
|
|
121
|
+
* @type {boolean}
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
private drag_;
|
|
103
125
|
/**
|
|
104
126
|
* Extent of the drawn box
|
|
105
127
|
* @type {import("../extent.js").Extent}
|
|
@@ -157,6 +179,7 @@ declare class Extent extends PointerInteraction {
|
|
|
157
179
|
private snapToVertex_;
|
|
158
180
|
/**
|
|
159
181
|
* @param {import("../MapBrowserEvent.js").default} mapBrowserEvent pointer move event
|
|
182
|
+
* @return {boolean} The event was handled.
|
|
160
183
|
* @private
|
|
161
184
|
*/
|
|
162
185
|
private handlePointerMove_;
|
|
@@ -168,10 +191,16 @@ declare class Extent extends PointerInteraction {
|
|
|
168
191
|
private createOrUpdateExtentFeature_;
|
|
169
192
|
/**
|
|
170
193
|
* @param {import("../coordinate.js").Coordinate} vertex location of feature
|
|
194
|
+
* @param {boolean} [createIfNotExists] create the feature if it does not exist
|
|
171
195
|
* @return {Feature} vertex as feature
|
|
172
196
|
* @private
|
|
173
197
|
*/
|
|
174
|
-
private
|
|
198
|
+
private updatePointerFeature_;
|
|
199
|
+
/**
|
|
200
|
+
* Remove the vertex feature if it exists.
|
|
201
|
+
* @private
|
|
202
|
+
*/
|
|
203
|
+
private noVertexFeature_;
|
|
175
204
|
/**
|
|
176
205
|
* Remove the interaction from its current map and attach it to the new map.
|
|
177
206
|
* Subclasses may set up event handlers to get notified about changes to
|
|
@@ -192,6 +221,7 @@ declare class Extent extends PointerInteraction {
|
|
|
192
221
|
*
|
|
193
222
|
* @return {import("../extent.js").Extent} Drawn extent in the view projection.
|
|
194
223
|
* @api
|
|
224
|
+
* @deprecated Use {@link module:ol/interaction/Extent~Extent#getExtent} instead.
|
|
195
225
|
*/
|
|
196
226
|
getExtentInternal(): import("../extent.js").Extent;
|
|
197
227
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Extent.d.ts","sourceRoot":"","sources":["Extent.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Extent.d.ts","sourceRoot":"","sources":["Extent.js"],"names":[],"mappings":"AA2DA;;;;GAIG;AACH;IACE;;OAEG;IACH,oBAFW,OAAO,cAAc,EAAE,MAAM,EAWvC;IANC;;;;OAIG;IACH,QAHU,OAAO,cAAc,EAAE,MAAM,CAGnB;CAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAGY,CAAU,IAAqC,EAArC,OAAO,kBAAkB,EAAE,UAAU,KAAG,OAAO,cAAc,EAAE,MAAM;;;;8BAI/E,MAAM,IACN,OAAO,eAAe,EAAE,WAAW,CAAC,OAAO,eAAe,EAAE,UAAU,EAAE,OAAO,oBAAoB,EAAE,OAAO,EAAE,MAAM,CAAC,GACjI,OAAW,eAAe,EAAE,WAAW,CAAC,OAAO,oBAAoB,EAAE,KAAK,GAC1E,eAAqB,EAAE,OAAO,WAAW,EAAE,WAAW,EAAE,MAAM,CAAC,GAC/D,OAAW,eAAe,EAAE,WAAW,CAAC,eAAe,EAAE,WAAW,EAAE,MAAM,CAAC,GAC7E,OAAW,eAAe,EAAE,mBAAmB,CAAC,OAAO,eAAe,EAAE,UAAU,GAAC,OAAO,oBAAoB,EAAE,KAAK,GACrH,eAAqB,GAAC,eAAe,EAAE,MAAM,CAAC;kBAhF7B,oBAAoB;AAqEtC;;GAEG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;;;GASG;AACH;IACE;;OAEG;IACH,sBAFW,OAAO,EA6HjB;IAtHC;;OAEG;IACH,IAFU,iBAAiB,CAAC,OAAO,WAAW,EAAE,SAAS,CAAC,CAEnD;IAEP;;OAEG;IACH,MAFU,iBAAiB,CAAC,OAAO,WAAW,EAAE,SAAS,CAAC,CAEjD;IAET;;OAEG;IACH,IAFU,iBAAiB,CAAC,IAAI,CAAC,CAE1B;IAEP;;;;OAIG;IACH,mBAAgE;IAEhE;;;OAGG;IACH,yBAAkE;IAElE;;;OAGG;IACH,cAAkC;IAElC;;;;OAIG;IACH,gBAAmB;IAEnB;;;;OAIG;IACH,wBAA2B;IAE3B;;;;OAIG;IACH,wBACoE;IAEpE;;;;OAIG;IACH,yBAA6B;IAE7B;;;;OAIG;IACH,uBAA0B;IAE1B;;;;OAIG;IACH,uBAA0B;IAM1B;;;;OAIG;IACH,uBAUE;IAEF;;;;OAIG;IACH,uBAUE;IAOJ;;;;;OAKG;IACH,sBAmCC;IAED;;;;OAIG;IACH,2BAsBC;IAED;;;;OAIG;IACH,qCAmBC;IAED;;;;;OAKG;IACH,8BAYC;IAED;;;OAGG;IACH,yBAKC;IAgID;;;;;;OAMG;IACH,qBAHW,OAAO,WAAW,EAAE,OAAO,QAOrC;IAED;;;;;OAKG;IACH,aAHY,OAAO,cAAc,EAAE,MAAM,CAQxC;IAED;;;;;;OAMG;IACH,qBAJY,OAAO,cAAc,EAAE,MAAM,CAMxC;IAED;;;;;OAKG;IACH,kBAHW,OAAO,cAAc,EAAE,MAAM,QAQvC;CACF;+BArgB8B,cAAc"}
|
package/interaction/Extent.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from '../coordinate.js';
|
|
12
12
|
import Event from '../events/Event.js';
|
|
13
13
|
import {always} from '../events/condition.js';
|
|
14
|
-
import {boundingExtent, getArea} from '../extent.js';
|
|
14
|
+
import {boundingExtent, containsCoordinate, getArea} from '../extent.js';
|
|
15
15
|
import Point from '../geom/Point.js';
|
|
16
16
|
import {fromExtent as polygonFromExtent} from '../geom/Polygon.js';
|
|
17
17
|
import VectorLayer from '../layer/Vector.js';
|
|
@@ -26,6 +26,11 @@ import PointerInteraction from './Pointer.js';
|
|
|
26
26
|
* takes a {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
|
|
27
27
|
* boolean to indicate whether that event should be handled.
|
|
28
28
|
* Default is {@link module:ol/events/condition.always}.
|
|
29
|
+
* @property {import("../events/condition.js").Condition|null} [createCondition=null] A function that
|
|
30
|
+
* takes a {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
|
|
31
|
+
* boolean to indicate whether that event should be handled to create a new extent.
|
|
32
|
+
* If `null`, the `condition` will also be used as `createCondition`.
|
|
33
|
+
* @property {boolean} [drag=false] An extent can be dragged.
|
|
29
34
|
* @property {import("../extent.js").Extent} [extent] Initial extent. Defaults to no
|
|
30
35
|
* initial extent.
|
|
31
36
|
* @property {import("../style/Style.js").StyleLike} [boxStyle]
|
|
@@ -91,7 +96,8 @@ export class ExtentEvent extends Event {
|
|
|
91
96
|
* @classdesc
|
|
92
97
|
* Allows the user to draw a vector box by clicking and dragging on the map.
|
|
93
98
|
* Once drawn, the vector box can be modified by dragging its vertices or edges.
|
|
94
|
-
*
|
|
99
|
+
* The interaction can also be configured with an initial extent and a `createCondition`
|
|
100
|
+
* to prevent the creation of a new extent on `pointerdown`, if desired.
|
|
95
101
|
*
|
|
96
102
|
* @fires ExtentEvent
|
|
97
103
|
* @api
|
|
@@ -127,6 +133,18 @@ class Extent extends PointerInteraction {
|
|
|
127
133
|
*/
|
|
128
134
|
this.condition_ = options.condition ? options.condition : always;
|
|
129
135
|
|
|
136
|
+
/**
|
|
137
|
+
* @type {import("../events/condition.js").Condition}
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
140
|
+
this.createCondition_ = options.createCondition || this.condition_;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @type {boolean}
|
|
144
|
+
* @private
|
|
145
|
+
*/
|
|
146
|
+
this.drag_ = options.drag || false;
|
|
147
|
+
|
|
130
148
|
/**
|
|
131
149
|
* Extent of the drawn box
|
|
132
150
|
* @type {import("../extent.js").Extent}
|
|
@@ -258,17 +276,31 @@ class Extent extends PointerInteraction {
|
|
|
258
276
|
|
|
259
277
|
/**
|
|
260
278
|
* @param {import("../MapBrowserEvent.js").default} mapBrowserEvent pointer move event
|
|
279
|
+
* @return {boolean} The event was handled.
|
|
261
280
|
* @private
|
|
262
281
|
*/
|
|
263
282
|
handlePointerMove_(mapBrowserEvent) {
|
|
264
283
|
const pixel = mapBrowserEvent.pixel;
|
|
265
284
|
const map = mapBrowserEvent.map;
|
|
285
|
+
const draggable =
|
|
286
|
+
this.drag_ &&
|
|
287
|
+
containsCoordinate(this.extent_, mapBrowserEvent.coordinate);
|
|
266
288
|
|
|
267
289
|
let vertex = this.snapToVertex_(pixel, map);
|
|
268
|
-
if (!vertex) {
|
|
290
|
+
if (!vertex && this.createCondition_(mapBrowserEvent) && !draggable) {
|
|
269
291
|
vertex = map.getCoordinateFromPixelInternal(pixel);
|
|
270
292
|
}
|
|
271
|
-
|
|
293
|
+
if (draggable && !vertex) {
|
|
294
|
+
this.getMap().getViewport().classList.add('ol-grab');
|
|
295
|
+
} else {
|
|
296
|
+
this.getMap().getViewport().classList.remove('ol-grab');
|
|
297
|
+
}
|
|
298
|
+
if (vertex) {
|
|
299
|
+
this.updatePointerFeature_(vertex);
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
this.noVertexFeature_();
|
|
303
|
+
return false;
|
|
272
304
|
}
|
|
273
305
|
|
|
274
306
|
/**
|
|
@@ -299,22 +331,35 @@ class Extent extends PointerInteraction {
|
|
|
299
331
|
|
|
300
332
|
/**
|
|
301
333
|
* @param {import("../coordinate.js").Coordinate} vertex location of feature
|
|
334
|
+
* @param {boolean} [createIfNotExists] create the feature if it does not exist
|
|
302
335
|
* @return {Feature} vertex as feature
|
|
303
336
|
* @private
|
|
304
337
|
*/
|
|
305
|
-
|
|
338
|
+
updatePointerFeature_(vertex, createIfNotExists = true) {
|
|
306
339
|
let vertexFeature = this.vertexFeature_;
|
|
307
|
-
if (!vertexFeature) {
|
|
340
|
+
if (createIfNotExists && !vertexFeature) {
|
|
308
341
|
vertexFeature = new Feature(new Point(vertex));
|
|
309
342
|
this.vertexFeature_ = vertexFeature;
|
|
310
343
|
this.vertexOverlay_.getSource().addFeature(vertexFeature);
|
|
311
|
-
}
|
|
344
|
+
}
|
|
345
|
+
if (vertexFeature) {
|
|
312
346
|
const geometry = vertexFeature.getGeometry();
|
|
313
347
|
geometry.setCoordinates(vertex);
|
|
314
348
|
}
|
|
315
349
|
return vertexFeature;
|
|
316
350
|
}
|
|
317
351
|
|
|
352
|
+
/**
|
|
353
|
+
* Remove the vertex feature if it exists.
|
|
354
|
+
* @private
|
|
355
|
+
*/
|
|
356
|
+
noVertexFeature_() {
|
|
357
|
+
if (this.vertexFeature_) {
|
|
358
|
+
this.vertexOverlay_.getSource().removeFeature(this.vertexFeature_);
|
|
359
|
+
this.vertexFeature_ = null;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
318
363
|
/**
|
|
319
364
|
* @param {import("../MapBrowserEvent.js").default} mapBrowserEvent Map browser event.
|
|
320
365
|
* @return {boolean} `false` to stop event propagation.
|
|
@@ -322,19 +367,23 @@ class Extent extends PointerInteraction {
|
|
|
322
367
|
*/
|
|
323
368
|
handleEvent(mapBrowserEvent) {
|
|
324
369
|
if (!mapBrowserEvent.originalEvent || !this.condition_(mapBrowserEvent)) {
|
|
370
|
+
this.noVertexFeature_();
|
|
325
371
|
return true;
|
|
326
372
|
}
|
|
373
|
+
|
|
374
|
+
let handled = this.handlingDownUpSequence;
|
|
375
|
+
|
|
327
376
|
//display pointer (if not dragging)
|
|
328
377
|
if (
|
|
329
378
|
mapBrowserEvent.type == MapBrowserEventType.POINTERMOVE &&
|
|
330
379
|
!this.handlingDownUpSequence
|
|
331
380
|
) {
|
|
332
|
-
this.handlePointerMove_(mapBrowserEvent);
|
|
381
|
+
handled = this.handlePointerMove_(mapBrowserEvent);
|
|
333
382
|
}
|
|
334
383
|
//call pointer to determine up/down/drag
|
|
335
384
|
super.handleEvent(mapBrowserEvent);
|
|
336
385
|
//return false to stop propagation
|
|
337
|
-
return
|
|
386
|
+
return !handled;
|
|
338
387
|
}
|
|
339
388
|
|
|
340
389
|
/**
|
|
@@ -390,13 +439,22 @@ class Extent extends PointerInteraction {
|
|
|
390
439
|
getOpposingPoint([extent[2], y]),
|
|
391
440
|
);
|
|
392
441
|
}
|
|
393
|
-
//no snap - new bbox
|
|
442
|
+
//no snap - new bbox or dragging existing bbox
|
|
394
443
|
} else {
|
|
395
444
|
vertex = map.getCoordinateFromPixelInternal(pixel);
|
|
396
|
-
|
|
397
|
-
this.
|
|
445
|
+
let drag = false;
|
|
446
|
+
if (this.drag_) {
|
|
447
|
+
if (containsCoordinate(extent, vertex)) {
|
|
448
|
+
this.pointerHandler_ = getDragHandler(extent, vertex);
|
|
449
|
+
drag = true;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (!drag && this.createCondition_(mapBrowserEvent)) {
|
|
453
|
+
this.setExtent([vertex[0], vertex[1], vertex[0], vertex[1]]);
|
|
454
|
+
this.pointerHandler_ = getPointHandler(vertex);
|
|
455
|
+
}
|
|
398
456
|
}
|
|
399
|
-
return
|
|
457
|
+
return !!this.pointerHandler_; //event handled; start downup sequence
|
|
400
458
|
}
|
|
401
459
|
|
|
402
460
|
/**
|
|
@@ -408,7 +466,7 @@ class Extent extends PointerInteraction {
|
|
|
408
466
|
if (this.pointerHandler_) {
|
|
409
467
|
const pixelCoordinate = mapBrowserEvent.coordinate;
|
|
410
468
|
this.setExtent(this.pointerHandler_(pixelCoordinate));
|
|
411
|
-
this.
|
|
469
|
+
this.updatePointerFeature_(pixelCoordinate, false);
|
|
412
470
|
}
|
|
413
471
|
}
|
|
414
472
|
|
|
@@ -459,6 +517,7 @@ class Extent extends PointerInteraction {
|
|
|
459
517
|
*
|
|
460
518
|
* @return {import("../extent.js").Extent} Drawn extent in the view projection.
|
|
461
519
|
* @api
|
|
520
|
+
* @deprecated Use {@link module:ol/interaction/Extent~Extent#getExtent} instead.
|
|
462
521
|
*/
|
|
463
522
|
getExtentInternal() {
|
|
464
523
|
return this.extent_;
|
|
@@ -531,6 +590,24 @@ function getEdgeHandler(fixedP1, fixedP2) {
|
|
|
531
590
|
return null;
|
|
532
591
|
}
|
|
533
592
|
|
|
593
|
+
/**
|
|
594
|
+
* @param {import("../extent.js").Extent} extent The extent that will be dragged
|
|
595
|
+
* @param {import("../coordinate.js").Coordinate} vertex The vertex that drag delta is calculated from
|
|
596
|
+
* @return {PointerHandler|null} event handler
|
|
597
|
+
*/
|
|
598
|
+
function getDragHandler(extent, vertex) {
|
|
599
|
+
return function (point) {
|
|
600
|
+
const deltaX = point[0] - vertex[0];
|
|
601
|
+
const deltaY = point[1] - vertex[1];
|
|
602
|
+
return [
|
|
603
|
+
extent[0] + deltaX,
|
|
604
|
+
extent[1] + deltaY,
|
|
605
|
+
extent[2] + deltaX,
|
|
606
|
+
extent[3] + deltaY,
|
|
607
|
+
];
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
|
|
534
611
|
/**
|
|
535
612
|
* @param {import("../extent.js").Extent} extent extent
|
|
536
613
|
* @return {Array<Array<import("../coordinate.js").Coordinate>>} extent line segments
|
package/package.json
CHANGED
package/util.js
CHANGED