solid-map-gl 1.11.3 → 1.12.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/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/source/components/Draw/drawingStyles.js +225 -0
- package/dist/source/components/Draw/index.jsx +35 -8
- package/dist/source/components/Draw/modes/index.js +9 -0
- package/dist/source/components/Draw/modes/line_string.js +43 -0
- package/dist/source/components/Draw/modes/measurements.js +76 -0
- package/dist/source/components/Draw/modes/multi_point.js +37 -0
- package/dist/source/components/Draw/modes/point.js +25 -0
- package/dist/source/components/Draw/modes/polygon.js +25 -0
- package/dist/source/components/Draw/modes/radius.js +138 -0
- package/dist/source/components/Draw/modes/rectangle.js +118 -0
- package/dist/source/components/Draw/modes/rectangle_assisted.js +233 -0
- package/dist/source/components/Layer3D/index.jsx +226 -11
- package/dist/types/components/Draw/drawingStyles.d.ts +20 -0
- package/dist/types/components/Draw/index.d.ts +5 -3
- package/dist/types/components/Draw/modes/index.d.ts +6 -0
- package/dist/types/components/Draw/modes/line_string.d.ts +2 -0
- package/dist/types/components/Draw/modes/multi_point.d.ts +2 -0
- package/dist/types/components/Draw/modes/point.d.ts +2 -0
- package/dist/types/components/Draw/modes/polygon.d.ts +2 -0
- package/dist/types/components/Draw/modes/radius.d.ts +2 -0
- package/dist/types/components/Draw/modes/rectangle.d.ts +2 -0
- package/dist/types/components/Draw/modes/rectangle_assisted.d.ts +18 -0
- package/package.json +20 -13
|
@@ -0,0 +1,118 @@
|
|
|
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;
|
|
@@ -0,0 +1,233 @@
|
|
|
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;
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { onCleanup, createUniqueId, createSignal, onMount, createContext, useContext, } from "solid-js";
|
|
2
2
|
import { useMapContext } from "../MapProvider";
|
|
3
|
+
const deg2rad = (degrees) => {
|
|
4
|
+
return (degrees * Math.PI) / 180;
|
|
5
|
+
};
|
|
6
|
+
const latLng2Mercator = (lat, lng, altitude) => {
|
|
7
|
+
const R = 6378137.0; // earth radius in meters
|
|
8
|
+
const x = R * deg2rad(lng);
|
|
9
|
+
const y = R * Math.log(Math.tan(Math.PI / 4 + deg2rad(lat) / 2));
|
|
10
|
+
return [x, y, altitude];
|
|
11
|
+
};
|
|
12
|
+
const latLng2Cartesian = ({ lat, lng }, altitude = 0) => {
|
|
13
|
+
const R = 6378137.0; // earth radius in meters
|
|
14
|
+
const x = R * Math.cos(deg2rad(lat)) * Math.cos(deg2rad(lng));
|
|
15
|
+
const y = R * Math.cos(deg2rad(lat)) * Math.sin(deg2rad(lng));
|
|
16
|
+
const z = altitude; // + R * Math.sin(deg2rad(lat));
|
|
17
|
+
return { x, y, z };
|
|
18
|
+
};
|
|
3
19
|
const LayerContext = createContext();
|
|
4
20
|
export const useScene = () => useContext(LayerContext);
|
|
5
21
|
export const Layer3D = (props) => {
|
|
@@ -38,20 +54,37 @@ export const Layer3D = (props) => {
|
|
|
38
54
|
const engine = new BABYLON.Engine(gl, true, {
|
|
39
55
|
useHighPrecisionMatrix: true,
|
|
40
56
|
}, true);
|
|
57
|
+
// this.index = 0;
|
|
41
58
|
this.scene = new BABYLON.Scene(engine);
|
|
42
59
|
this.scene.autoClear = false;
|
|
43
|
-
this.scene.autoClearDepthAndStencil = false;
|
|
60
|
+
// this.scene.autoClearDepthAndStencil = false;
|
|
44
61
|
// this.scene.detachControl();
|
|
45
62
|
this.scene.preventDefaultOnPointerDown = false;
|
|
46
63
|
this.scene.preventDefaultOnPointerUp = false;
|
|
47
|
-
this.scene.beforeRender = () => engine.wipeCaches(true);
|
|
48
|
-
|
|
64
|
+
// this.scene.beforeRender = () => engine.wipeCaches(true);
|
|
65
|
+
const camera = new BABYLON.UniversalCamera("Camera", BABYLON.Vector3.Zero());
|
|
66
|
+
camera.mode = BABYLON.Camera.ORTHOGRAPHIC_CAMERA;
|
|
67
|
+
camera.inertia = 0;
|
|
68
|
+
// this.scene.activeCamera.setTarget(new BABYLON.Vector3(-1, 0, 0));
|
|
69
|
+
// this.scene.activeCamera.rotationQuaternion =
|
|
70
|
+
// BABYLON.Quaternion.Identity();
|
|
71
|
+
// this.scene.activeCamera.updateUpVectorFromRotation = true;
|
|
72
|
+
// this.scene.activeCamera.noRotationConstraint = true;
|
|
73
|
+
// this.scene.activeCamera.inputs.addMouseWheel();
|
|
49
74
|
// this.scene.activeCamera.setTarget(BABYLON.Vector3.Zero());
|
|
50
|
-
//
|
|
51
|
-
//
|
|
75
|
+
// setTimeout(() => {
|
|
76
|
+
// this.scene.activeCamera.setPosition(
|
|
77
|
+
// new BABYLON.Vector3(100, 100, 100),
|
|
78
|
+
// );
|
|
79
|
+
// }, 2000);
|
|
80
|
+
// this.scene.activeCamera.attachControl(gl.canvas, true);
|
|
52
81
|
this.scene.ambientColor = new BABYLON.Color3(1, 1, 1);
|
|
53
82
|
if (props.defaultLight)
|
|
54
83
|
new BABYLON.HemisphericLight("Light", new BABYLON.Vector3(100, 10, 0), this.scene);
|
|
84
|
+
// this.scene.root_node = new BABYLON.TransformNode("rootNode");
|
|
85
|
+
// this.scene.root_node.lookAt(BABYLON.Vector3.Down());
|
|
86
|
+
// this.scene.root_node.addRotation(0, 0, Math.PI / 2);
|
|
87
|
+
// const axis = new BABYLON.AxesViewer(this.scene, 100);
|
|
55
88
|
}
|
|
56
89
|
else {
|
|
57
90
|
this.camera = new THREE.Camera();
|
|
@@ -74,12 +107,194 @@ export const Layer3D = (props) => {
|
|
|
74
107
|
},
|
|
75
108
|
render(gl, matrix) {
|
|
76
109
|
if (props.babylon) {
|
|
77
|
-
this.scene.activeCamera.freezeProjectionMatrix(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// this.scene.activeCamera.
|
|
82
|
-
//
|
|
110
|
+
this.scene.activeCamera.freezeProjectionMatrix(
|
|
111
|
+
// props.disableProjectionMatrix
|
|
112
|
+
// ? BABYLON.Matrix.FromArray(matrix)
|
|
113
|
+
worldMatrix.multiply(BABYLON.Matrix.FromArray(matrix)));
|
|
114
|
+
// this.scene.activeCamera.position =
|
|
115
|
+
// BABYLON.Vector3.TransformCoordinates(
|
|
116
|
+
// new BABYLON.Vector3(),
|
|
117
|
+
// worldMatrix.multiply(BABYLON.Matrix.FromArray(matrix)).invert(),
|
|
118
|
+
// );
|
|
119
|
+
// this.scene.activeCamera.rotation.z = matrix[0];
|
|
120
|
+
// this.scene.activeCamera.rotation.x = matrix[1];
|
|
121
|
+
// this.scene.activeCamera.rotation.y = matrix[2];
|
|
122
|
+
// console.log(this.scene.activeCamera.getProjectionMatrix(), matrix);
|
|
123
|
+
// const m = matrix;
|
|
124
|
+
// const transform = BABYLON.Matrix.FromArray(matrix);
|
|
125
|
+
// console.log(transform);
|
|
126
|
+
//
|
|
127
|
+
// const center = this.map.getCenter();
|
|
128
|
+
// const zoom = this.map.getZoom();
|
|
129
|
+
// const scale = Math.pow(2, zoom);
|
|
130
|
+
// const centerX = center.lng * scale;
|
|
131
|
+
// const centerZ = center.lat * scale;
|
|
132
|
+
// this.scene.activeCamera.position.x = centerX;
|
|
133
|
+
// this.scene.activeCamera.position.z = centerZ;
|
|
134
|
+
// this.scene.activeCamera.getWorldMatrix().copyFrom(transform);
|
|
135
|
+
const pitch = this.map.getPitch() * (Math.PI / 180);
|
|
136
|
+
const bearing = this.map.getBearing() * (Math.PI / 180);
|
|
137
|
+
// this.scene.activeCamera.rotation.x = Math.asin(pitch);
|
|
138
|
+
// this.scene.activeCamera.rotation.y = Math.atan(bearing / pitch);
|
|
139
|
+
// this.scene.activeCamera.rotation.z = -bearing;
|
|
140
|
+
// this.scene.activeCamera
|
|
141
|
+
// .getWorldMatrix()
|
|
142
|
+
// .invertToRef(this.scene.activeCamera.getViewMatrix());
|
|
143
|
+
// const cameraMatrix = BABYLON.Matrix.FromArray(matrix); //.invert();
|
|
144
|
+
// const scaling = BABYLON.Vector3.Zero(),
|
|
145
|
+
// rotation = BABYLON.Vector3.Zero(),
|
|
146
|
+
// transform = BABYLON.Vector3.Zero();
|
|
147
|
+
// cameraMatrix.decompose(scaling, rotation, transform);
|
|
148
|
+
// const scaling2 = BABYLON.Vector3.Zero(),
|
|
149
|
+
// rotation2 = BABYLON.Vector3.Zero(),
|
|
150
|
+
// transform2 = BABYLON.Vector3.Zero();
|
|
151
|
+
// worldMatrix.decompose(scaling2, rotation2, transform2);
|
|
152
|
+
// const lng2 =
|
|
153
|
+
// props.origin[0] -
|
|
154
|
+
// this.map.getFreeCameraOptions().position.toLngLat().lng;
|
|
155
|
+
// const lat2 =
|
|
156
|
+
// props.origin[1] -
|
|
157
|
+
// this.map.getFreeCameraOptions().position.toLngLat().lat;
|
|
158
|
+
//
|
|
159
|
+
// const pos = this.map.getFreeCameraOptions().position.toLngLat();
|
|
160
|
+
// const orient = this.map.getFreeCameraOptions().orientation;
|
|
161
|
+
// const camPos = latLng2Cartesian(
|
|
162
|
+
// this.map.getFreeCameraOptions().position.toLngLat(),
|
|
163
|
+
// this.map.getFreeCameraOptions().position.toAltitude(),
|
|
164
|
+
// );
|
|
165
|
+
// const orgPos = latLng2Cartesian({
|
|
166
|
+
// lng: props.origin[0],
|
|
167
|
+
// lat: props.origin[1],
|
|
168
|
+
// });
|
|
169
|
+
// const o = this.map.getFreeCameraOptions().orientation;
|
|
170
|
+
// const orient = latLng2Cartesian(
|
|
171
|
+
// new window.MapLib.MercatorCoordinate(
|
|
172
|
+
// ...this.map.getFreeCameraOptions().orientation,
|
|
173
|
+
// ).toLngLat(),
|
|
174
|
+
// );
|
|
175
|
+
// console
|
|
176
|
+
// .log
|
|
177
|
+
// this.map.getFreeCameraOptions().orientation,
|
|
178
|
+
// this.map.getFreeCameraOptions().position.toLngLat(),
|
|
179
|
+
// orgX,
|
|
180
|
+
// camX,
|
|
181
|
+
// camPos,
|
|
182
|
+
// orgPos,
|
|
183
|
+
// x,
|
|
184
|
+
// this.scene.activeCamera.minZ,
|
|
185
|
+
// this.scene.activeCamera.maxZ,
|
|
186
|
+
// this.map.getFreeCameraOptions(),
|
|
187
|
+
// this.map.getFreeCameraOptions().position.toAltitude(),
|
|
188
|
+
// camPos.z,
|
|
189
|
+
// orgPos.z,
|
|
190
|
+
// camPos.z - orgPos.z,
|
|
191
|
+
// this.scene.activeCamera.rotationQuaternion,
|
|
192
|
+
// matrix,
|
|
193
|
+
// camPos.z - orgPos.z,
|
|
194
|
+
// camPos.x - orgPos.x,
|
|
195
|
+
// camPos.y - orgPos.y,
|
|
196
|
+
// camPos.z - orgPos.z,
|
|
197
|
+
// this.index,
|
|
198
|
+
// orient,
|
|
199
|
+
// orient.x - orgPos.x,
|
|
200
|
+
// new BABYLON.Vector3(...orient),
|
|
201
|
+
// camY,
|
|
202
|
+
// camZ,
|
|
203
|
+
// pos.lng,
|
|
204
|
+
// x2,
|
|
205
|
+
// y2,
|
|
206
|
+
// z2,
|
|
207
|
+
// transform,
|
|
208
|
+
// matrix,
|
|
209
|
+
// cameraMatrix._m,
|
|
210
|
+
// cameraMatrix,
|
|
211
|
+
// new mapboxgl.MercatorCoordinate(
|
|
212
|
+
// transform.x,
|
|
213
|
+
// transform.y,
|
|
214
|
+
// transform.z,
|
|
215
|
+
// ).toLngLat(),
|
|
216
|
+
// worldOriginMercator.toLngLat(),
|
|
217
|
+
// this.map.getFreeCameraOptions().position.toLngLat(),
|
|
218
|
+
// this.map.getFreeCameraOptions().orientation,
|
|
219
|
+
// BABYLON.Quaternion.FromArray(
|
|
220
|
+
// this.map.getFreeCameraOptions().orientation,
|
|
221
|
+
// ),
|
|
222
|
+
// this.scene.activeCamera.rotationQuaternion,
|
|
223
|
+
// BABYLON.Vector3.FromArray(
|
|
224
|
+
// this.map.getFreeCameraOptions().orientation,
|
|
225
|
+
// ),
|
|
226
|
+
// ();
|
|
227
|
+
// this.scene.activeCamera.freezeProjectionMatrix(
|
|
228
|
+
// props.disableProjectionMatrix
|
|
229
|
+
// ? BABYLON.Matrix.FromArray(matrix)
|
|
230
|
+
// : worldMatrix.multiply(BABYLON.Matrix.FromArray(matrix)),
|
|
231
|
+
// );
|
|
232
|
+
//
|
|
233
|
+
// const { x, y } = this.map.project(
|
|
234
|
+
// new mapboxgl.MercatorCoordinate(pos.x, pos.y, pos.z).toLngLat(),
|
|
235
|
+
// );
|
|
236
|
+
// this.scene.activeCamera.position.y = 0; //-(camPos.x - orgPos.x);
|
|
237
|
+
// this.scene.activeCamera.position.x = 0; //-(camPos.y - orgPos.y);
|
|
238
|
+
// this.scene.activeCamera.position.z = -camPos.z; // - orgPos.z;
|
|
239
|
+
// console.log(this.scene.activeCamera.position);
|
|
240
|
+
// const [x, y, z, w] = this.map.getFreeCameraOptions().orientation;
|
|
241
|
+
// let rotation_y = Math.atan(z / x);
|
|
242
|
+
// if (x < 0) rotation_y += Math.PI;
|
|
243
|
+
// rotation_y = Math.PI / 2 - rotation_y;
|
|
244
|
+
// const rotation_x = Math.asin(-y);
|
|
245
|
+
// const camera_up_before_rotatez = new BABYLON.Vector3(
|
|
246
|
+
// -Math.cos(rotation_y),
|
|
247
|
+
// 0,
|
|
248
|
+
// Math.sin(rotation_y),
|
|
249
|
+
// );
|
|
250
|
+
// const rotation_z = Math.acos(
|
|
251
|
+
// camera_up.x * camera_up_before_rotatez.x +
|
|
252
|
+
// camera_up.y * camera_up_before_rotatez.y +
|
|
253
|
+
// camera_up.z * camera_up_before_rotatez.z,
|
|
254
|
+
// );
|
|
255
|
+
// rotation_z = Math.PI / 2 - rotation_z;
|
|
256
|
+
// if (camera_up.y < 0) rotation_z = Math.PI - rotation_z;
|
|
257
|
+
//
|
|
258
|
+
// this.scene.activeCamera.rotation.x = rotation_x;
|
|
259
|
+
// this.scene.activeCamera.rotation.y = rotation_y;
|
|
260
|
+
// this.scene.activeCamera.rotationQuaternion =
|
|
261
|
+
// // BABYLON.Quaternion.Identity();
|
|
262
|
+
// // BABYLON.Quaternion.FromEulerAngles(1, 0, 0);
|
|
263
|
+
// BABYLON.Quaternion.FromArray([-x, y, -z, w]);
|
|
264
|
+
// this.scene.activeCamera.alpha = -z;
|
|
265
|
+
// this.scene.activeCamera.alpha = -z;
|
|
266
|
+
// this.scene.activeCamera.radius = x; //Math.PI / 2 + this.index;
|
|
267
|
+
// this.scene.activeCamera.radius = y;
|
|
268
|
+
// this.index += 0.001;
|
|
269
|
+
// BABYLON.Quaternion.RotationYawPitchRoll(-1, 1, -1);
|
|
270
|
+
// BABYLON.Vector3.Zero();
|
|
271
|
+
// BABYLON.Vector3.FromArray(
|
|
272
|
+
// this.map.getFreeCameraOptions().orientation,
|
|
273
|
+
// );
|
|
274
|
+
// this.scene.activeCamera.setTarget(
|
|
275
|
+
// BABYLON.Vector3.Zero(),
|
|
276
|
+
// // new BABYLON.Vector3(
|
|
277
|
+
// // orient.x - orgPos.x,
|
|
278
|
+
// // 0, // orient.y - orgPos.y,
|
|
279
|
+
// // 0, // orient.z - orgPos.z,
|
|
280
|
+
// // ),
|
|
281
|
+
// );
|
|
282
|
+
// const o2 = this.map.project(
|
|
283
|
+
// new mapboxgl.MercatorCoordinate(
|
|
284
|
+
// orient[0],
|
|
285
|
+
// orient[1],
|
|
286
|
+
// orient[2],
|
|
287
|
+
// ).toLngLat(),
|
|
288
|
+
// );
|
|
289
|
+
// this.camera.setTarget(new BABYLON.Vector3(o2.x, o2.y, o2.z));
|
|
290
|
+
// console.log(
|
|
291
|
+
// this.map.getCamera(),
|
|
292
|
+
// this.map.project(
|
|
293
|
+
// new mapboxgl.MercatorCoordinate(pos.x, pos.y, pos.z).toLngLat(),
|
|
294
|
+
// ),
|
|
295
|
+
// this.map.getFreeCameraOptions().orientation,
|
|
296
|
+
// );
|
|
297
|
+
// console.log(this.scene.activeCamera.position);
|
|
83
298
|
// this.camera.position = BABYLON.Vector3.TransformCoordinates(
|
|
84
299
|
// new BABYLON.Vector3(x, y, z),
|
|
85
300
|
// this.scene.activeCamera.getProjectionMatrix().clone().invert(),
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
id: string;
|
|
3
|
+
type: string;
|
|
4
|
+
filter: (string | string[])[];
|
|
5
|
+
layout: {
|
|
6
|
+
"text-field": string[];
|
|
7
|
+
"text-anchor": string[];
|
|
8
|
+
"text-offset": (string | string[] | number[])[];
|
|
9
|
+
"text-size": number;
|
|
10
|
+
"text-allow-overlap": boolean;
|
|
11
|
+
"text-ignore-placement": boolean;
|
|
12
|
+
};
|
|
13
|
+
paint: {
|
|
14
|
+
"text-halo-color": string;
|
|
15
|
+
"text-halo-width": number;
|
|
16
|
+
"text-halo-blur": number;
|
|
17
|
+
"text-color": string;
|
|
18
|
+
};
|
|
19
|
+
}[];
|
|
20
|
+
export default _default;
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { VoidComponent } from
|
|
2
|
-
import type { drawEventTypes } from
|
|
1
|
+
import { VoidComponent } from "solid-js";
|
|
2
|
+
import type { drawEventTypes } from "../../events";
|
|
3
3
|
type Props = {
|
|
4
4
|
/** Draw Library */
|
|
5
5
|
lib: any;
|
|
6
6
|
/** Draw Options */
|
|
7
7
|
options?: object;
|
|
8
8
|
/** Draw Control Position */
|
|
9
|
-
position?:
|
|
9
|
+
position?: "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
10
10
|
/** Draw Control Instance */
|
|
11
11
|
getInstance?: (object: any) => void;
|
|
12
|
+
showLength?: boolean;
|
|
13
|
+
showArea?: boolean;
|
|
12
14
|
} & drawEventTypes;
|
|
13
15
|
export declare const Draw: VoidComponent<Props>;
|
|
14
16
|
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import draw_point from "./point";
|
|
2
|
+
import draw_polygon from "./polygon";
|
|
3
|
+
import draw_line_string from "./line_string";
|
|
4
|
+
import draw_radius from "./radius";
|
|
5
|
+
import draw_rectangle from "./rectangle";
|
|
6
|
+
export { draw_point, draw_polygon, draw_line_string, draw_radius, draw_rectangle, };
|