@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,154 @@
|
|
|
1
|
+
import booleanPointInPolygon from '@turf/boolean-point-in-polygon';
|
|
2
|
+
import turfDifference from '@turf/difference';
|
|
3
|
+
import turfBuffer from '@turf/buffer';
|
|
4
|
+
import lineIntersect from '@turf/line-intersect';
|
|
5
|
+
import { lineString } from '@turf/helpers';
|
|
6
|
+
import turfBearing from '@turf/bearing';
|
|
7
|
+
import turfDistance from '@turf/distance';
|
|
8
|
+
import turfDestination from '@turf/destination';
|
|
9
|
+
import turfPolygonToLine from '@turf/polygon-to-line';
|
|
10
|
+
import nearestPointOnLine from '@turf/nearest-point-on-line';
|
|
11
|
+
import { generatePointsParallelToLinePoints } from '../utils';
|
|
12
|
+
import { ModeHandler } from './mode-handler';
|
|
13
|
+
// TODO edit-modes: delete handlers once EditMode fully implemented
|
|
14
|
+
export class SplitPolygonHandler extends ModeHandler {
|
|
15
|
+
calculateMapCoords(clickSequence, mapCoords) {
|
|
16
|
+
const modeConfig = this.getModeConfig();
|
|
17
|
+
if (!modeConfig || !modeConfig.lock90Degree || !clickSequence.length) {
|
|
18
|
+
return mapCoords;
|
|
19
|
+
}
|
|
20
|
+
if (clickSequence.length === 1) {
|
|
21
|
+
// if first point is clicked, then find closest polygon point and build ~90deg vector
|
|
22
|
+
const firstPoint = clickSequence[0];
|
|
23
|
+
const selectedGeometry = this.getSelectedGeometry();
|
|
24
|
+
// @ts-expect-error turf type diff
|
|
25
|
+
const feature = turfPolygonToLine(selectedGeometry);
|
|
26
|
+
const lines = feature.type === 'FeatureCollection' ? feature.features : [feature];
|
|
27
|
+
let minDistance = Number.MAX_SAFE_INTEGER;
|
|
28
|
+
let closestPoint = null;
|
|
29
|
+
// If Multipolygon, then we should find nearest polygon line and stick split to it.
|
|
30
|
+
lines.forEach((line) => {
|
|
31
|
+
const snapPoint = nearestPointOnLine(line, firstPoint);
|
|
32
|
+
const distanceFromOrigin = turfDistance(snapPoint, firstPoint);
|
|
33
|
+
if (minDistance > distanceFromOrigin) {
|
|
34
|
+
minDistance = distanceFromOrigin;
|
|
35
|
+
closestPoint = snapPoint;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
if (closestPoint) {
|
|
39
|
+
// closest point is used as 90degree entry to the polygon
|
|
40
|
+
const lastBearing = turfBearing(firstPoint, closestPoint);
|
|
41
|
+
const currentDistance = turfDistance(firstPoint, mapCoords, { units: 'meters' });
|
|
42
|
+
return turfDestination(firstPoint, currentDistance, lastBearing, {
|
|
43
|
+
units: 'meters',
|
|
44
|
+
}).geometry.coordinates;
|
|
45
|
+
}
|
|
46
|
+
return mapCoords;
|
|
47
|
+
}
|
|
48
|
+
// Allow only 90 degree turns
|
|
49
|
+
const lastPoint = clickSequence[clickSequence.length - 1];
|
|
50
|
+
const [approximatePoint] = generatePointsParallelToLinePoints(clickSequence[clickSequence.length - 2], lastPoint, mapCoords);
|
|
51
|
+
// align point with current ground
|
|
52
|
+
const nearestPt = nearestPointOnLine(lineString([lastPoint, approximatePoint]), mapCoords)
|
|
53
|
+
.geometry.coordinates;
|
|
54
|
+
return nearestPt;
|
|
55
|
+
}
|
|
56
|
+
handleClick(event) {
|
|
57
|
+
super.handleClick({
|
|
58
|
+
...event,
|
|
59
|
+
mapCoords: this.calculateMapCoords(this.getClickSequence(), event.mapCoords),
|
|
60
|
+
});
|
|
61
|
+
const editAction = null;
|
|
62
|
+
const tentativeFeature = this.getTentativeFeature();
|
|
63
|
+
const selectedGeometry = this.getSelectedGeometry();
|
|
64
|
+
const clickSequence = this.getClickSequence();
|
|
65
|
+
if (!selectedGeometry) {
|
|
66
|
+
// eslint-disable-next-line no-console,no-undef
|
|
67
|
+
console.warn('A polygon must be selected for splitting');
|
|
68
|
+
this._setTentativeFeature(null);
|
|
69
|
+
return editAction;
|
|
70
|
+
}
|
|
71
|
+
const pt = {
|
|
72
|
+
type: 'Point',
|
|
73
|
+
coordinates: clickSequence[clickSequence.length - 1],
|
|
74
|
+
};
|
|
75
|
+
// @ts-expect-error turf type diff
|
|
76
|
+
const isPointInPolygon = booleanPointInPolygon(pt, selectedGeometry);
|
|
77
|
+
if (clickSequence.length > 1 && tentativeFeature && !isPointInPolygon) {
|
|
78
|
+
this.resetClickSequence();
|
|
79
|
+
// @ts-expect-error turf type diff
|
|
80
|
+
const isLineInterectingWithPolygon = lineIntersect(tentativeFeature, selectedGeometry);
|
|
81
|
+
if (isLineInterectingWithPolygon.features.length === 0) {
|
|
82
|
+
this._setTentativeFeature(null);
|
|
83
|
+
return editAction;
|
|
84
|
+
}
|
|
85
|
+
return this.splitPolygon();
|
|
86
|
+
}
|
|
87
|
+
return editAction;
|
|
88
|
+
}
|
|
89
|
+
handlePointerMove({ mapCoords }) {
|
|
90
|
+
const clickSequence = this.getClickSequence();
|
|
91
|
+
const result = { editAction: null, cancelMapPan: false };
|
|
92
|
+
if (clickSequence.length === 0) {
|
|
93
|
+
// nothing to do yet
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
this._setTentativeFeature({
|
|
97
|
+
type: 'Feature',
|
|
98
|
+
geometry: {
|
|
99
|
+
type: 'LineString',
|
|
100
|
+
coordinates: [...clickSequence, this.calculateMapCoords(clickSequence, mapCoords)],
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
splitPolygon() {
|
|
106
|
+
const selectedGeometry = this.getSelectedGeometry();
|
|
107
|
+
const tentativeFeature = this.getTentativeFeature();
|
|
108
|
+
const featureIndex = this.getSelectedFeatureIndexes()[0];
|
|
109
|
+
const modeConfig = this.getModeConfig() || {};
|
|
110
|
+
// Default gap in between the polygon
|
|
111
|
+
let { gap = 0.1, units = 'centimeters' } = modeConfig;
|
|
112
|
+
if (gap === 0) {
|
|
113
|
+
gap = 0.1;
|
|
114
|
+
units = 'centimeters';
|
|
115
|
+
}
|
|
116
|
+
// @ts-expect-error turf type diff
|
|
117
|
+
const buffer = turfBuffer(tentativeFeature, gap, { units });
|
|
118
|
+
// @ts-expect-error turf type diff
|
|
119
|
+
const updatedGeometry = turfDifference(selectedGeometry, buffer);
|
|
120
|
+
this._setTentativeFeature(null);
|
|
121
|
+
if (!updatedGeometry) {
|
|
122
|
+
// eslint-disable-next-line no-console,no-undef
|
|
123
|
+
console.warn('Canceling edit. Split Polygon erased');
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
const { type, coordinates } = updatedGeometry.geometry;
|
|
127
|
+
let updatedCoordinates = []; // TODO
|
|
128
|
+
if (type === 'Polygon') {
|
|
129
|
+
// Update the coordinates as per Multipolygon
|
|
130
|
+
updatedCoordinates = coordinates.map((c) => [c]);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
// Handle Case when Multipolygon has holes
|
|
134
|
+
updatedCoordinates = coordinates.reduce((agg, prev) => {
|
|
135
|
+
prev.forEach((p) => {
|
|
136
|
+
agg.push([p]);
|
|
137
|
+
});
|
|
138
|
+
return agg;
|
|
139
|
+
}, []);
|
|
140
|
+
}
|
|
141
|
+
// Update the type to Mulitpolygon
|
|
142
|
+
const updatedData = this.getImmutableFeatureCollection().replaceGeometry(featureIndex, {
|
|
143
|
+
type: 'MultiPolygon',
|
|
144
|
+
coordinates: updatedCoordinates,
|
|
145
|
+
});
|
|
146
|
+
const editAction = {
|
|
147
|
+
updatedData: updatedData.getObject(),
|
|
148
|
+
editType: 'split',
|
|
149
|
+
featureIndexes: [featureIndex],
|
|
150
|
+
editContext: null,
|
|
151
|
+
};
|
|
152
|
+
return editAction;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ModeHandler } from './mode-handler';
|
|
2
|
+
// TODO edit-modes: delete handlers once EditMode fully implemented
|
|
3
|
+
export class ThreeClickPolygonHandler extends ModeHandler {
|
|
4
|
+
handleClick(event) {
|
|
5
|
+
super.handleClick(event);
|
|
6
|
+
const tentativeFeature = this.getTentativeFeature();
|
|
7
|
+
const clickSequence = this.getClickSequence();
|
|
8
|
+
if (clickSequence.length > 2 &&
|
|
9
|
+
tentativeFeature &&
|
|
10
|
+
tentativeFeature.geometry.type === 'Polygon') {
|
|
11
|
+
const editAction = this.getAddFeatureOrBooleanPolygonAction(tentativeFeature.geometry);
|
|
12
|
+
this.resetClickSequence();
|
|
13
|
+
this._setTentativeFeature(null);
|
|
14
|
+
return editAction;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FeatureCollection, Position } from '../geojson-types';
|
|
2
|
+
import { PointerMoveEvent, StartDraggingEvent, StopDraggingEvent } from '../edit-modes/types';
|
|
3
|
+
import { EditAction, ModeHandler } from './mode-handler';
|
|
4
|
+
export declare class TranslateHandler extends ModeHandler {
|
|
5
|
+
_geometryBeforeTranslate: FeatureCollection | null | undefined;
|
|
6
|
+
_isTranslatable: boolean;
|
|
7
|
+
handlePointerMove(event: PointerMoveEvent): {
|
|
8
|
+
editAction: EditAction | null | undefined;
|
|
9
|
+
cancelMapPan: boolean;
|
|
10
|
+
};
|
|
11
|
+
handleStartDragging(event: StartDraggingEvent): EditAction | null | undefined;
|
|
12
|
+
handleStopDragging(event: StopDraggingEvent): EditAction | null | undefined;
|
|
13
|
+
getCursor({ isDragging }: {
|
|
14
|
+
isDragging: boolean;
|
|
15
|
+
}): string;
|
|
16
|
+
getTranslateAction(startDragPoint: Position, currentPoint: Position, editType: string): EditAction | null | undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import turfBearing from '@turf/bearing';
|
|
2
|
+
import turfDistance from '@turf/distance';
|
|
3
|
+
import turfTransformTranslate from '@turf/transform-translate';
|
|
4
|
+
import { point } from '@turf/helpers';
|
|
5
|
+
import { ModeHandler } from './mode-handler';
|
|
6
|
+
// TODO edit-modes: delete handlers once EditMode fully implemented
|
|
7
|
+
export class TranslateHandler extends ModeHandler {
|
|
8
|
+
_geometryBeforeTranslate;
|
|
9
|
+
_isTranslatable = undefined;
|
|
10
|
+
handlePointerMove(event) {
|
|
11
|
+
let editAction = null;
|
|
12
|
+
this._isTranslatable =
|
|
13
|
+
Boolean(this._geometryBeforeTranslate) || this.isSelectionPicked(event.picks);
|
|
14
|
+
if (!this._isTranslatable || !event.pointerDownMapCoords) {
|
|
15
|
+
// Nothing to do
|
|
16
|
+
return { editAction: null, cancelMapPan: false };
|
|
17
|
+
}
|
|
18
|
+
if (event.isDragging && this._geometryBeforeTranslate) {
|
|
19
|
+
// Translate the geometry
|
|
20
|
+
editAction = this.getTranslateAction(event.pointerDownMapCoords, event.mapCoords, 'translating');
|
|
21
|
+
}
|
|
22
|
+
return { editAction, cancelMapPan: true };
|
|
23
|
+
}
|
|
24
|
+
handleStartDragging(event) {
|
|
25
|
+
if (!this._isTranslatable) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
this._geometryBeforeTranslate = this.getSelectedFeaturesAsFeatureCollection();
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
handleStopDragging(event) {
|
|
32
|
+
let editAction = null;
|
|
33
|
+
if (this._geometryBeforeTranslate) {
|
|
34
|
+
// Translate the geometry
|
|
35
|
+
editAction = this.getTranslateAction(event.pointerDownMapCoords, event.mapCoords, 'translated');
|
|
36
|
+
this._geometryBeforeTranslate = null;
|
|
37
|
+
}
|
|
38
|
+
return editAction;
|
|
39
|
+
}
|
|
40
|
+
getCursor({ isDragging }) {
|
|
41
|
+
if (this._isTranslatable) {
|
|
42
|
+
return 'move';
|
|
43
|
+
}
|
|
44
|
+
return isDragging ? 'grabbing' : 'grab';
|
|
45
|
+
}
|
|
46
|
+
getTranslateAction(startDragPoint, currentPoint, editType) {
|
|
47
|
+
if (!this._geometryBeforeTranslate) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const p1 = point(startDragPoint);
|
|
51
|
+
const p2 = point(currentPoint);
|
|
52
|
+
const distanceMoved = turfDistance(p1, p2);
|
|
53
|
+
const direction = turfBearing(p1, p2);
|
|
54
|
+
// @ts-expect-error turf type diff
|
|
55
|
+
const movedFeatures = turfTransformTranslate(
|
|
56
|
+
// @ts-expect-error turf type diff
|
|
57
|
+
this._geometryBeforeTranslate, distanceMoved, direction);
|
|
58
|
+
let updatedData = this.getImmutableFeatureCollection();
|
|
59
|
+
const selectedIndexes = this.getSelectedFeatureIndexes();
|
|
60
|
+
for (let i = 0; i < selectedIndexes.length; i++) {
|
|
61
|
+
const selectedIndex = selectedIndexes[i];
|
|
62
|
+
const movedFeature = movedFeatures.features[i];
|
|
63
|
+
updatedData = updatedData.replaceGeometry(selectedIndex, movedFeature.geometry);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
updatedData: updatedData.getObject(),
|
|
67
|
+
editType,
|
|
68
|
+
featureIndexes: selectedIndexes,
|
|
69
|
+
editContext: null,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ModeHandler } from './mode-handler';
|
|
2
|
+
// TODO edit-modes: delete handlers once EditMode fully implemented
|
|
3
|
+
export class TwoClickPolygonHandler extends ModeHandler {
|
|
4
|
+
handleClick(event) {
|
|
5
|
+
super.handleClick(event);
|
|
6
|
+
const tentativeFeature = this.getTentativeFeature();
|
|
7
|
+
const clickSequence = this.getClickSequence();
|
|
8
|
+
if (clickSequence.length > 1 &&
|
|
9
|
+
tentativeFeature &&
|
|
10
|
+
tentativeFeature.geometry.type === 'Polygon') {
|
|
11
|
+
const editAction = this.getAddFeatureOrBooleanPolygonAction(tentativeFeature.geometry);
|
|
12
|
+
this.resetClickSequence();
|
|
13
|
+
this._setTentativeFeature(null);
|
|
14
|
+
return editAction;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Position } from '../geojson-types';
|
|
2
|
+
import { EditHandle, ModeHandler } from './mode-handler';
|
|
3
|
+
export declare class ViewHandler extends ModeHandler {
|
|
4
|
+
getCursor({ isDragging }: {
|
|
5
|
+
isDragging: boolean;
|
|
6
|
+
}): string;
|
|
7
|
+
getEditHandles(picks?: Array<Record<string, any>>, mapCoords?: Position): EditHandle[];
|
|
8
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModeHandler } from './mode-handler';
|
|
2
|
+
// TODO edit-modes: delete handlers once EditMode fully implemented
|
|
3
|
+
export class ViewHandler extends ModeHandler {
|
|
4
|
+
getCursor({ isDragging }) {
|
|
5
|
+
return isDragging ? 'grabbing' : 'grab';
|
|
6
|
+
}
|
|
7
|
+
getEditHandles(picks, mapCoords) {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// TODO - this module is a WIP
|
|
2
|
+
/* eslint-disable camelcase */
|
|
3
|
+
const INITIAL_STATE = {
|
|
4
|
+
color_uOpacity: 1.0,
|
|
5
|
+
color_uDesaturate: 0.0,
|
|
6
|
+
color_uBrightness: 1.0,
|
|
7
|
+
};
|
|
8
|
+
function getUniforms(opts = INITIAL_STATE) {
|
|
9
|
+
const uniforms = {};
|
|
10
|
+
if (opts.opacity) {
|
|
11
|
+
uniforms.color_uOpacity = opts.opacity;
|
|
12
|
+
}
|
|
13
|
+
return uniforms;
|
|
14
|
+
}
|
|
15
|
+
const vs = `\
|
|
16
|
+
in vec4 color_vColor;
|
|
17
|
+
|
|
18
|
+
color_setColor(vec4 color) {
|
|
19
|
+
color_vColor = color;
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
const fs = `\
|
|
23
|
+
uniform float color_uOpacity;
|
|
24
|
+
uniform float color_uDesaturate;
|
|
25
|
+
uniform float color_uBrightness;
|
|
26
|
+
|
|
27
|
+
in vec4 color_vColor;
|
|
28
|
+
|
|
29
|
+
out vec4 fragColor;
|
|
30
|
+
|
|
31
|
+
vec4 color_getColor() {
|
|
32
|
+
return color_vColor;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
vec4 color_filterColor(vec4 color) {
|
|
36
|
+
// apply desaturation and brightness
|
|
37
|
+
if (color_uDesaturate > 0.01) {
|
|
38
|
+
float luminance = (color.r + color.g + color.b) * 0.333333333 + color_uBrightness;
|
|
39
|
+
color = vec4(mix(color.rgb, vec3(luminance), color_uDesaturate), color.a);
|
|
40
|
+
|
|
41
|
+
// Apply opacity
|
|
42
|
+
color = vec4(color.rgb, color.a * color_uOpacity);
|
|
43
|
+
return color;
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
export default {
|
|
47
|
+
name: 'color',
|
|
48
|
+
vs,
|
|
49
|
+
fs,
|
|
50
|
+
getUniforms,
|
|
51
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare function getUniforms({ outlineEnabled, outlineRenderShadowmap, outlineShadowmap }?: Record<string, any>): Record<string, any>;
|
|
2
|
+
declare const _default: {
|
|
3
|
+
name: string;
|
|
4
|
+
vs: string;
|
|
5
|
+
fs: string;
|
|
6
|
+
getUniforms: typeof getUniforms;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
const INITIAL_STATE = {
|
|
3
|
+
outlineEnabled: false,
|
|
4
|
+
outlineRenderShadowmap: false,
|
|
5
|
+
outlineShadowmap: null,
|
|
6
|
+
};
|
|
7
|
+
function getUniforms({ outlineEnabled, outlineRenderShadowmap, outlineShadowmap } = INITIAL_STATE) {
|
|
8
|
+
const uniforms = {};
|
|
9
|
+
if (outlineEnabled !== undefined) {
|
|
10
|
+
// ? 1.0 : 0.0;
|
|
11
|
+
uniforms.outline_uEnabled = outlineEnabled;
|
|
12
|
+
}
|
|
13
|
+
if (outlineRenderShadowmap !== undefined) {
|
|
14
|
+
// ? 1.0 : 0.0;
|
|
15
|
+
uniforms.outline_uRenderOutlines = outlineRenderShadowmap;
|
|
16
|
+
}
|
|
17
|
+
if (outlineShadowmap !== undefined) {
|
|
18
|
+
uniforms.outline_uShadowmap = outlineShadowmap;
|
|
19
|
+
}
|
|
20
|
+
return uniforms;
|
|
21
|
+
}
|
|
22
|
+
const vs = `\
|
|
23
|
+
#version 300 es
|
|
24
|
+
in float instanceZLevel;
|
|
25
|
+
out float outline_vzLevel;
|
|
26
|
+
out vec4 outline_vPosition;
|
|
27
|
+
|
|
28
|
+
// Set the z level for the outline shadowmap rendering
|
|
29
|
+
void outline_setZLevel(float zLevel) {
|
|
30
|
+
outline_vzLevel = zLevel;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Store an adjusted position for texture2DProj
|
|
34
|
+
void outline_setUV(vec4 position) {
|
|
35
|
+
// mat4(
|
|
36
|
+
// 0.5, 0.0, 0.0, 0.0,
|
|
37
|
+
// 0.0, 0.5, 0.0, 0.0,
|
|
38
|
+
// 0.0, 0.0, 0.5, 0.0,
|
|
39
|
+
// 0.5, 0.5, 0.5, 1.0
|
|
40
|
+
// ) * position;
|
|
41
|
+
outline_vPosition = vec4(position.xyz * 0.5 + position.w * 0.5, position.w);
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
const fs = `\
|
|
45
|
+
uniform bool outline_uEnabled;
|
|
46
|
+
uniform bool outline_uRenderOutlines;
|
|
47
|
+
uniform sampler2D outline_uShadowmap;
|
|
48
|
+
|
|
49
|
+
in float outline_vzLevel;
|
|
50
|
+
// in vec2 outline_vUV;
|
|
51
|
+
in vec4 outline_vPosition;
|
|
52
|
+
|
|
53
|
+
out vec4 fragColor;
|
|
54
|
+
|
|
55
|
+
const float OUTLINE_Z_LEVEL_ERROR = 0.01;
|
|
56
|
+
|
|
57
|
+
// Return a darker color in shadowmap
|
|
58
|
+
vec4 outline_filterShadowColor(vec4 color) {
|
|
59
|
+
return vec4(outline_vzLevel / 255., outline_vzLevel / 255., outline_vzLevel / 255., 1.);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Return a darker color if in shadowmap
|
|
63
|
+
vec4 outline_filterDarkenColor(vec4 color) {
|
|
64
|
+
if (outline_uEnabled) {
|
|
65
|
+
float maxZLevel;
|
|
66
|
+
if (outline_vPosition.q > 0.0) {
|
|
67
|
+
maxZLevel = texture2DProj(outline_uShadowmap, outline_vPosition).r * 255.;
|
|
68
|
+
} else {
|
|
69
|
+
discard;
|
|
70
|
+
}
|
|
71
|
+
if (maxZLevel < outline_vzLevel + OUTLINE_Z_LEVEL_ERROR) {
|
|
72
|
+
vec4(color.rgb * 0.5, color.a);
|
|
73
|
+
} else {
|
|
74
|
+
discard;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return color;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// if enabled and rendering outlines - Render depth to shadowmap
|
|
81
|
+
// if enabled and rendering colors - Return a darker color if in shadowmap
|
|
82
|
+
// if disabled, just return color
|
|
83
|
+
vec4 outline_filterColor(vec4 color) {
|
|
84
|
+
if (outline_uEnabled) {
|
|
85
|
+
return outline_uRenderOutlines ?
|
|
86
|
+
outline_filterShadowColor(color) :
|
|
87
|
+
outline_filterDarkenColor(color);
|
|
88
|
+
}
|
|
89
|
+
return color;
|
|
90
|
+
}
|
|
91
|
+
`;
|
|
92
|
+
export default {
|
|
93
|
+
name: 'outline',
|
|
94
|
+
vs,
|
|
95
|
+
fs,
|
|
96
|
+
getUniforms,
|
|
97
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// TODO - this module is a WIP
|
|
2
|
+
/* eslint-disable camelcase */
|
|
3
|
+
const INITIAL_STATE = {};
|
|
4
|
+
function getUniforms({} = INITIAL_STATE) { }
|
|
5
|
+
const vs = `\
|
|
6
|
+
// Note - fairly generic, move to a UV or screen package, or even project?
|
|
7
|
+
vec2 project_clipspace_to_uv(vec4 position) {
|
|
8
|
+
vec2 p = vec2(position.x / position.w, position.y / position.w);
|
|
9
|
+
return vec2((p.x + 1.0) / 2.0, (p.y + 1.0) / 2.0);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
vec2 project_clipspace_to_projective_uv(vec4 position) {
|
|
13
|
+
// outline_vPosition = mat4(
|
|
14
|
+
// 0.5, 0.0, 0.0, 0.0,
|
|
15
|
+
// 0.0, 0.5, 0.0, 0.0,
|
|
16
|
+
// 0.0, 0.0, 0.5, 0.0,
|
|
17
|
+
// 0.5, 0.5, 0.5, 1.0
|
|
18
|
+
// ) * position;
|
|
19
|
+
return vec4(position.xyz * 0.5 + position.w * 0.5, position.w);
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
const fs = vs;
|
|
23
|
+
export default {
|
|
24
|
+
name: 'outline',
|
|
25
|
+
vs,
|
|
26
|
+
fs,
|
|
27
|
+
getUniforms,
|
|
28
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import turfCenter from '@turf/center';
|
|
2
|
+
import turfRhumbBearing from '@turf/rhumb-bearing';
|
|
3
|
+
import turfRhumbDistance from '@turf/rhumb-distance';
|
|
4
|
+
import turfRhumbDestination from '@turf/rhumb-destination';
|
|
5
|
+
import { mapCoords } from './edit-modes/utils';
|
|
6
|
+
// This function takes feature's center, moves it,
|
|
7
|
+
// and builds new feature around it keeping the proportions
|
|
8
|
+
export function translateFromCenter(feature, distance, direction) {
|
|
9
|
+
const initialCenterPoint = turfCenter(feature);
|
|
10
|
+
const movedCenterPoint = turfRhumbDestination(initialCenterPoint, distance, direction);
|
|
11
|
+
const movedCoordinates = mapCoords(feature.geometry.coordinates, (coordinate) => {
|
|
12
|
+
const distance = turfRhumbDistance(initialCenterPoint.geometry.coordinates, coordinate);
|
|
13
|
+
const direction = turfRhumbBearing(initialCenterPoint.geometry.coordinates, coordinate);
|
|
14
|
+
const movedPosition = turfRhumbDestination(movedCenterPoint.geometry.coordinates, distance, direction).geometry.coordinates;
|
|
15
|
+
return movedPosition;
|
|
16
|
+
});
|
|
17
|
+
feature.geometry.coordinates = movedCoordinates;
|
|
18
|
+
return feature;
|
|
19
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type LayerMouseEventResult = {
|
|
2
|
+
eventConsumed?: boolean;
|
|
3
|
+
eventSoftConsumed?: boolean;
|
|
4
|
+
mousePointer?: string | null | undefined;
|
|
5
|
+
shouldRedraw?: boolean | string[];
|
|
6
|
+
};
|
|
7
|
+
export type Color = [number, number, number, number];
|
|
8
|
+
export type Style = {
|
|
9
|
+
dashArray?: number[];
|
|
10
|
+
fillColor?: Color;
|
|
11
|
+
lineColor?: Color;
|
|
12
|
+
lineWidthMeters?: number;
|
|
13
|
+
pointRadiusMeters?: number;
|
|
14
|
+
outlineRadiusMeters?: number;
|
|
15
|
+
outlineColor?: Color;
|
|
16
|
+
mousePriority?: number;
|
|
17
|
+
arrowColor?: Color;
|
|
18
|
+
arrowStyle?: number;
|
|
19
|
+
arrowCount?: number;
|
|
20
|
+
iconNumber?: number;
|
|
21
|
+
text?: string;
|
|
22
|
+
tooltip?: string;
|
|
23
|
+
zLevel?: number;
|
|
24
|
+
};
|
|
25
|
+
export type Viewport = {
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
longitude: number;
|
|
29
|
+
latitude: number;
|
|
30
|
+
zoom: number;
|
|
31
|
+
isDragging?: boolean;
|
|
32
|
+
isMoving?: boolean;
|
|
33
|
+
bearing?: number;
|
|
34
|
+
pitch?: number;
|
|
35
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FeatureOf, FeatureWithProps, LineString, Point, Position } from './geojson-types';
|
|
2
|
+
import { Viewport } from './types';
|
|
3
|
+
export type NearestPointType = FeatureWithProps<Point, {
|
|
4
|
+
dist: number;
|
|
5
|
+
index: number;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function toDeckColor(color?: [number, number, number, number] | number, defaultColor?: [number, number, number, number]): [number, number, number, number];
|
|
8
|
+
export declare function recursivelyTraverseNestedArrays(array: Array<any>, prefix: Array<number>, fn: Function): boolean;
|
|
9
|
+
export declare function generatePointsParallelToLinePoints(p1: Position, p2: Position, mapCoords: Position): Position[];
|
|
10
|
+
export declare function distance2d(x1: number, y1: number, x2: number, y2: number): number;
|
|
11
|
+
export declare function mix(a: number, b: number, ratio: number): number;
|
|
12
|
+
export declare function nearestPointOnProjectedLine(line: FeatureOf<LineString>, inPoint: FeatureOf<Point>, viewport: Viewport): NearestPointType;
|
|
13
|
+
/**
|
|
14
|
+
* Inserts toInsert string into base string before insertBefore string.
|
|
15
|
+
* @param base A string to insert into.
|
|
16
|
+
* @param insertBefore A sub string in `base` string to insert before.
|
|
17
|
+
* @param toInsert A string to insert.
|
|
18
|
+
* @returns Combined string. `base` string if `insertBefore` string isn't found.
|
|
19
|
+
*/
|
|
20
|
+
export declare function insertBefore(base: string, insertBefore: string, toInsert: string): string;
|