solid-map-gl 1.13.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/esm/styles.css +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.jsx +0 -225
- package/dist/source/components/Draw/index.jsx +0 -52
- 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 -273
- 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/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 -96
- 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,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;
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import MapboxDraw from "@mapbox/mapbox-gl-draw";
|
|
2
|
-
import { getArea, getLength } from "./measurements";
|
|
3
|
-
const RectangleMode = {
|
|
4
|
-
...MapboxDraw.modes.draw_line_string,
|
|
5
|
-
// When the mode starts this function will be called.
|
|
6
|
-
onSetup: function (opts) {
|
|
7
|
-
const props = MapboxDraw.modes.draw_line_string.onSetup.call(this, opts);
|
|
8
|
-
const rectangle = this.newFeature({
|
|
9
|
-
type: "Feature",
|
|
10
|
-
properties: {},
|
|
11
|
-
geometry: {
|
|
12
|
-
type: "Polygon",
|
|
13
|
-
coordinates: [[]],
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
this.addFeature(rectangle);
|
|
17
|
-
return { ...props, ...opts, rectangle };
|
|
18
|
-
},
|
|
19
|
-
// support mobile taps
|
|
20
|
-
onTap: function (state, e) {
|
|
21
|
-
// emulate 'move mouse' to update feature coords
|
|
22
|
-
if (state.startPoint)
|
|
23
|
-
this.onMouseMove(state, e);
|
|
24
|
-
// emulate onClick
|
|
25
|
-
this.onClick(state, e);
|
|
26
|
-
},
|
|
27
|
-
// Whenever a user clicks on the map, Draw will call `onClick`
|
|
28
|
-
onClick: function (state, e) {
|
|
29
|
-
if (state.startPoint &&
|
|
30
|
-
state.startPoint[0] !== e.lngLat.lng &&
|
|
31
|
-
state.startPoint[1] !== e.lngLat.lat) {
|
|
32
|
-
// if state.startPoint exist, means its second click
|
|
33
|
-
// change to simple_select mode
|
|
34
|
-
this.updateUIClasses({ mouse: "pointer" });
|
|
35
|
-
state.endPoint = [e.lngLat.lng, e.lngLat.lat];
|
|
36
|
-
this.changeMode("simple_select", { featuresId: state.rectangle.id });
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
// if its first click, save clicked point coords as starting for rectangle
|
|
40
|
-
state.startPoint = [e.lngLat.lng, e.lngLat.lat];
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
onMouseMove: function (state, e) {
|
|
44
|
-
// if startPoint, update the feature coordinates, using the bounding box concept
|
|
45
|
-
// we are simply using the startingPoint coordinates and the current Mouse Position
|
|
46
|
-
// coordinates to calculate the bounding box on the fly, which will be our rectangle
|
|
47
|
-
if (state.startPoint) {
|
|
48
|
-
state.rectangle.updateCoordinate("0.0", state.startPoint[0], state.startPoint[1]); //minX, minY - the starting point
|
|
49
|
-
state.rectangle.updateCoordinate("0.1", e.lngLat.lng, state.startPoint[1]); // maxX, minY
|
|
50
|
-
state.rectangle.updateCoordinate("0.2", e.lngLat.lng, e.lngLat.lat); // maxX, maxY
|
|
51
|
-
state.rectangle.updateCoordinate("0.3", state.startPoint[0], e.lngLat.lat); // minX,maxY
|
|
52
|
-
state.rectangle.updateCoordinate("0.4", state.startPoint[0], state.startPoint[1]); //minX,minY - ending point (equals to starting point)
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
// Whenever a user clicks on a key while focused on the map, it will be sent here
|
|
56
|
-
onKeyUp: function (state, e) {
|
|
57
|
-
if (e.keyCode === 27)
|
|
58
|
-
return this.changeMode("simple_select");
|
|
59
|
-
},
|
|
60
|
-
onStop: function (state) {
|
|
61
|
-
MapboxDraw.modes.draw_line_string.onStop.call(this, state);
|
|
62
|
-
// check to see if we've deleted this feature
|
|
63
|
-
if (this.getFeature(state.rectangle.id) === undefined)
|
|
64
|
-
return;
|
|
65
|
-
//remove last added coordinate
|
|
66
|
-
state.rectangle.removeCoordinate("0.4");
|
|
67
|
-
if (state.rectangle.isValid()) {
|
|
68
|
-
this.map.fire("draw.create", {
|
|
69
|
-
features: [state.rectangle.toGeoJSON()],
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
this.deleteFeature([state.rectangle.id], { silent: true });
|
|
74
|
-
this.changeMode("simple_select", {}, { silent: true });
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
toDisplayFeatures: function (state, geojson, display) {
|
|
78
|
-
console.log(state);
|
|
79
|
-
const isActivePolygon = geojson.properties.id === state.rectangle.id;
|
|
80
|
-
geojson.properties.active = isActivePolygon ? "true" : "false";
|
|
81
|
-
if (!isActivePolygon)
|
|
82
|
-
return display(geojson);
|
|
83
|
-
// Only render the rectangular polygon if it has the starting point
|
|
84
|
-
if (!state.startPoint)
|
|
85
|
-
return;
|
|
86
|
-
display(geojson);
|
|
87
|
-
// create custom feature for the current pointer position
|
|
88
|
-
if (state.showLength) {
|
|
89
|
-
display(getLength({
|
|
90
|
-
type: "Feature",
|
|
91
|
-
geometry: {
|
|
92
|
-
type: "LineString",
|
|
93
|
-
coordinates: [
|
|
94
|
-
geojson.geometry.coordinates[0][0],
|
|
95
|
-
geojson.geometry.coordinates[0][1],
|
|
96
|
-
],
|
|
97
|
-
},
|
|
98
|
-
}, { parent: state.rectangle.id, anchor: "bottom" }));
|
|
99
|
-
display(getLength({
|
|
100
|
-
type: "Feature",
|
|
101
|
-
geometry: {
|
|
102
|
-
type: "LineString",
|
|
103
|
-
coordinates: [
|
|
104
|
-
geojson.geometry.coordinates[0][1],
|
|
105
|
-
geojson.geometry.coordinates[0][2],
|
|
106
|
-
],
|
|
107
|
-
},
|
|
108
|
-
}, { parent: state.rectangle.id, anchor: "left" }));
|
|
109
|
-
}
|
|
110
|
-
state.showArea && display(getArea(geojson, { parent: state.rectangle.id }));
|
|
111
|
-
return null;
|
|
112
|
-
},
|
|
113
|
-
onTrash: function (state) {
|
|
114
|
-
this.deleteFeature([state.rectangle.id], { silent: true });
|
|
115
|
-
this.changeMode("simple_select");
|
|
116
|
-
},
|
|
117
|
-
};
|
|
118
|
-
export default RectangleMode;
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
const doubleClickZoom = {
|
|
2
|
-
enable: (ctx) => {
|
|
3
|
-
setTimeout(() => {
|
|
4
|
-
// First check we've got a map and some context.
|
|
5
|
-
if (!ctx.map ||
|
|
6
|
-
!ctx.map.doubleClickZoom ||
|
|
7
|
-
!ctx._ctx ||
|
|
8
|
-
!ctx._ctx.store ||
|
|
9
|
-
!ctx._ctx.store.getInitialConfigValue)
|
|
10
|
-
return;
|
|
11
|
-
if (!ctx._ctx.store.getInitialConfigValue("doubleClickZoom"))
|
|
12
|
-
return;
|
|
13
|
-
ctx.map.doubleClickZoom.enable();
|
|
14
|
-
}, 0);
|
|
15
|
-
},
|
|
16
|
-
disable(ctx) {
|
|
17
|
-
setTimeout(() => {
|
|
18
|
-
if (!ctx.map || !ctx.map.doubleClickZoom)
|
|
19
|
-
return;
|
|
20
|
-
ctx.map.doubleClickZoom.disable();
|
|
21
|
-
}, 0);
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
const RectangleAssistedMode = {
|
|
25
|
-
onSetup: function (opts) {
|
|
26
|
-
const rectangle = this.newFeature({
|
|
27
|
-
type: "Feature",
|
|
28
|
-
properties: {},
|
|
29
|
-
geometry: {
|
|
30
|
-
type: "Polygon",
|
|
31
|
-
coordinates: [[]],
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
this.addFeature(rectangle);
|
|
35
|
-
this.clearSelectedFeatures();
|
|
36
|
-
doubleClickZoom.disable(this);
|
|
37
|
-
this.updateUIClasses({
|
|
38
|
-
mouse: "add",
|
|
39
|
-
});
|
|
40
|
-
this.setActionableState({
|
|
41
|
-
trash: true,
|
|
42
|
-
});
|
|
43
|
-
return {
|
|
44
|
-
rectangle,
|
|
45
|
-
currentVertexPosition: 0,
|
|
46
|
-
};
|
|
47
|
-
},
|
|
48
|
-
onTap: function (state, e) {
|
|
49
|
-
this.onClick(state, e);
|
|
50
|
-
},
|
|
51
|
-
onClick: function (state, e) {
|
|
52
|
-
if (state.currentVertexPosition === 2) {
|
|
53
|
-
const getpXY3 = this.calculatepXY3(state, e, false);
|
|
54
|
-
if (getpXY3) {
|
|
55
|
-
state.rectangle.updateCoordinate(`0.${state.currentVertexPosition + 1}`, getpXY3[0], getpXY3[1]);
|
|
56
|
-
}
|
|
57
|
-
this.updateUIClasses({
|
|
58
|
-
mouse: "pointer",
|
|
59
|
-
});
|
|
60
|
-
return this.changeMode("simple_select", {
|
|
61
|
-
featuresId: state.rectangle.id,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
state.rectangle.updateCoordinate(`0.${state.currentVertexPosition}`, e.lngLat.lng, e.lngLat.lat);
|
|
66
|
-
state.currentVertexPosition++;
|
|
67
|
-
state.rectangle.updateCoordinate(`0.${state.currentVertexPosition}`, e.lngLat.lng, e.lngLat.lat);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
onMouseMove: function (state, e) {
|
|
71
|
-
state.rectangle.updateCoordinate("0." + state.currentVertexPosition, e.lngLat.lng, e.lngLat.lat);
|
|
72
|
-
if (state.currentVertexPosition && state.currentVertexPosition > 0) {
|
|
73
|
-
this.calculateOrientedAnglePolygon(state);
|
|
74
|
-
}
|
|
75
|
-
if (state.currentVertexPosition === 2) {
|
|
76
|
-
const getpXY3 = this.calculatepXY3(state, e, true);
|
|
77
|
-
if (getpXY3) {
|
|
78
|
-
state.rectangle.updateCoordinate("0." + (state.currentVertexPosition + 1), getpXY3[0], getpXY3[1]);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
deegrees2meters(px) {
|
|
83
|
-
//gist from https://gist.github.com/springmeyer/871897
|
|
84
|
-
const x = (px[0] * 20037508.34) / 180;
|
|
85
|
-
let y = Math.log(Math.tan(((90 + px[1]) * Math.PI) / 360)) / (Math.PI / 180);
|
|
86
|
-
y = (y * 20037508.34) / 180;
|
|
87
|
-
return [x, y];
|
|
88
|
-
},
|
|
89
|
-
meters2degress(px) {
|
|
90
|
-
//gist from https://gist.github.com/springmeyer/871897
|
|
91
|
-
const lon = (px[0] * 180) / 20037508.34;
|
|
92
|
-
const lat = (Math.atan(Math.exp((px[1] * Math.PI) / 20037508.34)) * 360) / Math.PI -
|
|
93
|
-
90;
|
|
94
|
-
return [lon, lat];
|
|
95
|
-
},
|
|
96
|
-
calculateOrientedAnglePolygon: function (state) {
|
|
97
|
-
const pXY0 = state.rectangle.getCoordinate("0.0");
|
|
98
|
-
const pXY0_3857 = this.deegrees2meters(pXY0);
|
|
99
|
-
const pXY1 = state.rectangle.getCoordinate("0.1");
|
|
100
|
-
const pXY1_3857 = this.deegrees2meters(pXY1);
|
|
101
|
-
const angleStdGraus = (Math.atan2(pXY1_3857[1] - pXY0_3857[1], pXY1_3857[0] - pXY0_3857[0]) *
|
|
102
|
-
180) /
|
|
103
|
-
Math.PI;
|
|
104
|
-
let angleSudGraus = -1.0 * (angleStdGraus + 90);
|
|
105
|
-
const angle = angleSudGraus < 0 ? angleSudGraus + 360 : angleSudGraus;
|
|
106
|
-
state.angle = parseFloat(angle.toFixed(2));
|
|
107
|
-
},
|
|
108
|
-
calculatepXY3: function (state, e, tmp) {
|
|
109
|
-
const pXY0 = state.rectangle.getCoordinate("0.0");
|
|
110
|
-
const pXY0_3857 = this.deegrees2meters(pXY0);
|
|
111
|
-
const pXY1 = state.rectangle.getCoordinate("0.1");
|
|
112
|
-
const pXY1_3857 = this.deegrees2meters(pXY1);
|
|
113
|
-
let pXY2_3857 = this.deegrees2meters([e.lngLat.lng, e.lngLat.lat]);
|
|
114
|
-
const mouse_3857 = this.deegrees2meters([e.lngLat.lng, e.lngLat.lat]);
|
|
115
|
-
if (pXY0_3857[0] === pXY1_3857[0]) {
|
|
116
|
-
pXY2_3857 = [mouse_3857[0], pXY1_3857[1]];
|
|
117
|
-
}
|
|
118
|
-
else if (pXY0_3857[1] === pXY1_3857[1]) {
|
|
119
|
-
pXY2_3857 = [pXY1_3857[0], mouse_3857[1]];
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
const vector1_3857 = (pXY1_3857[1] - pXY0_3857[1]) / (pXY1_3857[0] - pXY0_3857[0]);
|
|
123
|
-
const vector2_3857 = -1.0 / vector1_3857;
|
|
124
|
-
if (Math.abs(vector2_3857) < 1) {
|
|
125
|
-
pXY2_3857[1] =
|
|
126
|
-
vector2_3857 * (mouse_3857[0] - pXY1_3857[0]) + pXY1_3857[1];
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
pXY2_3857[0] =
|
|
130
|
-
pXY1_3857[0] + (pXY2_3857[1] - pXY1_3857[1]) / vector2_3857;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
const vector_3857 = [
|
|
134
|
-
pXY1_3857[0] - pXY0_3857[0],
|
|
135
|
-
pXY1_3857[1] - pXY0_3857[1],
|
|
136
|
-
];
|
|
137
|
-
const pXY3_3857 = [
|
|
138
|
-
pXY2_3857[0] - vector_3857[0],
|
|
139
|
-
pXY2_3857[1] - vector_3857[1],
|
|
140
|
-
];
|
|
141
|
-
const pXY2G = this.meters2degress(pXY2_3857);
|
|
142
|
-
const pXY3G = this.meters2degress(pXY3_3857);
|
|
143
|
-
state.rectangle.updateCoordinate("0.2", pXY2G[0], pXY2G[1]);
|
|
144
|
-
state.rectangle.updateCoordinate("0.3", pXY3G[0], pXY3G[1]);
|
|
145
|
-
return pXY3G;
|
|
146
|
-
},
|
|
147
|
-
onKeyUp: function (state, e) {
|
|
148
|
-
if (e.keyCode === 27)
|
|
149
|
-
return this.changeMode("simple_select");
|
|
150
|
-
},
|
|
151
|
-
onStop: function (state) {
|
|
152
|
-
doubleClickZoom.enable(this);
|
|
153
|
-
this.updateUIClasses({
|
|
154
|
-
mouse: "none",
|
|
155
|
-
});
|
|
156
|
-
this.activateUIButton();
|
|
157
|
-
// check to see if we've deleted this feature
|
|
158
|
-
if (this.getFeature(state.rectangle.id) === undefined)
|
|
159
|
-
return;
|
|
160
|
-
//remove last added coordinate
|
|
161
|
-
state.rectangle.removeCoordinate("0.4");
|
|
162
|
-
if (state.rectangle.isValid()) {
|
|
163
|
-
this.map.fire("draw.create", {
|
|
164
|
-
features: [state.rectangle.toGeoJSON()],
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
this.deleteFeature([state.rectangle.id], {
|
|
169
|
-
silent: true,
|
|
170
|
-
});
|
|
171
|
-
this.changeMode("simple_select", {}, {
|
|
172
|
-
silent: true,
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
toDisplayFeatures: function (state, geojson, display) {
|
|
177
|
-
const isActivePolygon = geojson.properties.id === state.rectangle.id;
|
|
178
|
-
geojson.properties.active = isActivePolygon ? "true" : "false";
|
|
179
|
-
geojson.properties.angle = state.angle;
|
|
180
|
-
geojson.angle = state.angle;
|
|
181
|
-
if (!isActivePolygon)
|
|
182
|
-
return display(geojson);
|
|
183
|
-
const coordinateCount = geojson.geometry.coordinates[0].length;
|
|
184
|
-
if (coordinateCount < 3) {
|
|
185
|
-
const coordinates = geojson.geometry.coordinates[0][0];
|
|
186
|
-
const vertexPoint = {
|
|
187
|
-
type: "Feature",
|
|
188
|
-
properties: geojson.properties,
|
|
189
|
-
angle: state.angle,
|
|
190
|
-
geometry: {
|
|
191
|
-
coordinates: geojson.geometry.coordinates[0][0],
|
|
192
|
-
type: "Point",
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
if (coordinates) {
|
|
196
|
-
display(vertexPoint);
|
|
197
|
-
}
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
if (coordinateCount >= 3 && coordinateCount <= 4) {
|
|
201
|
-
const lineCoordinates = [
|
|
202
|
-
[
|
|
203
|
-
geojson.geometry.coordinates[0][0][0],
|
|
204
|
-
geojson.geometry.coordinates[0][0][1],
|
|
205
|
-
],
|
|
206
|
-
[
|
|
207
|
-
geojson.geometry.coordinates[0][1][0],
|
|
208
|
-
geojson.geometry.coordinates[0][1][1],
|
|
209
|
-
],
|
|
210
|
-
];
|
|
211
|
-
display({
|
|
212
|
-
type: "Feature",
|
|
213
|
-
properties: geojson.properties,
|
|
214
|
-
angle: state.angle,
|
|
215
|
-
geometry: {
|
|
216
|
-
coordinates: lineCoordinates,
|
|
217
|
-
type: "LineString",
|
|
218
|
-
},
|
|
219
|
-
});
|
|
220
|
-
if (coordinateCount === 3) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return display(geojson);
|
|
225
|
-
},
|
|
226
|
-
onTrash: function (state) {
|
|
227
|
-
this.deleteFeature([state.rectangle.id], {
|
|
228
|
-
silent: true,
|
|
229
|
-
});
|
|
230
|
-
this.changeMode("simple_select");
|
|
231
|
-
},
|
|
232
|
-
};
|
|
233
|
-
export default RectangleAssistedMode;
|