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,135 +0,0 @@
|
|
|
1
|
-
import { onCleanup, createSignal, createEffect, untrack, } from 'solid-js';
|
|
2
|
-
import { useMapContext } from '../MapProvider';
|
|
3
|
-
const PATTERN = {
|
|
4
|
-
diagonal_l: { size: 20, path: 'M20 0 0 20M-10 10 10-10M10 30 30 10' },
|
|
5
|
-
diagonal_r: { size: 20, path: 'M0 0 20 20M30 10 10-10M10 30-10 10' },
|
|
6
|
-
horizontal: { size: 14, path: 'M7 0V20' },
|
|
7
|
-
vertical: { size: 14, path: 'M0 7H20' },
|
|
8
|
-
cross: { size: 18, path: 'M9 0V18M0 9H18' },
|
|
9
|
-
hash: { size: 30, path: 'M15 0 30 15 15 30 0 15Z' },
|
|
10
|
-
chevron_h: { size: 20, path: 'M-5 5 0 10 10 0 20 10 25 5M0 30 10 20 20 30' },
|
|
11
|
-
chevron_v: { size: 20, path: 'M5-5 10 0 0 10 10 20 5 25M25 15 20 10 25 5' },
|
|
12
|
-
square: { size: 20, path: 'M8 8H12V12H8Z', fill: true },
|
|
13
|
-
hex: { size: 50, path: 'M0 0V50L50 25ZM50 0V50L0 25ZM25 0V50' },
|
|
14
|
-
circle: {
|
|
15
|
-
size: 25,
|
|
16
|
-
path: 'M8 10A2.5 2.5 0 118.01 10M18 15A2.5 2.5 0 1018.01 15',
|
|
17
|
-
fill: true,
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
export const patternList = Object.keys(PATTERN);
|
|
21
|
-
export const MGL_Image = props => {
|
|
22
|
-
const [ctx] = useMapContext();
|
|
23
|
-
const [size, setSize] = createSignal({ width: 0, height: 0 });
|
|
24
|
-
const debug = (text, value) => {
|
|
25
|
-
ctx.map.debug &&
|
|
26
|
-
console.debug('%c[MapGL]', 'color: #10b981', text, value || '');
|
|
27
|
-
};
|
|
28
|
-
// Remove Image
|
|
29
|
-
onCleanup(() => {
|
|
30
|
-
ctx.map?.hasImage(props.id) && ctx.map?.removeImage(props.id);
|
|
31
|
-
debug('Remove Image:', props.id);
|
|
32
|
-
});
|
|
33
|
-
// Add or Update Image
|
|
34
|
-
createEffect(() => {
|
|
35
|
-
if (!props.id)
|
|
36
|
-
throw new Error('Image - ID is required');
|
|
37
|
-
if (!props.source && !props.pattern)
|
|
38
|
-
throw new Error('Image - Image or Pattern is required');
|
|
39
|
-
const ops = props.pattern
|
|
40
|
-
? { pixelRatio: 2, ...props.options }
|
|
41
|
-
: props.options;
|
|
42
|
-
_loadImage(props.source || _createPattern(props.pattern), data => {
|
|
43
|
-
const { width, height } = data;
|
|
44
|
-
if (ctx.map && !ctx.map.hasImage(props.id))
|
|
45
|
-
ctx.map.addImage(props.id, data, ops);
|
|
46
|
-
if (!props.pattern &&
|
|
47
|
-
untrack(() => width === size().width && height === size().height)) {
|
|
48
|
-
ctx.map.updateImage(props.id, data);
|
|
49
|
-
ctx.map.triggerRepaint();
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
ctx.map.removeImage(props.id);
|
|
53
|
-
ctx.map.addImage(props.id, data, ops);
|
|
54
|
-
}
|
|
55
|
-
setSize({ width, height });
|
|
56
|
-
debug('Add Image:', props.id);
|
|
57
|
-
ctx.map.on('style.load', () => {
|
|
58
|
-
if (ctx.map.hasImage(props.id))
|
|
59
|
-
return;
|
|
60
|
-
ctx.map.addImage(props.id, data, ops);
|
|
61
|
-
debug('Re-Add Image:', props.id);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
// Load Image / SVG
|
|
66
|
-
const _loadImage = (image, callback) => {
|
|
67
|
-
if (typeof image == 'string' && image?.trimStart().startsWith('<svg')) {
|
|
68
|
-
image = new DOMParser().parseFromString(image, 'image/svg+xml')
|
|
69
|
-
.childNodes[0];
|
|
70
|
-
}
|
|
71
|
-
if (image instanceof SVGElement) {
|
|
72
|
-
props.options?.fill && image.setAttribute('fill', props.options.fill);
|
|
73
|
-
props.options?.stroke &&
|
|
74
|
-
image.setAttribute('stroke', props.options.stroke);
|
|
75
|
-
image = new XMLSerializer().serializeToString(image);
|
|
76
|
-
}
|
|
77
|
-
if (typeof image !== 'string')
|
|
78
|
-
return callback(image);
|
|
79
|
-
ctx.map.loadImage(image, async (error, imageData) => {
|
|
80
|
-
if (error) {
|
|
81
|
-
if (typeof image == 'string' && image?.trimEnd().endsWith('.svg')) {
|
|
82
|
-
image = await (await fetch(image)).text();
|
|
83
|
-
image = new DOMParser().parseFromString(image, 'image/svg+xml')
|
|
84
|
-
.childNodes[0];
|
|
85
|
-
image.setAttribute('fill', props.options.fill);
|
|
86
|
-
image.setAttribute('stroke', props.options.stroke);
|
|
87
|
-
image.setAttribute('transform', props.options.transform);
|
|
88
|
-
image = new XMLSerializer().serializeToString(image);
|
|
89
|
-
}
|
|
90
|
-
const img = new Image();
|
|
91
|
-
img.crossOrigin = 'Anonymous';
|
|
92
|
-
img.onload = () => {
|
|
93
|
-
const canvas = document.createElement('canvas');
|
|
94
|
-
canvas.width = Math.max(img.width, 50);
|
|
95
|
-
canvas.height = Math.max(img.height, 50);
|
|
96
|
-
const ctx = canvas.getContext('2d');
|
|
97
|
-
ctx.imageSmoothingEnabled = true;
|
|
98
|
-
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
99
|
-
return callback(ctx.getImageData(0, 0, canvas.width, canvas.height));
|
|
100
|
-
};
|
|
101
|
-
img.src = image.trimStart().startsWith('<svg')
|
|
102
|
-
? 'data:image/svg+xml;charset=utf-8,' + image
|
|
103
|
-
: image;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
return callback(imageData);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
const _createPattern = pattern => {
|
|
111
|
-
const p = PATTERN[pattern.type];
|
|
112
|
-
return {
|
|
113
|
-
width: p.size,
|
|
114
|
-
height: p.size,
|
|
115
|
-
data: new Uint8Array(p.size * p.size * 4),
|
|
116
|
-
onAdd: function () {
|
|
117
|
-
let canvas = document.createElement('canvas');
|
|
118
|
-
canvas.width = canvas.height = p.size;
|
|
119
|
-
this.ctx = canvas.getContext('2d', { willReadFrequently: true });
|
|
120
|
-
},
|
|
121
|
-
render: function () {
|
|
122
|
-
this.ctx.fillStyle = pattern.background || 'transparent';
|
|
123
|
-
this.ctx.fillRect(0, 0, this.width, this.height);
|
|
124
|
-
this.ctx.strokeStyle = this.ctx.fillStyle = pattern.color || 'black';
|
|
125
|
-
this.ctx.lineWidth = pattern.lineWith || 1;
|
|
126
|
-
this.ctx.stroke(new Path2D(p.path));
|
|
127
|
-
if (p.fill)
|
|
128
|
-
this.ctx.fill(new Path2D(p.path));
|
|
129
|
-
this.data = this.ctx.getImageData(0, 0, this.width, this.height).data;
|
|
130
|
-
return true;
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
};
|
|
134
|
-
return null;
|
|
135
|
-
};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { onCleanup, createEffect, createUniqueId } from "solid-js";
|
|
2
|
-
import { useMapContext } from "../MapProvider";
|
|
3
|
-
import { useSourceId } from "../Source";
|
|
4
|
-
import { layerEvents } from "../../events";
|
|
5
|
-
import { baseStyle, layoutStyles } from "../../styles";
|
|
6
|
-
const diff = (newProps = {}, prevProps = {}) => {
|
|
7
|
-
const keys = new Set([...Object.keys(newProps), ...Object.keys(prevProps)]);
|
|
8
|
-
return [...keys].reduce((acc, key) => {
|
|
9
|
-
const value = newProps[key];
|
|
10
|
-
if (value !== prevProps[key]) {
|
|
11
|
-
acc.push([key, value]);
|
|
12
|
-
}
|
|
13
|
-
return acc;
|
|
14
|
-
}, []);
|
|
15
|
-
};
|
|
16
|
-
const newKey = (key, type) => (key.startsWith(type) || key.startsWith("icon") || key.startsWith("text")
|
|
17
|
-
? ""
|
|
18
|
-
: type + "-") + key.replace(/[A-Z]/g, (s) => "-" + s.toLowerCase());
|
|
19
|
-
const updateStyle = (oldStyle) => {
|
|
20
|
-
if (!oldStyle)
|
|
21
|
-
return;
|
|
22
|
-
let layout = {};
|
|
23
|
-
let paint = {};
|
|
24
|
-
let style = {};
|
|
25
|
-
Object.entries(oldStyle).forEach(([key, value]) => {
|
|
26
|
-
if (baseStyle.includes(key))
|
|
27
|
-
style[key] = value;
|
|
28
|
-
else {
|
|
29
|
-
const nk = newKey(key, oldStyle.type);
|
|
30
|
-
layoutStyles.includes(nk) ? (layout[nk] = value) : (paint[nk] = value);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
if (oldStyle.paint)
|
|
34
|
-
Object.entries(oldStyle.paint).forEach(([key, value]) => (paint[newKey(key, oldStyle.type)] = value));
|
|
35
|
-
if (oldStyle.layout)
|
|
36
|
-
Object.entries(oldStyle.layout).forEach(([key, value]) => (layout[newKey(key, oldStyle.type)] = value));
|
|
37
|
-
return { ...style, paint, layout };
|
|
38
|
-
};
|
|
39
|
-
export const Layer = (props) => {
|
|
40
|
-
const [ctx] = useMapContext();
|
|
41
|
-
const sourceId = props.sourceId || props.style?.source || useSourceId();
|
|
42
|
-
const layerId = props.id || props.customLayer?.id || createUniqueId();
|
|
43
|
-
const debug = (text, value) => {
|
|
44
|
-
(ctx.map.debug || ctx.map.debugEvents) &&
|
|
45
|
-
console.debug("%c[MapGL]", "color: #10b981", text, value || "");
|
|
46
|
-
};
|
|
47
|
-
// Add Layer
|
|
48
|
-
ctx.map.addLayer(props.customLayer || {
|
|
49
|
-
...updateStyle(props.style),
|
|
50
|
-
id: layerId,
|
|
51
|
-
source: sourceId,
|
|
52
|
-
slot: props.slot || "",
|
|
53
|
-
metadata: {
|
|
54
|
-
smg: { beforeType: props.beforeType, beforeId: props.beforeId },
|
|
55
|
-
},
|
|
56
|
-
}, props.beforeType
|
|
57
|
-
? ctx.map.getStyle().layers.find((l) => l.type === props.beforeType)?.id
|
|
58
|
-
: props.beforeId);
|
|
59
|
-
ctx.map.layerIdList.push(layerId);
|
|
60
|
-
if (props.customLayer)
|
|
61
|
-
ctx.map.fire("load");
|
|
62
|
-
debug("Add Layer:", layerId);
|
|
63
|
-
// Hook up events
|
|
64
|
-
layerEvents.forEach((item) => {
|
|
65
|
-
if (props[item]) {
|
|
66
|
-
const event = item.slice(2).toLowerCase();
|
|
67
|
-
ctx.map.on(event, layerId, (evt) => {
|
|
68
|
-
evt.clickOnLayer = true;
|
|
69
|
-
props[item](evt);
|
|
70
|
-
ctx.map.debugEvent &&
|
|
71
|
-
debug(`Layer '${event}' event on '${layerId}':`, evt);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
// Update Style
|
|
76
|
-
createEffect((prev) => {
|
|
77
|
-
const style = updateStyle(props.style);
|
|
78
|
-
if (style === prev)
|
|
79
|
-
return;
|
|
80
|
-
if (style.layout !== prev?.layout)
|
|
81
|
-
diff(style.layout, prev?.layout).forEach(([key, value]) => ctx.map.setLayoutProperty(layerId, key, value, { validate: false }));
|
|
82
|
-
if (style.paint !== prev?.paint)
|
|
83
|
-
diff(style.paint, prev?.paint).forEach(([key, value]) => ctx.map.setPaintProperty(layerId, key, value, { validate: false }));
|
|
84
|
-
if (style.minzoom !== prev?.minzoom || style.maxzoom !== prev?.maxzoom)
|
|
85
|
-
ctx.map.setLayerZoomRange(layerId, style.minzoom, style.maxzoom);
|
|
86
|
-
if (style.filter !== prev?.filter)
|
|
87
|
-
ctx.map.setFilter(layerId, style.filter, { validate: false });
|
|
88
|
-
debug("Update Layer Style:", layerId);
|
|
89
|
-
return style;
|
|
90
|
-
}, updateStyle(props.style));
|
|
91
|
-
// Update Visibility
|
|
92
|
-
createEffect((prev) => {
|
|
93
|
-
if (props.visible === prev)
|
|
94
|
-
return;
|
|
95
|
-
ctx.map.setLayoutProperty(layerId, "visibility", props.visible ? "visible" : "none", { validate: false });
|
|
96
|
-
debug(`Update Visibility (${layerId}):`, props.visible.toString());
|
|
97
|
-
return props.visible;
|
|
98
|
-
}, props.visible);
|
|
99
|
-
// Update Filter
|
|
100
|
-
createEffect(async () => {
|
|
101
|
-
if (!props.filter)
|
|
102
|
-
return;
|
|
103
|
-
!ctx.map.isStyleLoaded() && (await ctx.map.once("styledata"));
|
|
104
|
-
ctx.map.setFilter(layerId, props.filter);
|
|
105
|
-
debug(`Update Filter (${layerId}):`, props.filter);
|
|
106
|
-
});
|
|
107
|
-
// Update Feature State
|
|
108
|
-
createEffect(async () => {
|
|
109
|
-
if (!props.featureState || props.featureState.id === null)
|
|
110
|
-
return;
|
|
111
|
-
!ctx.map.isStyleLoaded() && (await ctx.map.once("styledata"));
|
|
112
|
-
ctx.map.removeFeatureState({
|
|
113
|
-
source: sourceId,
|
|
114
|
-
sourceLayer: props.style["source-layer"],
|
|
115
|
-
});
|
|
116
|
-
ctx.map.setFeatureState({
|
|
117
|
-
source: sourceId,
|
|
118
|
-
sourceLayer: props.style["source-layer"],
|
|
119
|
-
id: props.featureState.id,
|
|
120
|
-
}, props.featureState.state);
|
|
121
|
-
});
|
|
122
|
-
//Remove Layer
|
|
123
|
-
onCleanup(() => ctx.map?.getLayer(layerId) && ctx.map?.removeLayer(layerId));
|
|
124
|
-
return props.children;
|
|
125
|
-
};
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
import { onCleanup, createUniqueId, createSignal, onMount, createContext, useContext, } from "solid-js";
|
|
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
|
-
};
|
|
19
|
-
const LayerContext = createContext();
|
|
20
|
-
export const useScene = () => useContext(LayerContext);
|
|
21
|
-
export const Layer3D = (props) => {
|
|
22
|
-
const [ctx] = useMapContext();
|
|
23
|
-
const [scene, setScene] = createSignal(null);
|
|
24
|
-
onMount(async () => {
|
|
25
|
-
props.id = props.id || createUniqueId();
|
|
26
|
-
const worldOriginMercator = window.MapLib.MercatorCoordinate.fromLngLat([props.origin[0] || 0, props.origin[1] || 0], props.origin[2] || 0);
|
|
27
|
-
const worldScale = worldOriginMercator.meterInMercatorCoordinateUnits();
|
|
28
|
-
const { x, y, z } = worldOriginMercator;
|
|
29
|
-
let worldMatrix = null;
|
|
30
|
-
let BABYLON = null;
|
|
31
|
-
let THREE = null;
|
|
32
|
-
if (props.babylon) {
|
|
33
|
-
BABYLON = await import("@babylonjs/core");
|
|
34
|
-
worldMatrix = BABYLON.Matrix.Compose(new BABYLON.Vector3(worldScale, worldScale, worldScale), BABYLON.Quaternion.FromEulerAngles(Math.PI / 2, 0, 0), new BABYLON.Vector3(x, y, z));
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
THREE = await import("three");
|
|
38
|
-
worldMatrix = {
|
|
39
|
-
translateX: x,
|
|
40
|
-
translateY: y,
|
|
41
|
-
translateZ: z,
|
|
42
|
-
rotateX: Math.PI / 2,
|
|
43
|
-
rotateY: 0,
|
|
44
|
-
rotateZ: 0,
|
|
45
|
-
scale: worldScale,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
ctx.map.addLayer({
|
|
49
|
-
id: props.id,
|
|
50
|
-
type: "custom",
|
|
51
|
-
renderingMode: "3d",
|
|
52
|
-
onAdd(map, gl) {
|
|
53
|
-
if (props.babylon) {
|
|
54
|
-
const engine = new BABYLON.Engine(gl, true, {
|
|
55
|
-
useHighPrecisionMatrix: true,
|
|
56
|
-
}, true);
|
|
57
|
-
// this.index = 0;
|
|
58
|
-
this.scene = new BABYLON.Scene(engine);
|
|
59
|
-
this.scene.autoClear = false;
|
|
60
|
-
// this.scene.autoClearDepthAndStencil = false;
|
|
61
|
-
// this.scene.detachControl();
|
|
62
|
-
this.scene.preventDefaultOnPointerDown = false;
|
|
63
|
-
this.scene.preventDefaultOnPointerUp = false;
|
|
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();
|
|
74
|
-
// this.scene.activeCamera.setTarget(BABYLON.Vector3.Zero());
|
|
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);
|
|
81
|
-
this.scene.ambientColor = new BABYLON.Color3(1, 1, 1);
|
|
82
|
-
if (props.defaultLight)
|
|
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);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
this.camera = new THREE.Camera();
|
|
91
|
-
this.scene = new THREE.Scene();
|
|
92
|
-
if (props.defaultLight) {
|
|
93
|
-
this.light = new THREE.DirectionalLight(0xffffff);
|
|
94
|
-
this.light.position.set(100, 0, 0).normalize();
|
|
95
|
-
this.scene.add(this.light);
|
|
96
|
-
}
|
|
97
|
-
this.renderer = new THREE.WebGLRenderer({
|
|
98
|
-
canvas: map.getCanvas(),
|
|
99
|
-
context: gl,
|
|
100
|
-
antialias: true,
|
|
101
|
-
});
|
|
102
|
-
this.renderer.autoClear = false;
|
|
103
|
-
}
|
|
104
|
-
this.map = map;
|
|
105
|
-
props.onAdd && props.onAdd(this.scene, this.map, gl);
|
|
106
|
-
setScene(this.scene);
|
|
107
|
-
},
|
|
108
|
-
render(gl, matrix) {
|
|
109
|
-
if (props.babylon) {
|
|
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);
|
|
298
|
-
// this.camera.position = BABYLON.Vector3.TransformCoordinates(
|
|
299
|
-
// new BABYLON.Vector3(x, y, z),
|
|
300
|
-
// this.scene.activeCamera.getProjectionMatrix().clone().invert(),
|
|
301
|
-
// );
|
|
302
|
-
this.scene.render(false);
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
const rotationX = new THREE.Matrix4().makeRotationAxis(new THREE.Vector3(1, 0, 0), worldMatrix.rotateX);
|
|
306
|
-
const rotationY = new THREE.Matrix4().makeRotationAxis(new THREE.Vector3(0, 1, 0), worldMatrix.rotateY);
|
|
307
|
-
const rotationZ = new THREE.Matrix4().makeRotationAxis(new THREE.Vector3(0, 0, 1), worldMatrix.rotateZ);
|
|
308
|
-
const m = new THREE.Matrix4().fromArray(matrix);
|
|
309
|
-
const l = new THREE.Matrix4()
|
|
310
|
-
.makeTranslation(worldMatrix.translateX, worldMatrix.translateY, worldMatrix.translateZ)
|
|
311
|
-
.scale(new THREE.Vector3(worldMatrix.scale, -worldMatrix.scale, worldMatrix.scale))
|
|
312
|
-
.multiply(rotationX)
|
|
313
|
-
.multiply(rotationY)
|
|
314
|
-
.multiply(rotationZ);
|
|
315
|
-
this.camera.projectionMatrix = m.multiply(l);
|
|
316
|
-
this.renderer.resetState();
|
|
317
|
-
this.renderer.render(this.scene, this.camera);
|
|
318
|
-
}
|
|
319
|
-
props.onRender && props.onRender(gl, matrix);
|
|
320
|
-
ctx.map.triggerRepaint();
|
|
321
|
-
},
|
|
322
|
-
}, props.beforeId);
|
|
323
|
-
});
|
|
324
|
-
onCleanup(() => {
|
|
325
|
-
ctx.map.getLayer(props.id) && ctx.map.removeLayer(props.id);
|
|
326
|
-
});
|
|
327
|
-
return (<LayerContext.Provider value={scene}>
|
|
328
|
-
{scene() && props.children}
|
|
329
|
-
</LayerContext.Provider>);
|
|
330
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { onCleanup, createEffect } from 'solid-js';
|
|
2
|
-
import { useMapContext } from '../MapProvider';
|
|
3
|
-
export const Light = (props) => {
|
|
4
|
-
const [ctx] = useMapContext();
|
|
5
|
-
// Add or Update Light Layer
|
|
6
|
-
createEffect(() => ctx.map.setLight(props.style || {}));
|
|
7
|
-
// Remove Light Layer
|
|
8
|
-
onCleanup(() => ctx.map?.setLight(null));
|
|
9
|
-
return null;
|
|
10
|
-
};
|