@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
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<h1 align="center">editable-layers | <a href="https://@deck.gl-community/editable-layers">Website</a></h1>
|
|
2
|
+
|
|
3
|
+
<h5 align="center">An editing framework for deck.gl</h5>
|
|
4
|
+
|
|
5
|
+
[](https://@deck.gl-community/editable-layers)
|
|
6
|
+
|
|
7
|
+
[@deck.gl-community/editable-layers](https://@deck.gl-community/editable-layers) provides editable and interactive map overlay layers, built using the power of [deck.gl](https://deck.gl/).
|
|
8
|
+
|
|
9
|
+
## Getting started
|
|
10
|
+
|
|
11
|
+
### Running the example
|
|
12
|
+
|
|
13
|
+
1. `git clone git@github.com:uber/@deck.gl-community/editable-layers.git`
|
|
14
|
+
2. `cd @deck.gl-community/editable-layers`
|
|
15
|
+
3. `yarn`
|
|
16
|
+
4. `cd examples/advanced`
|
|
17
|
+
5. `yarn`
|
|
18
|
+
6. `export MapboxAccessToken='<Add your key>'`
|
|
19
|
+
7. `yarn start-local`
|
|
20
|
+
8. You can now view and edit geometry.
|
|
21
|
+
|
|
22
|
+
### Installation
|
|
23
|
+
|
|
24
|
+
For npm
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @deck.gl-community/editable-layers
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
For yarn
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
yarn add @deck.gl-community/editable-layers
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### `EditableGeoJsonLayer`
|
|
37
|
+
|
|
38
|
+
[EditableGeoJsonLayer](/docs/modules/editor-layers/api-reference/editable-geojson-layer.md) is implemented as a [deck.gl](https://deck.gl) layer. It provides the ability to view and edit multiple types of geometry formatted as [GeoJSON](https://tools.ietf.org/html/rfc7946) (an open standard format for geometry) including polygons, lines, and points.
|
|
39
|
+
|
|
40
|
+
```jsx
|
|
41
|
+
import DeckGL from '@deck.gl/react';
|
|
42
|
+
import { EditableGeoJsonLayer, DrawPolygonMode } from '@deck.gl-community/editable-layers';
|
|
43
|
+
|
|
44
|
+
const myFeatureCollection = {
|
|
45
|
+
type: 'FeatureCollection',
|
|
46
|
+
features: [
|
|
47
|
+
/* insert features here */
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const selectedFeatureIndexes = [];
|
|
52
|
+
|
|
53
|
+
class App extends React.Component {
|
|
54
|
+
state = {
|
|
55
|
+
data: myFeatureCollection,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
render() {
|
|
59
|
+
const layer = new EditableGeoJsonLayer({
|
|
60
|
+
id: 'geojson-layer',
|
|
61
|
+
data: this.state.data,
|
|
62
|
+
mode: DrawPolygonMode,
|
|
63
|
+
selectedFeatureIndexes,
|
|
64
|
+
|
|
65
|
+
onEdit: ({ updatedData }) => {
|
|
66
|
+
this.setState({
|
|
67
|
+
data: updatedData,
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return <DeckGL {...this.props.viewport} layers={[layer]} />;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Useful examples (Codesandbox)
|
|
78
|
+
|
|
79
|
+
- [Hello World (using deck.gl)](https://codesandbox.io/s/hello-world-nebulagl-csvsm)
|
|
80
|
+
- [With Toolbox](https://codesandbox.io/s/hello-nebulagl-with-toolbox-oelkr)
|
|
81
|
+
- [No React](https://codesandbox.io/s/deckgl-and-nebulagl-editablegeojsonlayer-no-react-p9yrs)
|
|
82
|
+
- [Custom EditMode](https://codesandbox.io/s/connect-the-dots-mode-yow65)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A multiplier for screen-space width/scale for Arc, Line, Icon and Text layers.
|
|
3
|
+
* Required in order to maintain the same appearance after upgrading to deck.gl v8.5.
|
|
4
|
+
* https://github.com/visgl/deck.gl/blob/master/docs/upgrade-guide.md
|
|
5
|
+
*/
|
|
6
|
+
export declare const PROJECTED_PIXEL_SIZE_MULTIPLIER: number;
|
|
7
|
+
/**
|
|
8
|
+
* Unit literal to shader unit number conversion.
|
|
9
|
+
*/
|
|
10
|
+
export declare const UNIT: {
|
|
11
|
+
common: number;
|
|
12
|
+
meters: number;
|
|
13
|
+
pixels: number;
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A multiplier for screen-space width/scale for Arc, Line, Icon and Text layers.
|
|
3
|
+
* Required in order to maintain the same appearance after upgrading to deck.gl v8.5.
|
|
4
|
+
* https://github.com/visgl/deck.gl/blob/master/docs/upgrade-guide.md
|
|
5
|
+
*/
|
|
6
|
+
export const PROJECTED_PIXEL_SIZE_MULTIPLIER = 2 / 3;
|
|
7
|
+
/**
|
|
8
|
+
* Unit literal to shader unit number conversion.
|
|
9
|
+
*/
|
|
10
|
+
export const UNIT = {
|
|
11
|
+
common: 0,
|
|
12
|
+
meters: 1,
|
|
13
|
+
pixels: 2,
|
|
14
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import hermite from 'cubic-hermite-spline';
|
|
2
|
+
import turfDistance from '@turf/distance';
|
|
3
|
+
import { lineString } from '@turf/helpers';
|
|
4
|
+
const INTERPOLATION_INTERVAL = 0.005;
|
|
5
|
+
const INTERPOLATION_THRESHOLD = 0.001;
|
|
6
|
+
function calculateSingleTangent(p0, p1, d) {
|
|
7
|
+
const x = (p1[0] - p0[0]) / d;
|
|
8
|
+
const y = (p1[1] - p0[1]) / d;
|
|
9
|
+
return [x, y];
|
|
10
|
+
}
|
|
11
|
+
// eslint-disable-next-line max-statements
|
|
12
|
+
export function generateCurveFromControlPoints(line) {
|
|
13
|
+
// calculate knots
|
|
14
|
+
const knots = [0];
|
|
15
|
+
let prev = null;
|
|
16
|
+
let totalDistance = 0;
|
|
17
|
+
const { coordinates: coords } = line.geometry;
|
|
18
|
+
for (let i = 0; i < coords.length; i++) {
|
|
19
|
+
const cur = coords[i];
|
|
20
|
+
if (prev !== null) {
|
|
21
|
+
// @ts-expect-error turf types diff
|
|
22
|
+
totalDistance += turfDistance(prev, cur);
|
|
23
|
+
knots.push(totalDistance);
|
|
24
|
+
}
|
|
25
|
+
prev = cur;
|
|
26
|
+
}
|
|
27
|
+
// calculate tangents
|
|
28
|
+
const tangents = [];
|
|
29
|
+
// first tangent
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
tangents.push(calculateSingleTangent(coords[0], coords[1], knots[1] - knots[0]));
|
|
32
|
+
// second to before last
|
|
33
|
+
for (let i = 1; i < coords.length - 1; i++) {
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
const A = calculateSingleTangent(coords[i], coords[i + 1], knots[i + 1] - knots[i]);
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
const B = calculateSingleTangent(coords[i - 1], coords[i], knots[i] - knots[i - 1]);
|
|
38
|
+
const x = (A[0] + B[0]) / 2.0;
|
|
39
|
+
const y = (A[1] + B[1]) / 2.0;
|
|
40
|
+
tangents.push([x, y]);
|
|
41
|
+
}
|
|
42
|
+
// last tangent
|
|
43
|
+
const last = coords.length - 1;
|
|
44
|
+
tangents.push(
|
|
45
|
+
// @ts-ignore
|
|
46
|
+
calculateSingleTangent(coords[last - 1], coords[last], knots[last] - knots[last - 1]));
|
|
47
|
+
// generate curve
|
|
48
|
+
const result = [];
|
|
49
|
+
for (let i = 0; i < coords.length; i++) {
|
|
50
|
+
// add control point
|
|
51
|
+
result.push(coords[i]);
|
|
52
|
+
// add interpolated values
|
|
53
|
+
for (let t = knots[i] + INTERPOLATION_INTERVAL; t < knots[i + 1]; t += INTERPOLATION_INTERVAL) {
|
|
54
|
+
if (knots[i + 1] - t > INTERPOLATION_THRESHOLD) {
|
|
55
|
+
// Only add if not too close to a control point (knot = control point)
|
|
56
|
+
result.push(hermite(t, coords, tangents, knots));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return lineString(result);
|
|
61
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FeatureCollection } from '../geojson-types';
|
|
2
|
+
import { ModeProps, ClickEvent, PointerMoveEvent, StartDraggingEvent, StopDraggingEvent, DraggingEvent, GuideFeatureCollection } from './types';
|
|
3
|
+
import { GeoJsonEditMode } from './geojson-edit-mode';
|
|
4
|
+
export declare class CompositeMode extends GeoJsonEditMode {
|
|
5
|
+
_modes: Array<GeoJsonEditMode>;
|
|
6
|
+
constructor(modes: Array<GeoJsonEditMode>);
|
|
7
|
+
_coalesce<T>(callback: (arg0: GeoJsonEditMode) => T, resultEval?: ((arg0: T) => boolean | null | undefined) | null): T;
|
|
8
|
+
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>): void;
|
|
9
|
+
handlePointerMove(event: PointerMoveEvent, props: ModeProps<FeatureCollection>): void;
|
|
10
|
+
handleStartDragging(event: StartDraggingEvent, props: ModeProps<FeatureCollection>): void;
|
|
11
|
+
handleStopDragging(event: StopDraggingEvent, props: ModeProps<FeatureCollection>): void;
|
|
12
|
+
handleDragging(event: DraggingEvent, props: ModeProps<FeatureCollection>): void;
|
|
13
|
+
getGuides(props: ModeProps<FeatureCollection>): GuideFeatureCollection;
|
|
14
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { GeoJsonEditMode } from './geojson-edit-mode';
|
|
2
|
+
export class CompositeMode extends GeoJsonEditMode {
|
|
3
|
+
_modes;
|
|
4
|
+
constructor(modes) {
|
|
5
|
+
super();
|
|
6
|
+
this._modes = modes;
|
|
7
|
+
}
|
|
8
|
+
_coalesce(callback, resultEval = null) {
|
|
9
|
+
let result = null;
|
|
10
|
+
for (let i = 0; i < this._modes.length; i++) {
|
|
11
|
+
// eslint-disable-next-line callback-return
|
|
12
|
+
result = callback(this._modes[i]);
|
|
13
|
+
if (resultEval ? resultEval(result) : result) {
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
handleClick(event, props) {
|
|
20
|
+
this._coalesce((handler) => handler.handleClick(event, props));
|
|
21
|
+
}
|
|
22
|
+
handlePointerMove(event, props) {
|
|
23
|
+
return this._coalesce((handler) => handler.handlePointerMove(event, props));
|
|
24
|
+
}
|
|
25
|
+
handleStartDragging(event, props) {
|
|
26
|
+
return this._coalesce((handler) => handler.handleStartDragging(event, props));
|
|
27
|
+
}
|
|
28
|
+
handleStopDragging(event, props) {
|
|
29
|
+
return this._coalesce((handler) => handler.handleStopDragging(event, props));
|
|
30
|
+
}
|
|
31
|
+
handleDragging(event, props) {
|
|
32
|
+
return this._coalesce((handler) => handler.handleDragging(event, props));
|
|
33
|
+
}
|
|
34
|
+
getGuides(props) {
|
|
35
|
+
// TODO: Combine the guides *BUT* make sure if none of the results have
|
|
36
|
+
// changed to return the same object so that "guides !== this.state.guides"
|
|
37
|
+
// in editable-geojson-layer works.
|
|
38
|
+
const allGuides = [];
|
|
39
|
+
for (const mode of this._modes) {
|
|
40
|
+
allGuides.push(...mode.getGuides(props).features);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
type: 'FeatureCollection',
|
|
44
|
+
features: allGuides,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ClickEvent, PointerMoveEvent, ModeProps, GuideFeatureCollection, TentativeFeature } from './types';
|
|
2
|
+
import { Position, FeatureCollection } from '../geojson-types';
|
|
3
|
+
import { GeoJsonEditMode } from './geojson-edit-mode';
|
|
4
|
+
export declare class Draw90DegreePolygonMode extends GeoJsonEditMode {
|
|
5
|
+
createTentativeFeature(props: ModeProps<FeatureCollection>): TentativeFeature;
|
|
6
|
+
getGuides(props: ModeProps<FeatureCollection>): GuideFeatureCollection;
|
|
7
|
+
handlePointerMove(event: PointerMoveEvent, props: ModeProps<FeatureCollection>): void;
|
|
8
|
+
handleClick(event: ClickEvent, props: ModeProps<FeatureCollection>): void;
|
|
9
|
+
finalizedCoordinates(coords: Position[]): Position[][];
|
|
10
|
+
getIntermediatePoint(coordinates: Position[]): Position | null;
|
|
11
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import destination from '@turf/destination';
|
|
2
|
+
import bearing from '@turf/bearing';
|
|
3
|
+
import lineIntersect from '@turf/line-intersect';
|
|
4
|
+
import turfDistance from '@turf/distance';
|
|
5
|
+
import { point, lineString as turfLineString } from '@turf/helpers';
|
|
6
|
+
import { generatePointsParallelToLinePoints, getPickedEditHandle, getEditHandlesForGeometry, } from './utils';
|
|
7
|
+
import { GeoJsonEditMode } from './geojson-edit-mode';
|
|
8
|
+
export class Draw90DegreePolygonMode extends GeoJsonEditMode {
|
|
9
|
+
createTentativeFeature(props) {
|
|
10
|
+
const clickSequence = this.getClickSequence();
|
|
11
|
+
const { mapCoords } = props.lastPointerMoveEvent;
|
|
12
|
+
let p3;
|
|
13
|
+
if (clickSequence.length === 1) {
|
|
14
|
+
p3 = mapCoords;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const p1 = clickSequence[clickSequence.length - 2];
|
|
18
|
+
const p2 = clickSequence[clickSequence.length - 1];
|
|
19
|
+
[p3] = generatePointsParallelToLinePoints(p1, p2, mapCoords);
|
|
20
|
+
}
|
|
21
|
+
let tentativeFeature;
|
|
22
|
+
if (clickSequence.length < 3) {
|
|
23
|
+
// Draw a LineString connecting all the clicked points with the hovered point
|
|
24
|
+
tentativeFeature = {
|
|
25
|
+
type: 'Feature',
|
|
26
|
+
properties: {
|
|
27
|
+
guideType: 'tentative',
|
|
28
|
+
},
|
|
29
|
+
geometry: {
|
|
30
|
+
type: 'LineString',
|
|
31
|
+
coordinates: [...clickSequence, p3],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Draw a Polygon connecting all the clicked points with the hovered point
|
|
37
|
+
tentativeFeature = {
|
|
38
|
+
type: 'Feature',
|
|
39
|
+
properties: {
|
|
40
|
+
guideType: 'tentative',
|
|
41
|
+
},
|
|
42
|
+
geometry: {
|
|
43
|
+
type: 'Polygon',
|
|
44
|
+
coordinates: [[...clickSequence, p3, clickSequence[0]]],
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return tentativeFeature;
|
|
49
|
+
}
|
|
50
|
+
getGuides(props) {
|
|
51
|
+
const guides = {
|
|
52
|
+
type: 'FeatureCollection',
|
|
53
|
+
features: [],
|
|
54
|
+
};
|
|
55
|
+
const clickSequence = this.getClickSequence();
|
|
56
|
+
if (clickSequence.length === 0 || !props.lastPointerMoveEvent) {
|
|
57
|
+
return guides;
|
|
58
|
+
}
|
|
59
|
+
const tentativeFeature = this.createTentativeFeature(props);
|
|
60
|
+
guides.features.push(tentativeFeature);
|
|
61
|
+
guides.features = guides.features.concat(getEditHandlesForGeometry(tentativeFeature.geometry, -1));
|
|
62
|
+
// Slice off the handles that are are next to the pointer
|
|
63
|
+
guides.features = guides.features.slice(0, -1);
|
|
64
|
+
return guides;
|
|
65
|
+
}
|
|
66
|
+
handlePointerMove(event, props) {
|
|
67
|
+
props.onUpdateCursor('cell');
|
|
68
|
+
super.handlePointerMove(event, props);
|
|
69
|
+
}
|
|
70
|
+
handleClick(event, props) {
|
|
71
|
+
const { picks } = event;
|
|
72
|
+
const tentativeFeature = this.getTentativeGuide(props);
|
|
73
|
+
this.addClickSequence(event);
|
|
74
|
+
const clickSequence = this.getClickSequence();
|
|
75
|
+
if (!tentativeFeature) {
|
|
76
|
+
// nothing else to do
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (clickSequence.length === 3 && tentativeFeature.geometry.type === 'LineString') {
|
|
80
|
+
const lineString = tentativeFeature.geometry;
|
|
81
|
+
// Tweak the clicked position to be the snapped 90 degree point along the polygon
|
|
82
|
+
clickSequence[clickSequence.length - 1] =
|
|
83
|
+
lineString.coordinates[lineString.coordinates.length - 1];
|
|
84
|
+
}
|
|
85
|
+
else if (clickSequence.length > 3 && tentativeFeature.geometry.type === 'Polygon') {
|
|
86
|
+
const polygon = tentativeFeature.geometry;
|
|
87
|
+
// Tweak the clicked position to be the snapped 90 degree point along the polygon
|
|
88
|
+
clickSequence[clickSequence.length - 1] =
|
|
89
|
+
polygon.coordinates[0][polygon.coordinates[0].length - 2];
|
|
90
|
+
const clickedEditHandle = getPickedEditHandle(picks);
|
|
91
|
+
if (clickedEditHandle &&
|
|
92
|
+
Array.isArray(clickedEditHandle.properties.positionIndexes) &&
|
|
93
|
+
(clickedEditHandle.properties.positionIndexes[1] === 0 ||
|
|
94
|
+
clickedEditHandle.properties.positionIndexes[1] === polygon.coordinates[0].length - 3)) {
|
|
95
|
+
// They clicked the first or last point (or double-clicked), so complete the polygon
|
|
96
|
+
const polygonToAdd = {
|
|
97
|
+
type: 'Polygon',
|
|
98
|
+
coordinates: this.finalizedCoordinates([...polygon.coordinates[0]]),
|
|
99
|
+
};
|
|
100
|
+
this.resetClickSequence();
|
|
101
|
+
const editAction = this.getAddFeatureOrBooleanPolygonAction(polygonToAdd, props);
|
|
102
|
+
if (editAction) {
|
|
103
|
+
props.onEdit(editAction);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Trigger pointer move right away in order for it to update edit handles (to support double-click)
|
|
108
|
+
const fakePointerMoveEvent = {
|
|
109
|
+
screenCoords: [-1, -1],
|
|
110
|
+
mapCoords: event.mapCoords,
|
|
111
|
+
picks: [],
|
|
112
|
+
pointerDownPicks: null,
|
|
113
|
+
pointerDownScreenCoords: null,
|
|
114
|
+
pointerDownMapCoords: null,
|
|
115
|
+
cancelPan: () => { },
|
|
116
|
+
sourceEvent: null,
|
|
117
|
+
};
|
|
118
|
+
this.handlePointerMove(fakePointerMoveEvent, props);
|
|
119
|
+
}
|
|
120
|
+
finalizedCoordinates(coords) {
|
|
121
|
+
// Remove the hovered position
|
|
122
|
+
let coordinates = [[...coords.slice(0, -2), coords[0]]];
|
|
123
|
+
let pt = this.getIntermediatePoint([...coords]);
|
|
124
|
+
if (!pt) {
|
|
125
|
+
// if intermediate point with 90 degree not available
|
|
126
|
+
// try remove the last clicked point and get the intermediate point.
|
|
127
|
+
const tc = [...coords];
|
|
128
|
+
tc.splice(-3, 1);
|
|
129
|
+
pt = this.getIntermediatePoint([...tc]);
|
|
130
|
+
if (pt) {
|
|
131
|
+
coordinates = [[...coords.slice(0, -3), pt, coords[0]]];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
coordinates = [[...coords.slice(0, -2), pt, coords[0]]];
|
|
136
|
+
}
|
|
137
|
+
return coordinates;
|
|
138
|
+
}
|
|
139
|
+
getIntermediatePoint(coordinates) {
|
|
140
|
+
let pt = null;
|
|
141
|
+
if (coordinates.length > 4) {
|
|
142
|
+
const [p1, p2] = [...coordinates];
|
|
143
|
+
const angle1 = bearing(p1, p2);
|
|
144
|
+
const p3 = coordinates[coordinates.length - 3];
|
|
145
|
+
const p4 = coordinates[coordinates.length - 4];
|
|
146
|
+
const angle2 = bearing(p3, p4);
|
|
147
|
+
const angles = { first: [], second: [] };
|
|
148
|
+
// calculate 3 right angle points for first and last points in lineString
|
|
149
|
+
[1, 2, 3].forEach((factor) => {
|
|
150
|
+
const newAngle1 = angle1 + factor * 90;
|
|
151
|
+
// convert angles to 0 to -180 for anti-clock and 0 to 180 for clock wise
|
|
152
|
+
angles.first.push(newAngle1 > 180 ? newAngle1 - 360 : newAngle1);
|
|
153
|
+
const newAngle2 = angle2 + factor * 90;
|
|
154
|
+
angles.second.push(newAngle2 > 180 ? newAngle2 - 360 : newAngle2);
|
|
155
|
+
});
|
|
156
|
+
const distance = turfDistance(point(p1), point(p3));
|
|
157
|
+
// Draw imaginary right angle lines for both first and last points in lineString
|
|
158
|
+
// If there is intersection point for any 2 lines, will be the 90 degree point.
|
|
159
|
+
[0, 1, 2].forEach((indexFirst) => {
|
|
160
|
+
const line1 = turfLineString([
|
|
161
|
+
p1,
|
|
162
|
+
destination(p1, distance, angles.first[indexFirst]).geometry.coordinates,
|
|
163
|
+
]);
|
|
164
|
+
[0, 1, 2].forEach((indexSecond) => {
|
|
165
|
+
const line2 = turfLineString([
|
|
166
|
+
p3,
|
|
167
|
+
destination(p3, distance, angles.second[indexSecond]).geometry.coordinates,
|
|
168
|
+
]);
|
|
169
|
+
const fc = lineIntersect(line1, line2);
|
|
170
|
+
if (fc && fc.features.length) {
|
|
171
|
+
// found the intersect point
|
|
172
|
+
pt = fc.features[0].geometry.coordinates;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
return pt;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ModeProps, Tooltip } from './types';
|
|
2
|
+
import { Position, Polygon, FeatureOf, FeatureCollection } from '../geojson-types';
|
|
3
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
4
|
+
export declare class DrawCircleByDiameterMode extends TwoClickPolygonMode {
|
|
5
|
+
radius: number | null | undefined;
|
|
6
|
+
position: Position;
|
|
7
|
+
areaCircle: number | null | undefined;
|
|
8
|
+
diameter: number | null | undefined;
|
|
9
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): FeatureOf<Polygon>;
|
|
10
|
+
/**
|
|
11
|
+
* define the default function to display the tooltip for
|
|
12
|
+
* nebula geometry mode type
|
|
13
|
+
* @param props properties of geometry nebula mode
|
|
14
|
+
*/
|
|
15
|
+
getTooltips(props: ModeProps<FeatureCollection>): Tooltip[];
|
|
16
|
+
/**
|
|
17
|
+
* redefine the tooltip of geometry
|
|
18
|
+
* @param modeConfig
|
|
19
|
+
* @param radius
|
|
20
|
+
* @param areaCircle
|
|
21
|
+
* @param diameter
|
|
22
|
+
*/
|
|
23
|
+
_getTooltips: (args: any) => any;
|
|
24
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import circle from '@turf/circle';
|
|
2
|
+
import distance from '@turf/distance';
|
|
3
|
+
import area from '@turf/area';
|
|
4
|
+
import memoize from '../memoize';
|
|
5
|
+
import { getIntermediatePosition } from './geojson-edit-mode';
|
|
6
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
7
|
+
export class DrawCircleByDiameterMode extends TwoClickPolygonMode {
|
|
8
|
+
radius = null;
|
|
9
|
+
position = null;
|
|
10
|
+
areaCircle = null;
|
|
11
|
+
diameter = null;
|
|
12
|
+
getTwoClickPolygon(coord1, coord2, modeConfig) {
|
|
13
|
+
// Default turf value for circle is 64
|
|
14
|
+
const { steps = 64 } = modeConfig || {};
|
|
15
|
+
const options = { steps };
|
|
16
|
+
if (steps < 4) {
|
|
17
|
+
console.warn('Minimum steps to draw a circle is 4 '); // eslint-disable-line no-console,no-undef
|
|
18
|
+
options.steps = 4;
|
|
19
|
+
}
|
|
20
|
+
const centerCoordinates = getIntermediatePosition(coord1, coord2);
|
|
21
|
+
// setting value of radius as distance of center and other point
|
|
22
|
+
this.radius = Math.max(distance(coord1, centerCoordinates), 0.001);
|
|
23
|
+
// setting value of diameter as distance of points
|
|
24
|
+
this.diameter = Math.max(distance(coord1, coord2), 0.001);
|
|
25
|
+
// setting position tooltip as center of circle
|
|
26
|
+
this.position = centerCoordinates;
|
|
27
|
+
const geometry = circle(centerCoordinates, this.radius, options);
|
|
28
|
+
geometry.properties = geometry.properties || {};
|
|
29
|
+
geometry.properties.shape = 'Circle';
|
|
30
|
+
// calculate area of circle with turf function
|
|
31
|
+
this.areaCircle = area(geometry);
|
|
32
|
+
// @ts-expect-error turf types diff
|
|
33
|
+
return geometry;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* define the default function to display the tooltip for
|
|
37
|
+
* nebula geometry mode type
|
|
38
|
+
* @param props properties of geometry nebula mode
|
|
39
|
+
*/
|
|
40
|
+
getTooltips(props) {
|
|
41
|
+
return this._getTooltips({
|
|
42
|
+
modeConfig: props.modeConfig,
|
|
43
|
+
radius: this.radius,
|
|
44
|
+
areaCircle: this.areaCircle,
|
|
45
|
+
diameter: this.diameter,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* redefine the tooltip of geometry
|
|
50
|
+
* @param modeConfig
|
|
51
|
+
* @param radius
|
|
52
|
+
* @param areaCircle
|
|
53
|
+
* @param diameter
|
|
54
|
+
*/
|
|
55
|
+
_getTooltips = memoize(({ modeConfig, radius, areaCircle, diameter }) => {
|
|
56
|
+
let tooltips = [];
|
|
57
|
+
const { formatTooltip } = modeConfig || {};
|
|
58
|
+
let text;
|
|
59
|
+
if (radius && areaCircle) {
|
|
60
|
+
if (formatTooltip) {
|
|
61
|
+
text = formatTooltip(radius);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// By default, round to 2 decimal places and append units
|
|
65
|
+
text = `Radius: ${parseFloat(radius).toFixed(2)} kilometers
|
|
66
|
+
\n Area: ${parseFloat(areaCircle).toFixed(2)}
|
|
67
|
+
\n Diameter: ${parseFloat(diameter).toFixed(2)} kilometers`;
|
|
68
|
+
}
|
|
69
|
+
tooltips = [
|
|
70
|
+
{
|
|
71
|
+
position: this.position,
|
|
72
|
+
text,
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
return tooltips;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ModeProps, Tooltip } from './types';
|
|
2
|
+
import { Position, Polygon, FeatureOf, FeatureCollection } from '../geojson-types';
|
|
3
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
4
|
+
export declare class DrawCircleFromCenterMode extends TwoClickPolygonMode {
|
|
5
|
+
radius: number | null | undefined;
|
|
6
|
+
position: Position;
|
|
7
|
+
areaCircle: number | null | undefined;
|
|
8
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): FeatureOf<Polygon>;
|
|
9
|
+
/**
|
|
10
|
+
* define the default function to display the tooltip for
|
|
11
|
+
* nebula geometry mode type
|
|
12
|
+
* @param props properties of geometry nebula mode
|
|
13
|
+
*/
|
|
14
|
+
getTooltips(props: ModeProps<FeatureCollection>): Tooltip[];
|
|
15
|
+
/**
|
|
16
|
+
* redefine the tooltip of geometry
|
|
17
|
+
* @param modeConfig
|
|
18
|
+
* @param radius
|
|
19
|
+
* @param areaCircle
|
|
20
|
+
*/
|
|
21
|
+
_getTooltips: (args: any) => any;
|
|
22
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import circle from '@turf/circle';
|
|
2
|
+
import distance from '@turf/distance';
|
|
3
|
+
import area from '@turf/area';
|
|
4
|
+
import memoize from '../memoize';
|
|
5
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
6
|
+
export class DrawCircleFromCenterMode extends TwoClickPolygonMode {
|
|
7
|
+
radius = null;
|
|
8
|
+
position = null;
|
|
9
|
+
areaCircle = null;
|
|
10
|
+
getTwoClickPolygon(coord1, coord2, modeConfig) {
|
|
11
|
+
// Default turf value for circle is 64
|
|
12
|
+
const { steps = 64 } = modeConfig || {};
|
|
13
|
+
const options = { steps };
|
|
14
|
+
// setting with position of center of circle
|
|
15
|
+
this.position = coord2;
|
|
16
|
+
if (steps < 4) {
|
|
17
|
+
console.warn('Minimum steps to draw a circle is 4 '); // eslint-disable-line no-console,no-undef
|
|
18
|
+
options.steps = 4;
|
|
19
|
+
}
|
|
20
|
+
// setting value of radius as distance of center and other point
|
|
21
|
+
this.radius = Math.max(distance(coord1, coord2), 0.001);
|
|
22
|
+
const geometry = circle(coord1, this.radius, options);
|
|
23
|
+
geometry.properties = geometry.properties || {};
|
|
24
|
+
geometry.properties.shape = 'Circle';
|
|
25
|
+
// calculate area of circle with turf function
|
|
26
|
+
this.areaCircle = area(geometry);
|
|
27
|
+
// @ts-expect-error turf types diff
|
|
28
|
+
return geometry;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* define the default function to display the tooltip for
|
|
32
|
+
* nebula geometry mode type
|
|
33
|
+
* @param props properties of geometry nebula mode
|
|
34
|
+
*/
|
|
35
|
+
getTooltips(props) {
|
|
36
|
+
return this._getTooltips({
|
|
37
|
+
modeConfig: props?.modeConfig,
|
|
38
|
+
radius: this.radius,
|
|
39
|
+
areaCircle: this.areaCircle,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* redefine the tooltip of geometry
|
|
44
|
+
* @param modeConfig
|
|
45
|
+
* @param radius
|
|
46
|
+
* @param areaCircle
|
|
47
|
+
*/
|
|
48
|
+
_getTooltips = memoize(({ modeConfig, radius, areaCircle }) => {
|
|
49
|
+
let tooltips = [];
|
|
50
|
+
const { formatTooltip } = modeConfig || {};
|
|
51
|
+
let text;
|
|
52
|
+
if (radius && areaCircle) {
|
|
53
|
+
if (formatTooltip) {
|
|
54
|
+
text = formatTooltip(radius);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// By default, round to 2 decimal places and append units
|
|
58
|
+
text = `Radius: ${parseFloat(radius).toFixed(2)} kilometers
|
|
59
|
+
\n Area: ${parseFloat(areaCircle).toFixed(2)}`;
|
|
60
|
+
}
|
|
61
|
+
tooltips = [
|
|
62
|
+
{
|
|
63
|
+
position: this.position,
|
|
64
|
+
text,
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
return tooltips;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Position, Polygon, FeatureOf } from '../geojson-types';
|
|
2
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
3
|
+
export declare class DrawEllipseByBoundingBoxMode extends TwoClickPolygonMode {
|
|
4
|
+
getTwoClickPolygon(coord1: Position, coord2: Position, modeConfig: any): FeatureOf<Polygon>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import bboxPolygon from '@turf/bbox-polygon';
|
|
2
|
+
import distance from '@turf/distance';
|
|
3
|
+
import ellipse from '@turf/ellipse';
|
|
4
|
+
import { point } from '@turf/helpers';
|
|
5
|
+
import { getIntermediatePosition } from './geojson-edit-mode';
|
|
6
|
+
import { TwoClickPolygonMode } from './two-click-polygon-mode';
|
|
7
|
+
export class DrawEllipseByBoundingBoxMode extends TwoClickPolygonMode {
|
|
8
|
+
getTwoClickPolygon(coord1, coord2, modeConfig) {
|
|
9
|
+
const minX = Math.min(coord1[0], coord2[0]);
|
|
10
|
+
const minY = Math.min(coord1[1], coord2[1]);
|
|
11
|
+
const maxX = Math.max(coord1[0], coord2[0]);
|
|
12
|
+
const maxY = Math.max(coord1[1], coord2[1]);
|
|
13
|
+
const polygonPoints = bboxPolygon([minX, minY, maxX, maxY]).geometry.coordinates[0];
|
|
14
|
+
const centerCoordinates = getIntermediatePosition(coord1, coord2);
|
|
15
|
+
const xSemiAxis = Math.max(distance(point(polygonPoints[0]), point(polygonPoints[1])), 0.001);
|
|
16
|
+
const ySemiAxis = Math.max(distance(point(polygonPoints[0]), point(polygonPoints[3])), 0.001);
|
|
17
|
+
// @ts-expect-error fix return types
|
|
18
|
+
return ellipse(centerCoordinates, xSemiAxis, ySemiAxis);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Position, Polygon, FeatureOf } from '../geojson-types';
|
|
2
|
+
import { ThreeClickPolygonMode } from './three-click-polygon-mode';
|
|
3
|
+
export declare class DrawEllipseUsingThreePointsMode extends ThreeClickPolygonMode {
|
|
4
|
+
getThreeClickPolygon(coord1: Position, coord2: Position, coord3: Position, modeConfig: any): FeatureOf<Polygon> | null | undefined;
|
|
5
|
+
}
|