solid-map-gl 1.12.0 → 2.0.0
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 +157 -30
- package/dist/index.d.ts +489 -0
- package/dist/index.js +11 -0
- package/dist/index.jsx +2320 -0
- package/package.json +46 -35
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +0 -1
- package/dist/source/components/Atmosphere/index.jsx +0 -13
- package/dist/source/components/Camera/index.jsx +0 -108
- package/dist/source/components/Control/index.jsx +0 -33
- package/dist/source/components/Draw/drawingStyles.js +0 -225
- package/dist/source/components/Draw/index.jsx +0 -55
- package/dist/source/components/Draw/modes/index.js +0 -9
- package/dist/source/components/Draw/modes/line_string.js +0 -43
- package/dist/source/components/Draw/modes/measurements.js +0 -76
- package/dist/source/components/Draw/modes/multi_point.js +0 -37
- package/dist/source/components/Draw/modes/point.js +0 -25
- package/dist/source/components/Draw/modes/polygon.js +0 -25
- package/dist/source/components/Draw/modes/radius.js +0 -138
- package/dist/source/components/Draw/modes/rectangle.js +0 -118
- package/dist/source/components/Draw/modes/rectangle_assisted.js +0 -233
- package/dist/source/components/Image/index.jsx +0 -135
- package/dist/source/components/Layer/index.jsx +0 -125
- package/dist/source/components/Layer3D/index.jsx +0 -330
- package/dist/source/components/Light/index.jsx +0 -10
- package/dist/source/components/MapGL/index.jsx +0 -272
- package/dist/source/components/MapProvider/index.jsx +0 -9
- package/dist/source/components/Marker/index.jsx +0 -57
- package/dist/source/components/Popup/index.jsx +0 -38
- package/dist/source/components/Source/index.jsx +0 -89
- package/dist/source/components/Terrain/index.jsx +0 -30
- package/dist/source/events.js +0 -78
- package/dist/source/index.jsx +0 -14
- package/dist/source/mapStyles.js +0 -116
- package/dist/source/styles.js +0 -62
- package/dist/types/components/Atmosphere/index.d.ts +0 -8
- package/dist/types/components/Camera/index.d.ts +0 -54
- package/dist/types/components/Control/index.d.ts +0 -15
- package/dist/types/components/Draw/drawingStyles.d.ts +0 -20
- package/dist/types/components/Draw/index.d.ts +0 -16
- package/dist/types/components/Draw/modes/index.d.ts +0 -6
- package/dist/types/components/Draw/modes/line_string.d.ts +0 -2
- package/dist/types/components/Draw/modes/multi_point.d.ts +0 -2
- package/dist/types/components/Draw/modes/point.d.ts +0 -2
- package/dist/types/components/Draw/modes/polygon.d.ts +0 -2
- package/dist/types/components/Draw/modes/radius.d.ts +0 -2
- package/dist/types/components/Draw/modes/rectangle.d.ts +0 -2
- package/dist/types/components/Draw/modes/rectangle_assisted.d.ts +0 -18
- package/dist/types/components/Image/index.d.ts +0 -28
- package/dist/types/components/Layer/index.d.ts +0 -32
- package/dist/types/components/Layer3D/index.d.ts +0 -22
- package/dist/types/components/Light/index.d.ts +0 -8
- package/dist/types/components/MapGL/index.d.ts +0 -95
- package/dist/types/components/MapProvider/index.d.ts +0 -11
- package/dist/types/components/Marker/index.d.ts +0 -28
- package/dist/types/components/Popup/index.d.ts +0 -18
- package/dist/types/components/Source/index.d.ts +0 -13
- package/dist/types/components/Terrain/index.d.ts +0 -7
- package/dist/types/events.d.ts +0 -103
- package/dist/types/index.d.ts +0 -16
- package/dist/types/mapStyles.d.ts +0 -2
- package/dist/types/styles.d.ts +0 -2
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
export default [
|
|
2
|
-
// point active
|
|
3
|
-
// {
|
|
4
|
-
// id: "points-active-halo",
|
|
5
|
-
// type: "circle",
|
|
6
|
-
// filter: [
|
|
7
|
-
// "all",
|
|
8
|
-
// ["==", "$type", "Point"],
|
|
9
|
-
// ["==", "meta", "feature"],
|
|
10
|
-
// ["==", "active", "true"],
|
|
11
|
-
// ],
|
|
12
|
-
// paint: {
|
|
13
|
-
// "circle-radius": 9,
|
|
14
|
-
// "circle-color": "#f7ad3b",
|
|
15
|
-
// "circle-opacity": 0.75,
|
|
16
|
-
// },
|
|
17
|
-
// },
|
|
18
|
-
// {
|
|
19
|
-
// id: "highlight-active-points",
|
|
20
|
-
// type: "circle",
|
|
21
|
-
// filter: [
|
|
22
|
-
// "all",
|
|
23
|
-
// ["==", "$type", "Point"],
|
|
24
|
-
// ["==", "meta", "feature"],
|
|
25
|
-
// ["==", "active", "true"],
|
|
26
|
-
// ],
|
|
27
|
-
// paint: {
|
|
28
|
-
// "circle-radius": 5,
|
|
29
|
-
// "circle-color": ["get", "user_color"],
|
|
30
|
-
// },
|
|
31
|
-
// },
|
|
32
|
-
// // point inactive
|
|
33
|
-
// {
|
|
34
|
-
// id: "points-inactive-halo",
|
|
35
|
-
// type: "circle",
|
|
36
|
-
// filter: [
|
|
37
|
-
// "all",
|
|
38
|
-
// ["==", "$type", "Point"],
|
|
39
|
-
// ["==", "meta", "feature"],
|
|
40
|
-
// ["==", "active", "false"],
|
|
41
|
-
// ["!has", "user_label"],
|
|
42
|
-
// ],
|
|
43
|
-
// paint: {
|
|
44
|
-
// "circle-radius": 8,
|
|
45
|
-
// "circle-color": "#FFFFFF",
|
|
46
|
-
// "circle-opacity": 0.75,
|
|
47
|
-
// },
|
|
48
|
-
// },
|
|
49
|
-
// {
|
|
50
|
-
// id: "points-inactive",
|
|
51
|
-
// type: "circle",
|
|
52
|
-
// filter: [
|
|
53
|
-
// "all",
|
|
54
|
-
// ["==", "$type", "Point"],
|
|
55
|
-
// ["==", "meta", "feature"],
|
|
56
|
-
// ["==", "active", "false"],
|
|
57
|
-
// ["!has", "user_label"],
|
|
58
|
-
// ],
|
|
59
|
-
// paint: {
|
|
60
|
-
// "circle-radius": 5,
|
|
61
|
-
// "circle-color": ["get", "user_color"],
|
|
62
|
-
// },
|
|
63
|
-
// },
|
|
64
|
-
// {
|
|
65
|
-
// id: "points-inactive-label",
|
|
66
|
-
// type: "symbol",
|
|
67
|
-
// filter: [
|
|
68
|
-
// "all",
|
|
69
|
-
// ["==", "$type", "Point"],
|
|
70
|
-
// ["==", "meta", "feature"],
|
|
71
|
-
// ["==", "active", "false"],
|
|
72
|
-
// ["has", "user_label"],
|
|
73
|
-
// ],
|
|
74
|
-
// layout: {
|
|
75
|
-
// "text-field": ["get", "user_label"],
|
|
76
|
-
// "text-font": ["Arial Regular"],
|
|
77
|
-
// "text-anchor": "bottom",
|
|
78
|
-
// "text-size": 20,
|
|
79
|
-
// },
|
|
80
|
-
// paint: {
|
|
81
|
-
// "text-halo-color": "rgba(255,255,255,0.75)",
|
|
82
|
-
// "text-halo-width": 2,
|
|
83
|
-
// "text-halo-blur": 1,
|
|
84
|
-
// "text-color": ["get", "user_color"],
|
|
85
|
-
// },
|
|
86
|
-
// },
|
|
87
|
-
// // line avtive (being drawn)
|
|
88
|
-
// {
|
|
89
|
-
// id: "gl-draw-line-active",
|
|
90
|
-
// type: "line",
|
|
91
|
-
// filter: ["all", ["==", "$type", "LineString"], ["==", "active", "true"]],
|
|
92
|
-
// layout: {
|
|
93
|
-
// "line-cap": "round",
|
|
94
|
-
// "line-join": "round",
|
|
95
|
-
// },
|
|
96
|
-
// paint: {
|
|
97
|
-
// "line-color": "#f7ad3b",
|
|
98
|
-
// "line-dasharray": [0.2, 2],
|
|
99
|
-
// "line-width": 3,
|
|
100
|
-
// },
|
|
101
|
-
// },
|
|
102
|
-
// {
|
|
103
|
-
// id: "gl-draw-line-inactive",
|
|
104
|
-
// type: "line",
|
|
105
|
-
// filter: ["all", ["==", "$type", "LineString"], ["==", "active", "false"]],
|
|
106
|
-
// layout: {
|
|
107
|
-
// "line-cap": "round",
|
|
108
|
-
// "line-join": "round",
|
|
109
|
-
// },
|
|
110
|
-
// paint: {
|
|
111
|
-
// "line-color": [
|
|
112
|
-
// "case",
|
|
113
|
-
// ["has", "user_color"],
|
|
114
|
-
// ["get", "user_color"],
|
|
115
|
-
// "#f7ad3b",
|
|
116
|
-
// ],
|
|
117
|
-
// "line-width": 2,
|
|
118
|
-
// },
|
|
119
|
-
// },
|
|
120
|
-
// // vertex point halos
|
|
121
|
-
// {
|
|
122
|
-
// id: "gl-draw-polygon-and-line-vertex-halo-active",
|
|
123
|
-
// type: "circle",
|
|
124
|
-
// filter: [
|
|
125
|
-
// "all",
|
|
126
|
-
// ["==", "meta", "vertex"],
|
|
127
|
-
// ["==", "$type", "Point"],
|
|
128
|
-
// ["!=", "mode", "static"],
|
|
129
|
-
// ],
|
|
130
|
-
// paint: {
|
|
131
|
-
// "circle-radius": 5,
|
|
132
|
-
// "circle-color": "#FFF",
|
|
133
|
-
// "circle-opacity": 0.75,
|
|
134
|
-
// },
|
|
135
|
-
// },
|
|
136
|
-
// // vertex points
|
|
137
|
-
// {
|
|
138
|
-
// id: "gl-draw-polygon-and-line-vertex-active",
|
|
139
|
-
// type: "circle",
|
|
140
|
-
// filter: [
|
|
141
|
-
// "all",
|
|
142
|
-
// ["==", "meta", "vertex"],
|
|
143
|
-
// ["==", "$type", "Point"],
|
|
144
|
-
// ["!=", "mode", "static"],
|
|
145
|
-
// ],
|
|
146
|
-
// paint: {
|
|
147
|
-
// "circle-radius": 3,
|
|
148
|
-
// "circle-color": "#f7ad3b",
|
|
149
|
-
// },
|
|
150
|
-
// },
|
|
151
|
-
// // polygon fill
|
|
152
|
-
// {
|
|
153
|
-
// id: "gl-draw-polygon-fill-inactive",
|
|
154
|
-
// type: "fill",
|
|
155
|
-
// filter: ["==", "$type", "Polygon"],
|
|
156
|
-
// paint: {
|
|
157
|
-
// "fill-color": [
|
|
158
|
-
// "case",
|
|
159
|
-
// ["has", "user_color"],
|
|
160
|
-
// ["get", "user_color"],
|
|
161
|
-
// "#f7ad3b",
|
|
162
|
-
// ],
|
|
163
|
-
// "fill-opacity": 0.1,
|
|
164
|
-
// },
|
|
165
|
-
// },
|
|
166
|
-
// // polygon outline stroke
|
|
167
|
-
// // This doesn't style the first edge of the polygon, which uses the line stroke styling instead
|
|
168
|
-
// {
|
|
169
|
-
// id: "gl-draw-polygon-stroke-active",
|
|
170
|
-
// type: "line",
|
|
171
|
-
// filter: ["all", ["==", "$type", "Polygon"], ["==", "active", "true"]],
|
|
172
|
-
// layout: {
|
|
173
|
-
// "line-cap": "round",
|
|
174
|
-
// "line-join": "round",
|
|
175
|
-
// },
|
|
176
|
-
// paint: {
|
|
177
|
-
// "line-color": "#f7ad3b",
|
|
178
|
-
// "line-dasharray": [0.5, 2],
|
|
179
|
-
// "line-width": 2,
|
|
180
|
-
// },
|
|
181
|
-
// },
|
|
182
|
-
// {
|
|
183
|
-
// id: "gl-draw-polygon-stroke-inactive",
|
|
184
|
-
// type: "line",
|
|
185
|
-
// filter: ["all", ["==", "$type", "Polygon"], ["==", "active", "false"]],
|
|
186
|
-
// layout: {
|
|
187
|
-
// "line-cap": "round",
|
|
188
|
-
// "line-join": "round",
|
|
189
|
-
// },
|
|
190
|
-
// paint: {
|
|
191
|
-
// "line-color": [
|
|
192
|
-
// "case",
|
|
193
|
-
// ["has", "user_color"],
|
|
194
|
-
// ["get", "user_color"],
|
|
195
|
-
// "#f7ad3b",
|
|
196
|
-
// ],
|
|
197
|
-
// "line-width": 2,
|
|
198
|
-
// },
|
|
199
|
-
// },
|
|
200
|
-
{
|
|
201
|
-
id: "measure-label",
|
|
202
|
-
type: "symbol",
|
|
203
|
-
filter: ["all", ["==", "$type", "Point"], ["==", "user_type", "measure"]],
|
|
204
|
-
layout: {
|
|
205
|
-
"text-field": ["get", "user_value"],
|
|
206
|
-
"text-anchor": ["get", "user_anchor"],
|
|
207
|
-
"text-offset": [
|
|
208
|
-
"match",
|
|
209
|
-
["get", "user_anchor"],
|
|
210
|
-
"bottom",
|
|
211
|
-
[0, -0.5],
|
|
212
|
-
[0, 0],
|
|
213
|
-
],
|
|
214
|
-
"text-size": 12,
|
|
215
|
-
"text-allow-overlap": true,
|
|
216
|
-
"text-ignore-placement": true,
|
|
217
|
-
},
|
|
218
|
-
paint: {
|
|
219
|
-
"text-halo-color": "rgba(255,255,255,0.75)",
|
|
220
|
-
"text-halo-width": 2,
|
|
221
|
-
"text-halo-blur": 1,
|
|
222
|
-
"text-color": "#000",
|
|
223
|
-
},
|
|
224
|
-
},
|
|
225
|
-
];
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { onCleanup } from "solid-js";
|
|
2
|
-
import { useMapContext } from "../MapProvider";
|
|
3
|
-
import { drawEvents } from "../../events";
|
|
4
|
-
import styles from "./drawingStyles";
|
|
5
|
-
import { draw_point, draw_line_string, draw_polygon,
|
|
6
|
-
// draw_circle,
|
|
7
|
-
draw_radius, draw_rectangle, } from "./modes/index";
|
|
8
|
-
export const Draw = (props) => {
|
|
9
|
-
const [ctx] = useMapContext();
|
|
10
|
-
// const modes = props.lib.modes;
|
|
11
|
-
// modes.point = PointMode;
|
|
12
|
-
// modes.multi_point = MultiPointMode;
|
|
13
|
-
// modes.line_string = LineStringeMode;
|
|
14
|
-
// modes.draw_polygon = PolygonMode;
|
|
15
|
-
// modes.radius = RadiusMode;
|
|
16
|
-
// modes.rectangle = RectangleMode;
|
|
17
|
-
// modes.rectangle_assisted = RectangleAssistedMode;
|
|
18
|
-
// Add Draw Control
|
|
19
|
-
const draw = new props.lib({
|
|
20
|
-
styles: [...props.lib.lib.theme, ...styles],
|
|
21
|
-
modes: {
|
|
22
|
-
...props.lib.modes,
|
|
23
|
-
draw_point,
|
|
24
|
-
draw_line_string,
|
|
25
|
-
draw_polygon,
|
|
26
|
-
draw_radius,
|
|
27
|
-
draw_rectangle,
|
|
28
|
-
},
|
|
29
|
-
userProperties: {
|
|
30
|
-
showLength: props.showLength || false,
|
|
31
|
-
showArea: props.showArea || false,
|
|
32
|
-
},
|
|
33
|
-
...props.options,
|
|
34
|
-
});
|
|
35
|
-
ctx.map.addControl(draw, props.position || "top-right");
|
|
36
|
-
props.getInstance && props.getInstance(draw);
|
|
37
|
-
// Hook up events
|
|
38
|
-
const eventList = {};
|
|
39
|
-
drawEvents.forEach((item) => {
|
|
40
|
-
if (props[item]) {
|
|
41
|
-
const event = `draw.${item.slice(2).toLowerCase()}`;
|
|
42
|
-
const fn = (evt) => props[item](evt);
|
|
43
|
-
eventList[event] = fn;
|
|
44
|
-
ctx.map.on(event, fn);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
// Remove Draw Control
|
|
48
|
-
onCleanup(() => {
|
|
49
|
-
// Remove Events
|
|
50
|
-
Object.keys(eventList).forEach((event) => ctx.map.off(event, eventList[event]));
|
|
51
|
-
// Remove Control
|
|
52
|
-
ctx.map?.removeControl(draw);
|
|
53
|
-
});
|
|
54
|
-
return null;
|
|
55
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import draw_point from "./point";
|
|
2
|
-
import draw_polygon from "./polygon";
|
|
3
|
-
import draw_line_string from "./line_string";
|
|
4
|
-
// import draw_circle from "./circle";
|
|
5
|
-
import draw_radius from "./radius";
|
|
6
|
-
import draw_rectangle from "./rectangle";
|
|
7
|
-
export { draw_point, draw_polygon, draw_line_string,
|
|
8
|
-
// draw_circle,
|
|
9
|
-
draw_radius, draw_rectangle, };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import MapboxDraw from "@mapbox/mapbox-gl-draw";
|
|
2
|
-
import { getLength } from "./measurements";
|
|
3
|
-
const DrawLineString = MapboxDraw.modes.draw_line_string;
|
|
4
|
-
export default {
|
|
5
|
-
...DrawLineString,
|
|
6
|
-
onSetup: function () {
|
|
7
|
-
const draw = DrawLineString.onSetup.call(this);
|
|
8
|
-
const measure = this.newFeature({
|
|
9
|
-
type: "Feature",
|
|
10
|
-
properties: {
|
|
11
|
-
type: "measure",
|
|
12
|
-
value: "TTT",
|
|
13
|
-
},
|
|
14
|
-
geometry: {
|
|
15
|
-
type: "Point",
|
|
16
|
-
coordinates: [],
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
return { ...draw, measure };
|
|
20
|
-
},
|
|
21
|
-
onMouseMove: function (state, e) {
|
|
22
|
-
DrawLineString.onMouseMove.call(this, state, e);
|
|
23
|
-
if (state.line.coordinates.length >= 2) {
|
|
24
|
-
const { label, pos } = getLength(state.line.coordinates);
|
|
25
|
-
state.measure.properties.value = label;
|
|
26
|
-
state.measure.updateCoordinate("", pos[1], pos[0]);
|
|
27
|
-
// console.log(state.measure);
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
toDisplayFeatures: function (state, geojson, display) {
|
|
31
|
-
// const displayMeasure = (geojson) => {
|
|
32
|
-
// display(geojson);
|
|
33
|
-
// this.drawConfig.userProperties.showLength &&
|
|
34
|
-
// geojson.geometry.coordinates.forEach((coords, index) => {
|
|
35
|
-
// if (!Array.isArray(coords) || index == 0) return;
|
|
36
|
-
// display(getLength([geojson.geometry.coordinates[index - 1], coords]));
|
|
37
|
-
// });
|
|
38
|
-
// };
|
|
39
|
-
DrawLineString.toDisplayFeatures.call(this, state, geojson, display);
|
|
40
|
-
console.log(state, geojson);
|
|
41
|
-
display(state.measure.toGeoJSON());
|
|
42
|
-
},
|
|
43
|
-
};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import length from "@turf/length";
|
|
2
|
-
import area from "@turf/area";
|
|
3
|
-
import midpoint from "@turf/midpoint";
|
|
4
|
-
import { centerOfMass } from "@turf/center-of-mass";
|
|
5
|
-
export const getCoords = (coords) => {
|
|
6
|
-
return (new Intl.NumberFormat(undefined, {
|
|
7
|
-
maximumFractionDigits: 5,
|
|
8
|
-
}).format(coords[0]) +
|
|
9
|
-
"° " +
|
|
10
|
-
new Intl.NumberFormat(undefined, {
|
|
11
|
-
maximumFractionDigits: 5,
|
|
12
|
-
}).format(coords[1]) +
|
|
13
|
-
"°");
|
|
14
|
-
};
|
|
15
|
-
export const getLength = (coordinates, meta) => {
|
|
16
|
-
// length calculation in kilometers or miles
|
|
17
|
-
const lengthValue = length({
|
|
18
|
-
type: "Feature",
|
|
19
|
-
properties: {},
|
|
20
|
-
geometry: {
|
|
21
|
-
type: "LineString",
|
|
22
|
-
coordinates,
|
|
23
|
-
},
|
|
24
|
-
}, {
|
|
25
|
-
units: window.navigator.language === "en-US" ? "miles" : "kilometers",
|
|
26
|
-
});
|
|
27
|
-
const label = window.navigator.language === "en-US"
|
|
28
|
-
? new Intl.NumberFormat(undefined, {
|
|
29
|
-
style: "unit",
|
|
30
|
-
maximumFractionDigits: 2,
|
|
31
|
-
unit: lengthValue <= 1 ? "foot" : "mile",
|
|
32
|
-
}).format(lengthValue <= 1 ? lengthValue * 5280 : lengthValue)
|
|
33
|
-
: new Intl.NumberFormat(undefined, {
|
|
34
|
-
style: "unit",
|
|
35
|
-
maximumFractionDigits: 2,
|
|
36
|
-
unit: lengthValue <= 1 ? "meter" : "kilometer",
|
|
37
|
-
}).format(lengthValue <= 1 ? lengthValue * 1000 : lengthValue);
|
|
38
|
-
return {
|
|
39
|
-
label,
|
|
40
|
-
pos: midpoint(coordinates[0], coordinates[1]).geometry.coordinates,
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
export const getArea = (coordinates, meta) => {
|
|
44
|
-
// area calculation in square meters
|
|
45
|
-
const areaValue = area({
|
|
46
|
-
type: "Feature",
|
|
47
|
-
properties: {},
|
|
48
|
-
geometry: {
|
|
49
|
-
type: "Polygon",
|
|
50
|
-
coordinates,
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
const areaLabel = window.navigator.language === "en-US"
|
|
54
|
-
? new Intl.NumberFormat(undefined, {
|
|
55
|
-
style: "unit",
|
|
56
|
-
maximumFractionDigits: 2,
|
|
57
|
-
unit: areaValue <= 10.764 ? "foot" : "mile",
|
|
58
|
-
}).format(areaValue <= 10.764 ? areaValue * 10.764 : areaValue * 1.0000003861) + "²"
|
|
59
|
-
: new Intl.NumberFormat(undefined, {
|
|
60
|
-
style: "unit",
|
|
61
|
-
maximumFractionDigits: 2,
|
|
62
|
-
unit: areaValue <= 1000000 ? "meter" : "kilometer",
|
|
63
|
-
}).format(areaValue <= 1000000 ? areaValue : areaValue / 1000000) + "²";
|
|
64
|
-
return {
|
|
65
|
-
type: "Feature",
|
|
66
|
-
properties: {
|
|
67
|
-
meta: "measureLabel",
|
|
68
|
-
value: areaLabel,
|
|
69
|
-
...meta,
|
|
70
|
-
},
|
|
71
|
-
geometry: centerOfMass({
|
|
72
|
-
type: "Polygon",
|
|
73
|
-
coordinates,
|
|
74
|
-
}).geometry,
|
|
75
|
-
};
|
|
76
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const MultiPointMode = {};
|
|
2
|
-
// When the mode starts this function will be called.
|
|
3
|
-
// The `opts` argument comes from `draw.changeMode('lotsofpoints', {count:7})`.
|
|
4
|
-
// The value returned should be an object and will be passed to all other lifecycle functions
|
|
5
|
-
MultiPointMode.onSetup = function (opts) {
|
|
6
|
-
var state = {};
|
|
7
|
-
state.count = opts.count || 0;
|
|
8
|
-
return state;
|
|
9
|
-
};
|
|
10
|
-
// Whenever a user clicks on the map, Draw will call `onClick`
|
|
11
|
-
MultiPointMode.onClick = function (state, e) {
|
|
12
|
-
// `this.newFeature` takes geojson and makes a DrawFeature
|
|
13
|
-
var point = this.newFeature({
|
|
14
|
-
type: "Feature",
|
|
15
|
-
properties: {
|
|
16
|
-
count: state.count,
|
|
17
|
-
},
|
|
18
|
-
geometry: {
|
|
19
|
-
type: "Point",
|
|
20
|
-
coordinates: [e.lngLat.lng, e.lngLat.lat],
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
this.addFeature(point); // puts the point on the map
|
|
24
|
-
};
|
|
25
|
-
// Whenever a user clicks on a key while focused on the map, it will be sent here
|
|
26
|
-
MultiPointMode.onKeyUp = function (state, e) {
|
|
27
|
-
if (e.keyCode === 27)
|
|
28
|
-
return this.changeMode("simple_select");
|
|
29
|
-
};
|
|
30
|
-
// This is the only required function for a mode.
|
|
31
|
-
// It decides which features currently in Draw's data store will be rendered on the map.
|
|
32
|
-
// All features passed to `display` will be rendered, so you can pass multiple display features per internal feature.
|
|
33
|
-
// See `styling-draw` in `API.md` for advice on making display features
|
|
34
|
-
MultiPointMode.toDisplayFeatures = function (state, geojson, display) {
|
|
35
|
-
display(geojson);
|
|
36
|
-
};
|
|
37
|
-
export default MultiPointMode;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import MapboxDraw from "@mapbox/mapbox-gl-draw";
|
|
2
|
-
import { getCoords } from "./measurements";
|
|
3
|
-
const DrawPoint = MapboxDraw.modes.draw_point;
|
|
4
|
-
export default {
|
|
5
|
-
...DrawPoint,
|
|
6
|
-
onSetup: function () {
|
|
7
|
-
const draw = DrawPoint.onSetup.call(this);
|
|
8
|
-
draw.point.properties = {
|
|
9
|
-
...draw.point.properties,
|
|
10
|
-
type: "measure",
|
|
11
|
-
anchor: "bottom",
|
|
12
|
-
};
|
|
13
|
-
return draw;
|
|
14
|
-
},
|
|
15
|
-
onMouseMove: function (state, { lngLat }) {
|
|
16
|
-
state.point.properties.value = getCoords([lngLat.lng, lngLat.lat]);
|
|
17
|
-
state.point.updateCoordinate("", lngLat.lng, lngLat.lat);
|
|
18
|
-
},
|
|
19
|
-
toDisplayFeatures: function (state, geojson, display) {
|
|
20
|
-
const isActivePoint = geojson.properties.id === state.point.id;
|
|
21
|
-
geojson.properties.active = isActivePoint ? "" : "false";
|
|
22
|
-
console.log(geojson.properties);
|
|
23
|
-
return display(geojson);
|
|
24
|
-
},
|
|
25
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import MapboxDraw from "@mapbox/mapbox-gl-draw";
|
|
2
|
-
import { getLength, getArea } from "./measurements";
|
|
3
|
-
const DrawPolygon = MapboxDraw.modes.draw_polygon;
|
|
4
|
-
export default {
|
|
5
|
-
...DrawPolygon,
|
|
6
|
-
toDisplayFeatures: function (state, geojson, display) {
|
|
7
|
-
const displayMeasure = (geojson) => {
|
|
8
|
-
display(geojson);
|
|
9
|
-
if (this.drawConfig.userProperties.showLength) {
|
|
10
|
-
const arr = Array.isArray(geojson.geometry.coordinates[0][0])
|
|
11
|
-
? geojson.geometry.coordinates[0]
|
|
12
|
-
: geojson.geometry.coordinates;
|
|
13
|
-
arr.forEach((coords, index) => {
|
|
14
|
-
if (!Array.isArray(coords) || index == 0)
|
|
15
|
-
return;
|
|
16
|
-
display(getLength([arr[index - 1], coords]));
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
this.drawConfig.userProperties.showArea &&
|
|
20
|
-
geojson.geometry.coordinates[0].length >= 3 &&
|
|
21
|
-
display(getArea([geojson.geometry.coordinates[0]]));
|
|
22
|
-
};
|
|
23
|
-
DrawPolygon.toDisplayFeatures.call(this, state, geojson, displayMeasure);
|
|
24
|
-
},
|
|
25
|
-
};
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
// custom mapbopx-gl-draw mode that modifies draw_line_string
|
|
2
|
-
// shows a center point, radius line, and circle polygon while drawing
|
|
3
|
-
// forces draw.create on creation of second vertex
|
|
4
|
-
import MapboxDraw from "@mapbox/mapbox-gl-draw";
|
|
5
|
-
import length from "@turf/length";
|
|
6
|
-
import { getLength } from "./measurements";
|
|
7
|
-
function createVertex(parentId, coordinates, path, selected) {
|
|
8
|
-
return {
|
|
9
|
-
type: "Feature",
|
|
10
|
-
properties: {
|
|
11
|
-
meta: "vertex",
|
|
12
|
-
parent: parentId,
|
|
13
|
-
coord_path: path,
|
|
14
|
-
active: selected ? "true" : "false",
|
|
15
|
-
},
|
|
16
|
-
geometry: {
|
|
17
|
-
type: "Point",
|
|
18
|
-
coordinates,
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
// create a circle-like polygon given a center point and radius
|
|
23
|
-
// https://stackoverflow.com/questions/37599561/drawing-a-circle-with-the-radius-in-miles-meters-with-mapbox-gl-js/39006388#39006388
|
|
24
|
-
function createGeoJSONCircle(center, radius, parentId, points = 64) {
|
|
25
|
-
const ret = [];
|
|
26
|
-
const distanceX = radius / (111.32 * Math.cos((center[1] * Math.PI) / 180));
|
|
27
|
-
const distanceY = radius / 110.574;
|
|
28
|
-
for (let i = 0; i < points; i += 1) {
|
|
29
|
-
let theta = (i / points) * (2 * Math.PI);
|
|
30
|
-
let x = distanceX * Math.cos(theta);
|
|
31
|
-
let y = distanceY * Math.sin(theta);
|
|
32
|
-
ret.push([center[0] + x, center[1] + y]);
|
|
33
|
-
}
|
|
34
|
-
ret.push(ret[0]);
|
|
35
|
-
return {
|
|
36
|
-
type: "Feature",
|
|
37
|
-
geometry: {
|
|
38
|
-
type: "Polygon",
|
|
39
|
-
coordinates: [ret],
|
|
40
|
-
},
|
|
41
|
-
properties: {
|
|
42
|
-
parent: parentId,
|
|
43
|
-
active: "true",
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const doubleClickZoom = {
|
|
48
|
-
enable: (ctx) => {
|
|
49
|
-
setTimeout(() => {
|
|
50
|
-
// First check we've got a map and some context.
|
|
51
|
-
if (!ctx.map ||
|
|
52
|
-
!ctx.map.doubleClickZoom ||
|
|
53
|
-
!ctx._ctx ||
|
|
54
|
-
!ctx._ctx.store ||
|
|
55
|
-
!ctx._ctx.store.getInitialConfigValue)
|
|
56
|
-
return;
|
|
57
|
-
// Now check initial state wasn't false (we leave it disabled if so)
|
|
58
|
-
if (!ctx._ctx.store.getInitialConfigValue("doubleClickZoom"))
|
|
59
|
-
return;
|
|
60
|
-
ctx.map.doubleClickZoom.enable();
|
|
61
|
-
}, 0);
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
const RadiusMode = {
|
|
65
|
-
...MapboxDraw.modes.draw_line_string,
|
|
66
|
-
clickAnywhere: function (state, e) {
|
|
67
|
-
// this ends the drawing after the user creates a second point, triggering this.onStop
|
|
68
|
-
if (state.currentVertexPosition === 1) {
|
|
69
|
-
state.line.addCoordinate(0, e.lngLat.lng, e.lngLat.lat);
|
|
70
|
-
return this.changeMode("simple_select", { featureIds: [state.line.id] });
|
|
71
|
-
}
|
|
72
|
-
this.updateUIClasses({ mouse: "add" });
|
|
73
|
-
state.line.updateCoordinate(state.currentVertexPosition, e.lngLat.lng, e.lngLat.lat);
|
|
74
|
-
if (state.direction === "forward") {
|
|
75
|
-
state.currentVertexPosition += 1; // eslint-disable-line
|
|
76
|
-
state.line.updateCoordinate(state.currentVertexPosition, e.lngLat.lng, e.lngLat.lat);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
state.line.addCoordinate(0, e.lngLat.lng, e.lngLat.lat);
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
},
|
|
83
|
-
// creates the final geojson point feature with a radius property
|
|
84
|
-
// triggers draw.create
|
|
85
|
-
onStop: function (state) {
|
|
86
|
-
doubleClickZoom.enable(this);
|
|
87
|
-
this.activateUIButton();
|
|
88
|
-
// check to see if we've deleted this feature
|
|
89
|
-
if (this.getFeature(state.line.id) === undefined)
|
|
90
|
-
return;
|
|
91
|
-
console.log(state);
|
|
92
|
-
// remove last added coordinate
|
|
93
|
-
state.line.removeCoordinate("0");
|
|
94
|
-
if (state.line.isValid()) {
|
|
95
|
-
const lineGeoJson = state.line.toGeoJSON();
|
|
96
|
-
// reconfigure the geojson line into a geojson point with a radius property
|
|
97
|
-
const pointWithRadius = {
|
|
98
|
-
type: "Feature",
|
|
99
|
-
geometry: {
|
|
100
|
-
type: "Point",
|
|
101
|
-
coordinates: lineGeoJson.geometry.coordinates[0],
|
|
102
|
-
},
|
|
103
|
-
properties: {
|
|
104
|
-
radius: (length(lineGeoJson) * 1000).toFixed(1),
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
// this.map.fire("draw.create", {
|
|
108
|
-
// features: [pointWithRadius],
|
|
109
|
-
// });
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
this.deleteFeature([state.line.id], { silent: true });
|
|
113
|
-
this.changeMode("simple_select", {}, { silent: true });
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
toDisplayFeatures: function (state, geojson, display) {
|
|
117
|
-
const isActiveLine = geojson.properties.id === state.line.id;
|
|
118
|
-
geojson.properties.active = isActiveLine ? "true" : "false";
|
|
119
|
-
if (!isActiveLine)
|
|
120
|
-
return display(geojson);
|
|
121
|
-
// Only render the line if it has at least one real coordinate
|
|
122
|
-
if (geojson.geometry.coordinates.length < 2)
|
|
123
|
-
return null;
|
|
124
|
-
geojson.properties.meta = "feature";
|
|
125
|
-
// displays center vertex as a point feature
|
|
126
|
-
display(createVertex(state.line.id, geojson.geometry.coordinates[state.direction === "forward"
|
|
127
|
-
? geojson.geometry.coordinates.length - 2
|
|
128
|
-
: 1], `${state.direction === "forward" ? geojson.geometry.coordinates.length - 2 : 1}`, false));
|
|
129
|
-
// displays the line as it is drawn
|
|
130
|
-
display(geojson);
|
|
131
|
-
// display measurement
|
|
132
|
-
display(getLength(geojson, { parent: state.line.id }));
|
|
133
|
-
// create custom feature for circle
|
|
134
|
-
display(createGeoJSONCircle(geojson.geometry.coordinates[0], length(geojson), state.line.id));
|
|
135
|
-
return null;
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
export default RadiusMode;
|