solid-map-gl 1.7.1 → 1.8.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/Atmosphere/index.jsx +3 -5
- package/dist/source/components/Camera/index.jsx +19 -34
- package/dist/source/components/Control/index.jsx +1 -3
- package/dist/source/components/Draw/index.jsx +2 -4
- package/dist/source/components/Image/index.jsx +3 -5
- package/dist/source/components/Layer/index.jsx +2 -4
- package/dist/source/components/Light/index.jsx +2 -4
- package/dist/source/components/MapGL/index.jsx +51 -50
- package/dist/source/components/MapProvider/index.jsx +12 -0
- package/dist/source/components/Marker/index.jsx +2 -4
- package/dist/source/components/Popup/index.jsx +2 -4
- package/dist/source/components/Source/index.jsx +1 -3
- package/dist/source/components/Terrain/index.jsx +15 -22
- package/dist/source/index.jsx +2 -1
- package/dist/types/components/Atmosphere/index.d.ts +2 -2
- package/dist/types/components/Camera/index.d.ts +26 -3
- package/dist/types/components/Light/index.d.ts +1 -1
- package/dist/types/components/MapGL/index.d.ts +8 -2
- package/dist/types/components/MapProvider/index.d.ts +8 -0
- package/dist/types/components/Marker/index.d.ts +1 -3
- package/dist/types/components/Popup/index.d.ts +1 -2
- package/dist/types/components/Terrain/index.d.ts +2 -9
- package/dist/types/events.d.ts +1 -1
- package/dist/types/index.d.ts +2 -1
- package/package.json +13 -12
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createEffect, onCleanup } from 'solid-js';
|
|
2
|
-
import { useMap } from '../
|
|
2
|
+
import { useMap } from '../MapProvider';
|
|
3
3
|
// linearly interpolate between two positions [x,y,z] based on time
|
|
4
4
|
const lerp = (a, b, t) => a.map((_, idx) => (1.0 - t) * a[idx] + t * b[idx]);
|
|
5
5
|
// sphericaly interpolate between two positions [x,y,z] based on time
|
|
@@ -9,16 +9,6 @@ const slerp = (a, b, t) => {
|
|
|
9
9
|
return a.map((_, idx) => (Math.sin((1 - t) * theta) / Math.sin(theta)) * a[idx] +
|
|
10
10
|
(Math.sin(t * theta) / Math.sin(theta)) * b[idx]);
|
|
11
11
|
};
|
|
12
|
-
// const slerp = (a, b, t) => {
|
|
13
|
-
// const omega = 0.075
|
|
14
|
-
// // TODO: Proper Calculation
|
|
15
|
-
// // a.map((_, idx) => a[idx] * b[idx]).reduce((m, n) => m + n)
|
|
16
|
-
// return a.map(
|
|
17
|
-
// (_, idx) =>
|
|
18
|
-
// (Math.sin((1 - t) * omega) / Math.sin(omega)) * a[idx] +
|
|
19
|
-
// (Math.sin(t * omega) / Math.sin(omega)) * b[idx]
|
|
20
|
-
// )
|
|
21
|
-
// }
|
|
22
12
|
// calculations from: https://easings.net
|
|
23
13
|
const easeQuad = {
|
|
24
14
|
in: (x) => x * x,
|
|
@@ -26,9 +16,9 @@ const easeQuad = {
|
|
|
26
16
|
inOut: (x) => x < 0.5 ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2,
|
|
27
17
|
};
|
|
28
18
|
export const Camera = props => {
|
|
29
|
-
if (!useMap())
|
|
30
|
-
return;
|
|
31
19
|
const [map, userInteraction] = useMap();
|
|
20
|
+
if (!map())
|
|
21
|
+
return null;
|
|
32
22
|
let animationTime = 0.1;
|
|
33
23
|
let isReverse = false;
|
|
34
24
|
const updateCameraPosition = async ([lng, lat, alt], target) => {
|
|
@@ -37,7 +27,7 @@ export const Camera = props => {
|
|
|
37
27
|
camera.lookAtPoint(target);
|
|
38
28
|
map().setFreeCameraOptions(camera);
|
|
39
29
|
};
|
|
40
|
-
const frame = (
|
|
30
|
+
const frame = () => {
|
|
41
31
|
props.translate && window.requestAnimationFrame(frame);
|
|
42
32
|
const params = [
|
|
43
33
|
props.translate.start,
|
|
@@ -55,12 +45,13 @@ export const Camera = props => {
|
|
|
55
45
|
createEffect(() => {
|
|
56
46
|
props.translate && window.requestAnimationFrame(frame);
|
|
57
47
|
});
|
|
48
|
+
const options = { duration: 1000, easing: n => n };
|
|
58
49
|
const rotateGlobe = () => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const slowSpinZoom = props.rotateGlobe
|
|
50
|
+
if (userInteraction)
|
|
51
|
+
return;
|
|
52
|
+
const { secPerRev = 120, maxSpinZoom = 5, slowSpinZoom = 3, } = props.rotateGlobe;
|
|
62
53
|
const zoom = map().getZoom();
|
|
63
|
-
if (
|
|
54
|
+
if (zoom > maxSpinZoom)
|
|
64
55
|
return;
|
|
65
56
|
let distancePerSecond = 360 / secPerRev;
|
|
66
57
|
if (zoom > slowSpinZoom)
|
|
@@ -69,28 +60,22 @@ export const Camera = props => {
|
|
|
69
60
|
center.lng = props.reverse
|
|
70
61
|
? center.lng + distancePerSecond
|
|
71
62
|
: center.lng - distancePerSecond;
|
|
72
|
-
map().easeTo({ center,
|
|
63
|
+
map().easeTo({ center, ...options }, { rotate: true });
|
|
73
64
|
};
|
|
74
65
|
const rotateViewport = () => {
|
|
75
|
-
if (!props.rotateViewport || userInteraction
|
|
66
|
+
if (!props.rotateViewport || userInteraction)
|
|
76
67
|
return;
|
|
77
|
-
const
|
|
68
|
+
const rotateViewport = props.rotateViewport;
|
|
69
|
+
const secPerRev = rotateViewport?.secPerRev || 60;
|
|
78
70
|
const bearing = props.reverse
|
|
79
71
|
? map().getBearing() + 360 / secPerRev
|
|
80
72
|
: map().getBearing() - 360 / secPerRev;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
duration: 1000,
|
|
85
|
-
around: props.rotateViewport?.around,
|
|
86
|
-
easing: n => n,
|
|
87
|
-
}, { rotate: true });
|
|
88
|
-
};
|
|
89
|
-
const onMoveEnd = evt => {
|
|
90
|
-
evt.rotate && props.rotateGlobe ? rotateGlobe() : rotateViewport();
|
|
73
|
+
const pitch = rotateViewport?.pitch || 60;
|
|
74
|
+
const around = rotateViewport?.around;
|
|
75
|
+
map().easeTo({ bearing, pitch, around, ...options }, { rotate: true });
|
|
91
76
|
};
|
|
92
|
-
const
|
|
93
|
-
map().on('moveend',
|
|
77
|
+
const onEnd = () => (props.rotateGlobe ? rotateGlobe() : rotateViewport());
|
|
78
|
+
map().on('moveend', onEnd).on('dragend', onEnd);
|
|
94
79
|
let originalCenter;
|
|
95
80
|
createEffect(() => {
|
|
96
81
|
if (props.rotateGlobe == undefined)
|
|
@@ -114,6 +99,6 @@ export const Camera = props => {
|
|
|
114
99
|
? map().stop().resetNorthPitch()
|
|
115
100
|
: map().stop();
|
|
116
101
|
});
|
|
117
|
-
onCleanup(() => map().off('moveend',
|
|
102
|
+
onCleanup(() => map().off('moveend', onEnd).off('dragend', onEnd));
|
|
118
103
|
return props.children;
|
|
119
104
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createEffect, onCleanup } from 'solid-js';
|
|
2
|
-
import { useMap } from '../
|
|
2
|
+
import { useMap } from '../MapProvider';
|
|
3
3
|
const getControl = (lib, type, options, custom) => {
|
|
4
4
|
if (custom)
|
|
5
5
|
return new custom(options);
|
|
@@ -20,8 +20,6 @@ const getControl = (lib, type, options, custom) => {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
export const Control = props => {
|
|
23
|
-
if (!useMap())
|
|
24
|
-
return;
|
|
25
23
|
const [map] = useMap();
|
|
26
24
|
let control = null;
|
|
27
25
|
// Add or Update Control
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { onCleanup } from 'solid-js';
|
|
2
|
-
import { useMap } from '../
|
|
2
|
+
import { useMap } from '../MapProvider';
|
|
3
3
|
import { drawEvents } from '../../events';
|
|
4
|
-
export const Draw = props => {
|
|
5
|
-
if (!useMap())
|
|
6
|
-
return;
|
|
4
|
+
export const Draw = (props) => {
|
|
7
5
|
const [map] = useMap();
|
|
8
6
|
// Add Draw Control
|
|
9
7
|
const draw = new props.lib(props.options);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { onCleanup, createSignal, createEffect, untrack, } from 'solid-js';
|
|
2
|
-
import { useMap } from '../
|
|
2
|
+
import { useMap } from '../MapProvider';
|
|
3
3
|
const PATTERN = {
|
|
4
4
|
diagonal_l: { size: 20, path: 'M20 0 0 20M-10 10 10-10M10 30 30 10' },
|
|
5
5
|
diagonal_r: { size: 20, path: 'M0 0 20 20M30 10 10-10M10 30-10 10' },
|
|
@@ -19,8 +19,6 @@ const PATTERN = {
|
|
|
19
19
|
};
|
|
20
20
|
export const patternList = Object.keys(PATTERN);
|
|
21
21
|
export const MGL_Image = props => {
|
|
22
|
-
if (!useMap())
|
|
23
|
-
return;
|
|
24
22
|
const [map] = useMap();
|
|
25
23
|
const [size, setSize] = createSignal({ width: 0, height: 0 });
|
|
26
24
|
const debug = (text, value) => {
|
|
@@ -43,7 +41,7 @@ export const MGL_Image = props => {
|
|
|
43
41
|
: props.options;
|
|
44
42
|
_loadImage(props.source || _createPattern(props.pattern), data => {
|
|
45
43
|
const { width, height } = data;
|
|
46
|
-
if (!map().hasImage(props.id))
|
|
44
|
+
if (map() && !map().hasImage(props.id))
|
|
47
45
|
map().addImage(props.id, data, ops);
|
|
48
46
|
if (!props.pattern &&
|
|
49
47
|
untrack(() => width === size().width && height === size().height)) {
|
|
@@ -56,7 +54,7 @@ export const MGL_Image = props => {
|
|
|
56
54
|
}
|
|
57
55
|
setSize({ width, height });
|
|
58
56
|
debug('Add Image:', props.id);
|
|
59
|
-
map().on('
|
|
57
|
+
map().on('style.load', () => {
|
|
60
58
|
if (map().hasImage(props.id))
|
|
61
59
|
return;
|
|
62
60
|
map().addImage(props.id, data, ops);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { onCleanup, createEffect, createUniqueId } from 'solid-js';
|
|
2
|
-
import { useMap } from '../
|
|
2
|
+
import { useMap } from '../MapProvider';
|
|
3
3
|
import { useSourceId } from '../Source';
|
|
4
4
|
import { layerEvents } from '../../events';
|
|
5
5
|
const diff = (newProps = {}, prevProps = {}) => {
|
|
@@ -13,8 +13,6 @@ const diff = (newProps = {}, prevProps = {}) => {
|
|
|
13
13
|
}, []);
|
|
14
14
|
};
|
|
15
15
|
export const Layer = props => {
|
|
16
|
-
if (!useMap())
|
|
17
|
-
return;
|
|
18
16
|
const [map] = useMap();
|
|
19
17
|
const sourceId = props.style?.source || useSourceId();
|
|
20
18
|
props.id ??= createUniqueId();
|
|
@@ -50,7 +48,7 @@ export const Layer = props => {
|
|
|
50
48
|
// Update Style
|
|
51
49
|
createEffect((prev) => {
|
|
52
50
|
const style = props.style;
|
|
53
|
-
if (style === prev
|
|
51
|
+
if (style === prev)
|
|
54
52
|
return;
|
|
55
53
|
if (style.layout !== prev?.layout)
|
|
56
54
|
diff(style.layout, prev?.layout).forEach(([key, value]) => map().setLayoutProperty(props.id, key, value, { validate: false }));
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { onCleanup, createEffect } from 'solid-js';
|
|
2
|
-
import { useMap } from '../
|
|
3
|
-
export const Light = props => {
|
|
4
|
-
if (!useMap())
|
|
5
|
-
return;
|
|
2
|
+
import { useMap } from '../MapProvider';
|
|
3
|
+
export const Light = (props) => {
|
|
6
4
|
const [map] = useMap();
|
|
7
5
|
// Add or Update Light Layer
|
|
8
6
|
createEffect(() => map().setLight(props.style || {}));
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { createSignal, createEffect, onMount, onCleanup,
|
|
1
|
+
import { createSignal, createEffect, onMount, onCleanup, createUniqueId, on, } from 'solid-js';
|
|
2
|
+
import { MapProvider } from '../MapProvider';
|
|
2
3
|
import { mapEvents } from '../../events';
|
|
3
4
|
import { vectorStyleList } from '../../mapStyles';
|
|
4
|
-
const MapContext = createContext();
|
|
5
|
-
/** Provides the Mapbox Map Object */
|
|
6
|
-
export const useMap = () => useContext(MapContext);
|
|
7
5
|
/** Creates a new Map Container */
|
|
8
6
|
export const MapGL = props => {
|
|
9
7
|
props.id ??= createUniqueId();
|
|
@@ -11,13 +9,13 @@ export const MapGL = props => {
|
|
|
11
9
|
let mapRef;
|
|
12
10
|
let resizeObserver;
|
|
13
11
|
let mutationObserver;
|
|
14
|
-
const [mapLoaded, setMapLoaded] = createSignal(
|
|
15
|
-
const [mapRoot, setMapRoot] = createSignal();
|
|
12
|
+
const [mapLoaded, setMapLoaded] = createSignal(null);
|
|
16
13
|
const [darkMode, setDarkMode] = createSignal((typeof window !== 'undefined' &&
|
|
17
14
|
window.matchMedia('(prefers-color-scheme: dark)').matches) ||
|
|
18
15
|
(typeof document !== 'undefined' &&
|
|
19
16
|
document.body.classList.contains('dark')));
|
|
20
17
|
const [userInteraction, setUserInteraction] = createSignal(false);
|
|
18
|
+
const [internal, setInternal] = createSignal(false);
|
|
21
19
|
// debounce user interactions
|
|
22
20
|
createEffect(() => props.onUserInteraction?.(userInteraction()));
|
|
23
21
|
const debug = (text, value) => {
|
|
@@ -25,7 +23,7 @@ export const MapGL = props => {
|
|
|
25
23
|
console.debug('%c[MapGL]', 'color: #0ea5e9', text, value || '');
|
|
26
24
|
};
|
|
27
25
|
const getStyle = (light, dark) => {
|
|
28
|
-
const style = darkMode()
|
|
26
|
+
const style = darkMode() && dark ? dark : light;
|
|
29
27
|
return typeof style === 'string' || style instanceof String
|
|
30
28
|
? style
|
|
31
29
|
?.split(':')
|
|
@@ -59,8 +57,7 @@ export const MapGL = props => {
|
|
|
59
57
|
map.sourceIdList = [];
|
|
60
58
|
map.layerIdList = [];
|
|
61
59
|
map.once('load', () => {
|
|
62
|
-
|
|
63
|
-
setMapLoaded(true);
|
|
60
|
+
setMapLoaded(map);
|
|
64
61
|
debug('Map loaded');
|
|
65
62
|
['mousedown', 'touchstart', 'wheel'].forEach(event => map.on(event, evt => !evt.rotate && setUserInteraction(true)));
|
|
66
63
|
['moveend', 'mouseup', 'touchend'].forEach(event => map.on(event, evt => !evt.rotate && setUserInteraction(false)));
|
|
@@ -74,80 +71,81 @@ export const MapGL = props => {
|
|
|
74
71
|
mutationObserver = new MutationObserver(() => {
|
|
75
72
|
const darkTheme = document.body.classList.contains('dark');
|
|
76
73
|
setDarkMode(darkTheme);
|
|
77
|
-
debug('Set
|
|
74
|
+
debug('Set theme to:', darkTheme);
|
|
78
75
|
});
|
|
79
76
|
mutationObserver.observe(document.body, { attributes: true });
|
|
80
77
|
// Listen to map container size changes
|
|
81
|
-
if (!props.disableResize) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
78
|
+
// if (!props.disableResize) {
|
|
79
|
+
// resizeObserver = new ResizeObserver(() => {
|
|
80
|
+
// map?.resize()
|
|
81
|
+
// debug('Map resized')
|
|
82
|
+
// })
|
|
83
|
+
// resizeObserver.observe(mapRef as Element)
|
|
84
|
+
// }
|
|
88
85
|
// Hook up events
|
|
89
86
|
mapEvents.forEach(item => {
|
|
90
87
|
const prop = props[item];
|
|
88
|
+
let isFirstMessage = true;
|
|
91
89
|
if (prop) {
|
|
92
90
|
const event = item.slice(2).toLowerCase();
|
|
93
91
|
if (typeof prop === 'function') {
|
|
94
92
|
map.on(event, e => {
|
|
95
93
|
prop(e);
|
|
96
|
-
debug(`Map '${event}' event:`, e);
|
|
94
|
+
isFirstMessage && debug(`Map '${event}' event:`, e);
|
|
95
|
+
isFirstMessage = false;
|
|
97
96
|
});
|
|
98
97
|
}
|
|
99
98
|
else {
|
|
100
99
|
Object.keys(prop).forEach(layerId => {
|
|
101
100
|
map.on(event, layerId, e => {
|
|
102
101
|
prop[layerId](e);
|
|
103
|
-
|
|
102
|
+
isFirstMessage &&
|
|
103
|
+
debug(`Map '${event}' event on '${layerId}':`, e);
|
|
104
|
+
isFirstMessage = false;
|
|
104
105
|
});
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
109
|
});
|
|
109
|
-
//
|
|
110
|
+
// Update Viewport
|
|
110
111
|
map.on('move', event => {
|
|
111
112
|
const viewport = {
|
|
112
113
|
...props.viewport,
|
|
113
114
|
id: props.id,
|
|
114
|
-
point: { x: event.originalEvent?.x, y: event.originalEvent?.y },
|
|
115
|
+
// point: { x: event.originalEvent?.x, y: event.originalEvent?.y },
|
|
115
116
|
center: props.viewport?.center?.lat
|
|
116
117
|
? map.getCenter()
|
|
117
118
|
: [map.getCenter().lng, map.getCenter().lat],
|
|
118
119
|
zoom: map.getZoom(),
|
|
119
120
|
pitch: map.getPitch(),
|
|
120
121
|
bearing: map.getBearing(),
|
|
122
|
+
inTransit: true,
|
|
121
123
|
};
|
|
122
|
-
|
|
124
|
+
setInternal(true);
|
|
125
|
+
!event.viewport && props.onViewportChange?.(viewport);
|
|
126
|
+
});
|
|
127
|
+
map.on('moveend', event => {
|
|
128
|
+
!event.rotate &&
|
|
129
|
+
props.onViewportChange?.({ ...props.viewport, inTransit: false });
|
|
130
|
+
setInternal(false);
|
|
123
131
|
});
|
|
124
132
|
});
|
|
125
133
|
});
|
|
126
|
-
//
|
|
127
|
-
createEffect(() => {
|
|
134
|
+
// Hook up viewport event
|
|
135
|
+
createEffect(on(() => props.viewport, vp => {
|
|
136
|
+
if (props.id !== vp?.id || internal())
|
|
137
|
+
return;
|
|
128
138
|
const viewport = {
|
|
129
|
-
...
|
|
130
|
-
|
|
139
|
+
...vp,
|
|
140
|
+
...(vp.bounds
|
|
141
|
+
? map.cameraForBounds(vp.bounds, {
|
|
142
|
+
padding: vp?.padding,
|
|
143
|
+
})
|
|
144
|
+
: null),
|
|
131
145
|
};
|
|
132
|
-
|
|
133
|
-
return;
|
|
134
|
-
map?.stop()[props.transitionType || 'flyTo'](viewport, { viewport: true });
|
|
146
|
+
map.stop()[props.transitionType || 'flyTo'](viewport);
|
|
135
147
|
debug(`Update Viewport (${props.transitionType || 'flyTo'}):`, viewport);
|
|
136
|
-
});
|
|
137
|
-
// Update boundaries
|
|
138
|
-
createEffect(prev => {
|
|
139
|
-
const bounds = props.viewport?.bounds;
|
|
140
|
-
if (map && bounds && prev !== bounds && !userInteraction()) {
|
|
141
|
-
props.onViewportChange({
|
|
142
|
-
...props.viewport,
|
|
143
|
-
...map?.cameraForBounds(bounds, {
|
|
144
|
-
padding: props.viewport?.padding,
|
|
145
|
-
}),
|
|
146
|
-
});
|
|
147
|
-
debug(`Update Viewport Boundaries:`, bounds);
|
|
148
|
-
}
|
|
149
|
-
return bounds;
|
|
150
|
-
}, props.viewport?.bounds);
|
|
148
|
+
}, { defer: true }));
|
|
151
149
|
// Update Projection
|
|
152
150
|
createEffect(() => {
|
|
153
151
|
const proj = props.options?.projection;
|
|
@@ -223,14 +221,17 @@ export const MapGL = props => {
|
|
|
223
221
|
map?.remove();
|
|
224
222
|
debug('Map removed');
|
|
225
223
|
});
|
|
226
|
-
return (
|
|
227
|
-
<div ref={mapRef} id={props.id} class={props?.class} classList={props?.classList} style={props?.
|
|
228
|
-
?
|
|
229
|
-
: {
|
|
224
|
+
return (<>
|
|
225
|
+
<div ref={mapRef} id={props.id} class={props?.class} classList={props?.classList} style={props?.class || props?.classList
|
|
226
|
+
? null
|
|
227
|
+
: props.style || {
|
|
230
228
|
position: 'absolute',
|
|
231
229
|
inset: 0,
|
|
232
230
|
'z-index': -1,
|
|
233
231
|
}}/>
|
|
234
|
-
{mapLoaded() &&
|
|
235
|
-
|
|
232
|
+
{mapLoaded() &&
|
|
233
|
+
<MapProvider map={mapLoaded()}>
|
|
234
|
+
{props.children}
|
|
235
|
+
</MapProvider>}
|
|
236
|
+
</>);
|
|
236
237
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createContext, useContext, createSignal } from "solid-js";
|
|
2
|
+
const [map, setMap] = createSignal(null);
|
|
3
|
+
const [userInteraction, setUserInteraction] = createSignal(null);
|
|
4
|
+
export const MapContext = createContext([map, userInteraction]);
|
|
5
|
+
export const useMap = () => useContext(MapContext);
|
|
6
|
+
export const MapProvider = props => {
|
|
7
|
+
props.map && setMap(props.map);
|
|
8
|
+
props.userInteraction && setUserInteraction(props.userInteraction);
|
|
9
|
+
return (<MapContext.Provider value={[map, userInteraction]}>
|
|
10
|
+
{props.children}
|
|
11
|
+
</MapContext.Provider>);
|
|
12
|
+
};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { onCleanup, createEffect, untrack } from 'solid-js';
|
|
2
|
-
import { useMap } from '../
|
|
3
|
-
export const Marker = props => {
|
|
4
|
-
if (!useMap())
|
|
5
|
-
return;
|
|
2
|
+
import { useMap } from '../MapProvider';
|
|
3
|
+
export const Marker = (props) => {
|
|
6
4
|
const [map] = useMap();
|
|
7
5
|
let marker = null;
|
|
8
6
|
let popup = null;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { onCleanup, createEffect, untrack } from 'solid-js';
|
|
2
|
-
import { useMap } from '../
|
|
3
|
-
export const Popup = props => {
|
|
4
|
-
if (!useMap())
|
|
5
|
-
return;
|
|
2
|
+
import { useMap } from '../MapProvider';
|
|
3
|
+
export const Popup = (props) => {
|
|
6
4
|
const [map] = useMap();
|
|
7
5
|
let popup = null;
|
|
8
6
|
if (!props.trackPointer && !props.lngLat)
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { onCleanup, createEffect, createContext, useContext, createUniqueId, } from 'solid-js';
|
|
2
|
-
import { useMap } from '../
|
|
2
|
+
import { useMap } from '../MapProvider';
|
|
3
3
|
import { rasterStyleList } from '../../mapStyles';
|
|
4
4
|
const SourceContext = createContext();
|
|
5
5
|
export const useSourceId = () => useContext(SourceContext);
|
|
6
6
|
export const Source = props => {
|
|
7
|
-
if (!useMap())
|
|
8
|
-
return;
|
|
9
7
|
const [map] = useMap();
|
|
10
8
|
props.id ??= createUniqueId();
|
|
11
9
|
const debug = (text, value) => {
|
|
@@ -1,35 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useMap } from '../
|
|
1
|
+
import { createEffect, createUniqueId } from 'solid-js';
|
|
2
|
+
import { useMap } from '../MapProvider';
|
|
3
3
|
import { useSourceId } from '../Source';
|
|
4
|
-
export const Terrain = props => {
|
|
5
|
-
if (!useMap())
|
|
6
|
-
return;
|
|
4
|
+
export const Terrain = (props) => {
|
|
7
5
|
const [map] = useMap();
|
|
8
6
|
let sourceId = useSourceId();
|
|
9
|
-
// Add Terrain
|
|
10
|
-
if (sourceId
|
|
7
|
+
// Add Terrain Source if not already defined
|
|
8
|
+
if (!sourceId && !props.source) {
|
|
11
9
|
sourceId = createUniqueId();
|
|
12
|
-
map().addSource(sourceId,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
:
|
|
19
|
-
|
|
20
|
-
url: 'mapbox://mapbox.terrain-rgb',
|
|
21
|
-
tileSize: 512,
|
|
22
|
-
maxzoom: 14,
|
|
23
|
-
});
|
|
10
|
+
map().addSource(sourceId, {
|
|
11
|
+
type: 'raster-dem',
|
|
12
|
+
url: map().isMapLibre
|
|
13
|
+
? 'https://demotiles.maplibre.org/terrain-tiles/tiles.json'
|
|
14
|
+
: 'mapbox://mapbox.terrain-rgb',
|
|
15
|
+
tileSize: map().isMapLibre ? 256 : 512,
|
|
16
|
+
maxzoom: map().isMapLibre ? undefined : 14
|
|
17
|
+
});
|
|
24
18
|
map().sourceIdList.push(sourceId);
|
|
25
19
|
}
|
|
20
|
+
// Add or Update Terrain Layer
|
|
26
21
|
createEffect(() => {
|
|
27
22
|
map().setTerrain({
|
|
28
23
|
exaggeration: props.exaggeration || 1,
|
|
29
|
-
source: sourceId,
|
|
24
|
+
source: props.source || sourceId,
|
|
30
25
|
});
|
|
31
26
|
});
|
|
32
|
-
// Remove Terrain Layer
|
|
33
|
-
onCleanup(() => map().setTerrain(null));
|
|
34
27
|
return null;
|
|
35
28
|
};
|
package/dist/source/index.jsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { MapGL as default
|
|
1
|
+
export { MapGL as default } from './components/MapGL';
|
|
2
|
+
export { MapProvider, useMap } from './components/MapProvider';
|
|
2
3
|
export { Source, useSourceId } from './components/Source';
|
|
3
4
|
export { Layer } from './components/Layer';
|
|
4
5
|
export { Atmosphere } from './components/Atmosphere';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { VoidComponent } from 'solid-js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Fog } from 'mapbox-gl';
|
|
3
3
|
type Props = {
|
|
4
4
|
/** Fog/Atmosphere Specifications */
|
|
5
|
-
style?:
|
|
5
|
+
style?: Fog;
|
|
6
6
|
};
|
|
7
7
|
export declare const Atmosphere: VoidComponent<Props>;
|
|
8
8
|
export {};
|
|
@@ -1,30 +1,53 @@
|
|
|
1
1
|
import { Component } from 'solid-js';
|
|
2
|
-
import type LngLatLike from 'mapbox-gl
|
|
2
|
+
import type { LngLatLike } from 'mapbox-gl';
|
|
3
|
+
/** Options for rotating the globe. */
|
|
3
4
|
interface RotateGlobeOptions {
|
|
5
|
+
/** The number of seconds per revolution. */
|
|
4
6
|
secPerRev?: number;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
/** The maximum zoom level for spinning the globe. */
|
|
8
|
+
maxSpinZoom?: number;
|
|
9
|
+
/** The zoom level at which the spinning slows down. */
|
|
10
|
+
slowSpinZoom?: number;
|
|
7
11
|
}
|
|
12
|
+
/** Options for rotating the viewport. */
|
|
8
13
|
interface RotateViewportOptions {
|
|
14
|
+
/** The number of seconds per revolution. */
|
|
9
15
|
secPerRev?: number;
|
|
16
|
+
/** The pitch angle in degrees. */
|
|
10
17
|
pitch?: number;
|
|
18
|
+
/** The center of rotation. */
|
|
11
19
|
around?: LngLatLike;
|
|
12
20
|
}
|
|
21
|
+
/** Props for the component. */
|
|
13
22
|
type Props = {
|
|
23
|
+
/** Whether to rotate the globe. */
|
|
14
24
|
rotateGlobe?: boolean | RotateGlobeOptions;
|
|
25
|
+
/** Whether to rotate the viewport. */
|
|
15
26
|
rotateViewport?: boolean | RotateViewportOptions;
|
|
27
|
+
/** Whether to reverse the rotation direction. */
|
|
16
28
|
reverse?: boolean;
|
|
29
|
+
/** Whether to reset the rotation when stopped. */
|
|
17
30
|
resetWhenStopped?: boolean;
|
|
31
|
+
/** Translation options. */
|
|
18
32
|
translate?: {
|
|
33
|
+
/** The type of translation. */
|
|
19
34
|
type?: 'line' | 'sphere';
|
|
35
|
+
/** The starting position. */
|
|
20
36
|
start: [number, number, number];
|
|
37
|
+
/** The ending position. */
|
|
21
38
|
end: [number, number, number];
|
|
39
|
+
/** The target position. */
|
|
22
40
|
target: LngLatLike;
|
|
41
|
+
/** The ending target position. */
|
|
23
42
|
targetEnd?: LngLatLike;
|
|
43
|
+
/** The easing function to use. */
|
|
24
44
|
easing?: 'in' | 'out' | 'inOut';
|
|
45
|
+
/** Whether to loop the translation. */
|
|
25
46
|
loop?: boolean;
|
|
47
|
+
/** The duration of the translation in milliseconds. */
|
|
26
48
|
duration: number;
|
|
27
49
|
};
|
|
50
|
+
/** The children to render. */
|
|
28
51
|
children?: any;
|
|
29
52
|
};
|
|
30
53
|
export declare const Camera: Component<Props>;
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { Component } from 'solid-js';
|
|
2
2
|
import type { mapEventTypes } from '../../events';
|
|
3
|
+
import type mapboxgl from 'mapbox-gl';
|
|
3
4
|
import type { MapboxOptions } from 'mapbox-gl/src/ui/map';
|
|
4
5
|
import type { LngLatLike } from 'mapbox-gl/src/geo/lng_lat.js';
|
|
5
6
|
import type { LngLatBounds } from 'mapbox-gl/src/geo/lng_lat_bounds.js';
|
|
6
7
|
import type { PaddingOptions } from 'mapbox-gl/src/geo/edge_insets.js';
|
|
7
8
|
import type { StyleSpecification } from 'mapbox-gl/src/style-spec/types.js';
|
|
8
9
|
import type { JSX } from 'solid-js';
|
|
10
|
+
export type Map = mapboxgl.Map & {
|
|
11
|
+
mapLib: any;
|
|
12
|
+
debug: boolean;
|
|
13
|
+
sourceIdList: string[];
|
|
14
|
+
layerIdList: string[];
|
|
15
|
+
};
|
|
9
16
|
export type Viewport = {
|
|
10
17
|
id?: string;
|
|
11
18
|
point?: {
|
|
@@ -18,6 +25,7 @@ export type Viewport = {
|
|
|
18
25
|
pitch?: number;
|
|
19
26
|
bearing?: number;
|
|
20
27
|
padding?: PaddingOptions;
|
|
28
|
+
inTransit?: boolean;
|
|
21
29
|
};
|
|
22
30
|
type Props = {
|
|
23
31
|
/** ID for the map container element */
|
|
@@ -63,8 +71,6 @@ type Props = {
|
|
|
63
71
|
/** Children within the Map Container */
|
|
64
72
|
children?: any;
|
|
65
73
|
} & mapEventTypes;
|
|
66
|
-
/** Provides the Mapbox Map Object */
|
|
67
|
-
export declare const useMap: () => MapboxMap;
|
|
68
74
|
/** Creates a new Map Container */
|
|
69
75
|
export declare const MapGL: Component<Props>;
|
|
70
76
|
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ParentComponent } from "solid-js";
|
|
2
|
+
import type { Map } from '../MapGL';
|
|
3
|
+
export declare const MapContext: import("solid-js").Context<import("solid-js").Accessor<any>[]>;
|
|
4
|
+
export declare const useMap: () => import("solid-js").Accessor<any>[];
|
|
5
|
+
export declare const MapProvider: ParentComponent<{
|
|
6
|
+
map?: Map;
|
|
7
|
+
userInteraction?: boolean;
|
|
8
|
+
}>;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Component } from 'solid-js';
|
|
2
|
-
import type { PopupOptions } from 'mapbox-gl
|
|
3
|
-
import type { MarkerOptions } from 'mapbox-gl/src/ui/marker.js';
|
|
4
|
-
import type { LngLatLike } from 'mapbox-gl/src/geo/lng_lat.js';
|
|
2
|
+
import type { PopupOptions, MarkerOptions, LngLatLike } from 'mapbox-gl';
|
|
5
3
|
type Props = {
|
|
6
4
|
/** Options for the Mapbox GL JS marker */
|
|
7
5
|
options?: MarkerOptions & {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Component } from 'solid-js';
|
|
2
|
-
import type { PopupOptions } from 'mapbox-gl
|
|
3
|
-
import type { LngLatLike } from 'mapbox-gl/src/geo/lng_lat.js';
|
|
2
|
+
import type { PopupOptions, LngLatLike } from 'mapbox-gl';
|
|
4
3
|
type Props = {
|
|
5
4
|
/** Options for configuring the popup */
|
|
6
5
|
options?: PopupOptions;
|