@deck.gl-community/editable-layers 9.0.0-alpha.1
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/README.md +82 -0
- package/dist/constants.d.ts +14 -0
- package/dist/constants.js +14 -0
- package/dist/curve-utils.d.ts +2 -0
- package/dist/curve-utils.js +61 -0
- package/dist/edit-modes/composite-mode.d.ts +14 -0
- package/dist/edit-modes/composite-mode.js +47 -0
- package/dist/edit-modes/draw-90degree-polygon-mode.d.ts +11 -0
- package/dist/edit-modes/draw-90degree-polygon-mode.js +179 -0
- package/dist/edit-modes/draw-circle-by-diameter-mode.d.ts +24 -0
- package/dist/edit-modes/draw-circle-by-diameter-mode.js +78 -0
- package/dist/edit-modes/draw-circle-from-center-mode.d.ts +22 -0
- package/dist/edit-modes/draw-circle-from-center-mode.js +70 -0
- package/dist/edit-modes/draw-ellipse-by-bounding-box-mode.d.ts +5 -0
- package/dist/edit-modes/draw-ellipse-by-bounding-box-mode.js +20 -0
- package/dist/edit-modes/draw-ellipse-using-three-points-mode.d.ts +5 -0
- package/dist/edit-modes/draw-ellipse-using-three-points-mode.js +16 -0
- package/dist/edit-modes/draw-line-string-mode.d.ts +25 -0
- package/dist/edit-modes/draw-line-string-mode.js +170 -0
- package/dist/edit-modes/draw-point-mode.d.ts +8 -0
- package/dist/edit-modes/draw-point-mode.js +28 -0
- package/dist/edit-modes/draw-polygon-by-dragging-mode.d.ts +14 -0
- package/dist/edit-modes/draw-polygon-by-dragging-mode.js +87 -0
- package/dist/edit-modes/draw-polygon-mode.d.ts +10 -0
- package/dist/edit-modes/draw-polygon-mode.js +143 -0
- package/dist/edit-modes/draw-rectangle-from-center-mode.d.ts +5 -0
- package/dist/edit-modes/draw-rectangle-from-center-mode.js +17 -0
- package/dist/edit-modes/draw-rectangle-mode.d.ts +5 -0
- package/dist/edit-modes/draw-rectangle-mode.js +11 -0
- package/dist/edit-modes/draw-rectangle-using-three-points-mode.d.ts +5 -0
- package/dist/edit-modes/draw-rectangle-using-three-points-mode.js +28 -0
- package/dist/edit-modes/draw-square-from-center-mode.d.ts +5 -0
- package/dist/edit-modes/draw-square-from-center-mode.js +35 -0
- package/dist/edit-modes/draw-square-mode.d.ts +5 -0
- package/dist/edit-modes/draw-square-mode.js +28 -0
- package/dist/edit-modes/duplicate-mode.d.ts +7 -0
- package/dist/edit-modes/duplicate-mode.js +17 -0
- package/dist/edit-modes/edit-mode.d.ts +11 -0
- package/dist/edit-modes/edit-mode.js +2 -0
- package/dist/edit-modes/elevation-mode.d.ts +13 -0
- package/dist/edit-modes/elevation-mode.js +49 -0
- package/dist/edit-modes/extend-line-string-mode.d.ts +9 -0
- package/dist/edit-modes/extend-line-string-mode.js +72 -0
- package/dist/edit-modes/extrude-mode.d.ts +15 -0
- package/dist/edit-modes/extrude-mode.js +186 -0
- package/dist/edit-modes/geojson-edit-mode.d.ts +33 -0
- package/dist/edit-modes/geojson-edit-mode.js +208 -0
- package/dist/edit-modes/immutable-feature-collection.d.ts +43 -0
- package/dist/edit-modes/immutable-feature-collection.js +300 -0
- package/dist/edit-modes/measure-angle-mode.d.ts +11 -0
- package/dist/edit-modes/measure-angle-mode.js +99 -0
- package/dist/edit-modes/measure-area-mode.d.ts +8 -0
- package/dist/edit-modes/measure-area-mode.js +50 -0
- package/dist/edit-modes/measure-distance-mode.d.ts +19 -0
- package/dist/edit-modes/measure-distance-mode.js +171 -0
- package/dist/edit-modes/modify-mode.d.ts +15 -0
- package/dist/edit-modes/modify-mode.js +203 -0
- package/dist/edit-modes/resize-circle-mode.d.ts +16 -0
- package/dist/edit-modes/resize-circle-mode.js +142 -0
- package/dist/edit-modes/rotate-mode.d.ts +17 -0
- package/dist/edit-modes/rotate-mode.js +151 -0
- package/dist/edit-modes/scale-mode.d.ts +27 -0
- package/dist/edit-modes/scale-mode.js +173 -0
- package/dist/edit-modes/snappable-mode.d.ts +21 -0
- package/dist/edit-modes/snappable-mode.js +109 -0
- package/dist/edit-modes/split-polygon-mode.d.ts +10 -0
- package/dist/edit-modes/split-polygon-mode.js +164 -0
- package/dist/edit-modes/three-click-polygon-mode.d.ts +10 -0
- package/dist/edit-modes/three-click-polygon-mode.js +72 -0
- package/dist/edit-modes/transform-mode.d.ts +9 -0
- package/dist/edit-modes/transform-mode.js +63 -0
- package/dist/edit-modes/translate-mode.d.ts +13 -0
- package/dist/edit-modes/translate-mode.js +113 -0
- package/dist/edit-modes/two-click-polygon-mode.d.ts +13 -0
- package/dist/edit-modes/two-click-polygon-mode.js +93 -0
- package/dist/edit-modes/types.d.ts +86 -0
- package/dist/edit-modes/types.js +1 -0
- package/dist/edit-modes/utils.d.ts +36 -0
- package/dist/edit-modes/utils.js +381 -0
- package/dist/edit-modes/view-mode.d.ts +3 -0
- package/dist/edit-modes/view-mode.js +3 -0
- package/dist/editable-layers/editable-geojson-layer.d.ts +98 -0
- package/dist/editable-layers/editable-geojson-layer.js +450 -0
- package/dist/editable-layers/editable-h3-cluster-layer.d.ts +34 -0
- package/dist/editable-layers/editable-h3-cluster-layer.js +164 -0
- package/dist/editable-layers/editable-layer.d.ts +49 -0
- package/dist/editable-layers/editable-layer.js +195 -0
- package/dist/editable-layers/editable-path-layer.d.ts +9 -0
- package/dist/editable-layers/editable-path-layer.js +34 -0
- package/dist/editable-layers/elevated-edit-handle-layer.d.ts +7 -0
- package/dist/editable-layers/elevated-edit-handle-layer.js +24 -0
- package/dist/editable-layers/junction-scatterplot-layer.d.ts +14 -0
- package/dist/editable-layers/junction-scatterplot-layer.js +41 -0
- package/dist/editable-layers/path-marker-layer/arrow-2d-geometry.d.ts +4 -0
- package/dist/editable-layers/path-marker-layer/arrow-2d-geometry.js +55 -0
- package/dist/editable-layers/path-marker-layer/create-path-markers.d.ts +16 -0
- package/dist/editable-layers/path-marker-layer/create-path-markers.js +75 -0
- package/dist/editable-layers/path-marker-layer/path-marker-layer.d.ts +40 -0
- package/dist/editable-layers/path-marker-layer/path-marker-layer.js +121 -0
- package/dist/editable-layers/path-marker-layer/polyline.d.ts +18 -0
- package/dist/editable-layers/path-marker-layer/polyline.js +37 -0
- package/dist/editable-layers/path-outline-layer/path-outline-layer.d.ts +26 -0
- package/dist/editable-layers/path-outline-layer/path-outline-layer.js +106 -0
- package/dist/editable-layers/selection-layer.d.ts +26 -0
- package/dist/editable-layers/selection-layer.js +167 -0
- package/dist/geojson-types.d.ts +58 -0
- package/dist/geojson-types.js +2 -0
- package/dist/index.cjs +5825 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +62 -0
- package/dist/lib/constants.d.ts +6 -0
- package/dist/lib/constants.js +6 -0
- package/dist/lib/deck-renderer/deck-cache.d.ts +14 -0
- package/dist/lib/deck-renderer/deck-cache.js +51 -0
- package/dist/lib/deck-renderer/deck-drawer.d.ts +63 -0
- package/dist/lib/deck-renderer/deck-drawer.js +232 -0
- package/dist/lib/feature.d.ts +10 -0
- package/dist/lib/feature.js +16 -0
- package/dist/lib/layer-mouse-event.d.ts +11 -0
- package/dist/lib/layer-mouse-event.js +24 -0
- package/dist/lib/layers/junctions-layer.d.ts +8 -0
- package/dist/lib/layers/junctions-layer.js +33 -0
- package/dist/lib/layers/segments-layer.d.ts +18 -0
- package/dist/lib/layers/segments-layer.js +94 -0
- package/dist/lib/layers/texts-layer.d.ts +8 -0
- package/dist/lib/layers/texts-layer.js +32 -0
- package/dist/lib/math.d.ts +11 -0
- package/dist/lib/math.js +22 -0
- package/dist/lib/nebula-layer.d.ts +13 -0
- package/dist/lib/nebula-layer.js +26 -0
- package/dist/lib/nebula.d.ts +34 -0
- package/dist/lib/nebula.js +254 -0
- package/dist/lib/style.d.ts +19 -0
- package/dist/lib/style.js +20 -0
- package/dist/memoize.d.ts +6 -0
- package/dist/memoize.js +40 -0
- package/dist/mode-handlers/composite-mode-handler.d.ts +24 -0
- package/dist/mode-handlers/composite-mode-handler.js +55 -0
- package/dist/mode-handlers/draw-90degree-polygon-handler.d.ts +13 -0
- package/dist/mode-handlers/draw-90degree-polygon-handler.js +169 -0
- package/dist/mode-handlers/draw-circle-by-bounding-box-handler.d.ts +9 -0
- package/dist/mode-handlers/draw-circle-by-bounding-box-handler.js +29 -0
- package/dist/mode-handlers/draw-circle-from-center-handler.d.ts +9 -0
- package/dist/mode-handlers/draw-circle-from-center-handler.js +27 -0
- package/dist/mode-handlers/draw-ellipse-by-bounding-box-handler.d.ts +9 -0
- package/dist/mode-handlers/draw-ellipse-by-bounding-box-handler.js +30 -0
- package/dist/mode-handlers/draw-ellipse-using-three-points-handler.d.ts +9 -0
- package/dist/mode-handlers/draw-ellipse-using-three-points-handler.js +37 -0
- package/dist/mode-handlers/draw-line-string-handler.d.ts +9 -0
- package/dist/mode-handlers/draw-line-string-handler.js +83 -0
- package/dist/mode-handlers/draw-point-handler.d.ts +5 -0
- package/dist/mode-handlers/draw-point-handler.js +11 -0
- package/dist/mode-handlers/draw-polygon-handler.d.ts +11 -0
- package/dist/mode-handlers/draw-polygon-handler.js +92 -0
- package/dist/mode-handlers/draw-rectangle-handler.d.ts +9 -0
- package/dist/mode-handlers/draw-rectangle-handler.js +18 -0
- package/dist/mode-handlers/draw-rectangle-using-three-points-handler.d.ts +9 -0
- package/dist/mode-handlers/draw-rectangle-using-three-points-handler.js +49 -0
- package/dist/mode-handlers/duplicate-handler.d.ts +9 -0
- package/dist/mode-handlers/duplicate-handler.js +19 -0
- package/dist/mode-handlers/elevation-handler.d.ts +19 -0
- package/dist/mode-handlers/elevation-handler.js +48 -0
- package/dist/mode-handlers/extrude-handler.d.ts +18 -0
- package/dist/mode-handlers/extrude-handler.js +176 -0
- package/dist/mode-handlers/mode-handler.d.ts +61 -0
- package/dist/mode-handlers/mode-handler.js +286 -0
- package/dist/mode-handlers/modify-handler.d.ts +19 -0
- package/dist/mode-handlers/modify-handler.js +193 -0
- package/dist/mode-handlers/rotate-handler.d.ts +17 -0
- package/dist/mode-handlers/rotate-handler.js +74 -0
- package/dist/mode-handlers/scale-handler.d.ts +17 -0
- package/dist/mode-handlers/scale-handler.js +76 -0
- package/dist/mode-handlers/snappable-handler.d.ts +33 -0
- package/dist/mode-handlers/snappable-handler.js +133 -0
- package/dist/mode-handlers/split-polygon-handler.d.ts +11 -0
- package/dist/mode-handlers/split-polygon-handler.js +154 -0
- package/dist/mode-handlers/three-click-polygon-handler.d.ts +5 -0
- package/dist/mode-handlers/three-click-polygon-handler.js +18 -0
- package/dist/mode-handlers/translate-handler.d.ts +17 -0
- package/dist/mode-handlers/translate-handler.js +72 -0
- package/dist/mode-handlers/two-click-polygon-handler.d.ts +5 -0
- package/dist/mode-handlers/two-click-polygon-handler.js +18 -0
- package/dist/mode-handlers/view-handler.d.ts +8 -0
- package/dist/mode-handlers/view-handler.js +10 -0
- package/dist/shaderlib/color/color.d.ts +8 -0
- package/dist/shaderlib/color/color.js +51 -0
- package/dist/shaderlib/outline/outline.d.ts +8 -0
- package/dist/shaderlib/outline/outline.js +97 -0
- package/dist/shaderlib/utils/utils.d.ts +8 -0
- package/dist/shaderlib/utils/utils.js +28 -0
- package/dist/translateFromCenter.d.ts +4 -0
- package/dist/translateFromCenter.js +19 -0
- package/dist/types.d.ts +35 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.js +144 -0
- package/package.json +84 -0
- package/src/constants.ts +15 -0
- package/src/curve-utils.ts +77 -0
- package/src/edit-modes/composite-mode.ts +74 -0
- package/src/edit-modes/draw-90degree-polygon-mode.ts +220 -0
- package/src/edit-modes/draw-circle-by-diameter-mode.ts +88 -0
- package/src/edit-modes/draw-circle-from-center-mode.ts +79 -0
- package/src/edit-modes/draw-ellipse-by-bounding-box-mode.ts +25 -0
- package/src/edit-modes/draw-ellipse-using-three-points-mode.ts +23 -0
- package/src/edit-modes/draw-line-string-mode.ts +200 -0
- package/src/edit-modes/draw-point-mode.ts +35 -0
- package/src/edit-modes/draw-polygon-by-dragging-mode.ts +106 -0
- package/src/edit-modes/draw-polygon-mode.ts +171 -0
- package/src/edit-modes/draw-rectangle-from-center-mode.ts +23 -0
- package/src/edit-modes/draw-rectangle-mode.ts +14 -0
- package/src/edit-modes/draw-rectangle-using-three-points-mode.ts +36 -0
- package/src/edit-modes/draw-square-from-center-mode.ts +46 -0
- package/src/edit-modes/draw-square-mode.ts +36 -0
- package/src/edit-modes/duplicate-mode.ts +21 -0
- package/src/edit-modes/edit-mode.ts +30 -0
- package/src/edit-modes/elevation-mode.ts +86 -0
- package/src/edit-modes/extend-line-string-mode.ts +87 -0
- package/src/edit-modes/extrude-mode.ts +254 -0
- package/src/edit-modes/geojson-edit-mode.ts +283 -0
- package/src/edit-modes/immutable-feature-collection.ts +417 -0
- package/src/edit-modes/measure-angle-mode.ts +127 -0
- package/src/edit-modes/measure-area-mode.ts +62 -0
- package/src/edit-modes/measure-distance-mode.ts +215 -0
- package/src/edit-modes/modify-mode.ts +293 -0
- package/src/edit-modes/resize-circle-mode.ts +202 -0
- package/src/edit-modes/rotate-mode.ts +208 -0
- package/src/edit-modes/scale-mode.ts +231 -0
- package/src/edit-modes/snappable-mode.ts +174 -0
- package/src/edit-modes/split-polygon-mode.ts +201 -0
- package/src/edit-modes/three-click-polygon-mode.ts +111 -0
- package/src/edit-modes/transform-mode.ts +75 -0
- package/src/edit-modes/translate-mode.ts +161 -0
- package/src/edit-modes/two-click-polygon-mode.ts +132 -0
- package/src/edit-modes/types.ts +135 -0
- package/src/edit-modes/utils.ts +513 -0
- package/src/edit-modes/view-mode.ts +3 -0
- package/src/editable-layers/editable-geojson-layer.ts +603 -0
- package/src/editable-layers/editable-h3-cluster-layer.ts +226 -0
- package/src/editable-layers/editable-layer.ts +252 -0
- package/src/editable-layers/editable-path-layer.ts +51 -0
- package/src/editable-layers/elevated-edit-handle-layer.ts +33 -0
- package/src/editable-layers/junction-scatterplot-layer.ts +53 -0
- package/src/editable-layers/path-marker-layer/arrow-2d-geometry.ts +61 -0
- package/src/editable-layers/path-marker-layer/create-path-markers.ts +107 -0
- package/src/editable-layers/path-marker-layer/path-marker-layer.ts +179 -0
- package/src/editable-layers/path-marker-layer/polyline.ts +40 -0
- package/src/editable-layers/path-outline-layer/path-outline-layer.ts +147 -0
- package/src/editable-layers/selection-layer.ts +209 -0
- package/src/geojson-types.ts +89 -0
- package/src/index.ts +125 -0
- package/src/lib/constants.ts +6 -0
- package/src/lib/deck-renderer/deck-cache.ts +61 -0
- package/src/lib/deck-renderer/deck-drawer.ts +263 -0
- package/src/lib/feature.ts +27 -0
- package/src/lib/layer-mouse-event.ts +32 -0
- package/src/lib/layers/junctions-layer.ts +40 -0
- package/src/lib/layers/segments-layer.ts +108 -0
- package/src/lib/layers/texts-layer.ts +43 -0
- package/src/lib/math.ts +26 -0
- package/src/lib/nebula-layer.ts +33 -0
- package/src/lib/nebula.ts +323 -0
- package/src/lib/style.ts +22 -0
- package/src/memoize.ts +43 -0
- package/src/mode-handlers/composite-mode-handler.ts +89 -0
- package/src/mode-handlers/draw-90degree-polygon-handler.ts +201 -0
- package/src/mode-handlers/draw-circle-by-bounding-box-handler.ts +39 -0
- package/src/mode-handlers/draw-circle-from-center-handler.ts +38 -0
- package/src/mode-handlers/draw-ellipse-by-bounding-box-handler.ts +41 -0
- package/src/mode-handlers/draw-ellipse-using-three-points-handler.ts +46 -0
- package/src/mode-handlers/draw-line-string-handler.ts +108 -0
- package/src/mode-handlers/draw-point-handler.ts +15 -0
- package/src/mode-handlers/draw-polygon-handler.ts +121 -0
- package/src/mode-handlers/draw-rectangle-handler.ts +28 -0
- package/src/mode-handlers/draw-rectangle-using-three-points-handler.ts +60 -0
- package/src/mode-handlers/duplicate-handler.ts +25 -0
- package/src/mode-handlers/elevation-handler.ts +88 -0
- package/src/mode-handlers/extrude-handler.ts +245 -0
- package/src/mode-handlers/mode-handler.ts +394 -0
- package/src/mode-handlers/modify-handler.ts +263 -0
- package/src/mode-handlers/rotate-handler.ts +107 -0
- package/src/mode-handlers/scale-handler.ts +105 -0
- package/src/mode-handlers/snappable-handler.ts +184 -0
- package/src/mode-handlers/split-polygon-handler.ts +177 -0
- package/src/mode-handlers/three-click-polygon-handler.ts +25 -0
- package/src/mode-handlers/translate-handler.ts +110 -0
- package/src/mode-handlers/two-click-polygon-handler.ts +25 -0
- package/src/mode-handlers/view-handler.ts +13 -0
- package/src/shaderlib/color/color.ts +56 -0
- package/src/shaderlib/outline/outline.ts +101 -0
- package/src/shaderlib/utils/utils.ts +33 -0
- package/src/translateFromCenter.ts +48 -0
- package/src/types.ts +39 -0
- package/src/utils.ts +185 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import lineIntersect from '@turf/line-intersect';
|
|
2
|
+
import { lineString as turfLineString } from '@turf/helpers';
|
|
3
|
+
import {
|
|
4
|
+
ClickEvent,
|
|
5
|
+
PointerMoveEvent,
|
|
6
|
+
ModeProps,
|
|
7
|
+
GuideFeatureCollection,
|
|
8
|
+
TentativeFeature,
|
|
9
|
+
GuideFeature,
|
|
10
|
+
} from './types';
|
|
11
|
+
import { Polygon, FeatureCollection } from '../geojson-types';
|
|
12
|
+
import { getPickedEditHandle } from './utils';
|
|
13
|
+
import { GeoJsonEditMode } from './geojson-edit-mode';
|
|
14
|
+
|
|
15
|
+
export class DrawPolygonMode extends GeoJsonEditMode {
|
|
16
|
+
createTentativeFeature(props: ModeProps<FeatureCollection>): TentativeFeature {
|
|
17
|
+
const { lastPointerMoveEvent } = props;
|
|
18
|
+
const clickSequence = this.getClickSequence();
|
|
19
|
+
|
|
20
|
+
const lastCoords = lastPointerMoveEvent ? [lastPointerMoveEvent.mapCoords] : [];
|
|
21
|
+
|
|
22
|
+
let tentativeFeature;
|
|
23
|
+
if (clickSequence.length === 1 || clickSequence.length === 2) {
|
|
24
|
+
tentativeFeature = {
|
|
25
|
+
type: 'Feature',
|
|
26
|
+
properties: {
|
|
27
|
+
guideType: 'tentative',
|
|
28
|
+
},
|
|
29
|
+
geometry: {
|
|
30
|
+
type: 'LineString',
|
|
31
|
+
coordinates: [...clickSequence, ...lastCoords],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
} else if (clickSequence.length > 2) {
|
|
35
|
+
tentativeFeature = {
|
|
36
|
+
type: 'Feature',
|
|
37
|
+
properties: {
|
|
38
|
+
guideType: 'tentative',
|
|
39
|
+
},
|
|
40
|
+
geometry: {
|
|
41
|
+
type: 'Polygon',
|
|
42
|
+
coordinates: [[...clickSequence, ...lastCoords, clickSequence[0]]],
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return tentativeFeature;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getGuides(props: ModeProps<FeatureCollection>): GuideFeatureCollection {
|
|
51
|
+
const clickSequence = this.getClickSequence();
|
|
52
|
+
|
|
53
|
+
const guides: GuideFeatureCollection = {
|
|
54
|
+
type: 'FeatureCollection',
|
|
55
|
+
features: [],
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const tentativeFeature = this.createTentativeFeature(props);
|
|
59
|
+
if (tentativeFeature) {
|
|
60
|
+
guides.features.push(tentativeFeature);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const editHandles: GuideFeature[] = clickSequence.map((clickedCoord, index) => ({
|
|
64
|
+
type: 'Feature',
|
|
65
|
+
properties: {
|
|
66
|
+
guideType: 'editHandle',
|
|
67
|
+
editHandleType: 'existing',
|
|
68
|
+
featureIndex: -1,
|
|
69
|
+
positionIndexes: [index],
|
|
70
|
+
},
|
|
71
|
+
geometry: {
|
|
72
|
+
type: 'Point',
|
|
73
|
+
coordinates: clickedCoord,
|
|
74
|
+
},
|
|
75
|
+
}));
|
|
76
|
+
|
|
77
|
+
guides.features.push(...editHandles);
|
|
78
|
+
|
|
79
|
+
return guides;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>) {
|
|
83
|
+
const { picks } = event;
|
|
84
|
+
const clickedEditHandle = getPickedEditHandle(picks);
|
|
85
|
+
const clickSequence = this.getClickSequence();
|
|
86
|
+
|
|
87
|
+
let overlappingLines = false;
|
|
88
|
+
if (clickSequence.length > 2 && props.modeConfig && props.modeConfig.preventOverlappingLines) {
|
|
89
|
+
const currentLine = turfLineString([
|
|
90
|
+
clickSequence[clickSequence.length - 1],
|
|
91
|
+
event.mapCoords,
|
|
92
|
+
]);
|
|
93
|
+
const otherLines = turfLineString([...clickSequence.slice(0, clickSequence.length - 1)]);
|
|
94
|
+
const intersectingPoints = lineIntersect(currentLine, otherLines);
|
|
95
|
+
if (intersectingPoints.features.length > 0) {
|
|
96
|
+
overlappingLines = true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let positionAdded = false;
|
|
101
|
+
if (!clickedEditHandle && !overlappingLines) {
|
|
102
|
+
// Don't add another point right next to an existing one
|
|
103
|
+
this.addClickSequence(event);
|
|
104
|
+
positionAdded = true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (
|
|
108
|
+
clickSequence.length > 2 &&
|
|
109
|
+
clickedEditHandle &&
|
|
110
|
+
Array.isArray(clickedEditHandle.properties.positionIndexes) &&
|
|
111
|
+
(clickedEditHandle.properties.positionIndexes[0] === 0 ||
|
|
112
|
+
clickedEditHandle.properties.positionIndexes[0] === clickSequence.length - 1)
|
|
113
|
+
) {
|
|
114
|
+
// They clicked the first or last point (or double-clicked), so complete the polygon
|
|
115
|
+
|
|
116
|
+
// Remove the hovered position
|
|
117
|
+
const polygonToAdd: Polygon = {
|
|
118
|
+
type: 'Polygon',
|
|
119
|
+
coordinates: [[...clickSequence, clickSequence[0]]],
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
this.resetClickSequence();
|
|
123
|
+
|
|
124
|
+
const editAction = this.getAddFeatureOrBooleanPolygonAction(polygonToAdd, props);
|
|
125
|
+
if (editAction) {
|
|
126
|
+
props.onEdit(editAction);
|
|
127
|
+
}
|
|
128
|
+
} else if (positionAdded) {
|
|
129
|
+
// new tentative point
|
|
130
|
+
props.onEdit({
|
|
131
|
+
// data is the same
|
|
132
|
+
updatedData: props.data,
|
|
133
|
+
editType: 'addTentativePosition',
|
|
134
|
+
editContext: {
|
|
135
|
+
position: event.mapCoords,
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection>) {
|
|
142
|
+
if (event.key === 'Enter') {
|
|
143
|
+
const clickSequence = this.getClickSequence();
|
|
144
|
+
if (clickSequence.length > 2) {
|
|
145
|
+
const polygonToAdd: Polygon = {
|
|
146
|
+
type: 'Polygon',
|
|
147
|
+
coordinates: [[...clickSequence, clickSequence[0]]],
|
|
148
|
+
};
|
|
149
|
+
this.resetClickSequence();
|
|
150
|
+
|
|
151
|
+
const editAction = this.getAddFeatureOrBooleanPolygonAction(polygonToAdd, props);
|
|
152
|
+
if (editAction) {
|
|
153
|
+
props.onEdit(editAction);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
} else if (event.key === 'Escape') {
|
|
157
|
+
this.resetClickSequence();
|
|
158
|
+
props.onEdit({
|
|
159
|
+
// Because the new drawing feature is dropped, so the data will keep as the same.
|
|
160
|
+
updatedData: props.data,
|
|
161
|
+
editType: 'cancelFeature',
|
|
162
|
+
editContext: {},
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
handlePointerMove(event: PointerMoveEvent, props: ModeProps<FeatureCollection>) {
|
|
168
|
+
props.onUpdateCursor('cell');
|
|
169
|
+
super.handlePointerMove(event, props);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import bboxPolygon from '@turf/bbox-polygon';
|
|
2
|
+
import { Position, Polygon, FeatureOf } from '../geojson-types';
|
|
3
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
4
|
+
|
|
5
|
+
export class DrawRectangleFromCenterMode extends TwoClickPolygonMode {
|
|
6
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): FeatureOf<Polygon> {
|
|
7
|
+
const longitude =
|
|
8
|
+
coord1[0] > coord2[0]
|
|
9
|
+
? coord1[0] + Math.abs(coord1[0] - coord2[0])
|
|
10
|
+
: coord1[0] - Math.abs(coord1[0] - coord2[0]);
|
|
11
|
+
const latitude =
|
|
12
|
+
coord1[1] > coord2[1]
|
|
13
|
+
? coord1[1] + Math.abs(coord1[1] - coord2[1])
|
|
14
|
+
: coord1[1] - Math.abs(coord1[1] - coord2[1]);
|
|
15
|
+
|
|
16
|
+
const rectangle = bboxPolygon([longitude, latitude, coord2[0], coord2[1]]);
|
|
17
|
+
rectangle.properties = rectangle.properties || {};
|
|
18
|
+
rectangle.properties.shape = 'Rectangle';
|
|
19
|
+
|
|
20
|
+
// @ts-expect-error turf typing too wide
|
|
21
|
+
return rectangle;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import bboxPolygon from '@turf/bbox-polygon';
|
|
2
|
+
import { Position, Polygon, FeatureOf } from '../geojson-types';
|
|
3
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
4
|
+
|
|
5
|
+
export class DrawRectangleMode extends TwoClickPolygonMode {
|
|
6
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): FeatureOf<Polygon> {
|
|
7
|
+
const rectangle = bboxPolygon([coord1[0], coord1[1], coord2[0], coord2[1]]);
|
|
8
|
+
rectangle.properties = rectangle.properties || {};
|
|
9
|
+
rectangle.properties.shape = 'Rectangle';
|
|
10
|
+
|
|
11
|
+
// @ts-expect-error turf typing too wide
|
|
12
|
+
return rectangle;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { generatePointsParallelToLinePoints } from './utils';
|
|
2
|
+
import { Position, Polygon, FeatureOf } from '../geojson-types';
|
|
3
|
+
import { ThreeClickPolygonMode } from './three-click-polygon-mode';
|
|
4
|
+
|
|
5
|
+
export class DrawRectangleUsingThreePointsMode extends ThreeClickPolygonMode {
|
|
6
|
+
getThreeClickPolygon(
|
|
7
|
+
coord1: Position,
|
|
8
|
+
coord2: Position,
|
|
9
|
+
coord3: Position,
|
|
10
|
+
modeConfig: any
|
|
11
|
+
): FeatureOf<Polygon> | null | undefined {
|
|
12
|
+
const [p3, p4] = generatePointsParallelToLinePoints(coord1, coord2, coord3);
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
type: 'Feature',
|
|
16
|
+
properties: {
|
|
17
|
+
shape: 'Rectangle',
|
|
18
|
+
},
|
|
19
|
+
geometry: {
|
|
20
|
+
type: 'Polygon',
|
|
21
|
+
coordinates: [
|
|
22
|
+
[
|
|
23
|
+
// Draw a polygon containing all the points of the LineString,
|
|
24
|
+
// then the points orthogonal to the lineString,
|
|
25
|
+
// then back to the starting position
|
|
26
|
+
coord1,
|
|
27
|
+
coord2,
|
|
28
|
+
p3,
|
|
29
|
+
p4,
|
|
30
|
+
coord1,
|
|
31
|
+
],
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import bboxPolygon from '@turf/bbox-polygon';
|
|
2
|
+
import turfDistance from '@turf/distance';
|
|
3
|
+
import turfAlong from '@turf/along';
|
|
4
|
+
import { point, lineString as turfLineString } from '@turf/helpers';
|
|
5
|
+
import { Position, Polygon, FeatureOf } from '../geojson-types';
|
|
6
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
7
|
+
|
|
8
|
+
export class DrawSquareFromCenterMode extends TwoClickPolygonMode {
|
|
9
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): FeatureOf<Polygon> {
|
|
10
|
+
// get the coordinates of the other two rectangle vertices
|
|
11
|
+
const coord3 = [coord2[0], coord1[1]];
|
|
12
|
+
const coord4 = [coord1[0], coord2[1]];
|
|
13
|
+
|
|
14
|
+
// determine the shortest distance to the origin, which will be the length of each square side
|
|
15
|
+
const distance1 = turfDistance(point(coord3), point(coord1));
|
|
16
|
+
const distance2 = turfDistance(point(coord4), point(coord1));
|
|
17
|
+
const shortestDistance = distance1 <= distance2 ? distance1 : distance2;
|
|
18
|
+
|
|
19
|
+
// determine which coordinate pair of the two is closest to the origin
|
|
20
|
+
const closestPoint = distance1 <= distance2 ? coord3 : coord4;
|
|
21
|
+
|
|
22
|
+
// create a linestring which will used to locate the second square vertex
|
|
23
|
+
const line = turfLineString([closestPoint, coord2]);
|
|
24
|
+
|
|
25
|
+
// get the coordinates of the second square vertex
|
|
26
|
+
const newPoint = turfAlong(line, shortestDistance);
|
|
27
|
+
const corner = newPoint.geometry.coordinates;
|
|
28
|
+
|
|
29
|
+
// determine the longitude and latitude values of the opposite corner
|
|
30
|
+
const longitude =
|
|
31
|
+
coord1[0] > corner[0]
|
|
32
|
+
? coord1[0] + Math.abs(coord1[0] - corner[0])
|
|
33
|
+
: coord1[0] - Math.abs(coord1[0] - corner[0]);
|
|
34
|
+
const latitude =
|
|
35
|
+
coord1[1] > corner[1]
|
|
36
|
+
? coord1[1] + Math.abs(coord1[1] - corner[1])
|
|
37
|
+
: coord1[1] - Math.abs(coord1[1] - corner[1]);
|
|
38
|
+
|
|
39
|
+
const square = bboxPolygon([longitude, latitude, corner[0], corner[1]]);
|
|
40
|
+
square.properties = square.properties || {};
|
|
41
|
+
square.properties.shape = 'Square';
|
|
42
|
+
|
|
43
|
+
// @ts-expect-error turf typing too wide
|
|
44
|
+
return square;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import bboxPolygon from '@turf/bbox-polygon';
|
|
2
|
+
import turfDistance from '@turf/distance';
|
|
3
|
+
import turfAlong from '@turf/along';
|
|
4
|
+
import { point, lineString as turfLineString } from '@turf/helpers';
|
|
5
|
+
import { Position, Polygon, FeatureOf } from '../geojson-types';
|
|
6
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
7
|
+
|
|
8
|
+
export class DrawSquareMode extends TwoClickPolygonMode {
|
|
9
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): FeatureOf<Polygon> {
|
|
10
|
+
// get the coordinates of the other two rectangle vertices
|
|
11
|
+
const coord3 = [coord2[0], coord1[1]];
|
|
12
|
+
const coord4 = [coord1[0], coord2[1]];
|
|
13
|
+
|
|
14
|
+
// determine the shortest distance to the origin, which will be the length of each square side
|
|
15
|
+
const distance1 = turfDistance(point(coord3), point(coord1));
|
|
16
|
+
const distance2 = turfDistance(point(coord4), point(coord1));
|
|
17
|
+
const shortestDistance = distance1 <= distance2 ? distance1 : distance2;
|
|
18
|
+
|
|
19
|
+
// determine which coordinate pair of the two is closest to the origin
|
|
20
|
+
const closestPoint = distance1 <= distance2 ? coord3 : coord4;
|
|
21
|
+
|
|
22
|
+
// create a linestring which will used to locate the second square vertex
|
|
23
|
+
const line = turfLineString([closestPoint, coord2]);
|
|
24
|
+
|
|
25
|
+
// get the coordinates of the second square vertex
|
|
26
|
+
const newPoint = turfAlong(line, shortestDistance);
|
|
27
|
+
const corner = newPoint.geometry.coordinates;
|
|
28
|
+
|
|
29
|
+
const square = bboxPolygon([coord1[0], coord1[1], corner[0], corner[1]]);
|
|
30
|
+
square.properties = square.properties || {};
|
|
31
|
+
square.properties.shape = 'Square';
|
|
32
|
+
|
|
33
|
+
// @ts-expect-error turf types too wide
|
|
34
|
+
return square;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { StartDraggingEvent, ModeProps } from './types';
|
|
2
|
+
import { FeatureCollection } from '../geojson-types';
|
|
3
|
+
import { TranslateMode } from './translate-mode';
|
|
4
|
+
|
|
5
|
+
export class DuplicateMode extends TranslateMode {
|
|
6
|
+
handleStartDragging(event: StartDraggingEvent, props: ModeProps<FeatureCollection>) {
|
|
7
|
+
super.handleStartDragging(event, props);
|
|
8
|
+
|
|
9
|
+
if (this._geometryBeforeTranslate) {
|
|
10
|
+
props.onEdit(this.getAddManyFeaturesAction(this._geometryBeforeTranslate, props.data));
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
updateCursor(props: ModeProps<FeatureCollection>) {
|
|
15
|
+
if (this._isTranslatable) {
|
|
16
|
+
props.onUpdateCursor('copy');
|
|
17
|
+
} else {
|
|
18
|
+
props.onUpdateCursor(null);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* istanbul ignore file */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ClickEvent,
|
|
5
|
+
PointerMoveEvent,
|
|
6
|
+
StartDraggingEvent,
|
|
7
|
+
StopDraggingEvent,
|
|
8
|
+
DraggingEvent,
|
|
9
|
+
Tooltip,
|
|
10
|
+
ModeProps,
|
|
11
|
+
} from './types';
|
|
12
|
+
|
|
13
|
+
export interface EditMode<TData, TGuides> {
|
|
14
|
+
// Called when the pointer went down and up without dragging regardless of whether something was picked
|
|
15
|
+
handleClick(event: ClickEvent, props: ModeProps<TData>): void;
|
|
16
|
+
// Called when the pointer moved, regardless of whether the pointer is down, up, and whether something was picked
|
|
17
|
+
handlePointerMove(event: PointerMoveEvent, props: ModeProps<TData>): void;
|
|
18
|
+
// Called when the pointer went down on something rendered by this layer and the pointer started to move
|
|
19
|
+
handleStartDragging(event: StartDraggingEvent, props: ModeProps<TData>): void;
|
|
20
|
+
// Called when the pointer went down on something rendered by this layer, the pointer moved, and now the pointer is up
|
|
21
|
+
handleStopDragging(event: StopDraggingEvent, props: ModeProps<TData>): void;
|
|
22
|
+
// Called when the pointer went down and is moving, regardless of whether something was picked
|
|
23
|
+
handleDragging(event: DraggingEvent, props: ModeProps<TData>): void;
|
|
24
|
+
// Called when the key is up;
|
|
25
|
+
handleKeyUp(event: KeyboardEvent, props: ModeProps<TData>): void;
|
|
26
|
+
// Return features that can be used as a guide for editing the data
|
|
27
|
+
getGuides(props: ModeProps<TData>): TGuides | undefined;
|
|
28
|
+
// Return tooltips
|
|
29
|
+
getTooltips(props: ModeProps<TData>): Tooltip[];
|
|
30
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { ModeProps, PointerMoveEvent, StopDraggingEvent } from './types';
|
|
2
|
+
import { Position, FeatureCollection } from '../geojson-types';
|
|
3
|
+
import { getPickedEditHandle } from './utils';
|
|
4
|
+
import { ModifyMode } from './modify-mode';
|
|
5
|
+
|
|
6
|
+
function defaultCalculateElevationChange({
|
|
7
|
+
pointerDownScreenCoords,
|
|
8
|
+
screenCoords,
|
|
9
|
+
}: {
|
|
10
|
+
pointerDownScreenCoords: Position;
|
|
11
|
+
screenCoords: Position;
|
|
12
|
+
}) {
|
|
13
|
+
return 10 * (pointerDownScreenCoords[1] - screenCoords[1]);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class ElevationMode extends ModifyMode {
|
|
17
|
+
makeElevatedEvent(
|
|
18
|
+
event: PointerMoveEvent | StopDraggingEvent,
|
|
19
|
+
position: Position,
|
|
20
|
+
props: ModeProps<FeatureCollection>
|
|
21
|
+
): Record<string, any> {
|
|
22
|
+
const {
|
|
23
|
+
minElevation = 0,
|
|
24
|
+
maxElevation = 20000,
|
|
25
|
+
calculateElevationChange = defaultCalculateElevationChange,
|
|
26
|
+
} = props.modeConfig || {};
|
|
27
|
+
|
|
28
|
+
if (!event.pointerDownScreenCoords) {
|
|
29
|
+
return event;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// $FlowFixMe - really, I know it has something at index 2
|
|
33
|
+
let elevation = position.length === 3 ? position[2] : 0;
|
|
34
|
+
|
|
35
|
+
// calculateElevationChange is configurable because (at this time) modes are not aware of the viewport
|
|
36
|
+
elevation += calculateElevationChange({
|
|
37
|
+
pointerDownScreenCoords: event.pointerDownScreenCoords,
|
|
38
|
+
screenCoords: event.screenCoords,
|
|
39
|
+
});
|
|
40
|
+
elevation = Math.min(elevation, maxElevation);
|
|
41
|
+
elevation = Math.max(elevation, minElevation);
|
|
42
|
+
|
|
43
|
+
return Object.assign({}, event, {
|
|
44
|
+
mapCoords: [position[0], position[1], elevation],
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
handlePointerMove(event: PointerMoveEvent, props: ModeProps<FeatureCollection>) {
|
|
49
|
+
const editHandle = getPickedEditHandle(event.pointerDownPicks);
|
|
50
|
+
const position = editHandle ? editHandle.geometry.coordinates : event.mapCoords;
|
|
51
|
+
// @ts-expect-error return type too wide
|
|
52
|
+
super.handlePointerMove(this.makeElevatedEvent(event, position, props), props);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
handleStopDragging(event: StopDraggingEvent, props: ModeProps<FeatureCollection>) {
|
|
56
|
+
const editHandle = getPickedEditHandle(event.picks);
|
|
57
|
+
const position = editHandle ? editHandle.geometry.coordinates : event.mapCoords;
|
|
58
|
+
// @ts-expect-error return type too wide
|
|
59
|
+
super.handleStopDragging(this.makeElevatedEvent(event, position, props), props);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getCursor(event: PointerMoveEvent): string | null | undefined {
|
|
63
|
+
let cursor = super.getCursor(event);
|
|
64
|
+
if (cursor === 'cell') {
|
|
65
|
+
cursor = 'ns-resize';
|
|
66
|
+
}
|
|
67
|
+
return cursor;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static calculateElevationChangeWithViewport(
|
|
71
|
+
viewport: any,
|
|
72
|
+
{
|
|
73
|
+
pointerDownScreenCoords,
|
|
74
|
+
screenCoords,
|
|
75
|
+
}: {
|
|
76
|
+
pointerDownScreenCoords: Position;
|
|
77
|
+
screenCoords: Position;
|
|
78
|
+
}
|
|
79
|
+
): number {
|
|
80
|
+
// Source: https://gis.stackexchange.com/a/127949/111804
|
|
81
|
+
const metersPerPixel =
|
|
82
|
+
(156543.03392 * Math.cos((viewport.latitude * Math.PI) / 180)) / Math.pow(2, viewport.zoom);
|
|
83
|
+
|
|
84
|
+
return (metersPerPixel * (pointerDownScreenCoords[1] - screenCoords[1])) / 2;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Position, LineString, FeatureCollection } from '../geojson-types';
|
|
2
|
+
import { ClickEvent, PointerMoveEvent, ModeProps, GuideFeatureCollection } from './types';
|
|
3
|
+
import { GeoJsonEditMode } from './geojson-edit-mode';
|
|
4
|
+
import { ImmutableFeatureCollection } from './immutable-feature-collection';
|
|
5
|
+
|
|
6
|
+
export class ExtendLineStringMode extends GeoJsonEditMode {
|
|
7
|
+
getSingleSelectedLineString(props: ModeProps<FeatureCollection>): LineString | null | undefined {
|
|
8
|
+
const selectedGeometry = this.getSelectedGeometry(props);
|
|
9
|
+
|
|
10
|
+
if (selectedGeometry && selectedGeometry.type === 'LineString') {
|
|
11
|
+
return selectedGeometry;
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>) {
|
|
17
|
+
const { selectedIndexes } = props;
|
|
18
|
+
const selectedLineString = this.getSingleSelectedLineString(props);
|
|
19
|
+
|
|
20
|
+
if (!selectedLineString) {
|
|
21
|
+
console.warn(`ExtendLineStringMode only supported for single LineString selection`); // eslint-disable-line
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Extend the LineString
|
|
26
|
+
let positionIndexes = [selectedLineString.coordinates.length];
|
|
27
|
+
|
|
28
|
+
const modeConfig = props.modeConfig;
|
|
29
|
+
if (modeConfig && modeConfig.drawAtFront) {
|
|
30
|
+
positionIndexes = [0];
|
|
31
|
+
}
|
|
32
|
+
const featureIndex = selectedIndexes[0];
|
|
33
|
+
const updatedData = new ImmutableFeatureCollection(props.data)
|
|
34
|
+
.addPosition(featureIndex, positionIndexes, event.mapCoords)
|
|
35
|
+
.getObject();
|
|
36
|
+
|
|
37
|
+
props.onEdit({
|
|
38
|
+
updatedData,
|
|
39
|
+
editType: 'addPosition',
|
|
40
|
+
editContext: {
|
|
41
|
+
featureIndexes: [featureIndex],
|
|
42
|
+
positionIndexes,
|
|
43
|
+
position: event.mapCoords,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getGuides(props: ModeProps<FeatureCollection>): GuideFeatureCollection {
|
|
49
|
+
const guides: GuideFeatureCollection = {
|
|
50
|
+
type: 'FeatureCollection',
|
|
51
|
+
features: [],
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const selectedLineString = this.getSingleSelectedLineString(props);
|
|
55
|
+
if (!selectedLineString) {
|
|
56
|
+
return guides;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const mapCoords = props.lastPointerMoveEvent && props.lastPointerMoveEvent.mapCoords;
|
|
60
|
+
|
|
61
|
+
// Draw an extension line starting from one end of the selected LineString to the cursor
|
|
62
|
+
let startPosition: Position | null | undefined = null;
|
|
63
|
+
const { modeConfig } = props;
|
|
64
|
+
if (modeConfig && modeConfig.drawAtFront) {
|
|
65
|
+
startPosition = selectedLineString.coordinates[0];
|
|
66
|
+
} else {
|
|
67
|
+
startPosition = selectedLineString.coordinates[selectedLineString.coordinates.length - 1];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
guides.features.push({
|
|
71
|
+
type: 'Feature',
|
|
72
|
+
properties: {
|
|
73
|
+
guideType: 'tentative',
|
|
74
|
+
},
|
|
75
|
+
geometry: {
|
|
76
|
+
type: 'LineString',
|
|
77
|
+
coordinates: [startPosition, mapCoords],
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return guides;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
handlePointerMove(event: PointerMoveEvent, props: ModeProps<FeatureCollection>) {
|
|
85
|
+
props.onUpdateCursor('cell');
|
|
86
|
+
}
|
|
87
|
+
}
|