@deck.gl-community/editable-layers 9.2.0-beta.8 → 9.2.5
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.map +1 -1
- package/dist/edit-modes/draw-90degree-polygon-mode.js.map +1 -1
- 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-polygon-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-polygon-mode.js +48 -52
- package/dist/edit-modes/draw-polygon-mode.js.map +1 -1
- package/dist/edit-modes/draw-square-mode.d.ts.map +1 -1
- package/dist/edit-modes/draw-square-mode.js.map +1 -1
- 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/geojson-edit-mode.d.ts.map +1 -1
- package/dist/edit-modes/geojson-edit-mode.js.map +1 -1
- package/dist/edit-modes/modify-mode.d.ts.map +1 -1
- package/dist/edit-modes/modify-mode.js +23 -19
- package/dist/edit-modes/modify-mode.js.map +1 -1
- package/dist/edit-modes/resize-circle-mode.d.ts.map +1 -1
- package/dist/edit-modes/resize-circle-mode.js.map +1 -1
- package/dist/edit-modes/rotate-mode.d.ts.map +1 -1
- package/dist/edit-modes/rotate-mode.js.map +1 -1
- package/dist/edit-modes/scale-mode.d.ts.map +1 -1
- package/dist/edit-modes/scale-mode.js.map +1 -1
- 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.map +1 -1
- package/dist/edit-modes/split-polygon-mode.js.map +1 -1
- package/dist/edit-modes/three-click-polygon-mode.d.ts.map +1 -1
- package/dist/edit-modes/three-click-polygon-mode.js +14 -18
- package/dist/edit-modes/three-click-polygon-mode.js.map +1 -1
- package/dist/edit-modes/translate-mode.d.ts.map +1 -1
- package/dist/edit-modes/translate-mode.js +2 -2
- package/dist/edit-modes/translate-mode.js.map +1 -1
- 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/utils.js +1 -1
- package/dist/edit-modes/utils.js.map +1 -1
- package/dist/editable-layers/editable-geojson-layer.d.ts.map +1 -1
- package/dist/editable-layers/editable-geojson-layer.js +20 -4
- package/dist/editable-layers/editable-geojson-layer.js.map +1 -1
- package/dist/index.cjs +246 -55
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mode-handlers/mode-handler.d.ts.map +1 -1
- package/dist/mode-handlers/mode-handler.js +1 -1
- package/dist/mode-handlers/mode-handler.js.map +1 -1
- package/dist/mode-handlers/rotate-handler.d.ts.map +1 -1
- package/dist/mode-handlers/rotate-handler.js.map +1 -1
- package/dist/mode-handlers/scale-handler.d.ts.map +1 -1
- package/dist/mode-handlers/scale-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.map +1 -1
- package/dist/utils/geojson-types.d.ts.map +1 -1
- 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.js +1 -1
- package/dist/utils/utils.js.map +1 -1
- package/dist/widgets/edit-mode-tray-widget.d.ts +1 -0
- package/dist/widgets/edit-mode-tray-widget.d.ts.map +1 -1
- package/dist/widgets/edit-mode-tray-widget.js +1 -0
- package/dist/widgets/edit-mode-tray-widget.js.map +1 -1
- package/dist/widgets/editor-toolbar-widget.d.ts +40 -0
- package/dist/widgets/editor-toolbar-widget.d.ts.map +1 -0
- package/dist/widgets/editor-toolbar-widget.js +170 -0
- package/dist/widgets/editor-toolbar-widget.js.map +1 -0
- package/package.json +16 -12
- package/src/edit-modes/draw-90degree-polygon-mode.ts +7 -1
- package/src/edit-modes/draw-line-string-mode.ts +6 -1
- package/src/edit-modes/draw-polygon-mode.ts +96 -117
- package/src/edit-modes/draw-square-mode.ts +0 -1
- package/src/edit-modes/extend-line-string-mode.ts +9 -2
- package/src/edit-modes/geojson-edit-mode.ts +15 -3
- package/src/edit-modes/immutable-feature-collection.ts +1 -1
- package/src/edit-modes/modify-mode.ts +33 -21
- package/src/edit-modes/resize-circle-mode.ts +8 -3
- package/src/edit-modes/rotate-mode.ts +3 -8
- package/src/edit-modes/scale-mode.ts +5 -6
- package/src/edit-modes/snappable-mode.ts +6 -1
- package/src/edit-modes/split-polygon-mode.ts +9 -3
- package/src/edit-modes/three-click-polygon-mode.ts +28 -31
- package/src/edit-modes/translate-mode.ts +8 -3
- package/src/edit-modes/two-click-polygon-mode.ts +7 -1
- package/src/edit-modes/utils.ts +1 -1
- package/src/editable-layers/editable-geojson-layer.ts +20 -4
- package/src/index.ts +3 -0
- package/src/mode-handlers/mode-handler.ts +21 -6
- package/src/mode-handlers/rotate-handler.ts +1 -4
- package/src/mode-handlers/scale-handler.ts +3 -7
- package/src/mode-handlers/split-polygon-handler.ts +3 -1
- package/src/utils/geojson-types.ts +22 -6
- package/src/utils/translate-from-center.ts +11 -24
- package/src/utils/utils.ts +1 -1
- package/src/widgets/edit-mode-tray-widget.tsx +2 -6
- package/src/widgets/editor-toolbar-widget.tsx +348 -0
|
@@ -14,7 +14,13 @@ import {
|
|
|
14
14
|
getPickedEditHandle,
|
|
15
15
|
NearestPointType
|
|
16
16
|
} from './utils';
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
LineString,
|
|
19
|
+
Point,
|
|
20
|
+
FeatureCollection,
|
|
21
|
+
Feature,
|
|
22
|
+
SimpleFeatureCollection
|
|
23
|
+
} from '../utils/geojson-types';
|
|
18
24
|
import {Viewport} from '../utils/types';
|
|
19
25
|
import {
|
|
20
26
|
ModeProps,
|
|
@@ -24,7 +30,7 @@ import {
|
|
|
24
30
|
DraggingEvent,
|
|
25
31
|
EditHandleFeature,
|
|
26
32
|
GuideFeatureCollection,
|
|
27
|
-
GuideFeature
|
|
33
|
+
GuideFeature
|
|
28
34
|
} from './types';
|
|
29
35
|
import {GeoJsonEditMode} from './geojson-edit-mode';
|
|
30
36
|
import {ImmutableFeatureCollection} from './immutable-feature-collection';
|
|
@@ -69,7 +75,6 @@ export class ResizeCircleMode extends GeoJsonEditMode {
|
|
|
69
75
|
(lineString, prefix) => {
|
|
70
76
|
const lineStringFeature = toLineString(lineString);
|
|
71
77
|
const candidateIntermediatePoint = this.getNearestPoint(
|
|
72
|
-
|
|
73
78
|
lineStringFeature,
|
|
74
79
|
referencePoint,
|
|
75
80
|
props.modeConfig && props.modeConfig.viewport
|
|
@@ -172,14 +172,9 @@ export class RotateMode extends GeoJsonEditMode {
|
|
|
172
172
|
}
|
|
173
173
|
const centroid = turfCentroid(this._geometryBeingRotated);
|
|
174
174
|
const angle = getRotationAngle(centroid.geometry.coordinates, startDragPoint, currentPoint);
|
|
175
|
-
const rotatedFeatures = turfTransformRotate(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
angle,
|
|
179
|
-
{
|
|
180
|
-
pivot: centroid
|
|
181
|
-
}
|
|
182
|
-
);
|
|
175
|
+
const rotatedFeatures = turfTransformRotate(this._geometryBeingRotated, angle, {
|
|
176
|
+
pivot: centroid
|
|
177
|
+
});
|
|
183
178
|
|
|
184
179
|
let updatedData = new ImmutableFeatureCollection(props.data);
|
|
185
180
|
|
|
@@ -64,7 +64,10 @@ export class ScaleMode extends GeoJsonEditMode {
|
|
|
64
64
|
);
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
_getUpdatedData = (
|
|
67
|
+
_getUpdatedData = (
|
|
68
|
+
props: ModeProps<SimpleFeatureCollection>,
|
|
69
|
+
editedData: SimpleFeatureCollection
|
|
70
|
+
) => {
|
|
68
71
|
let updatedData = new ImmutableFeatureCollection(props.data);
|
|
69
72
|
const selectedIndexes = props.selectedIndexes;
|
|
70
73
|
for (let i = 0; i < selectedIndexes.length; i++) {
|
|
@@ -92,11 +95,7 @@ export class ScaleMode extends GeoJsonEditMode {
|
|
|
92
95
|
|
|
93
96
|
const scaleFactor = getScaleFactor(origin, startDragPoint, currentPoint);
|
|
94
97
|
|
|
95
|
-
const scaledFeatures = turfTransformScale(
|
|
96
|
-
this._geometryBeingScaled,
|
|
97
|
-
scaleFactor,
|
|
98
|
-
{origin}
|
|
99
|
-
);
|
|
98
|
+
const scaledFeatures = turfTransformScale(this._geometryBeingScaled, scaleFactor, {origin});
|
|
100
99
|
|
|
101
100
|
return {
|
|
102
101
|
updatedData: this._getUpdatedData(props, scaledFeatures),
|
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Position,
|
|
7
|
+
FeatureCollection,
|
|
8
|
+
SimpleFeatureCollection,
|
|
9
|
+
SimpleFeature
|
|
10
|
+
} from '../utils/geojson-types';
|
|
6
11
|
import {
|
|
7
12
|
PointerMoveEvent,
|
|
8
13
|
StartDraggingEvent,
|
|
@@ -26,7 +26,11 @@ import {GeoJsonEditMode, GeoJsonEditAction} from './geojson-edit-mode';
|
|
|
26
26
|
import {ImmutableFeatureCollection} from './immutable-feature-collection';
|
|
27
27
|
|
|
28
28
|
export class SplitPolygonMode extends GeoJsonEditMode {
|
|
29
|
-
calculateMapCoords(
|
|
29
|
+
calculateMapCoords(
|
|
30
|
+
clickSequence: any,
|
|
31
|
+
mapCoords: any,
|
|
32
|
+
props: ModeProps<SimpleFeatureCollection>
|
|
33
|
+
) {
|
|
30
34
|
const modeConfig = props.modeConfig;
|
|
31
35
|
if (!modeConfig || !modeConfig.lock90Degree || !clickSequence.length) {
|
|
32
36
|
return mapCoords;
|
|
@@ -53,7 +57,7 @@ export class SplitPolygonMode extends GeoJsonEditMode {
|
|
|
53
57
|
if (closestPoint) {
|
|
54
58
|
// closest point is used as 90degree entry to the polygon
|
|
55
59
|
const lastBearing = turfBearing(firstPoint, closestPoint);
|
|
56
|
-
const currentDistance = turfDistance(firstPoint, mapCoords, {
|
|
60
|
+
const currentDistance = turfDistance(firstPoint, mapCoords, {units: 'meters'});
|
|
57
61
|
return turfDestination(firstPoint, currentDistance, lastBearing, {
|
|
58
62
|
units: 'meters'
|
|
59
63
|
}).geometry.coordinates;
|
|
@@ -161,7 +165,9 @@ export class SplitPolygonMode extends GeoJsonEditMode {
|
|
|
161
165
|
}
|
|
162
166
|
|
|
163
167
|
const buffer = turfBuffer(tentativeFeature, gap, {units});
|
|
164
|
-
const updatedGeometry = turfDifference(
|
|
168
|
+
const updatedGeometry = turfDifference(
|
|
169
|
+
featureCollection([turfFeature(selectedGeometry as PolygonGeometry), buffer])
|
|
170
|
+
);
|
|
165
171
|
if (!updatedGeometry) {
|
|
166
172
|
// eslint-disable-next-line no-console,no-undef
|
|
167
173
|
console.warn('Canceling edit. Split Polygon erased');
|
|
@@ -9,26 +9,31 @@ import {
|
|
|
9
9
|
GuideFeatureCollection,
|
|
10
10
|
TentativeFeature
|
|
11
11
|
} from './types';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
Position,
|
|
14
|
+
Polygon,
|
|
15
|
+
Feature,
|
|
16
|
+
FeatureCollection,
|
|
17
|
+
SimpleFeatureCollection
|
|
18
|
+
} from '../utils/geojson-types';
|
|
13
19
|
import {GeoJsonEditMode} from './geojson-edit-mode';
|
|
14
|
-
import omit from 'lodash.omit';
|
|
15
20
|
|
|
16
21
|
export class ThreeClickPolygonMode extends GeoJsonEditMode {
|
|
17
22
|
handleClick(event: ClickEvent, props: ModeProps<SimpleFeatureCollection>) {
|
|
18
23
|
this.addClickSequence(event);
|
|
24
|
+
|
|
25
|
+
const {modeConfig} = props;
|
|
19
26
|
const clickSequence = this.getClickSequence();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const editAction = this.getAddFeatureOrBooleanPolygonAction(
|
|
28
|
-
tentativeFeature.geometry,
|
|
29
|
-
props,
|
|
30
|
-
omit(tentativeFeature.properties, 'guideType')
|
|
27
|
+
|
|
28
|
+
if (clickSequence.length > 2) {
|
|
29
|
+
const {geometry, properties} = this.getThreeClickPolygon(
|
|
30
|
+
clickSequence[0],
|
|
31
|
+
clickSequence[1],
|
|
32
|
+
clickSequence[2],
|
|
33
|
+
modeConfig
|
|
31
34
|
);
|
|
35
|
+
|
|
36
|
+
const editAction = this.getAddFeatureOrBooleanPolygonAction(geometry, props, properties);
|
|
32
37
|
this.resetClickSequence();
|
|
33
38
|
|
|
34
39
|
if (editAction) {
|
|
@@ -46,14 +51,12 @@ export class ThreeClickPolygonMode extends GeoJsonEditMode {
|
|
|
46
51
|
features: []
|
|
47
52
|
};
|
|
48
53
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const hoveredCoord = lastPointerMoveEvent.mapCoords;
|
|
54
|
+
const coords = [
|
|
55
|
+
...clickSequence,
|
|
56
|
+
...(lastPointerMoveEvent ? [lastPointerMoveEvent.mapCoords] : [])
|
|
57
|
+
];
|
|
55
58
|
|
|
56
|
-
if (
|
|
59
|
+
if (coords.length === 2) {
|
|
57
60
|
guides.features.push({
|
|
58
61
|
type: 'Feature',
|
|
59
62
|
properties: {
|
|
@@ -61,24 +64,18 @@ export class ThreeClickPolygonMode extends GeoJsonEditMode {
|
|
|
61
64
|
},
|
|
62
65
|
geometry: {
|
|
63
66
|
type: 'LineString',
|
|
64
|
-
coordinates: [
|
|
67
|
+
coordinates: [coords[0], coords[1]]
|
|
65
68
|
}
|
|
66
69
|
});
|
|
67
|
-
} else {
|
|
68
|
-
const polygon = this.getThreeClickPolygon(
|
|
69
|
-
clickSequence[0],
|
|
70
|
-
clickSequence[1],
|
|
71
|
-
hoveredCoord,
|
|
72
|
-
modeConfig
|
|
73
|
-
);
|
|
70
|
+
} else if (coords.length > 2) {
|
|
71
|
+
const polygon = this.getThreeClickPolygon(coords[0], coords[1], coords[2], modeConfig);
|
|
74
72
|
if (polygon) {
|
|
75
73
|
guides.features.push({
|
|
76
|
-
|
|
74
|
+
...polygon,
|
|
77
75
|
properties: {
|
|
78
76
|
...polygon.properties,
|
|
79
77
|
guideType: 'tentative'
|
|
80
|
-
}
|
|
81
|
-
geometry: polygon.geometry
|
|
78
|
+
}
|
|
82
79
|
});
|
|
83
80
|
}
|
|
84
81
|
}
|
|
@@ -6,8 +6,13 @@ import turfBearing from '@turf/bearing';
|
|
|
6
6
|
import turfDistance from '@turf/distance';
|
|
7
7
|
import clone from '@turf/clone';
|
|
8
8
|
import {point} from '@turf/helpers';
|
|
9
|
-
import {WebMercatorViewport} from '
|
|
10
|
-
import {
|
|
9
|
+
import {WebMercatorViewport} from '@math.gl/web-mercator';
|
|
10
|
+
import {
|
|
11
|
+
FeatureCollection,
|
|
12
|
+
Position,
|
|
13
|
+
SimpleGeometry,
|
|
14
|
+
SimpleFeatureCollection
|
|
15
|
+
} from '../utils/geojson-types';
|
|
11
16
|
import {
|
|
12
17
|
PointerMoveEvent,
|
|
13
18
|
StartDraggingEvent,
|
|
@@ -132,7 +137,7 @@ export class TranslateMode extends GeoJsonEditMode {
|
|
|
132
137
|
|
|
133
138
|
updatedData = updatedData.replaceGeometry(selectedIndex, {
|
|
134
139
|
type: feature.geometry.type,
|
|
135
|
-
coordinates
|
|
140
|
+
coordinates
|
|
136
141
|
} as SimpleGeometry);
|
|
137
142
|
}
|
|
138
143
|
}
|
|
@@ -11,7 +11,13 @@ import {
|
|
|
11
11
|
GuideFeatureCollection,
|
|
12
12
|
TentativeFeature
|
|
13
13
|
} from './types';
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
Polygon,
|
|
16
|
+
FeatureCollection,
|
|
17
|
+
Feature,
|
|
18
|
+
Position,
|
|
19
|
+
SimpleFeatureCollection
|
|
20
|
+
} from '../utils/geojson-types';
|
|
15
21
|
import {GeoJsonEditMode} from './geojson-edit-mode';
|
|
16
22
|
import omit from 'lodash.omit';
|
|
17
23
|
|
package/src/edit-modes/utils.ts
CHANGED
|
@@ -10,7 +10,7 @@ import pointToLineDistance from '@turf/point-to-line-distance';
|
|
|
10
10
|
import {flattenEach} from '@turf/meta';
|
|
11
11
|
import {point} from '@turf/helpers';
|
|
12
12
|
import {getCoords} from '@turf/invariant';
|
|
13
|
-
import {WebMercatorViewport} from '
|
|
13
|
+
import {WebMercatorViewport} from '@math.gl/web-mercator';
|
|
14
14
|
import {Viewport, Pick, EditHandleFeature, EditHandleType, StartDraggingEvent} from './types';
|
|
15
15
|
import {
|
|
16
16
|
SimpleGeometry,
|
|
@@ -333,10 +333,26 @@ export class EditableGeoJsonLayer extends EditableLayer<
|
|
|
333
333
|
},
|
|
334
334
|
|
|
335
335
|
updateTriggers: {
|
|
336
|
-
getLineColor: [
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
336
|
+
getLineColor: [
|
|
337
|
+
this.props.updateTriggers.getLineColor,
|
|
338
|
+
this.props.selectedFeatureIndexes,
|
|
339
|
+
this.props.mode
|
|
340
|
+
],
|
|
341
|
+
getFillColor: [
|
|
342
|
+
this.props.updateTriggers.getFillColor,
|
|
343
|
+
this.props.selectedFeatureIndexes,
|
|
344
|
+
this.props.mode
|
|
345
|
+
],
|
|
346
|
+
getPointRadius: [
|
|
347
|
+
this.props.updateTriggers.getPointRadius,
|
|
348
|
+
this.props.selectedFeatureIndexes,
|
|
349
|
+
this.props.mode
|
|
350
|
+
],
|
|
351
|
+
getLineWidth: [
|
|
352
|
+
this.props.updateTriggers.getLineWidth,
|
|
353
|
+
this.props.selectedFeatureIndexes,
|
|
354
|
+
this.props.mode
|
|
355
|
+
]
|
|
340
356
|
}
|
|
341
357
|
});
|
|
342
358
|
|
package/src/index.ts
CHANGED
|
@@ -22,6 +22,9 @@ export type {
|
|
|
22
22
|
EditModeTrayWidgetSelectEvent
|
|
23
23
|
} from './widgets/edit-mode-tray-widget';
|
|
24
24
|
|
|
25
|
+
export {EditorToolbarWidget} from './widgets/editor-toolbar-widget';
|
|
26
|
+
export type {EditorToolbarWidgetProps, BooleanOperation} from './widgets/editor-toolbar-widget';
|
|
27
|
+
|
|
25
28
|
// Layers move to deck.gl-community/layers?
|
|
26
29
|
export {JunctionScatterplotLayer} from './editable-layers/junction-scatterplot-layer';
|
|
27
30
|
|
|
@@ -9,7 +9,16 @@ import turfUnion from '@turf/union';
|
|
|
9
9
|
import turfDifference from '@turf/difference';
|
|
10
10
|
import turfIntersect from '@turf/intersect';
|
|
11
11
|
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
FeatureCollection,
|
|
14
|
+
Feature,
|
|
15
|
+
Polygon,
|
|
16
|
+
SimpleGeometry,
|
|
17
|
+
Position,
|
|
18
|
+
PolygonGeometry,
|
|
19
|
+
SimpleFeatureCollection,
|
|
20
|
+
SimpleFeature
|
|
21
|
+
} from '../utils/geojson-types';
|
|
13
22
|
|
|
14
23
|
import {
|
|
15
24
|
ClickEvent,
|
|
@@ -74,7 +83,7 @@ export class ModeHandler {
|
|
|
74
83
|
}
|
|
75
84
|
|
|
76
85
|
getSelectedFeaturesAsFeatureCollection(): SimpleFeatureCollection {
|
|
77
|
-
const {
|
|
86
|
+
const {features} = this.featureCollection.getObject();
|
|
78
87
|
const selectedFeatures = this.getSelectedFeatureIndexes().map(
|
|
79
88
|
(selectedIndex) => features[selectedIndex]
|
|
80
89
|
);
|
|
@@ -222,16 +231,22 @@ export class ModeHandler {
|
|
|
222
231
|
const feature: Feature<Polygon> = {
|
|
223
232
|
type: 'Feature',
|
|
224
233
|
geometry,
|
|
225
|
-
properties: {}
|
|
234
|
+
properties: {}
|
|
226
235
|
};
|
|
227
236
|
|
|
228
237
|
let updatedGeometry;
|
|
229
238
|
if (modeConfig.booleanOperation === 'union') {
|
|
230
|
-
updatedGeometry = turfUnion(
|
|
239
|
+
updatedGeometry = turfUnion(
|
|
240
|
+
turfFeatureCollection([selectedFeature as Feature<PolygonGeometry>, feature])
|
|
241
|
+
);
|
|
231
242
|
} else if (modeConfig.booleanOperation === 'difference') {
|
|
232
|
-
updatedGeometry = turfDifference(
|
|
243
|
+
updatedGeometry = turfDifference(
|
|
244
|
+
turfFeatureCollection([selectedFeature as Feature<PolygonGeometry>, feature])
|
|
245
|
+
);
|
|
233
246
|
} else if (modeConfig.booleanOperation === 'intersection') {
|
|
234
|
-
updatedGeometry = turfIntersect(
|
|
247
|
+
updatedGeometry = turfIntersect(
|
|
248
|
+
turfFeatureCollection([selectedFeature as Feature<PolygonGeometry>, feature])
|
|
249
|
+
);
|
|
235
250
|
} else {
|
|
236
251
|
// eslint-disable-next-line no-console,no-undef
|
|
237
252
|
console.warn(`Invalid booleanOperation ${modeConfig.booleanOperation}`);
|
|
@@ -69,10 +69,7 @@ export class RotateHandler extends ModeHandler {
|
|
|
69
69
|
const centroid = turfCentroid(this._geometryBeingRotated);
|
|
70
70
|
const angle = getRotationAngle(centroid.geometry.coordinates, startPosition, currentPoint);
|
|
71
71
|
|
|
72
|
-
const rotatedFeatures = turfTransformRotate(
|
|
73
|
-
this._geometryBeingRotated,
|
|
74
|
-
angle
|
|
75
|
-
);
|
|
72
|
+
const rotatedFeatures = turfTransformRotate(this._geometryBeingRotated, angle);
|
|
76
73
|
|
|
77
74
|
let updatedData = this.getImmutableFeatureCollection();
|
|
78
75
|
|
|
@@ -68,13 +68,9 @@ export class ScaleHandler extends ModeHandler {
|
|
|
68
68
|
const startPosition = startDragPoint;
|
|
69
69
|
const centroid = turfCentroid(this._geometryBeingScaled);
|
|
70
70
|
const factor = getScaleFactor(centroid.geometry.coordinates, startPosition, currentPoint);
|
|
71
|
-
const scaledFeatures = turfTransformScale(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
{
|
|
75
|
-
origin: centroid
|
|
76
|
-
}
|
|
77
|
-
);
|
|
71
|
+
const scaledFeatures = turfTransformScale(this._geometryBeingScaled, factor, {
|
|
72
|
+
origin: centroid
|
|
73
|
+
});
|
|
78
74
|
|
|
79
75
|
let updatedData = this.getImmutableFeatureCollection();
|
|
80
76
|
|
|
@@ -140,7 +140,9 @@ export class SplitPolygonHandler extends ModeHandler {
|
|
|
140
140
|
units = 'centimeters';
|
|
141
141
|
}
|
|
142
142
|
const buffer = turfBuffer(tentativeFeature, gap, {units});
|
|
143
|
-
const updatedGeometry = turfDifference(
|
|
143
|
+
const updatedGeometry = turfDifference(
|
|
144
|
+
featureCollection([turfFeature(selectedGeometry as PolygonGeometry), buffer])
|
|
145
|
+
);
|
|
144
146
|
this._setTentativeFeature(null);
|
|
145
147
|
if (!updatedGeometry) {
|
|
146
148
|
// eslint-disable-next-line no-console,no-undef
|
|
@@ -11,22 +11,38 @@ import type {
|
|
|
11
11
|
MultiPolygon,
|
|
12
12
|
Position,
|
|
13
13
|
Feature,
|
|
14
|
-
FeatureCollection
|
|
14
|
+
FeatureCollection
|
|
15
15
|
} from 'geojson';
|
|
16
16
|
|
|
17
|
-
export {
|
|
17
|
+
export {
|
|
18
|
+
Point,
|
|
19
|
+
LineString,
|
|
20
|
+
Polygon,
|
|
21
|
+
MultiPoint,
|
|
22
|
+
MultiLineString,
|
|
23
|
+
MultiPolygon,
|
|
24
|
+
Position,
|
|
25
|
+
Feature,
|
|
26
|
+
FeatureCollection
|
|
27
|
+
};
|
|
18
28
|
|
|
19
29
|
/** Simple geometries (excludes GeometryCollection) */
|
|
20
|
-
export type SimpleGeometry =
|
|
30
|
+
export type SimpleGeometry =
|
|
31
|
+
| Point
|
|
32
|
+
| LineString
|
|
33
|
+
| Polygon
|
|
34
|
+
| MultiPoint
|
|
35
|
+
| MultiLineString
|
|
36
|
+
| MultiPolygon;
|
|
21
37
|
|
|
22
38
|
/** Feature with any geometry except GeometryCollection */
|
|
23
|
-
export type SimpleFeature = Feature<SimpleGeometry
|
|
39
|
+
export type SimpleFeature = Feature<SimpleGeometry>;
|
|
24
40
|
|
|
25
41
|
/** FeatureCollection with any geometries except GeometryCollection */
|
|
26
|
-
export type SimpleFeatureCollection = FeatureCollection<SimpleGeometry
|
|
42
|
+
export type SimpleFeatureCollection = FeatureCollection<SimpleGeometry>;
|
|
27
43
|
|
|
28
44
|
/** Coordinates of any geometry except GeometryCollection */
|
|
29
|
-
export type SimpleGeometryCoordinates = SimpleGeometry['coordinates']
|
|
45
|
+
export type SimpleGeometryCoordinates = SimpleGeometry['coordinates'];
|
|
30
46
|
|
|
31
47
|
/** Polygon and MultiPolygon geometries */
|
|
32
48
|
export type PolygonGeometry = Polygon | MultiPolygon;
|
|
@@ -11,35 +11,22 @@ import type {SimpleFeature} from './geojson-types';
|
|
|
11
11
|
|
|
12
12
|
// This function takes feature's center, moves it,
|
|
13
13
|
// and builds new feature around it keeping the proportions
|
|
14
|
-
export function translateFromCenter(
|
|
15
|
-
feature: SimpleFeature,
|
|
16
|
-
distance: number,
|
|
17
|
-
direction: number
|
|
18
|
-
) {
|
|
14
|
+
export function translateFromCenter(feature: SimpleFeature, distance: number, direction: number) {
|
|
19
15
|
const initialCenterPoint = turfCenter(feature);
|
|
20
16
|
|
|
21
17
|
const movedCenterPoint = turfRhumbDestination(initialCenterPoint, distance, direction);
|
|
22
18
|
|
|
23
|
-
const movedCoordinates = mapCoords(
|
|
24
|
-
|
|
25
|
-
(coordinate)
|
|
26
|
-
const rhumbDistance = turfRhumbDistance(
|
|
27
|
-
initialCenterPoint.geometry.coordinates,
|
|
28
|
-
coordinate
|
|
29
|
-
);
|
|
30
|
-
const rhumbDirection = turfRhumbBearing(
|
|
31
|
-
initialCenterPoint.geometry.coordinates,
|
|
32
|
-
coordinate
|
|
33
|
-
);
|
|
19
|
+
const movedCoordinates = mapCoords(feature.geometry.coordinates, (coordinate) => {
|
|
20
|
+
const rhumbDistance = turfRhumbDistance(initialCenterPoint.geometry.coordinates, coordinate);
|
|
21
|
+
const rhumbDirection = turfRhumbBearing(initialCenterPoint.geometry.coordinates, coordinate);
|
|
34
22
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
);
|
|
23
|
+
const movedPosition = turfRhumbDestination(
|
|
24
|
+
movedCenterPoint.geometry.coordinates,
|
|
25
|
+
rhumbDistance,
|
|
26
|
+
rhumbDirection
|
|
27
|
+
).geometry.coordinates;
|
|
28
|
+
return movedPosition;
|
|
29
|
+
});
|
|
43
30
|
|
|
44
31
|
feature.geometry.coordinates = movedCoordinates;
|
|
45
32
|
|
package/src/utils/utils.ts
CHANGED
|
@@ -6,7 +6,7 @@ import destination from '@turf/destination';
|
|
|
6
6
|
import bearing from '@turf/bearing';
|
|
7
7
|
import pointToLineDistance from '@turf/point-to-line-distance';
|
|
8
8
|
import {point} from '@turf/helpers';
|
|
9
|
-
import {WebMercatorViewport} from '
|
|
9
|
+
import {WebMercatorViewport} from '@math.gl/web-mercator';
|
|
10
10
|
import {Feature, LineString, Point, Position} from './geojson-types';
|
|
11
11
|
import {Viewport} from './types';
|
|
12
12
|
|
|
@@ -4,12 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import {render} from 'preact';
|
|
6
6
|
import type {ComponentChild, JSX} from 'preact';
|
|
7
|
-
import {
|
|
8
|
-
Widget,
|
|
9
|
-
type WidgetProps,
|
|
10
|
-
type WidgetPlacement,
|
|
11
|
-
type Deck
|
|
12
|
-
} from '@deck.gl/core';
|
|
7
|
+
import {Widget, type WidgetProps, type WidgetPlacement, type Deck} from '@deck.gl/core';
|
|
13
8
|
import type {
|
|
14
9
|
GeoJsonEditModeConstructor,
|
|
15
10
|
GeoJsonEditModeType
|
|
@@ -106,6 +101,7 @@ const BUTTON_LABEL_STYLE: JSX.CSSProperties = {
|
|
|
106
101
|
export class EditModeTrayWidget extends Widget<EditModeTrayWidgetProps> {
|
|
107
102
|
static override defaultProps = {
|
|
108
103
|
id: 'edit-mode-tray',
|
|
104
|
+
_container: null,
|
|
109
105
|
placement: 'top-left',
|
|
110
106
|
layout: 'vertical',
|
|
111
107
|
modes: [],
|