solid-map-gl 1.11.3 → 1.13.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.
@@ -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
- this.scene.activeCamera = new BABYLON.UniversalCamera("Camera", BABYLON.Vector3.Zero(), this.scene);
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
- // this.camera.inputs.addMouseWheel()
51
- // this.scene.activeCamera.attachControl(gl, true);
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(props.disableProjectionMatrix
78
- ? BABYLON.Matrix.FromArray(matrix)
79
- : worldMatrix.multiply(BABYLON.Matrix.FromArray(matrix)));
80
- // const { x, y, z } = this.map.getFreeCameraOptions().position;
81
- // this.scene.activeCamera.setPosition(new BABYLON.Vector3(x, y, z));
82
- // console.log(this.scene.activeCamera);
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(),
@@ -1,4 +1,5 @@
1
1
  import { createSignal, createEffect, onMount, onCleanup, on, } from "solid-js";
2
+ import "mapbox-gl/dist/mapbox-gl.css";
2
3
  import { MapProvider } from "../MapProvider";
3
4
  import { mapEvents } from "../../events";
4
5
  import { vectorStyleList } from "../../mapStyles";
@@ -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 'solid-js';
2
- import type { drawEventTypes } from '../../events';
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?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
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,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const MultiPointMode: {};
2
+ export default MultiPointMode;
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const RadiusMode: any;
2
+ export default RadiusMode;
@@ -0,0 +1,2 @@
1
+ declare const RectangleMode: any;
2
+ export default RectangleMode;
@@ -0,0 +1,18 @@
1
+ declare const RectangleAssistedMode: {
2
+ onSetup: (opts: any) => {
3
+ rectangle: any;
4
+ currentVertexPosition: number;
5
+ };
6
+ onTap: (state: any, e: any) => void;
7
+ onClick: (state: any, e: any) => any;
8
+ onMouseMove: (state: any, e: any) => void;
9
+ deegrees2meters(px: any): number[];
10
+ meters2degress(px: any): number[];
11
+ calculateOrientedAnglePolygon: (state: any) => void;
12
+ calculatepXY3: (state: any, e: any, tmp: any) => any;
13
+ onKeyUp: (state: any, e: any) => any;
14
+ onStop: (state: any) => void;
15
+ toDisplayFeatures: (state: any, geojson: any, display: any) => any;
16
+ onTrash: (state: any) => void;
17
+ };
18
+ export default RectangleAssistedMode;
@@ -1,4 +1,5 @@
1
1
  import { Component } from "solid-js";
2
+ import "mapbox-gl/dist/mapbox-gl.css";
2
3
  import type { mapEventTypes } from "../../events";
3
4
  import type mapboxgl from "mapbox-gl";
4
5
  import type { MapboxOptions } from "mapbox-gl/src/ui/map";
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.11.3",
2
+ "version": "1.13.0",
3
3
  "name": "solid-map-gl",
4
4
  "description": "Solid Component Library for Mapbox GL JS",
5
5
  "info": "Solid Component Library for Mapbox GL JS. Mapbox GL JS is a JavaScript library that renders interactive maps from vector tiles and Mapbox styles using WebGL. This project is intended to be as close as possible to the Mapbox GL JS API.",
@@ -54,19 +54,19 @@
54
54
  ],
55
55
  "devDependencies": {
56
56
  "@rollup/plugin-terser": "^0.4.4",
57
- "@solidjs/testing-library": "^0.8.8",
58
- "@testing-library/jest-dom": "^6.4.5",
59
- "@types/mapbox-gl": "^3.1.0",
60
- "@vitest/coverage-v8": "^1.6.0",
61
- "jsdom": "^24.1.0",
57
+ "@solidjs/testing-library": "^0.8.10",
58
+ "@testing-library/jest-dom": "^6.8.0",
59
+ "@types/mapbox-gl": "^3.4.1",
60
+ "@vitest/coverage-v8": "^3.2.4",
61
+ "jsdom": "^26.1.0",
62
62
  "jsdom-worker": "^0.3.0",
63
- "rollup": "^4.18.0",
64
- "rollup-plugin-import-css": "^3.5.0",
65
- "rollup-preset-solid": "^2.0.1",
66
- "typescript": "^5.4.5",
67
- "vite": "^5.2.11",
68
- "vite-plugin-solid": "^2.10.2",
69
- "vitest": "^1.6.0"
63
+ "rollup": "^4.47.1",
64
+ "rollup-plugin-import-css": "^4.0.2",
65
+ "rollup-preset-solid": "^3.0.0",
66
+ "typescript": "^5.9.2",
67
+ "vite": "^7.1.3",
68
+ "vite-plugin-solid": "^2.11.8",
69
+ "vitest": "^3.2.4"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "@babylonjs/core": "^6.24.0",
@@ -81,5 +81,12 @@
81
81
  "three": {
82
82
  "optional": true
83
83
  }
84
+ },
85
+ "dependencies": {
86
+ "@turf/area": "^7.2.0",
87
+ "@turf/center-of-mass": "^7.2.0",
88
+ "@turf/centroid": "^7.2.0",
89
+ "@turf/length": "^7.2.0",
90
+ "@turf/midpoint": "^7.2.0"
84
91
  }
85
92
  }