@deck.gl-community/editable-layers 9.2.0-beta.5 → 9.2.0-beta.8
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/edit-modes/draw-90degree-polygon-mode.d.ts +2 -2
- package/dist/edit-modes/draw-90degree-polygon-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-90degree-polygon-mode.js.map +1 -1
- package/dist/edit-modes/draw-circle-by-diameter-mode.d.ts +2 -2
- package/dist/edit-modes/draw-circle-by-diameter-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-circle-by-diameter-mode.js +0 -1
- package/dist/edit-modes/draw-circle-by-diameter-mode.js.map +1 -1
- package/dist/edit-modes/draw-circle-from-center-mode.d.ts +2 -2
- package/dist/edit-modes/draw-circle-from-center-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-circle-from-center-mode.js +0 -1
- package/dist/edit-modes/draw-circle-from-center-mode.js.map +1 -1
- package/dist/edit-modes/draw-ellipse-by-bounding-box-mode.d.ts +2 -2
- package/dist/edit-modes/draw-ellipse-by-bounding-box-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-ellipse-by-bounding-box-mode.js +1 -2
- package/dist/edit-modes/draw-ellipse-by-bounding-box-mode.js.map +1 -1
- package/dist/edit-modes/draw-ellipse-using-three-points-mode.d.ts +2 -2
- package/dist/edit-modes/draw-ellipse-using-three-points-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-ellipse-using-three-points-mode.js +0 -2
- package/dist/edit-modes/draw-ellipse-using-three-points-mode.js.map +1 -1
- package/dist/edit-modes/draw-line-string-mode.d.ts +5 -5
- package/dist/edit-modes/draw-line-string-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-line-string-mode.js.map +1 -1
- package/dist/edit-modes/draw-point-mode.d.ts +2 -2
- package/dist/edit-modes/draw-point-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-point-mode.js.map +1 -1
- package/dist/edit-modes/draw-polygon-by-dragging-mode.d.ts +8 -8
- package/dist/edit-modes/draw-polygon-by-dragging-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-polygon-by-dragging-mode.js.map +1 -1
- package/dist/edit-modes/draw-polygon-mode.d.ts +9 -5
- package/dist/edit-modes/draw-polygon-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-polygon-mode.js +226 -81
- package/dist/edit-modes/draw-polygon-mode.js.map +1 -1
- package/dist/edit-modes/draw-rectangle-from-center-mode.d.ts +2 -2
- package/dist/edit-modes/draw-rectangle-from-center-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-rectangle-from-center-mode.js +0 -1
- package/dist/edit-modes/draw-rectangle-from-center-mode.js.map +1 -1
- package/dist/edit-modes/draw-rectangle-mode.d.ts +2 -2
- package/dist/edit-modes/draw-rectangle-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-rectangle-mode.js +0 -1
- package/dist/edit-modes/draw-rectangle-mode.js.map +1 -1
- package/dist/edit-modes/draw-rectangle-using-three-points-mode.d.ts +2 -2
- package/dist/edit-modes/draw-rectangle-using-three-points-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-square-from-center-mode.d.ts +2 -2
- package/dist/edit-modes/draw-square-from-center-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-square-from-center-mode.js +0 -1
- package/dist/edit-modes/draw-square-from-center-mode.js.map +1 -1
- package/dist/edit-modes/draw-square-mode.d.ts +2 -2
- package/dist/edit-modes/draw-square-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-square-mode.js +0 -1
- package/dist/edit-modes/draw-square-mode.js.map +1 -1
- package/dist/edit-modes/duplicate-mode.d.ts +2 -2
- package/dist/edit-modes/duplicate-mode.d.ts.map +1 -1
- package/dist/edit-modes/duplicate-mode.js.map +1 -1
- package/dist/edit-modes/extend-line-string-mode.d.ts +4 -4
- package/dist/edit-modes/extend-line-string-mode.d.ts.map +1 -1
- package/dist/edit-modes/extend-line-string-mode.js.map +1 -1
- package/dist/edit-modes/extrude-mode.d.ts +7 -7
- package/dist/edit-modes/extrude-mode.d.ts.map +1 -1
- package/dist/edit-modes/extrude-mode.js.map +1 -1
- package/dist/edit-modes/geojson-edit-mode.d.ts +9 -9
- package/dist/edit-modes/geojson-edit-mode.d.ts.map +1 -1
- package/dist/edit-modes/geojson-edit-mode.js +4 -7
- package/dist/edit-modes/geojson-edit-mode.js.map +1 -1
- package/dist/edit-modes/immutable-feature-collection.d.ts +7 -7
- package/dist/edit-modes/immutable-feature-collection.d.ts.map +1 -1
- package/dist/edit-modes/immutable-feature-collection.js.map +1 -1
- package/dist/edit-modes/measure-area-mode.d.ts +3 -3
- package/dist/edit-modes/measure-area-mode.d.ts.map +1 -1
- package/dist/edit-modes/measure-area-mode.js.map +1 -1
- package/dist/edit-modes/modify-mode.d.ts +8 -8
- package/dist/edit-modes/modify-mode.d.ts.map +1 -1
- package/dist/edit-modes/modify-mode.js +2 -4
- package/dist/edit-modes/modify-mode.js.map +1 -1
- package/dist/edit-modes/resize-circle-mode.d.ts +3 -3
- package/dist/edit-modes/resize-circle-mode.d.ts.map +1 -1
- package/dist/edit-modes/resize-circle-mode.js +1 -5
- package/dist/edit-modes/resize-circle-mode.js.map +1 -1
- package/dist/edit-modes/rotate-mode.d.ts +7 -7
- package/dist/edit-modes/rotate-mode.d.ts.map +1 -1
- package/dist/edit-modes/rotate-mode.js +2 -9
- package/dist/edit-modes/rotate-mode.js.map +1 -1
- package/dist/edit-modes/scale-mode.d.ts +11 -11
- package/dist/edit-modes/scale-mode.d.ts.map +1 -1
- package/dist/edit-modes/scale-mode.js +1 -6
- package/dist/edit-modes/scale-mode.js.map +1 -1
- package/dist/edit-modes/snappable-mode.d.ts +5 -5
- package/dist/edit-modes/snappable-mode.d.ts.map +1 -1
- package/dist/edit-modes/snappable-mode.js.map +1 -1
- package/dist/edit-modes/split-polygon-mode.d.ts +5 -5
- package/dist/edit-modes/split-polygon-mode.d.ts.map +1 -1
- package/dist/edit-modes/split-polygon-mode.js +2 -5
- package/dist/edit-modes/split-polygon-mode.js.map +1 -1
- package/dist/edit-modes/three-click-polygon-mode.d.ts +3 -3
- package/dist/edit-modes/three-click-polygon-mode.d.ts.map +1 -1
- package/dist/edit-modes/three-click-polygon-mode.js.map +1 -1
- package/dist/edit-modes/translate-mode.d.ts +6 -6
- package/dist/edit-modes/translate-mode.d.ts.map +1 -1
- package/dist/edit-modes/translate-mode.js +1 -2
- package/dist/edit-modes/translate-mode.js.map +1 -1
- package/dist/edit-modes/two-click-polygon-mode.d.ts +6 -6
- package/dist/edit-modes/two-click-polygon-mode.d.ts.map +1 -1
- package/dist/edit-modes/two-click-polygon-mode.js.map +1 -1
- package/dist/edit-modes/types.d.ts +3 -3
- package/dist/edit-modes/types.d.ts.map +1 -1
- package/dist/edit-modes/utils.d.ts +7 -7
- package/dist/edit-modes/utils.d.ts.map +1 -1
- package/dist/edit-modes/utils.js +0 -3
- package/dist/edit-modes/utils.js.map +1 -1
- package/dist/editable-layers/editable-geojson-layer.d.ts +5 -13
- package/dist/editable-layers/editable-geojson-layer.d.ts.map +1 -1
- package/dist/editable-layers/editable-geojson-layer.js +4 -4
- package/dist/editable-layers/editable-geojson-layer.js.map +1 -1
- package/dist/editable-layers/selection-layer.d.ts +1 -2
- package/dist/editable-layers/selection-layer.d.ts.map +1 -1
- package/dist/editable-layers/selection-layer.js +2 -2
- package/dist/editable-layers/selection-layer.js.map +1 -1
- package/dist/index.cjs +369 -995
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +3 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -10
- package/dist/index.js.map +1 -1
- package/dist/mode-handlers/composite-mode-handler.d.ts +3 -3
- package/dist/mode-handlers/composite-mode-handler.d.ts.map +1 -1
- package/dist/mode-handlers/composite-mode-handler.js.map +1 -1
- package/dist/mode-handlers/draw-90degree-polygon-handler.d.ts.map +1 -1
- package/dist/mode-handlers/draw-90degree-polygon-handler.js +4 -2
- package/dist/mode-handlers/draw-90degree-polygon-handler.js.map +1 -1
- package/dist/mode-handlers/draw-circle-by-bounding-box-handler.d.ts.map +1 -1
- package/dist/mode-handlers/draw-circle-by-bounding-box-handler.js +0 -1
- package/dist/mode-handlers/draw-circle-by-bounding-box-handler.js.map +1 -1
- package/dist/mode-handlers/draw-circle-from-center-handler.d.ts.map +1 -1
- package/dist/mode-handlers/draw-circle-from-center-handler.js +0 -1
- package/dist/mode-handlers/draw-circle-from-center-handler.js.map +1 -1
- package/dist/mode-handlers/draw-ellipse-by-bounding-box-handler.d.ts.map +1 -1
- package/dist/mode-handlers/draw-ellipse-by-bounding-box-handler.js +1 -2
- package/dist/mode-handlers/draw-ellipse-by-bounding-box-handler.js.map +1 -1
- package/dist/mode-handlers/draw-ellipse-using-three-points-handler.d.ts.map +1 -1
- package/dist/mode-handlers/draw-ellipse-using-three-points-handler.js +2 -2
- package/dist/mode-handlers/draw-ellipse-using-three-points-handler.js.map +1 -1
- package/dist/mode-handlers/draw-point-handler.js.map +1 -1
- package/dist/mode-handlers/draw-polygon-handler.d.ts.map +1 -1
- package/dist/mode-handlers/draw-polygon-handler.js +4 -2
- package/dist/mode-handlers/draw-polygon-handler.js.map +1 -1
- package/dist/mode-handlers/draw-rectangle-handler.d.ts.map +1 -1
- package/dist/mode-handlers/draw-rectangle-handler.js +0 -1
- package/dist/mode-handlers/draw-rectangle-handler.js.map +1 -1
- package/dist/mode-handlers/draw-rectangle-using-three-points-handler.d.ts.map +1 -1
- package/dist/mode-handlers/draw-rectangle-using-three-points-handler.js +4 -2
- package/dist/mode-handlers/draw-rectangle-using-three-points-handler.js.map +1 -1
- package/dist/mode-handlers/mode-handler.d.ts +12 -12
- package/dist/mode-handlers/mode-handler.d.ts.map +1 -1
- package/dist/mode-handlers/mode-handler.js +6 -7
- package/dist/mode-handlers/mode-handler.js.map +1 -1
- package/dist/mode-handlers/modify-handler.d.ts +2 -2
- package/dist/mode-handlers/modify-handler.d.ts.map +1 -1
- package/dist/mode-handlers/modify-handler.js +1 -4
- package/dist/mode-handlers/modify-handler.js.map +1 -1
- package/dist/mode-handlers/rotate-handler.d.ts +2 -2
- package/dist/mode-handlers/rotate-handler.d.ts.map +1 -1
- package/dist/mode-handlers/rotate-handler.js +2 -7
- package/dist/mode-handlers/rotate-handler.js.map +1 -1
- package/dist/mode-handlers/scale-handler.d.ts +2 -2
- package/dist/mode-handlers/scale-handler.d.ts.map +1 -1
- package/dist/mode-handlers/scale-handler.js +2 -7
- package/dist/mode-handlers/scale-handler.js.map +1 -1
- package/dist/mode-handlers/snappable-handler.d.ts +3 -3
- package/dist/mode-handlers/snappable-handler.d.ts.map +1 -1
- package/dist/mode-handlers/snappable-handler.js.map +1 -1
- package/dist/mode-handlers/split-polygon-handler.d.ts.map +1 -1
- package/dist/mode-handlers/split-polygon-handler.js +4 -5
- package/dist/mode-handlers/split-polygon-handler.js.map +1 -1
- package/dist/mode-handlers/translate-handler.d.ts +2 -2
- package/dist/mode-handlers/translate-handler.d.ts.map +1 -1
- package/dist/mode-handlers/translate-handler.js +1 -4
- package/dist/mode-handlers/translate-handler.js.map +1 -1
- package/dist/utils/geojson-types.d.ts +13 -34
- package/dist/utils/geojson-types.d.ts.map +1 -1
- package/dist/utils/translate-from-center.d.ts +2 -4
- package/dist/utils/translate-from-center.d.ts.map +1 -1
- package/dist/utils/translate-from-center.js.map +1 -1
- package/dist/utils/utils.d.ts +3 -3
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js.map +1 -1
- package/package.json +33 -33
- package/src/edit-modes/draw-90degree-polygon-mode.ts +2 -2
- package/src/edit-modes/draw-circle-by-diameter-mode.ts +3 -3
- package/src/edit-modes/draw-circle-from-center-mode.ts +3 -3
- package/src/edit-modes/draw-ellipse-by-bounding-box-mode.ts +4 -4
- package/src/edit-modes/draw-ellipse-using-three-points-mode.ts +3 -4
- package/src/edit-modes/draw-line-string-mode.ts +5 -5
- package/src/edit-modes/draw-point-mode.ts +2 -2
- package/src/edit-modes/draw-polygon-by-dragging-mode.ts +8 -8
- package/src/edit-modes/draw-polygon-mode.ts +304 -100
- package/src/edit-modes/draw-rectangle-from-center-mode.ts +2 -3
- package/src/edit-modes/draw-rectangle-mode.ts +2 -3
- package/src/edit-modes/draw-rectangle-using-three-points-mode.ts +2 -2
- package/src/edit-modes/draw-square-from-center-mode.ts +2 -3
- package/src/edit-modes/draw-square-mode.ts +3 -3
- package/src/edit-modes/duplicate-mode.ts +2 -2
- package/src/edit-modes/extend-line-string-mode.ts +4 -4
- package/src/edit-modes/extrude-mode.ts +7 -7
- package/src/edit-modes/geojson-edit-mode.ts +16 -19
- package/src/edit-modes/immutable-feature-collection.ts +10 -11
- package/src/edit-modes/measure-area-mode.ts +3 -3
- package/src/edit-modes/modify-mode.ts +13 -13
- package/src/edit-modes/resize-circle-mode.ts +6 -8
- package/src/edit-modes/rotate-mode.ts +9 -15
- package/src/edit-modes/scale-mode.ts +11 -15
- package/src/edit-modes/snappable-mode.ts +5 -5
- package/src/edit-modes/split-polygon-mode.ts +12 -16
- package/src/edit-modes/three-click-polygon-mode.ts +3 -3
- package/src/edit-modes/translate-mode.ts +10 -12
- package/src/edit-modes/two-click-polygon-mode.ts +7 -7
- package/src/edit-modes/types.ts +4 -4
- package/src/edit-modes/utils.ts +12 -16
- package/src/editable-layers/editable-geojson-layer.ts +19 -18
- package/src/editable-layers/selection-layer.ts +3 -3
- package/src/index.ts +8 -28
- package/src/mode-handlers/composite-mode-handler.ts +3 -3
- package/src/mode-handlers/draw-90degree-polygon-handler.ts +4 -2
- package/src/mode-handlers/draw-circle-by-bounding-box-handler.ts +0 -1
- package/src/mode-handlers/draw-circle-from-center-handler.ts +0 -1
- package/src/mode-handlers/draw-ellipse-by-bounding-box-handler.ts +1 -2
- package/src/mode-handlers/draw-ellipse-using-three-points-handler.ts +3 -2
- package/src/mode-handlers/draw-point-handler.ts +2 -2
- package/src/mode-handlers/draw-polygon-handler.ts +4 -2
- package/src/mode-handlers/draw-rectangle-handler.ts +0 -1
- package/src/mode-handlers/draw-rectangle-using-three-points-handler.ts +4 -2
- package/src/mode-handlers/mode-handler.ts +20 -21
- package/src/mode-handlers/modify-handler.ts +2 -4
- package/src/mode-handlers/rotate-handler.ts +4 -8
- package/src/mode-handlers/scale-handler.ts +4 -8
- package/src/mode-handlers/snappable-handler.ts +3 -3
- package/src/mode-handlers/split-polygon-handler.ts +6 -7
- package/src/mode-handlers/translate-handler.ts +3 -5
- package/src/utils/geojson-types.ts +15 -54
- package/src/utils/translate-from-center.ts +6 -11
- package/src/utils/utils.ts +4 -4
- package/dist/lib/constants.d.ts +0 -7
- package/dist/lib/constants.d.ts.map +0 -1
- package/dist/lib/constants.js +0 -10
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/deck-renderer/deck-cache.d.ts +0 -15
- package/dist/lib/deck-renderer/deck-cache.d.ts.map +0 -1
- package/dist/lib/deck-renderer/deck-cache.js +0 -52
- package/dist/lib/deck-renderer/deck-cache.js.map +0 -1
- package/dist/lib/deck-renderer/deck-drawer.d.ts +0 -63
- package/dist/lib/deck-renderer/deck-drawer.d.ts.map +0 -1
- package/dist/lib/deck-renderer/deck-drawer.js +0 -233
- package/dist/lib/deck-renderer/deck-drawer.js.map +0 -1
- package/dist/lib/feature.d.ts +0 -11
- package/dist/lib/feature.d.ts.map +0 -1
- package/dist/lib/feature.js +0 -20
- package/dist/lib/feature.js.map +0 -1
- package/dist/lib/layer-mouse-event.d.ts +0 -12
- package/dist/lib/layer-mouse-event.d.ts.map +0 -1
- package/dist/lib/layer-mouse-event.js +0 -28
- package/dist/lib/layer-mouse-event.js.map +0 -1
- package/dist/lib/layers/junctions-layer.d.ts +0 -9
- package/dist/lib/layers/junctions-layer.d.ts.map +0 -1
- package/dist/lib/layers/junctions-layer.js +0 -37
- package/dist/lib/layers/junctions-layer.js.map +0 -1
- package/dist/lib/layers/segments-layer.d.ts +0 -19
- package/dist/lib/layers/segments-layer.d.ts.map +0 -1
- package/dist/lib/layers/segments-layer.js +0 -98
- package/dist/lib/layers/segments-layer.js.map +0 -1
- package/dist/lib/layers/texts-layer.d.ts +0 -9
- package/dist/lib/layers/texts-layer.d.ts.map +0 -1
- package/dist/lib/layers/texts-layer.js +0 -36
- package/dist/lib/layers/texts-layer.js.map +0 -1
- package/dist/lib/math.d.ts +0 -12
- package/dist/lib/math.d.ts.map +0 -1
- package/dist/lib/math.js +0 -26
- package/dist/lib/math.js.map +0 -1
- package/dist/lib/nebula-core.d.ts +0 -35
- package/dist/lib/nebula-core.d.ts.map +0 -1
- package/dist/lib/nebula-core.js +0 -258
- package/dist/lib/nebula-core.js.map +0 -1
- package/dist/lib/nebula-layer.d.ts +0 -14
- package/dist/lib/nebula-layer.d.ts.map +0 -1
- package/dist/lib/nebula-layer.js +0 -30
- package/dist/lib/nebula-layer.js.map +0 -1
- package/dist/lib/style.d.ts +0 -20
- package/dist/lib/style.d.ts.map +0 -1
- package/dist/lib/style.js +0 -24
- package/dist/lib/style.js.map +0 -1
- package/dist/utils/curve-utils.d.ts +0 -3
- package/dist/utils/curve-utils.d.ts.map +0 -1
- package/dist/utils/curve-utils.js +0 -65
- package/dist/utils/curve-utils.js.map +0 -1
- package/src/lib/constants.ts +0 -10
- package/src/lib/deck-renderer/deck-cache.ts +0 -61
- package/src/lib/deck-renderer/deck-drawer.ts +0 -263
- package/src/lib/feature.ts +0 -31
- package/src/lib/layer-mouse-event.ts +0 -33
- package/src/lib/layers/junctions-layer.ts +0 -44
- package/src/lib/layers/segments-layer.ts +0 -112
- package/src/lib/layers/texts-layer.ts +0 -47
- package/src/lib/math.ts +0 -30
- package/src/lib/nebula-core.ts +0 -327
- package/src/lib/nebula-layer.ts +0 -37
- package/src/lib/style.ts +0 -26
- package/src/utils/curve-utils.ts +0 -81
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import lineIntersect from '@turf/line-intersect';
|
|
6
|
-
import {
|
|
6
|
+
import { polygon as turfPolygon} from '@turf/helpers';
|
|
7
|
+
import booleanWithin from "@turf/boolean-within";
|
|
8
|
+
import type {Geometry} from 'geojson'
|
|
9
|
+
|
|
7
10
|
import {
|
|
8
11
|
ClickEvent,
|
|
9
12
|
PointerMoveEvent,
|
|
@@ -13,129 +16,151 @@ import {
|
|
|
13
16
|
GuideFeature,
|
|
14
17
|
DoubleClickEvent
|
|
15
18
|
} from './types';
|
|
16
|
-
import {
|
|
19
|
+
import {Position, FeatureCollection, SimpleFeatureCollection} from '../utils/geojson-types';
|
|
17
20
|
import {getPickedEditHandle} from './utils';
|
|
18
21
|
import {GeoJsonEditMode} from './geojson-edit-mode';
|
|
22
|
+
import { ImmutableFeatureCollection } from './immutable-feature-collection';
|
|
23
|
+
|
|
19
24
|
|
|
20
25
|
export class DrawPolygonMode extends GeoJsonEditMode {
|
|
26
|
+
|
|
27
|
+
holeSequence: Position[] = [];
|
|
28
|
+
isDrawingHole = false;
|
|
29
|
+
|
|
21
30
|
createTentativeFeature(props: ModeProps<FeatureCollection>): TentativeFeature {
|
|
22
|
-
const {lastPointerMoveEvent} = props;
|
|
31
|
+
const { lastPointerMoveEvent } = props;
|
|
23
32
|
const clickSequence = this.getClickSequence();
|
|
33
|
+
const holeSequence = this.holeSequence;
|
|
34
|
+
const lastCoords = lastPointerMoveEvent
|
|
35
|
+
? [lastPointerMoveEvent.mapCoords]
|
|
36
|
+
: [];
|
|
24
37
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
geometry: {
|
|
35
|
-
type: 'LineString',
|
|
36
|
-
coordinates: [...clickSequence, ...lastCoords]
|
|
37
|
-
}
|
|
38
|
+
let geometry: Geometry;
|
|
39
|
+
|
|
40
|
+
if (this.isDrawingHole && holeSequence.length > 1) {
|
|
41
|
+
geometry = {
|
|
42
|
+
type: "Polygon",
|
|
43
|
+
coordinates: [
|
|
44
|
+
[...clickSequence, clickSequence[0]],
|
|
45
|
+
[...holeSequence, ...lastCoords, holeSequence[0]],
|
|
46
|
+
],
|
|
38
47
|
};
|
|
39
48
|
} else if (clickSequence.length > 2) {
|
|
40
|
-
|
|
41
|
-
type:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
+
geometry = {
|
|
50
|
+
type: "Polygon",
|
|
51
|
+
coordinates: [[...clickSequence, ...lastCoords, clickSequence[0]]],
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
geometry = {
|
|
55
|
+
type: "LineString",
|
|
56
|
+
coordinates: [...clickSequence, ...lastCoords],
|
|
49
57
|
};
|
|
50
58
|
}
|
|
51
59
|
|
|
52
|
-
return
|
|
60
|
+
return {
|
|
61
|
+
type: "Feature",
|
|
62
|
+
properties: {
|
|
63
|
+
guideType: "tentative",
|
|
64
|
+
},
|
|
65
|
+
geometry,
|
|
66
|
+
};
|
|
53
67
|
}
|
|
54
68
|
|
|
55
69
|
getGuides(props: ModeProps<FeatureCollection>): GuideFeatureCollection {
|
|
56
|
-
const clickSequence = this.getClickSequence();
|
|
57
|
-
|
|
58
70
|
const guides: GuideFeatureCollection = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
type: "FeatureCollection",
|
|
72
|
+
features: [],
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const tentative = this.createTentativeFeature(props);
|
|
76
|
+
if (tentative) guides.features.push(tentative);
|
|
77
|
+
|
|
78
|
+
const sequence = this.isDrawingHole
|
|
79
|
+
? this.holeSequence
|
|
80
|
+
: this.getClickSequence();
|
|
81
|
+
|
|
82
|
+
const handles: GuideFeature[] = sequence.map((coord, index) => ({
|
|
83
|
+
type: "Feature",
|
|
84
|
+
properties: {
|
|
85
|
+
guideType: "editHandle",
|
|
86
|
+
editHandleType: "existing",
|
|
87
|
+
featureIndex: -1,
|
|
88
|
+
positionIndexes: [index],
|
|
89
|
+
},
|
|
90
|
+
geometry: {
|
|
91
|
+
type: "Point",
|
|
92
|
+
coordinates: coord,
|
|
93
|
+
},
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
guides.features.push(...handles);
|
|
97
|
+
return guides;
|
|
85
98
|
}
|
|
86
99
|
|
|
87
|
-
|
|
100
|
+
// eslint-disable-next-line complexity, max-statements
|
|
101
|
+
handleClick(event: ClickEvent, props: ModeProps<SimpleFeatureCollection>) {
|
|
102
|
+
const {picks} = event;
|
|
103
|
+
const clickedEditHandle = getPickedEditHandle(picks);
|
|
88
104
|
const clickSequence = this.getClickSequence();
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
105
|
+
const coords = event.mapCoords;
|
|
106
|
+
|
|
107
|
+
// Check if they clicked on an edit handle to complete the polygon
|
|
108
|
+
if (
|
|
109
|
+
!this.isDrawingHole &&
|
|
110
|
+
clickSequence.length > 2 &&
|
|
111
|
+
clickedEditHandle &&
|
|
112
|
+
Array.isArray(clickedEditHandle.properties.positionIndexes) &&
|
|
113
|
+
(clickedEditHandle.properties.positionIndexes[0] === 0 ||
|
|
114
|
+
clickedEditHandle.properties.positionIndexes[0] === clickSequence.length - 1)
|
|
115
|
+
) {
|
|
116
|
+
// They clicked the first or last point, so complete the polygon
|
|
117
|
+
this.finishDrawing(props);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Check if they clicked near the first point to complete the polygon
|
|
122
|
+
if (!this.isDrawingHole && clickSequence.length > 2) {
|
|
123
|
+
if (isNearFirstPoint(coords, clickSequence[0])) {
|
|
124
|
+
this.finishDrawing(props);
|
|
125
|
+
this.resetClickSequence();
|
|
126
|
+
return;
|
|
99
127
|
}
|
|
100
128
|
}
|
|
101
|
-
|
|
129
|
+
|
|
130
|
+
if (this.isDrawingHole) {
|
|
131
|
+
const current = this.holeSequence;
|
|
132
|
+
current.push(coords);
|
|
102
133
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
134
|
+
if (current.length > 2) {
|
|
135
|
+
const poly: Geometry = {
|
|
136
|
+
type: "Polygon",
|
|
137
|
+
coordinates: [
|
|
138
|
+
[...clickSequence, clickSequence[0]],
|
|
139
|
+
[...current, current[0]],
|
|
140
|
+
],
|
|
141
|
+
};
|
|
108
142
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
overlappingLines = true;
|
|
143
|
+
this.resetClickSequence();
|
|
144
|
+
this.holeSequence = [];
|
|
145
|
+
this.isDrawingHole = false;
|
|
146
|
+
|
|
147
|
+
const editAction = this.getAddFeatureOrBooleanPolygonAction(
|
|
148
|
+
poly,
|
|
149
|
+
props,
|
|
150
|
+
);
|
|
151
|
+
if (editAction) props.onEdit(editAction);
|
|
119
152
|
}
|
|
153
|
+
return;
|
|
120
154
|
}
|
|
121
155
|
|
|
156
|
+
// Add the click if we didn't click on a handle
|
|
122
157
|
let positionAdded = false;
|
|
123
|
-
if (!clickedEditHandle
|
|
124
|
-
// Don't add another point right next to an existing one
|
|
158
|
+
if (!clickedEditHandle) {
|
|
125
159
|
this.addClickSequence(event);
|
|
126
160
|
positionAdded = true;
|
|
127
161
|
}
|
|
128
162
|
|
|
129
|
-
if (
|
|
130
|
-
clickSequence.length > 2 &&
|
|
131
|
-
clickedEditHandle &&
|
|
132
|
-
Array.isArray(clickedEditHandle.properties.positionIndexes) &&
|
|
133
|
-
(clickedEditHandle.properties.positionIndexes[0] === 0 ||
|
|
134
|
-
clickedEditHandle.properties.positionIndexes[0] === clickSequence.length - 1)
|
|
135
|
-
) {
|
|
136
|
-
// They clicked the first or last point (or double-clicked), so complete the polygon
|
|
137
|
-
this.finishDrawing(props);
|
|
138
|
-
} else if (positionAdded) {
|
|
163
|
+
if (positionAdded) {
|
|
139
164
|
// new tentative point
|
|
140
165
|
props.onEdit({
|
|
141
166
|
// data is the same
|
|
@@ -148,20 +173,24 @@ export class DrawPolygonMode extends GeoJsonEditMode {
|
|
|
148
173
|
}
|
|
149
174
|
}
|
|
150
175
|
|
|
151
|
-
handleDoubleClick(
|
|
176
|
+
handleDoubleClick(_event: DoubleClickEvent, props: ModeProps<SimpleFeatureCollection>) {
|
|
152
177
|
this.finishDrawing(props);
|
|
178
|
+
this.resetClickSequence();
|
|
153
179
|
}
|
|
154
180
|
|
|
155
|
-
handleKeyUp(event: KeyboardEvent, props: ModeProps<
|
|
156
|
-
if (event.key ===
|
|
181
|
+
handleKeyUp(event: KeyboardEvent, props: ModeProps<SimpleFeatureCollection>) {
|
|
182
|
+
if (event.key === "Enter") {
|
|
157
183
|
this.finishDrawing(props);
|
|
158
|
-
} else if (event.key === 'Escape') {
|
|
159
184
|
this.resetClickSequence();
|
|
185
|
+
} else if (event.key === "Escape") {
|
|
186
|
+
this.resetClickSequence();
|
|
187
|
+
this.holeSequence = [];
|
|
188
|
+
this.isDrawingHole = false;
|
|
189
|
+
|
|
160
190
|
props.onEdit({
|
|
161
|
-
// Because the new drawing feature is dropped, so the data will keep as the same.
|
|
162
191
|
updatedData: props.data,
|
|
163
|
-
editType:
|
|
164
|
-
editContext: {}
|
|
192
|
+
editType: "cancelFeature",
|
|
193
|
+
editContext: {},
|
|
165
194
|
});
|
|
166
195
|
}
|
|
167
196
|
}
|
|
@@ -170,4 +199,179 @@ export class DrawPolygonMode extends GeoJsonEditMode {
|
|
|
170
199
|
props.onUpdateCursor('cell');
|
|
171
200
|
super.handlePointerMove(event, props);
|
|
172
201
|
}
|
|
202
|
+
|
|
203
|
+
// eslint-disable-next-line max-statements, complexity
|
|
204
|
+
finishDrawing(props: ModeProps<SimpleFeatureCollection>) {
|
|
205
|
+
const clickSequence = this.getClickSequence();
|
|
206
|
+
const polygon = [...clickSequence, clickSequence[0]];
|
|
207
|
+
|
|
208
|
+
const newPolygon = turfPolygon([polygon]);
|
|
209
|
+
|
|
210
|
+
const canAddHole = canAddHoleToPolygon(props);
|
|
211
|
+
const canOverlap = canPolygonOverlap(props);
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
// Check if the polygon intersects itself (excluding shared start/end point)
|
|
215
|
+
if (!canOverlap) {
|
|
216
|
+
const overlapping = lineIntersect(
|
|
217
|
+
newPolygon,
|
|
218
|
+
newPolygon,
|
|
219
|
+
).features.filter(
|
|
220
|
+
(intersection) =>
|
|
221
|
+
!newPolygon.geometry.coordinates[0].some(
|
|
222
|
+
(coord) =>
|
|
223
|
+
coord[0] === intersection.geometry.coordinates[0] &&
|
|
224
|
+
coord[1] === intersection.geometry.coordinates[1],
|
|
225
|
+
),
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
if (overlapping.length > 0) {
|
|
229
|
+
// ❌ Invalid polygon: overlaps
|
|
230
|
+
props.onEdit({
|
|
231
|
+
updatedData: props.data,
|
|
232
|
+
editType: "invalidPolygon",
|
|
233
|
+
editContext: { reason: "overlaps" },
|
|
234
|
+
});
|
|
235
|
+
this.resetClickSequence();
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (canAddHole) {
|
|
241
|
+
const holeResult = this.tryAddHoleToExistingPolygon(newPolygon, polygon, props);
|
|
242
|
+
if (holeResult.handled) {
|
|
243
|
+
this.resetClickSequence();
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// If no valid hole was found, add the polygon as a new feature
|
|
249
|
+
const editAction = this.getAddFeatureOrBooleanPolygonAction(
|
|
250
|
+
{
|
|
251
|
+
type: "Polygon",
|
|
252
|
+
coordinates: [[...this.getClickSequence(), this.getClickSequence()[0]]],
|
|
253
|
+
},
|
|
254
|
+
props,
|
|
255
|
+
);
|
|
256
|
+
if (editAction) props.onEdit(editAction);
|
|
257
|
+
this.resetClickSequence();
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
private tryAddHoleToExistingPolygon(
|
|
262
|
+
newPolygon: any,
|
|
263
|
+
polygon: Position[],
|
|
264
|
+
props: ModeProps<SimpleFeatureCollection>
|
|
265
|
+
): { handled: boolean } {
|
|
266
|
+
for (const [featureIndex, feature] of props.data.features.entries()) {
|
|
267
|
+
if (feature.geometry.type === "Polygon") {
|
|
268
|
+
const result = this.validateAndCreateHole(feature, featureIndex, newPolygon, polygon, props);
|
|
269
|
+
if (result.handled) {
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return { handled: false };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
private validateAndCreateHole(
|
|
279
|
+
feature: any,
|
|
280
|
+
featureIndex: number,
|
|
281
|
+
newPolygon: any,
|
|
282
|
+
polygon: Position[],
|
|
283
|
+
props: ModeProps<SimpleFeatureCollection>
|
|
284
|
+
): { handled: boolean } {
|
|
285
|
+
const outer = turfPolygon(feature.geometry.coordinates);
|
|
286
|
+
|
|
287
|
+
// Check existing holes for conflicts
|
|
288
|
+
for (let i = 1; i < feature.geometry.coordinates.length; i++) {
|
|
289
|
+
const hole = turfPolygon([feature.geometry.coordinates[i]]);
|
|
290
|
+
const intersection = lineIntersect(hole, newPolygon);
|
|
291
|
+
|
|
292
|
+
if (intersection.features.length > 0) {
|
|
293
|
+
props.onEdit({
|
|
294
|
+
updatedData: props.data,
|
|
295
|
+
editType: "invalidHole",
|
|
296
|
+
editContext: { reason: "intersects-existing-hole" },
|
|
297
|
+
});
|
|
298
|
+
return { handled: true };
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (booleanWithin(hole, newPolygon) || booleanWithin(newPolygon, hole)) {
|
|
302
|
+
props.onEdit({
|
|
303
|
+
updatedData: props.data,
|
|
304
|
+
editType: "invalidHole",
|
|
305
|
+
editContext: { reason: "contains-or-contained-by-existing-hole" },
|
|
306
|
+
});
|
|
307
|
+
return { handled: true };
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Check outer polygon conflicts
|
|
312
|
+
const intersectionWithOuter = lineIntersect(outer, newPolygon);
|
|
313
|
+
if (intersectionWithOuter.features.length > 0) {
|
|
314
|
+
props.onEdit({
|
|
315
|
+
updatedData: props.data,
|
|
316
|
+
editType: "invalidPolygon",
|
|
317
|
+
editContext: { reason: "intersects-existing-polygon" },
|
|
318
|
+
});
|
|
319
|
+
return { handled: true };
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (booleanWithin(outer, newPolygon)) {
|
|
323
|
+
props.onEdit({
|
|
324
|
+
updatedData: props.data,
|
|
325
|
+
editType: "invalidPolygon",
|
|
326
|
+
editContext: { reason: "contains-existing-polygon" },
|
|
327
|
+
});
|
|
328
|
+
return { handled: true };
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// Check if new polygon is within outer polygon (valid hole)
|
|
332
|
+
if (booleanWithin(newPolygon, outer)) {
|
|
333
|
+
const updatedData = new ImmutableFeatureCollection(props.data)
|
|
334
|
+
.replaceGeometry(featureIndex, {
|
|
335
|
+
...feature.geometry,
|
|
336
|
+
coordinates: [...feature.geometry.coordinates, polygon],
|
|
337
|
+
})
|
|
338
|
+
.getObject();
|
|
339
|
+
|
|
340
|
+
props.onEdit({
|
|
341
|
+
updatedData,
|
|
342
|
+
editType: "addHole",
|
|
343
|
+
editContext: { hole: newPolygon.geometry },
|
|
344
|
+
});
|
|
345
|
+
return { handled: true };
|
|
346
|
+
}
|
|
347
|
+
return { handled: false };
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Helper function to check if a point is near the first point in the sequence
|
|
352
|
+
function isNearFirstPoint(
|
|
353
|
+
click: Position,
|
|
354
|
+
first: Position,
|
|
355
|
+
threshold = 1e-4,
|
|
356
|
+
): boolean {
|
|
357
|
+
const dx = click[0] - first[0];
|
|
358
|
+
const dy = click[1] - first[1];
|
|
359
|
+
return dx * dx + dy * dy < threshold * threshold;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Helper function to determine if a hole can be added to a polygon
|
|
363
|
+
function canAddHoleToPolygon(
|
|
364
|
+
props: ModeProps<FeatureCollection>
|
|
365
|
+
): boolean {
|
|
366
|
+
// For simplicity, always return true in this example.
|
|
367
|
+
// Implement your own logic based on application requirements.
|
|
368
|
+
return props.modeConfig?.allowHoles ?? false;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// Helper function to determine if a polygon can intersect itself
|
|
372
|
+
function canPolygonOverlap(
|
|
373
|
+
props: ModeProps<FeatureCollection>
|
|
374
|
+
): boolean {
|
|
375
|
+
// Return the value of allowSelfIntersection (defaults to false for safety)
|
|
376
|
+
return props.modeConfig?.allowSelfIntersection ?? false;
|
|
173
377
|
}
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import bboxPolygon from '@turf/bbox-polygon';
|
|
6
|
-
import {Position, Polygon,
|
|
6
|
+
import {Position, Polygon, Feature} from '../utils/geojson-types';
|
|
7
7
|
import {TwoClickPolygonMode} from './two-click-polygon-mode';
|
|
8
8
|
|
|
9
9
|
export class DrawRectangleFromCenterMode extends TwoClickPolygonMode {
|
|
10
|
-
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any):
|
|
10
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): Feature<Polygon> {
|
|
11
11
|
const longitude =
|
|
12
12
|
coord1[0] > coord2[0]
|
|
13
13
|
? coord1[0] + Math.abs(coord1[0] - coord2[0])
|
|
@@ -21,7 +21,6 @@ export class DrawRectangleFromCenterMode extends TwoClickPolygonMode {
|
|
|
21
21
|
rectangle.properties = rectangle.properties || {};
|
|
22
22
|
rectangle.properties.shape = 'Rectangle';
|
|
23
23
|
|
|
24
|
-
// @ts-expect-error turf typing too wide
|
|
25
24
|
return rectangle;
|
|
26
25
|
}
|
|
27
26
|
}
|
|
@@ -3,16 +3,15 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import bboxPolygon from '@turf/bbox-polygon';
|
|
6
|
-
import {Position, Polygon,
|
|
6
|
+
import {Position, Polygon, Feature} from '../utils/geojson-types';
|
|
7
7
|
import {TwoClickPolygonMode} from './two-click-polygon-mode';
|
|
8
8
|
|
|
9
9
|
export class DrawRectangleMode extends TwoClickPolygonMode {
|
|
10
|
-
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any):
|
|
10
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): Feature<Polygon> {
|
|
11
11
|
const rectangle = bboxPolygon([coord1[0], coord1[1], coord2[0], coord2[1]]);
|
|
12
12
|
rectangle.properties = rectangle.properties || {};
|
|
13
13
|
rectangle.properties.shape = 'Rectangle';
|
|
14
14
|
|
|
15
|
-
// @ts-expect-error turf typing too wide
|
|
16
15
|
return rectangle;
|
|
17
16
|
}
|
|
18
17
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {generatePointsParallelToLinePoints} from './utils';
|
|
6
|
-
import {Position, Polygon,
|
|
6
|
+
import {Position, Polygon, Feature} from '../utils/geojson-types';
|
|
7
7
|
import {ThreeClickPolygonMode} from './three-click-polygon-mode';
|
|
8
8
|
|
|
9
9
|
export class DrawRectangleUsingThreePointsMode extends ThreeClickPolygonMode {
|
|
@@ -12,7 +12,7 @@ export class DrawRectangleUsingThreePointsMode extends ThreeClickPolygonMode {
|
|
|
12
12
|
coord2: Position,
|
|
13
13
|
coord3: Position,
|
|
14
14
|
modeConfig: any
|
|
15
|
-
):
|
|
15
|
+
): Feature<Polygon> | null | undefined {
|
|
16
16
|
const [p3, p4] = generatePointsParallelToLinePoints(coord1, coord2, coord3);
|
|
17
17
|
|
|
18
18
|
return {
|
|
@@ -6,11 +6,11 @@ import bboxPolygon from '@turf/bbox-polygon';
|
|
|
6
6
|
import turfDistance from '@turf/distance';
|
|
7
7
|
import turfAlong from '@turf/along';
|
|
8
8
|
import {point, lineString as turfLineString} from '@turf/helpers';
|
|
9
|
-
import {Position, Polygon,
|
|
9
|
+
import {Position, Polygon, Feature} from '../utils/geojson-types';
|
|
10
10
|
import {TwoClickPolygonMode} from './two-click-polygon-mode';
|
|
11
11
|
|
|
12
12
|
export class DrawSquareFromCenterMode extends TwoClickPolygonMode {
|
|
13
|
-
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any):
|
|
13
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): Feature<Polygon> {
|
|
14
14
|
// get the coordinates of the other two rectangle vertices
|
|
15
15
|
const coord3 = [coord2[0], coord1[1]];
|
|
16
16
|
const coord4 = [coord1[0], coord2[1]];
|
|
@@ -44,7 +44,6 @@ export class DrawSquareFromCenterMode extends TwoClickPolygonMode {
|
|
|
44
44
|
square.properties = square.properties || {};
|
|
45
45
|
square.properties.shape = 'Square';
|
|
46
46
|
|
|
47
|
-
// @ts-expect-error turf typing too wide
|
|
48
47
|
return square;
|
|
49
48
|
}
|
|
50
49
|
}
|
|
@@ -6,11 +6,11 @@ import bboxPolygon from '@turf/bbox-polygon';
|
|
|
6
6
|
import turfDistance from '@turf/distance';
|
|
7
7
|
import turfAlong from '@turf/along';
|
|
8
8
|
import {point, lineString as turfLineString} from '@turf/helpers';
|
|
9
|
-
import {Position, Polygon,
|
|
9
|
+
import {Position, Polygon, Feature} from '../utils/geojson-types';
|
|
10
10
|
import {TwoClickPolygonMode} from './two-click-polygon-mode';
|
|
11
11
|
|
|
12
12
|
export class DrawSquareMode extends TwoClickPolygonMode {
|
|
13
|
-
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any):
|
|
13
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): Feature<Polygon> {
|
|
14
14
|
// get the coordinates of the other two rectangle vertices
|
|
15
15
|
const coord3 = [coord2[0], coord1[1]];
|
|
16
16
|
const coord4 = [coord1[0], coord2[1]];
|
|
@@ -34,7 +34,7 @@ export class DrawSquareMode extends TwoClickPolygonMode {
|
|
|
34
34
|
square.properties = square.properties || {};
|
|
35
35
|
square.properties.shape = 'Square';
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
return square;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {StartDraggingEvent, ModeProps} from './types';
|
|
6
|
-
import {FeatureCollection} from '../utils/geojson-types';
|
|
6
|
+
import {FeatureCollection, SimpleFeatureCollection} from '../utils/geojson-types';
|
|
7
7
|
import {TranslateMode} from './translate-mode';
|
|
8
8
|
|
|
9
9
|
export class DuplicateMode extends TranslateMode {
|
|
10
|
-
handleStartDragging(event: StartDraggingEvent, props: ModeProps<
|
|
10
|
+
handleStartDragging(event: StartDraggingEvent, props: ModeProps<SimpleFeatureCollection>) {
|
|
11
11
|
super.handleStartDragging(event, props);
|
|
12
12
|
|
|
13
13
|
if (this._geometryBeforeTranslate) {
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {Position, LineString, FeatureCollection} from '../utils/geojson-types';
|
|
5
|
+
import {Position, LineString, FeatureCollection, SimpleFeatureCollection} from '../utils/geojson-types';
|
|
6
6
|
import {ClickEvent, PointerMoveEvent, ModeProps, GuideFeatureCollection} from './types';
|
|
7
7
|
import {GeoJsonEditMode} from './geojson-edit-mode';
|
|
8
8
|
import {ImmutableFeatureCollection} from './immutable-feature-collection';
|
|
9
9
|
|
|
10
10
|
export class ExtendLineStringMode extends GeoJsonEditMode {
|
|
11
|
-
getSingleSelectedLineString(props: ModeProps<
|
|
11
|
+
getSingleSelectedLineString(props: ModeProps<SimpleFeatureCollection>): LineString | null | undefined {
|
|
12
12
|
const selectedGeometry = this.getSelectedGeometry(props);
|
|
13
13
|
|
|
14
14
|
if (selectedGeometry && selectedGeometry.type === 'LineString') {
|
|
@@ -17,7 +17,7 @@ export class ExtendLineStringMode extends GeoJsonEditMode {
|
|
|
17
17
|
return null;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
handleClick(event: ClickEvent, props: ModeProps<
|
|
20
|
+
handleClick(event: ClickEvent, props: ModeProps<SimpleFeatureCollection>) {
|
|
21
21
|
const {selectedIndexes} = props;
|
|
22
22
|
const selectedLineString = this.getSingleSelectedLineString(props);
|
|
23
23
|
|
|
@@ -49,7 +49,7 @@ export class ExtendLineStringMode extends GeoJsonEditMode {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
getGuides(props: ModeProps<
|
|
52
|
+
getGuides(props: ModeProps<SimpleFeatureCollection>): GuideFeatureCollection {
|
|
53
53
|
const guides: GuideFeatureCollection = {
|
|
54
54
|
type: 'FeatureCollection',
|
|
55
55
|
features: []
|