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,273 +0,0 @@
|
|
|
1
|
-
import { createSignal, createEffect, onMount, onCleanup, on, } from "solid-js";
|
|
2
|
-
import "mapbox-gl/dist/mapbox-gl.css";
|
|
3
|
-
import { MapProvider } from "../MapProvider";
|
|
4
|
-
import { mapEvents } from "../../events";
|
|
5
|
-
import { vectorStyleList } from "../../mapStyles";
|
|
6
|
-
/** Creates a new Map Container */
|
|
7
|
-
export const MapGL = (props) => {
|
|
8
|
-
let map;
|
|
9
|
-
let mapRef;
|
|
10
|
-
let resizeObserver;
|
|
11
|
-
let mutationObserver;
|
|
12
|
-
const [mapLoaded, setMapLoaded] = createSignal(null);
|
|
13
|
-
const [darkMode, setDarkMode] = createSignal((typeof window !== "undefined" &&
|
|
14
|
-
window.matchMedia("(prefers-color-scheme: dark)").matches) ||
|
|
15
|
-
(typeof document !== "undefined" &&
|
|
16
|
-
document.body.classList.contains("dark")));
|
|
17
|
-
const [internal, setInternal] = createSignal(false);
|
|
18
|
-
const debug = (text, value) => (props.debug || props.debugEvents) &&
|
|
19
|
-
console.debug("%c[MapGL]", "color: #0ea5e9", text, value || "");
|
|
20
|
-
const getStyle = (light, dark) => {
|
|
21
|
-
const style = darkMode() && dark ? dark : light;
|
|
22
|
-
return typeof style === "string" || style instanceof String
|
|
23
|
-
? style
|
|
24
|
-
?.split(":")
|
|
25
|
-
.reduce((p, c) => p && p[c], vectorStyleList)
|
|
26
|
-
?.replace("{apikey}",
|
|
27
|
-
//@ts-ignore
|
|
28
|
-
props.apikey || import.meta.env.VITE_VECTOR_API_KEY) || style
|
|
29
|
-
: style;
|
|
30
|
-
};
|
|
31
|
-
onMount(async () => {
|
|
32
|
-
let mapLib = props.mapLib || (await import("mapbox-gl"));
|
|
33
|
-
if (!mapLib.Map)
|
|
34
|
-
mapLib = window["maplibregl"] || window["mapboxgl"];
|
|
35
|
-
if (typeof mapLib.supported === "function" && !mapLib.supported())
|
|
36
|
-
throw new Error("Mapbox GL not supported");
|
|
37
|
-
debug(`Map (v${mapLib.version}) loading...`);
|
|
38
|
-
map = new mapLib.Map({
|
|
39
|
-
accessToken:
|
|
40
|
-
//@ts-ignore
|
|
41
|
-
props.options?.accessToken || import.meta.env.VITE_MAPBOX_ACCESS_TOKEN,
|
|
42
|
-
interactive: props.options?.interactive || !!props.onViewportChange,
|
|
43
|
-
...props.options,
|
|
44
|
-
...props.viewport,
|
|
45
|
-
projection: props.options?.projection,
|
|
46
|
-
container: mapRef,
|
|
47
|
-
style: getStyle(props.options?.style, props.darkStyle),
|
|
48
|
-
fitBoundsOptions: { padding: props.viewport?.padding },
|
|
49
|
-
});
|
|
50
|
-
map.debug = props.debug;
|
|
51
|
-
map.debugEvents = props.debugEvents;
|
|
52
|
-
map.sourceIdList = [];
|
|
53
|
-
map.layerIdList = [];
|
|
54
|
-
window.MapLib = mapLib;
|
|
55
|
-
// Hook up events
|
|
56
|
-
mapEvents.forEach((item) => {
|
|
57
|
-
const prop = props[item];
|
|
58
|
-
if (prop) {
|
|
59
|
-
const event = item.slice(2).toLowerCase();
|
|
60
|
-
if (typeof prop === "function") {
|
|
61
|
-
map.on(event, (evt) => {
|
|
62
|
-
setTimeout(() => {
|
|
63
|
-
if (evt.clickOnLayer)
|
|
64
|
-
return;
|
|
65
|
-
prop(evt);
|
|
66
|
-
props.debugEvents && debug(`Map '${event}' event:`, evt);
|
|
67
|
-
}, 0);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
Object.keys(prop).forEach((layerId) => {
|
|
72
|
-
map.on(event, layerId, (evt) => {
|
|
73
|
-
setTimeout(() => {
|
|
74
|
-
if (evt.clickOnLayer)
|
|
75
|
-
return;
|
|
76
|
-
prop[layerId](evt);
|
|
77
|
-
props.debugEvents &&
|
|
78
|
-
debug(`Map '${event}' event on '${layerId}':`, evt);
|
|
79
|
-
}, 0);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
map.once("load", () => {
|
|
86
|
-
setMapLoaded(map);
|
|
87
|
-
debug("Map loaded");
|
|
88
|
-
// Handle User Interaction
|
|
89
|
-
["mousedown", "touchstart", "wheel"].forEach((event) => map.on(event, (evt) => !evt.rotate && props.onUserInteraction?.(true)));
|
|
90
|
-
["moveend", "mouseup", "touchend"].forEach((event) => map.on(event, (evt) => !evt.rotate && props.onUserInteraction?.(false)));
|
|
91
|
-
// Listen to dark theme changes
|
|
92
|
-
const darkTheme = typeof window !== "undefined" &&
|
|
93
|
-
window?.matchMedia("(prefers-color-scheme: dark)");
|
|
94
|
-
darkTheme?.addEventListener("change", () => {
|
|
95
|
-
setDarkMode(darkTheme.matches);
|
|
96
|
-
debug("Set dark theme to:", darkTheme.matches?.toString());
|
|
97
|
-
});
|
|
98
|
-
mutationObserver = new MutationObserver(() => {
|
|
99
|
-
const darkTheme = document.body.classList.contains("dark");
|
|
100
|
-
setDarkMode(darkTheme);
|
|
101
|
-
debug("Set theme to:", darkTheme);
|
|
102
|
-
});
|
|
103
|
-
mutationObserver.observe(document.body, { attributes: true });
|
|
104
|
-
// Listen to map container size changes
|
|
105
|
-
if (!props.disableResize) {
|
|
106
|
-
resizeObserver = new ResizeObserver(() => {
|
|
107
|
-
setTimeout(() => {
|
|
108
|
-
map?.resize();
|
|
109
|
-
}, 0);
|
|
110
|
-
debug("Map resized");
|
|
111
|
-
});
|
|
112
|
-
resizeObserver.observe(mapRef);
|
|
113
|
-
}
|
|
114
|
-
// Update Configuration
|
|
115
|
-
createEffect(() => {
|
|
116
|
-
for (const key in props.config) {
|
|
117
|
-
if (!key || key === "id")
|
|
118
|
-
continue;
|
|
119
|
-
const id = props.config?.id || "basemap";
|
|
120
|
-
const value = props.config[key];
|
|
121
|
-
//@ts-ignore
|
|
122
|
-
map?.setConfigProperty(id, key, value);
|
|
123
|
-
debug(`Set Config (${id}:${key}) to:`, value);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
// Update Viewport
|
|
127
|
-
map.on("move", (event) => {
|
|
128
|
-
const viewport = {
|
|
129
|
-
...props.viewport,
|
|
130
|
-
id: props.id,
|
|
131
|
-
point: {
|
|
132
|
-
x: event.originalEvent?.x,
|
|
133
|
-
y: event.originalEvent?.y,
|
|
134
|
-
},
|
|
135
|
-
center: props.viewport?.center?.lat
|
|
136
|
-
? map.getCenter()
|
|
137
|
-
: [map.getCenter().lng, map.getCenter().lat],
|
|
138
|
-
zoom: map.getZoom(),
|
|
139
|
-
pitch: map.getPitch(),
|
|
140
|
-
bearing: map.getBearing(),
|
|
141
|
-
inTransit: true,
|
|
142
|
-
bounds: null,
|
|
143
|
-
// !internal()
|
|
144
|
-
// ? props.viewport?.center?.lat
|
|
145
|
-
// ? map.getBounds()
|
|
146
|
-
// : [
|
|
147
|
-
// [
|
|
148
|
-
// map.getBounds().getNorthEast().lng,
|
|
149
|
-
// map.getBounds().getNorthEast().lat,
|
|
150
|
-
// ],
|
|
151
|
-
// [
|
|
152
|
-
// map.getBounds().getSouthWest().lng,
|
|
153
|
-
// map.getBounds().getSouthWest().lat,
|
|
154
|
-
// ],
|
|
155
|
-
// ]
|
|
156
|
-
// : null,
|
|
157
|
-
};
|
|
158
|
-
setInternal(true);
|
|
159
|
-
!event.viewport && props.onViewportChange?.(viewport);
|
|
160
|
-
});
|
|
161
|
-
map.on("moveend", (event) => {
|
|
162
|
-
!event.rotate &&
|
|
163
|
-
props.onViewportChange?.({ ...props.viewport, inTransit: false });
|
|
164
|
-
setInternal(false);
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
// Hook up viewport event
|
|
169
|
-
createEffect(on(() => props.viewport, (vp) => {
|
|
170
|
-
if (props.id !== vp?.id || internal())
|
|
171
|
-
return;
|
|
172
|
-
const viewport = {
|
|
173
|
-
...vp,
|
|
174
|
-
...(vp.bounds
|
|
175
|
-
? map.cameraForBounds(vp.bounds, {
|
|
176
|
-
bearing: vp?.bearing,
|
|
177
|
-
pitch: vp?.pitch,
|
|
178
|
-
padding: vp?.padding,
|
|
179
|
-
})
|
|
180
|
-
: null),
|
|
181
|
-
};
|
|
182
|
-
map.stop()[props.transitionType || "flyTo"](viewport);
|
|
183
|
-
debug(`Update Viewport (${props.transitionType || "flyTo"}):`, viewport);
|
|
184
|
-
}, { defer: true }));
|
|
185
|
-
// Update Projection
|
|
186
|
-
createEffect(() => {
|
|
187
|
-
const proj = props.options?.projection;
|
|
188
|
-
if (!map || !proj)
|
|
189
|
-
return;
|
|
190
|
-
map.setProjection(proj);
|
|
191
|
-
debug("Set Projection to:", proj);
|
|
192
|
-
});
|
|
193
|
-
// Update Cursor
|
|
194
|
-
createEffect(() => {
|
|
195
|
-
const cur = props.cursorStyle;
|
|
196
|
-
if (!map || !cur)
|
|
197
|
-
return;
|
|
198
|
-
map.getCanvas().style.cursor = cur;
|
|
199
|
-
debug("Set Cursor to:", cur);
|
|
200
|
-
});
|
|
201
|
-
const insertLayers = (list, layers) => {
|
|
202
|
-
layers.forEach((layer) => {
|
|
203
|
-
const index = list.findIndex((i) => layer.metadata.smg.beforeType
|
|
204
|
-
? i.type === layer.metadata.smg.beforeType
|
|
205
|
-
: i.id === layer.metadata.smg.beforeId);
|
|
206
|
-
list =
|
|
207
|
-
index === -1
|
|
208
|
-
? [...list, layer]
|
|
209
|
-
: [...list.slice(0, index), layer, ...list.slice(index + 1)];
|
|
210
|
-
});
|
|
211
|
-
return list;
|
|
212
|
-
};
|
|
213
|
-
// Update map style
|
|
214
|
-
createEffect((prev) => {
|
|
215
|
-
const style = getStyle(props.options?.style, props.darkStyle);
|
|
216
|
-
if (map?.isStyleLoaded() && prev !== style) {
|
|
217
|
-
const oldStyle = map.getStyle();
|
|
218
|
-
const oldLayers = oldStyle.layers.filter((l) => map.layerIdList.includes(l.id));
|
|
219
|
-
const oldSources = Object.keys(oldStyle.sources)
|
|
220
|
-
.filter((s) => map.sourceIdList.includes(s))
|
|
221
|
-
.reduce((obj, key) => ({ ...obj, [key]: oldStyle.sources[key] }), {});
|
|
222
|
-
map.setStyle(style);
|
|
223
|
-
map.once("styledata", () => {
|
|
224
|
-
if (!oldLayers)
|
|
225
|
-
return;
|
|
226
|
-
const newStyle = map.getStyle();
|
|
227
|
-
map.setStyle({
|
|
228
|
-
...newStyle,
|
|
229
|
-
sources: { ...newStyle.sources, ...oldSources },
|
|
230
|
-
layers: insertLayers(newStyle.layers, oldLayers),
|
|
231
|
-
fog: oldStyle.fog,
|
|
232
|
-
terrain: oldStyle.terrain,
|
|
233
|
-
});
|
|
234
|
-
debug("Set Mapstyle to:", style);
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
return style;
|
|
238
|
-
}, props.options?.style);
|
|
239
|
-
// Update debug features
|
|
240
|
-
[
|
|
241
|
-
"showTileBoundaries",
|
|
242
|
-
"showTerrainWireframe",
|
|
243
|
-
"showCollisionBoxes",
|
|
244
|
-
"showPadding",
|
|
245
|
-
"showOverdrawInspector",
|
|
246
|
-
].forEach((item) => {
|
|
247
|
-
createEffect(() => {
|
|
248
|
-
const prop = props[item];
|
|
249
|
-
if (!map || !prop)
|
|
250
|
-
return;
|
|
251
|
-
map[item] = prop;
|
|
252
|
-
debug(`Set ${item} to:`, prop);
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
onCleanup(() => {
|
|
256
|
-
resizeObserver?.disconnect();
|
|
257
|
-
mutationObserver?.disconnect();
|
|
258
|
-
map?.remove();
|
|
259
|
-
debug("Map removed");
|
|
260
|
-
});
|
|
261
|
-
return (<div ref={mapRef} id={props.id} class={props?.class} classList={props?.classList} style={props?.class || props?.classList
|
|
262
|
-
? null
|
|
263
|
-
: props.style || {
|
|
264
|
-
position: "absolute",
|
|
265
|
-
inset: 0,
|
|
266
|
-
"z-index": -1,
|
|
267
|
-
}}>
|
|
268
|
-
{mapLoaded() && (<MapProvider map={mapLoaded()}>
|
|
269
|
-
<style>{`.overlay{position:relative;width:100%;height:100%;pointer-events:none}.overlay>*{pointer-events:auto}`}</style>
|
|
270
|
-
<div class="overlay">{props.children}</div>
|
|
271
|
-
</MapProvider>)}
|
|
272
|
-
</div>);
|
|
273
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext } from 'solid-js';
|
|
2
|
-
import { createStore } from 'solid-js/store';
|
|
3
|
-
const [state, setState] = createStore({ map: null });
|
|
4
|
-
export const MapContext = createContext([state]);
|
|
5
|
-
export const useMapContext = () => useContext(MapContext);
|
|
6
|
-
export const MapProvider = (props) => {
|
|
7
|
-
props.map && setState('map', props.map);
|
|
8
|
-
return (<MapContext.Provider value={[state]}>{props.children}</MapContext.Provider>);
|
|
9
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { onCleanup, createEffect, splitProps } from 'solid-js';
|
|
2
|
-
import { useMapContext } from '../MapProvider';
|
|
3
|
-
export const Marker = (props) => {
|
|
4
|
-
if (!props.lngLat)
|
|
5
|
-
throw new Error('Marker - lngLat is required');
|
|
6
|
-
const [update, create_popup, create_marker] = splitProps(props, ['lngLat', 'children', 'showPopup', 'draggable'], ['popup', 'onOpen', 'onClose']);
|
|
7
|
-
const [ctx] = useMapContext();
|
|
8
|
-
let marker = null;
|
|
9
|
-
let popup = null;
|
|
10
|
-
const LNGLAT = update.lngLat;
|
|
11
|
-
// Add or Update Popup
|
|
12
|
-
createEffect(() => {
|
|
13
|
-
if (!ctx.map)
|
|
14
|
-
return;
|
|
15
|
-
popup?.remove();
|
|
16
|
-
popup = new window.MapLib.Popup({
|
|
17
|
-
closeOnClick: false,
|
|
18
|
-
focusAfterOpen: false,
|
|
19
|
-
...create_popup.popup,
|
|
20
|
-
})
|
|
21
|
-
.on('open', () => create_popup.onOpen?.())
|
|
22
|
-
.on('close', () => create_popup.onClose?.());
|
|
23
|
-
// Update Popup Content
|
|
24
|
-
createEffect(() => {
|
|
25
|
-
if (update.children === undefined)
|
|
26
|
-
return;
|
|
27
|
-
typeof update.children === 'string'
|
|
28
|
-
? popup?.setHTML(update.children)
|
|
29
|
-
: popup?.setDOMContent(update.children);
|
|
30
|
-
marker?.setPopup(popup);
|
|
31
|
-
});
|
|
32
|
-
// Toggle Popup
|
|
33
|
-
createEffect(() => update.showPopup !== popup?.isOpen() && marker?.togglePopup());
|
|
34
|
-
});
|
|
35
|
-
// Add or Update Marker
|
|
36
|
-
createEffect(() => {
|
|
37
|
-
if (!ctx.map)
|
|
38
|
-
return;
|
|
39
|
-
marker?.remove();
|
|
40
|
-
marker = new window.MapLib.Marker(create_marker.options)
|
|
41
|
-
.on('dragstart', () => create_marker.onDragStart?.())
|
|
42
|
-
.on('dragend', () => create_marker.onDragEnd?.())
|
|
43
|
-
.on('drag', () => create_marker.onDrag?.(marker?.getLngLat().toArray()))
|
|
44
|
-
.setPopup(popup)
|
|
45
|
-
.setLngLat(LNGLAT)
|
|
46
|
-
.addTo(ctx.map);
|
|
47
|
-
// Toggle Popup
|
|
48
|
-
createEffect(() => update.showPopup !== popup?.isOpen() && marker?.togglePopup());
|
|
49
|
-
});
|
|
50
|
-
// Update Position
|
|
51
|
-
createEffect(() => marker?.setLngLat(update.lngLat));
|
|
52
|
-
// Update Draggable
|
|
53
|
-
createEffect(() => marker?.setDraggable(update.draggable));
|
|
54
|
-
// Remove Marker
|
|
55
|
-
onCleanup(() => marker?.remove());
|
|
56
|
-
return null;
|
|
57
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { onCleanup, createEffect, splitProps } from "solid-js";
|
|
2
|
-
import { useMapContext } from "../MapProvider";
|
|
3
|
-
export const Popup = (props) => {
|
|
4
|
-
if (!props.trackPointer && !props.lngLat)
|
|
5
|
-
throw new Error("Popup - lngLat or trackPointer is required");
|
|
6
|
-
const [update, create] = splitProps(props, [
|
|
7
|
-
"lngLat",
|
|
8
|
-
"children",
|
|
9
|
-
"trackPointer",
|
|
10
|
-
]);
|
|
11
|
-
const [ctx] = useMapContext();
|
|
12
|
-
let popup;
|
|
13
|
-
// Update Popup
|
|
14
|
-
createEffect(() => {
|
|
15
|
-
if (!ctx.map)
|
|
16
|
-
return;
|
|
17
|
-
popup?.remove();
|
|
18
|
-
popup = new window.MapLib.Popup({
|
|
19
|
-
closeOnClick: false,
|
|
20
|
-
focusAfterOpen: false,
|
|
21
|
-
...create.options,
|
|
22
|
-
})
|
|
23
|
-
.on("open", () => create.onOpen?.())
|
|
24
|
-
.on("close", () => create.onClose?.())
|
|
25
|
-
.addTo(ctx.map);
|
|
26
|
-
// Update Position
|
|
27
|
-
createEffect(() => update.trackPointer
|
|
28
|
-
? popup.trackPointer()
|
|
29
|
-
: popup.setLngLat(update.lngLat));
|
|
30
|
-
// Update Content
|
|
31
|
-
createEffect(() => typeof update.children === "string"
|
|
32
|
-
? popup.setHTML(update.children)
|
|
33
|
-
: popup.setDOMContent(update.children));
|
|
34
|
-
});
|
|
35
|
-
// Remove Popup
|
|
36
|
-
onCleanup(() => popup?.remove());
|
|
37
|
-
return null;
|
|
38
|
-
};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { onCleanup, createEffect, createContext, useContext, createUniqueId, } from 'solid-js';
|
|
2
|
-
import { useMapContext } from '../MapProvider';
|
|
3
|
-
import { rasterStyleList } from '../../mapStyles';
|
|
4
|
-
const SourceContext = createContext();
|
|
5
|
-
export const useSourceId = () => useContext(SourceContext);
|
|
6
|
-
export const Source = props => {
|
|
7
|
-
const [ctx] = useMapContext();
|
|
8
|
-
props.id ??= createUniqueId();
|
|
9
|
-
const debug = (text, value) => {
|
|
10
|
-
ctx.map.debug &&
|
|
11
|
-
console.debug('%c[MapGL]', 'color: #ec4899', text, value || '');
|
|
12
|
-
};
|
|
13
|
-
const lookup = url => {
|
|
14
|
-
const s = url?.split(':').reduce((p, c) => p && p[c], rasterStyleList);
|
|
15
|
-
const source = s
|
|
16
|
-
? {
|
|
17
|
-
...props.source,
|
|
18
|
-
url: '',
|
|
19
|
-
tiles: [
|
|
20
|
-
s
|
|
21
|
-
.replace('{apikey}', //@ts-ignore
|
|
22
|
-
props.source.apikey || import.meta.env.VITE_RASTER_API_KEY)
|
|
23
|
-
.replace('{r}', window.devicePixelRatio > 1 ? '@2x' : ''),
|
|
24
|
-
],
|
|
25
|
-
attribution: rasterStyleList[url.split(':')[0]]._copy,
|
|
26
|
-
}
|
|
27
|
-
: props.source;
|
|
28
|
-
source.tiles &&
|
|
29
|
-
(source.tiles = ['a', 'b', 'c'].map(i => source.tiles[0].replace('{s}', i)));
|
|
30
|
-
return source;
|
|
31
|
-
};
|
|
32
|
-
// Add Source
|
|
33
|
-
ctx.map.addSource(props.id, lookup(props.source.url));
|
|
34
|
-
ctx.map.sourceIdList.push(props.id);
|
|
35
|
-
debug('Add Source:', props.id);
|
|
36
|
-
// Update Data
|
|
37
|
-
const source = ctx.map.getSource(props.id);
|
|
38
|
-
switch (props.source.type) {
|
|
39
|
-
case 'geojson':
|
|
40
|
-
createEffect(() => {
|
|
41
|
-
const data = props.source.data;
|
|
42
|
-
if (!ctx.map.isSourceLoaded(props.id))
|
|
43
|
-
return;
|
|
44
|
-
source.setData(data || {});
|
|
45
|
-
debug('Update GeoJSON Data:', props.id);
|
|
46
|
-
});
|
|
47
|
-
break;
|
|
48
|
-
case 'image':
|
|
49
|
-
createEffect(() => {
|
|
50
|
-
const url = props.source.url;
|
|
51
|
-
const coords = props.source.coordinates;
|
|
52
|
-
if (!ctx.map.isSourceLoaded(props.id))
|
|
53
|
-
return;
|
|
54
|
-
source.updateImage(url, coords);
|
|
55
|
-
debug('Update Image Data:', props.id);
|
|
56
|
-
});
|
|
57
|
-
break;
|
|
58
|
-
case 'vector':
|
|
59
|
-
createEffect(() => {
|
|
60
|
-
const url = props.source.url;
|
|
61
|
-
const tiles = props.source.tiles;
|
|
62
|
-
if (!ctx.map.isSourceLoaded(props.id))
|
|
63
|
-
return;
|
|
64
|
-
url ? source.setUrl(url) : source.setTiles(tiles);
|
|
65
|
-
debug('Update Vector Data:', props.id);
|
|
66
|
-
});
|
|
67
|
-
break;
|
|
68
|
-
case 'raster':
|
|
69
|
-
createEffect(() => {
|
|
70
|
-
const src = lookup(props.source.url);
|
|
71
|
-
if (!ctx.map.isSourceLoaded(props.id))
|
|
72
|
-
return;
|
|
73
|
-
src.url ? source.setUrl(src.url) : source.setTiles(src.tiles);
|
|
74
|
-
debug('Update Raster Data:', props.id);
|
|
75
|
-
});
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
// Remove Source
|
|
79
|
-
onCleanup(() => {
|
|
80
|
-
ctx.map
|
|
81
|
-
?.getStyle()
|
|
82
|
-
.layers.forEach(layer => layer.source === props.id && ctx.map.removeLayer(layer.id));
|
|
83
|
-
ctx.map?.getSource(props.id) && ctx.map?.removeSource(props.id);
|
|
84
|
-
debug('Remove Source:', props.id);
|
|
85
|
-
});
|
|
86
|
-
return (<SourceContext.Provider value={props.id}>
|
|
87
|
-
{props.children}
|
|
88
|
-
</SourceContext.Provider>);
|
|
89
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { createEffect, createUniqueId, onCleanup, } from 'solid-js';
|
|
2
|
-
import { useMapContext } from '../MapProvider';
|
|
3
|
-
import { useSourceId } from '../Source';
|
|
4
|
-
export const Terrain = (props) => {
|
|
5
|
-
const [ctx] = useMapContext();
|
|
6
|
-
let sourceId = useSourceId();
|
|
7
|
-
// Add Terrain Source if not already defined
|
|
8
|
-
if (!sourceId && !props?.source) {
|
|
9
|
-
sourceId = createUniqueId();
|
|
10
|
-
ctx.map.addSource(sourceId, {
|
|
11
|
-
type: 'raster-dem',
|
|
12
|
-
url: ctx.map.isMapLibre
|
|
13
|
-
? 'https://demotiles.maplibre.org/terrain-tiles/tiles.json'
|
|
14
|
-
: 'mapbox://mapbox.terrain-rgb',
|
|
15
|
-
tileSize: ctx.map.isMapLibre ? 256 : 512,
|
|
16
|
-
maxzoom: ctx.map.isMapLibre ? undefined : 14,
|
|
17
|
-
});
|
|
18
|
-
ctx.map.sourceIdList.push(sourceId);
|
|
19
|
-
}
|
|
20
|
-
// Add or Update Terrain Layer
|
|
21
|
-
createEffect(() => {
|
|
22
|
-
ctx.map.setTerrain({
|
|
23
|
-
exaggeration: props.exaggeration || 1,
|
|
24
|
-
source: props?.source || sourceId,
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
//Remove Terrain
|
|
28
|
-
onCleanup(() => ctx.map?.setTerrain(null));
|
|
29
|
-
return null;
|
|
30
|
-
};
|
package/dist/source/events.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
const mapEvents = [
|
|
2
|
-
'onMouseDown',
|
|
3
|
-
'onMouseUp',
|
|
4
|
-
'onMouseOver',
|
|
5
|
-
'onMouseOut',
|
|
6
|
-
'onMouseMove',
|
|
7
|
-
'onMouseEnter',
|
|
8
|
-
'onMouseLeave',
|
|
9
|
-
'onPreClick',
|
|
10
|
-
'onClick',
|
|
11
|
-
'onDblClick',
|
|
12
|
-
'onContextMenu',
|
|
13
|
-
'onTouchStart',
|
|
14
|
-
'onTouchEnd',
|
|
15
|
-
'onTouchCancel',
|
|
16
|
-
'onWheel',
|
|
17
|
-
'onResize',
|
|
18
|
-
'onRemove',
|
|
19
|
-
'onTouchMove',
|
|
20
|
-
'onMoveStart',
|
|
21
|
-
'onMove',
|
|
22
|
-
'onMoveEnd',
|
|
23
|
-
'onDragStart',
|
|
24
|
-
'onDrag',
|
|
25
|
-
'onDragEnd',
|
|
26
|
-
'onZoomStart',
|
|
27
|
-
'onZoom',
|
|
28
|
-
'onZoomEnd',
|
|
29
|
-
'onRotateStart',
|
|
30
|
-
'onRotate',
|
|
31
|
-
'onRotatEnd',
|
|
32
|
-
'onPitchStart',
|
|
33
|
-
'onPitch',
|
|
34
|
-
'onPitchEnd',
|
|
35
|
-
'onBoxZoomStart',
|
|
36
|
-
'onBoxZoomEnd',
|
|
37
|
-
'onBoxZoomCancel',
|
|
38
|
-
'onWebglContextLost',
|
|
39
|
-
'onWebglContextRestored',
|
|
40
|
-
'onLoad',
|
|
41
|
-
'onRender',
|
|
42
|
-
'onIdle',
|
|
43
|
-
'onError',
|
|
44
|
-
'onData',
|
|
45
|
-
'onStyleData',
|
|
46
|
-
'onSourceData',
|
|
47
|
-
'onDataLoading',
|
|
48
|
-
'onStyleDataLoading',
|
|
49
|
-
'onSourceDataLoading',
|
|
50
|
-
'onStyleImageMissing',
|
|
51
|
-
];
|
|
52
|
-
const layerEvents = [
|
|
53
|
-
'onMouseDown',
|
|
54
|
-
'onMouseUp',
|
|
55
|
-
'onMouseOver',
|
|
56
|
-
'onMouseOut',
|
|
57
|
-
'onMouseMove',
|
|
58
|
-
'onMouseEnter',
|
|
59
|
-
'onMouseLeave',
|
|
60
|
-
'onClick',
|
|
61
|
-
'onDblClick',
|
|
62
|
-
'onContextMenu',
|
|
63
|
-
'onTouchStart',
|
|
64
|
-
'onTouchEnd',
|
|
65
|
-
'onTouchCancel',
|
|
66
|
-
];
|
|
67
|
-
const drawEvents = [
|
|
68
|
-
'onCreate',
|
|
69
|
-
'onDelete',
|
|
70
|
-
'onCombine',
|
|
71
|
-
'onUncombine',
|
|
72
|
-
'onUpdate',
|
|
73
|
-
'onSelectionchange',
|
|
74
|
-
'onModechange',
|
|
75
|
-
'onRender',
|
|
76
|
-
'onActionable',
|
|
77
|
-
];
|
|
78
|
-
export { mapEvents, layerEvents, drawEvents };
|
package/dist/source/index.jsx
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export { MapGL as default } from "./components/MapGL";
|
|
2
|
-
export { MapProvider, useMapContext } from "./components/MapProvider";
|
|
3
|
-
export { Source, useSourceId } from "./components/Source";
|
|
4
|
-
export { Layer } from "./components/Layer";
|
|
5
|
-
export { Layer3D, useScene } from "./components/Layer3D";
|
|
6
|
-
export { Atmosphere } from "./components/Atmosphere";
|
|
7
|
-
export { Terrain } from "./components/Terrain";
|
|
8
|
-
export { Control } from "./components/Control";
|
|
9
|
-
export { Marker } from "./components/Marker";
|
|
10
|
-
export { Popup } from "./components/Popup";
|
|
11
|
-
export { MGL_Image as Image, patternList } from "./components/Image";
|
|
12
|
-
export { Camera } from "./components/Camera";
|
|
13
|
-
export { Light } from "./components/Light";
|
|
14
|
-
export { Draw } from "./components/Draw";
|