@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,16 @@
|
|
|
1
|
+
import distance from '@turf/distance';
|
|
2
|
+
import ellipse from '@turf/ellipse';
|
|
3
|
+
import bearing from '@turf/bearing';
|
|
4
|
+
import { point } from '@turf/helpers';
|
|
5
|
+
import { getIntermediatePosition } from './geojson-edit-mode';
|
|
6
|
+
import { ThreeClickPolygonMode } from './three-click-polygon-mode';
|
|
7
|
+
export class DrawEllipseUsingThreePointsMode extends ThreeClickPolygonMode {
|
|
8
|
+
getThreeClickPolygon(coord1, coord2, coord3, modeConfig) {
|
|
9
|
+
const centerCoordinates = getIntermediatePosition(coord1, coord2);
|
|
10
|
+
const xSemiAxis = Math.max(distance(centerCoordinates, point(coord3)), 0.001);
|
|
11
|
+
const ySemiAxis = Math.max(distance(coord1, coord2), 0.001) / 2;
|
|
12
|
+
const options = { angle: bearing(coord1, coord2) };
|
|
13
|
+
// @ts-expect-error fix return types
|
|
14
|
+
return ellipse(centerCoordinates, xSemiAxis, ySemiAxis, options);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FeatureCollection, Position } from '../geojson-types';
|
|
2
|
+
import { ClickEvent, PointerMoveEvent, ModeProps, GuideFeatureCollection, Tooltip } from './types';
|
|
3
|
+
import { GeoJsonEditMode } from './geojson-edit-mode';
|
|
4
|
+
export declare class DrawLineStringMode extends GeoJsonEditMode {
|
|
5
|
+
dist: number;
|
|
6
|
+
position: Position;
|
|
7
|
+
elems: Position[];
|
|
8
|
+
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>): void;
|
|
9
|
+
handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection>): void;
|
|
10
|
+
getGuides(props: ModeProps<FeatureCollection>): GuideFeatureCollection;
|
|
11
|
+
handlePointerMove(event: PointerMoveEvent, props: ModeProps<FeatureCollection>): void;
|
|
12
|
+
/**
|
|
13
|
+
* define the default function to display the tooltip for
|
|
14
|
+
* nebula geometry mode type
|
|
15
|
+
* @param props properties of geometry nebula mode
|
|
16
|
+
*/
|
|
17
|
+
getTooltips(props: ModeProps<FeatureCollection>): Tooltip[];
|
|
18
|
+
calculateInfoDraw(clickSequence: any): void;
|
|
19
|
+
/**
|
|
20
|
+
* redefine the tooltip of geometry
|
|
21
|
+
* @param modeConfig
|
|
22
|
+
* @param dist
|
|
23
|
+
*/
|
|
24
|
+
_getTooltips: (args: any) => any;
|
|
25
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import distance from '@turf/distance';
|
|
2
|
+
import memoize from '../memoize';
|
|
3
|
+
import { getPickedEditHandle } from './utils';
|
|
4
|
+
import { GeoJsonEditMode } from './geojson-edit-mode';
|
|
5
|
+
export class DrawLineStringMode extends GeoJsonEditMode {
|
|
6
|
+
// declaration of variables for the calculation of the distance of linestring
|
|
7
|
+
dist = 0;
|
|
8
|
+
position = null;
|
|
9
|
+
elems = [];
|
|
10
|
+
handleClick(event, props) {
|
|
11
|
+
const { picks } = event;
|
|
12
|
+
const clickedEditHandle = getPickedEditHandle(picks);
|
|
13
|
+
let positionAdded = false;
|
|
14
|
+
if (!clickedEditHandle) {
|
|
15
|
+
// Don't add another point right next to an existing one
|
|
16
|
+
this.addClickSequence(event);
|
|
17
|
+
positionAdded = true;
|
|
18
|
+
}
|
|
19
|
+
const clickSequence = this.getClickSequence();
|
|
20
|
+
// check if the pointer is on editable state calculate the distance of new point
|
|
21
|
+
if (!clickedEditHandle) {
|
|
22
|
+
this.calculateInfoDraw(clickSequence);
|
|
23
|
+
}
|
|
24
|
+
if (clickSequence.length > 1 &&
|
|
25
|
+
clickedEditHandle &&
|
|
26
|
+
Array.isArray(clickedEditHandle.properties.positionIndexes) &&
|
|
27
|
+
clickedEditHandle.properties.positionIndexes[0] === clickSequence.length - 1) {
|
|
28
|
+
// They clicked the last point (or double-clicked), so add the LineString
|
|
29
|
+
// reset distance to new calculate
|
|
30
|
+
this.dist = 0;
|
|
31
|
+
const lineStringToAdd = {
|
|
32
|
+
type: 'LineString',
|
|
33
|
+
coordinates: [...clickSequence],
|
|
34
|
+
};
|
|
35
|
+
this.resetClickSequence();
|
|
36
|
+
const editAction = this.getAddFeatureAction(lineStringToAdd, props.data);
|
|
37
|
+
if (editAction) {
|
|
38
|
+
props.onEdit(editAction);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else if (positionAdded) {
|
|
42
|
+
// new tentative point
|
|
43
|
+
props.onEdit({
|
|
44
|
+
// data is the same
|
|
45
|
+
updatedData: props.data,
|
|
46
|
+
editType: 'addTentativePosition',
|
|
47
|
+
editContext: {
|
|
48
|
+
position: event.mapCoords,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
handleKeyUp(event, props) {
|
|
54
|
+
const { key } = event;
|
|
55
|
+
if (key === 'Enter') {
|
|
56
|
+
const clickSequence = this.getClickSequence();
|
|
57
|
+
if (clickSequence.length > 1) {
|
|
58
|
+
const lineStringToAdd = {
|
|
59
|
+
type: 'LineString',
|
|
60
|
+
coordinates: [...clickSequence],
|
|
61
|
+
};
|
|
62
|
+
this.resetClickSequence();
|
|
63
|
+
const editAction = this.getAddFeatureAction(lineStringToAdd, props.data);
|
|
64
|
+
if (editAction) {
|
|
65
|
+
props.onEdit(editAction);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (key === 'Escape') {
|
|
70
|
+
this.resetClickSequence();
|
|
71
|
+
props.onEdit({
|
|
72
|
+
// Because the new drawing feature is dropped, so the data will keep as the same.
|
|
73
|
+
updatedData: props.data,
|
|
74
|
+
editType: 'cancelFeature',
|
|
75
|
+
editContext: {},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
getGuides(props) {
|
|
80
|
+
const { lastPointerMoveEvent } = props;
|
|
81
|
+
const clickSequence = this.getClickSequence();
|
|
82
|
+
const lastCoords = lastPointerMoveEvent ? [lastPointerMoveEvent.mapCoords] : [];
|
|
83
|
+
const guides = {
|
|
84
|
+
type: 'FeatureCollection',
|
|
85
|
+
features: [],
|
|
86
|
+
};
|
|
87
|
+
let tentativeFeature;
|
|
88
|
+
if (clickSequence.length > 0) {
|
|
89
|
+
tentativeFeature = {
|
|
90
|
+
type: 'Feature',
|
|
91
|
+
properties: {
|
|
92
|
+
guideType: 'tentative',
|
|
93
|
+
},
|
|
94
|
+
geometry: {
|
|
95
|
+
type: 'LineString',
|
|
96
|
+
coordinates: [...clickSequence, ...lastCoords],
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
if (tentativeFeature) {
|
|
101
|
+
guides.features.push(tentativeFeature);
|
|
102
|
+
}
|
|
103
|
+
const editHandles = clickSequence.map((clickedCoord, index) => ({
|
|
104
|
+
type: 'Feature',
|
|
105
|
+
properties: {
|
|
106
|
+
guideType: 'editHandle',
|
|
107
|
+
editHandleType: 'existing',
|
|
108
|
+
featureIndex: -1,
|
|
109
|
+
positionIndexes: [index],
|
|
110
|
+
},
|
|
111
|
+
geometry: {
|
|
112
|
+
type: 'Point',
|
|
113
|
+
coordinates: clickedCoord,
|
|
114
|
+
},
|
|
115
|
+
}));
|
|
116
|
+
guides.features.push(...editHandles);
|
|
117
|
+
return guides;
|
|
118
|
+
}
|
|
119
|
+
handlePointerMove(event, props) {
|
|
120
|
+
props.onUpdateCursor('cell');
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* define the default function to display the tooltip for
|
|
124
|
+
* nebula geometry mode type
|
|
125
|
+
* @param props properties of geometry nebula mode
|
|
126
|
+
*/
|
|
127
|
+
getTooltips(props) {
|
|
128
|
+
return this._getTooltips({
|
|
129
|
+
modeConfig: props.modeConfig,
|
|
130
|
+
dist: this.dist,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
// utility function
|
|
134
|
+
calculateInfoDraw(clickSequence) {
|
|
135
|
+
// check if the selected points are at least 2
|
|
136
|
+
if (clickSequence.length > 1) {
|
|
137
|
+
// setting the last point
|
|
138
|
+
this.position = clickSequence[clickSequence.length - 1];
|
|
139
|
+
// calculate the new distance by adding the
|
|
140
|
+
// distance of the new drawn linestring
|
|
141
|
+
this.dist += distance(clickSequence[clickSequence.length - 2], clickSequence[clickSequence.length - 1]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* redefine the tooltip of geometry
|
|
146
|
+
* @param modeConfig
|
|
147
|
+
* @param dist
|
|
148
|
+
*/
|
|
149
|
+
_getTooltips = memoize(({ modeConfig, dist }) => {
|
|
150
|
+
let tooltips = [];
|
|
151
|
+
const { formatTooltip } = modeConfig || {};
|
|
152
|
+
let text;
|
|
153
|
+
if (dist) {
|
|
154
|
+
if (formatTooltip) {
|
|
155
|
+
text = formatTooltip(dist);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
// By default, round to 2 decimal places and append units
|
|
159
|
+
text = `Distance: ${parseFloat(dist).toFixed(2)} kilometers`;
|
|
160
|
+
}
|
|
161
|
+
tooltips = [
|
|
162
|
+
{
|
|
163
|
+
position: this.position,
|
|
164
|
+
text,
|
|
165
|
+
},
|
|
166
|
+
];
|
|
167
|
+
}
|
|
168
|
+
return tooltips;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ClickEvent, PointerMoveEvent, ModeProps, TentativeFeature } from './types';
|
|
2
|
+
import { FeatureCollection } from '../geojson-types';
|
|
3
|
+
import { GeoJsonEditMode } from './geojson-edit-mode';
|
|
4
|
+
export declare class DrawPointMode extends GeoJsonEditMode {
|
|
5
|
+
createTentativeFeature(props: ModeProps<FeatureCollection>): TentativeFeature;
|
|
6
|
+
handleClick({ mapCoords }: ClickEvent, props: ModeProps<FeatureCollection>): void;
|
|
7
|
+
handlePointerMove(event: PointerMoveEvent, props: ModeProps<FeatureCollection>): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { GeoJsonEditMode } from './geojson-edit-mode';
|
|
2
|
+
export class DrawPointMode extends GeoJsonEditMode {
|
|
3
|
+
createTentativeFeature(props) {
|
|
4
|
+
const { lastPointerMoveEvent } = props;
|
|
5
|
+
const lastCoords = lastPointerMoveEvent ? [lastPointerMoveEvent.mapCoords] : [];
|
|
6
|
+
return {
|
|
7
|
+
type: 'Feature',
|
|
8
|
+
properties: {
|
|
9
|
+
guideType: 'tentative',
|
|
10
|
+
},
|
|
11
|
+
geometry: {
|
|
12
|
+
type: 'Point',
|
|
13
|
+
coordinates: lastCoords[0],
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
handleClick({ mapCoords }, props) {
|
|
18
|
+
const geometry = {
|
|
19
|
+
type: 'Point',
|
|
20
|
+
coordinates: mapCoords,
|
|
21
|
+
};
|
|
22
|
+
props.onEdit(this.getAddFeatureAction(geometry, props.data));
|
|
23
|
+
}
|
|
24
|
+
handlePointerMove(event, props) {
|
|
25
|
+
props.onUpdateCursor('cell');
|
|
26
|
+
super.handlePointerMove(event, props);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ClickEvent, StartDraggingEvent, StopDraggingEvent, DraggingEvent, ModeProps } from './types';
|
|
2
|
+
import { FeatureCollection } from '../geojson-types';
|
|
3
|
+
import { DrawPolygonMode } from './draw-polygon-mode';
|
|
4
|
+
type DraggingHandler = (event: DraggingEvent, props: ModeProps<FeatureCollection>) => void;
|
|
5
|
+
export declare class DrawPolygonByDraggingMode extends DrawPolygonMode {
|
|
6
|
+
handleDraggingThrottled: DraggingHandler | null | undefined;
|
|
7
|
+
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>): void;
|
|
8
|
+
handleStartDragging(event: StartDraggingEvent, props: ModeProps<FeatureCollection>): void;
|
|
9
|
+
handleStopDragging(event: StopDraggingEvent, props: ModeProps<FeatureCollection>): void;
|
|
10
|
+
handleDraggingAux(event: DraggingEvent, props: ModeProps<FeatureCollection>): void;
|
|
11
|
+
handleDragging(event: DraggingEvent, props: ModeProps<FeatureCollection>): void;
|
|
12
|
+
handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection>): void;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import throttle from 'lodash.throttle';
|
|
2
|
+
import { getPickedEditHandle } from './utils';
|
|
3
|
+
import { DrawPolygonMode } from './draw-polygon-mode';
|
|
4
|
+
export class DrawPolygonByDraggingMode extends DrawPolygonMode {
|
|
5
|
+
handleDraggingThrottled = null;
|
|
6
|
+
handleClick(event, props) {
|
|
7
|
+
// No-op
|
|
8
|
+
}
|
|
9
|
+
handleStartDragging(event, props) {
|
|
10
|
+
event.cancelPan();
|
|
11
|
+
if (props.modeConfig && props.modeConfig.throttleMs) {
|
|
12
|
+
this.handleDraggingThrottled = throttle(this.handleDraggingAux, props.modeConfig.throttleMs);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
this.handleDraggingThrottled = this.handleDraggingAux;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
handleStopDragging(event, props) {
|
|
19
|
+
this.addClickSequence(event);
|
|
20
|
+
const clickSequence = this.getClickSequence();
|
|
21
|
+
// @ts-expect-error cancel() not typed
|
|
22
|
+
if (this.handleDraggingThrottled && this.handleDraggingThrottled.cancel) {
|
|
23
|
+
// @ts-expect-error cancel() not typed
|
|
24
|
+
this.handleDraggingThrottled.cancel();
|
|
25
|
+
}
|
|
26
|
+
if (clickSequence.length > 2) {
|
|
27
|
+
// Complete the polygon.
|
|
28
|
+
const polygonToAdd = {
|
|
29
|
+
type: 'Polygon',
|
|
30
|
+
coordinates: [[...clickSequence, clickSequence[0]]],
|
|
31
|
+
};
|
|
32
|
+
const editAction = this.getAddFeatureOrBooleanPolygonAction(polygonToAdd, props);
|
|
33
|
+
if (editAction) {
|
|
34
|
+
props.onEdit(editAction);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
this.resetClickSequence();
|
|
38
|
+
}
|
|
39
|
+
handleDraggingAux(event, props) {
|
|
40
|
+
const { picks } = event;
|
|
41
|
+
const clickedEditHandle = getPickedEditHandle(picks);
|
|
42
|
+
if (!clickedEditHandle) {
|
|
43
|
+
// Don't add another point right next to an existing one.
|
|
44
|
+
this.addClickSequence(event);
|
|
45
|
+
props.onEdit({
|
|
46
|
+
updatedData: props.data,
|
|
47
|
+
editType: 'addTentativePosition',
|
|
48
|
+
editContext: {
|
|
49
|
+
position: event.mapCoords,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
handleDragging(event, props) {
|
|
55
|
+
if (this.handleDraggingThrottled) {
|
|
56
|
+
this.handleDraggingThrottled(event, props);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
handleKeyUp(event, props) {
|
|
60
|
+
if (event.key === 'Enter') {
|
|
61
|
+
const clickSequence = this.getClickSequence();
|
|
62
|
+
if (clickSequence.length > 2) {
|
|
63
|
+
const polygonToAdd = {
|
|
64
|
+
type: 'Polygon',
|
|
65
|
+
coordinates: [[...clickSequence, clickSequence[0]]],
|
|
66
|
+
};
|
|
67
|
+
this.resetClickSequence();
|
|
68
|
+
const editAction = this.getAddFeatureOrBooleanPolygonAction(polygonToAdd, props);
|
|
69
|
+
if (editAction) {
|
|
70
|
+
props.onEdit(editAction);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else if (event.key === 'Escape') {
|
|
75
|
+
this.resetClickSequence();
|
|
76
|
+
if (this.handleDraggingThrottled) {
|
|
77
|
+
this.handleDraggingThrottled = null;
|
|
78
|
+
}
|
|
79
|
+
props.onEdit({
|
|
80
|
+
// Because the new drawing feature is dropped, so the data will keep as the same.
|
|
81
|
+
updatedData: props.data,
|
|
82
|
+
editType: 'cancelFeature',
|
|
83
|
+
editContext: {},
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ClickEvent, PointerMoveEvent, ModeProps, GuideFeatureCollection, TentativeFeature } from './types';
|
|
2
|
+
import { FeatureCollection } from '../geojson-types';
|
|
3
|
+
import { GeoJsonEditMode } from './geojson-edit-mode';
|
|
4
|
+
export declare class DrawPolygonMode extends GeoJsonEditMode {
|
|
5
|
+
createTentativeFeature(props: ModeProps<FeatureCollection>): TentativeFeature;
|
|
6
|
+
getGuides(props: ModeProps<FeatureCollection>): GuideFeatureCollection;
|
|
7
|
+
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>): void;
|
|
8
|
+
handleKeyUp(event: KeyboardEvent, props: ModeProps<FeatureCollection>): void;
|
|
9
|
+
handlePointerMove(event: PointerMoveEvent, props: ModeProps<FeatureCollection>): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import lineIntersect from '@turf/line-intersect';
|
|
2
|
+
import { lineString as turfLineString } from '@turf/helpers';
|
|
3
|
+
import { getPickedEditHandle } from './utils';
|
|
4
|
+
import { GeoJsonEditMode } from './geojson-edit-mode';
|
|
5
|
+
export class DrawPolygonMode extends GeoJsonEditMode {
|
|
6
|
+
createTentativeFeature(props) {
|
|
7
|
+
const { lastPointerMoveEvent } = props;
|
|
8
|
+
const clickSequence = this.getClickSequence();
|
|
9
|
+
const lastCoords = lastPointerMoveEvent ? [lastPointerMoveEvent.mapCoords] : [];
|
|
10
|
+
let tentativeFeature;
|
|
11
|
+
if (clickSequence.length === 1 || clickSequence.length === 2) {
|
|
12
|
+
tentativeFeature = {
|
|
13
|
+
type: 'Feature',
|
|
14
|
+
properties: {
|
|
15
|
+
guideType: 'tentative',
|
|
16
|
+
},
|
|
17
|
+
geometry: {
|
|
18
|
+
type: 'LineString',
|
|
19
|
+
coordinates: [...clickSequence, ...lastCoords],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
else if (clickSequence.length > 2) {
|
|
24
|
+
tentativeFeature = {
|
|
25
|
+
type: 'Feature',
|
|
26
|
+
properties: {
|
|
27
|
+
guideType: 'tentative',
|
|
28
|
+
},
|
|
29
|
+
geometry: {
|
|
30
|
+
type: 'Polygon',
|
|
31
|
+
coordinates: [[...clickSequence, ...lastCoords, clickSequence[0]]],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return tentativeFeature;
|
|
36
|
+
}
|
|
37
|
+
getGuides(props) {
|
|
38
|
+
const clickSequence = this.getClickSequence();
|
|
39
|
+
const guides = {
|
|
40
|
+
type: 'FeatureCollection',
|
|
41
|
+
features: [],
|
|
42
|
+
};
|
|
43
|
+
const tentativeFeature = this.createTentativeFeature(props);
|
|
44
|
+
if (tentativeFeature) {
|
|
45
|
+
guides.features.push(tentativeFeature);
|
|
46
|
+
}
|
|
47
|
+
const editHandles = clickSequence.map((clickedCoord, index) => ({
|
|
48
|
+
type: 'Feature',
|
|
49
|
+
properties: {
|
|
50
|
+
guideType: 'editHandle',
|
|
51
|
+
editHandleType: 'existing',
|
|
52
|
+
featureIndex: -1,
|
|
53
|
+
positionIndexes: [index],
|
|
54
|
+
},
|
|
55
|
+
geometry: {
|
|
56
|
+
type: 'Point',
|
|
57
|
+
coordinates: clickedCoord,
|
|
58
|
+
},
|
|
59
|
+
}));
|
|
60
|
+
guides.features.push(...editHandles);
|
|
61
|
+
return guides;
|
|
62
|
+
}
|
|
63
|
+
handleClick(event, props) {
|
|
64
|
+
const { picks } = event;
|
|
65
|
+
const clickedEditHandle = getPickedEditHandle(picks);
|
|
66
|
+
const clickSequence = this.getClickSequence();
|
|
67
|
+
let overlappingLines = false;
|
|
68
|
+
if (clickSequence.length > 2 && props.modeConfig && props.modeConfig.preventOverlappingLines) {
|
|
69
|
+
const currentLine = turfLineString([
|
|
70
|
+
clickSequence[clickSequence.length - 1],
|
|
71
|
+
event.mapCoords,
|
|
72
|
+
]);
|
|
73
|
+
const otherLines = turfLineString([...clickSequence.slice(0, clickSequence.length - 1)]);
|
|
74
|
+
const intersectingPoints = lineIntersect(currentLine, otherLines);
|
|
75
|
+
if (intersectingPoints.features.length > 0) {
|
|
76
|
+
overlappingLines = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
let positionAdded = false;
|
|
80
|
+
if (!clickedEditHandle && !overlappingLines) {
|
|
81
|
+
// Don't add another point right next to an existing one
|
|
82
|
+
this.addClickSequence(event);
|
|
83
|
+
positionAdded = true;
|
|
84
|
+
}
|
|
85
|
+
if (clickSequence.length > 2 &&
|
|
86
|
+
clickedEditHandle &&
|
|
87
|
+
Array.isArray(clickedEditHandle.properties.positionIndexes) &&
|
|
88
|
+
(clickedEditHandle.properties.positionIndexes[0] === 0 ||
|
|
89
|
+
clickedEditHandle.properties.positionIndexes[0] === clickSequence.length - 1)) {
|
|
90
|
+
// They clicked the first or last point (or double-clicked), so complete the polygon
|
|
91
|
+
// Remove the hovered position
|
|
92
|
+
const polygonToAdd = {
|
|
93
|
+
type: 'Polygon',
|
|
94
|
+
coordinates: [[...clickSequence, clickSequence[0]]],
|
|
95
|
+
};
|
|
96
|
+
this.resetClickSequence();
|
|
97
|
+
const editAction = this.getAddFeatureOrBooleanPolygonAction(polygonToAdd, props);
|
|
98
|
+
if (editAction) {
|
|
99
|
+
props.onEdit(editAction);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (positionAdded) {
|
|
103
|
+
// new tentative point
|
|
104
|
+
props.onEdit({
|
|
105
|
+
// data is the same
|
|
106
|
+
updatedData: props.data,
|
|
107
|
+
editType: 'addTentativePosition',
|
|
108
|
+
editContext: {
|
|
109
|
+
position: event.mapCoords,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
handleKeyUp(event, props) {
|
|
115
|
+
if (event.key === 'Enter') {
|
|
116
|
+
const clickSequence = this.getClickSequence();
|
|
117
|
+
if (clickSequence.length > 2) {
|
|
118
|
+
const polygonToAdd = {
|
|
119
|
+
type: 'Polygon',
|
|
120
|
+
coordinates: [[...clickSequence, clickSequence[0]]],
|
|
121
|
+
};
|
|
122
|
+
this.resetClickSequence();
|
|
123
|
+
const editAction = this.getAddFeatureOrBooleanPolygonAction(polygonToAdd, props);
|
|
124
|
+
if (editAction) {
|
|
125
|
+
props.onEdit(editAction);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (event.key === 'Escape') {
|
|
130
|
+
this.resetClickSequence();
|
|
131
|
+
props.onEdit({
|
|
132
|
+
// Because the new drawing feature is dropped, so the data will keep as the same.
|
|
133
|
+
updatedData: props.data,
|
|
134
|
+
editType: 'cancelFeature',
|
|
135
|
+
editContext: {},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
handlePointerMove(event, props) {
|
|
140
|
+
props.onUpdateCursor('cell');
|
|
141
|
+
super.handlePointerMove(event, props);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Position, Polygon, FeatureOf } from '../geojson-types';
|
|
2
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
3
|
+
export declare class DrawRectangleFromCenterMode extends TwoClickPolygonMode {
|
|
4
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): FeatureOf<Polygon>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import bboxPolygon from '@turf/bbox-polygon';
|
|
2
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
3
|
+
export class DrawRectangleFromCenterMode extends TwoClickPolygonMode {
|
|
4
|
+
getTwoClickPolygon(coord1, coord2, modeConfig) {
|
|
5
|
+
const longitude = coord1[0] > coord2[0]
|
|
6
|
+
? coord1[0] + Math.abs(coord1[0] - coord2[0])
|
|
7
|
+
: coord1[0] - Math.abs(coord1[0] - coord2[0]);
|
|
8
|
+
const latitude = coord1[1] > coord2[1]
|
|
9
|
+
? coord1[1] + Math.abs(coord1[1] - coord2[1])
|
|
10
|
+
: coord1[1] - Math.abs(coord1[1] - coord2[1]);
|
|
11
|
+
const rectangle = bboxPolygon([longitude, latitude, coord2[0], coord2[1]]);
|
|
12
|
+
rectangle.properties = rectangle.properties || {};
|
|
13
|
+
rectangle.properties.shape = 'Rectangle';
|
|
14
|
+
// @ts-expect-error turf typing too wide
|
|
15
|
+
return rectangle;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Position, Polygon, FeatureOf } from '../geojson-types';
|
|
2
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
3
|
+
export declare class DrawRectangleMode extends TwoClickPolygonMode {
|
|
4
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): FeatureOf<Polygon>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import bboxPolygon from '@turf/bbox-polygon';
|
|
2
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
3
|
+
export class DrawRectangleMode extends TwoClickPolygonMode {
|
|
4
|
+
getTwoClickPolygon(coord1, coord2, modeConfig) {
|
|
5
|
+
const rectangle = bboxPolygon([coord1[0], coord1[1], coord2[0], coord2[1]]);
|
|
6
|
+
rectangle.properties = rectangle.properties || {};
|
|
7
|
+
rectangle.properties.shape = 'Rectangle';
|
|
8
|
+
// @ts-expect-error turf typing too wide
|
|
9
|
+
return rectangle;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Position, Polygon, FeatureOf } from '../geojson-types';
|
|
2
|
+
import { ThreeClickPolygonMode } from './three-click-polygon-mode';
|
|
3
|
+
export declare class DrawRectangleUsingThreePointsMode extends ThreeClickPolygonMode {
|
|
4
|
+
getThreeClickPolygon(coord1: Position, coord2: Position, coord3: Position, modeConfig: any): FeatureOf<Polygon> | null | undefined;
|
|
5
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { generatePointsParallelToLinePoints } from './utils';
|
|
2
|
+
import { ThreeClickPolygonMode } from './three-click-polygon-mode';
|
|
3
|
+
export class DrawRectangleUsingThreePointsMode extends ThreeClickPolygonMode {
|
|
4
|
+
getThreeClickPolygon(coord1, coord2, coord3, modeConfig) {
|
|
5
|
+
const [p3, p4] = generatePointsParallelToLinePoints(coord1, coord2, coord3);
|
|
6
|
+
return {
|
|
7
|
+
type: 'Feature',
|
|
8
|
+
properties: {
|
|
9
|
+
shape: 'Rectangle',
|
|
10
|
+
},
|
|
11
|
+
geometry: {
|
|
12
|
+
type: 'Polygon',
|
|
13
|
+
coordinates: [
|
|
14
|
+
[
|
|
15
|
+
// Draw a polygon containing all the points of the LineString,
|
|
16
|
+
// then the points orthogonal to the lineString,
|
|
17
|
+
// then back to the starting position
|
|
18
|
+
coord1,
|
|
19
|
+
coord2,
|
|
20
|
+
p3,
|
|
21
|
+
p4,
|
|
22
|
+
coord1,
|
|
23
|
+
],
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Position, Polygon, FeatureOf } from '../geojson-types';
|
|
2
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
3
|
+
export declare class DrawSquareFromCenterMode extends TwoClickPolygonMode {
|
|
4
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): FeatureOf<Polygon>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
6
|
+
export class DrawSquareFromCenterMode extends TwoClickPolygonMode {
|
|
7
|
+
getTwoClickPolygon(coord1, coord2, modeConfig) {
|
|
8
|
+
// get the coordinates of the other two rectangle vertices
|
|
9
|
+
const coord3 = [coord2[0], coord1[1]];
|
|
10
|
+
const coord4 = [coord1[0], coord2[1]];
|
|
11
|
+
// determine the shortest distance to the origin, which will be the length of each square side
|
|
12
|
+
const distance1 = turfDistance(point(coord3), point(coord1));
|
|
13
|
+
const distance2 = turfDistance(point(coord4), point(coord1));
|
|
14
|
+
const shortestDistance = distance1 <= distance2 ? distance1 : distance2;
|
|
15
|
+
// determine which coordinate pair of the two is closest to the origin
|
|
16
|
+
const closestPoint = distance1 <= distance2 ? coord3 : coord4;
|
|
17
|
+
// create a linestring which will used to locate the second square vertex
|
|
18
|
+
const line = turfLineString([closestPoint, coord2]);
|
|
19
|
+
// get the coordinates of the second square vertex
|
|
20
|
+
const newPoint = turfAlong(line, shortestDistance);
|
|
21
|
+
const corner = newPoint.geometry.coordinates;
|
|
22
|
+
// determine the longitude and latitude values of the opposite corner
|
|
23
|
+
const longitude = coord1[0] > corner[0]
|
|
24
|
+
? coord1[0] + Math.abs(coord1[0] - corner[0])
|
|
25
|
+
: coord1[0] - Math.abs(coord1[0] - corner[0]);
|
|
26
|
+
const latitude = coord1[1] > corner[1]
|
|
27
|
+
? coord1[1] + Math.abs(coord1[1] - corner[1])
|
|
28
|
+
: coord1[1] - Math.abs(coord1[1] - corner[1]);
|
|
29
|
+
const square = bboxPolygon([longitude, latitude, corner[0], corner[1]]);
|
|
30
|
+
square.properties = square.properties || {};
|
|
31
|
+
square.properties.shape = 'Square';
|
|
32
|
+
// @ts-expect-error turf typing too wide
|
|
33
|
+
return square;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Position, Polygon, FeatureOf } from '../geojson-types';
|
|
2
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
3
|
+
export declare class DrawSquareMode extends TwoClickPolygonMode {
|
|
4
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): FeatureOf<Polygon>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
6
|
+
export class DrawSquareMode extends TwoClickPolygonMode {
|
|
7
|
+
getTwoClickPolygon(coord1, coord2, modeConfig) {
|
|
8
|
+
// get the coordinates of the other two rectangle vertices
|
|
9
|
+
const coord3 = [coord2[0], coord1[1]];
|
|
10
|
+
const coord4 = [coord1[0], coord2[1]];
|
|
11
|
+
// determine the shortest distance to the origin, which will be the length of each square side
|
|
12
|
+
const distance1 = turfDistance(point(coord3), point(coord1));
|
|
13
|
+
const distance2 = turfDistance(point(coord4), point(coord1));
|
|
14
|
+
const shortestDistance = distance1 <= distance2 ? distance1 : distance2;
|
|
15
|
+
// determine which coordinate pair of the two is closest to the origin
|
|
16
|
+
const closestPoint = distance1 <= distance2 ? coord3 : coord4;
|
|
17
|
+
// create a linestring which will used to locate the second square vertex
|
|
18
|
+
const line = turfLineString([closestPoint, coord2]);
|
|
19
|
+
// get the coordinates of the second square vertex
|
|
20
|
+
const newPoint = turfAlong(line, shortestDistance);
|
|
21
|
+
const corner = newPoint.geometry.coordinates;
|
|
22
|
+
const square = bboxPolygon([coord1[0], coord1[1], corner[0], corner[1]]);
|
|
23
|
+
square.properties = square.properties || {};
|
|
24
|
+
square.properties.shape = 'Square';
|
|
25
|
+
// @ts-expect-error turf types too wide
|
|
26
|
+
return square;
|
|
27
|
+
}
|
|
28
|
+
}
|