solid-map-gl 1.1.28 → 1.2.2

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.
Files changed (44) hide show
  1. package/README.md +13 -7
  2. package/dist/{esm/styles.css → cjs/index.css} +0 -0
  3. package/dist/cjs/index.js +2 -0
  4. package/dist/cjs/index.js.map +1 -0
  5. package/dist/esm/index.css +1 -0
  6. package/dist/esm/index.js +1 -1
  7. package/dist/esm/index.js.map +1 -1
  8. package/dist/index/components/Camera/index.d.ts +16 -0
  9. package/dist/index/components/Camera/index.jsx +49 -0
  10. package/dist/{types → index}/components/Control/index.d.ts +2 -2
  11. package/dist/{source → index}/components/Control/index.jsx +6 -6
  12. package/dist/{types → index}/components/Fog/index.d.ts +2 -2
  13. package/dist/index/components/Fog/index.jsx +17 -0
  14. package/dist/{types → index}/components/Image/index.d.ts +1 -2
  15. package/dist/{source → index}/components/Image/index.jsx +4 -10
  16. package/dist/{types → index}/components/Layer/index.d.ts +2 -2
  17. package/dist/{source → index}/components/Layer/index.jsx +26 -28
  18. package/dist/{types → index}/components/MapGL/index.d.ts +22 -5
  19. package/dist/index/components/MapGL/index.jsx +149 -0
  20. package/dist/{types → index}/components/Marker/index.d.ts +2 -2
  21. package/dist/{source → index}/components/Marker/index.jsx +4 -5
  22. package/dist/{types → index}/components/Popup/index.d.ts +2 -2
  23. package/dist/{source → index}/components/Popup/index.jsx +5 -6
  24. package/dist/{types → index}/components/Sky/index.d.ts +2 -2
  25. package/dist/index/components/Sky/index.jsx +18 -0
  26. package/dist/index/components/Source/index.d.ts +10 -0
  27. package/dist/index/components/Source/index.jsx +68 -0
  28. package/dist/{types → index}/components/Terrain/index.d.ts +2 -2
  29. package/dist/index/components/Terrain/index.jsx +19 -0
  30. package/dist/{types → index}/events.d.ts +0 -0
  31. package/dist/{source → index}/events.js +0 -0
  32. package/dist/index/index.d.ts +12 -0
  33. package/dist/index/index.jsx +11 -0
  34. package/dist/index/styles.d.ts +56 -0
  35. package/dist/index/styles.js +121 -0
  36. package/package.json +16 -14
  37. package/dist/source/components/Fog/index.jsx +0 -21
  38. package/dist/source/components/MapGL/index.jsx +0 -139
  39. package/dist/source/components/Sky/index.jsx +0 -22
  40. package/dist/source/components/Source/index.jsx +0 -32
  41. package/dist/source/components/Terrain/index.jsx +0 -23
  42. package/dist/source/index.jsx +0 -10
  43. package/dist/types/components/Source/index.d.ts +0 -8
  44. package/dist/types/index.d.ts +0 -11
@@ -1,21 +0,0 @@
1
- import { onMount, onCleanup, createEffect } from 'solid-js';
2
- import { useMap } from '../MapGL';
3
- const Fog = props => {
4
- const map = useMap();
5
- // Add Fog Layer
6
- onMount(async () => {
7
- !map().isStyleLoaded() && (await map().once('styledata'));
8
- map().setFog(props.style);
9
- });
10
- // Remove Fog Layer
11
- onCleanup(() => map().setFog(null));
12
- // Update Visibility
13
- createEffect(async () => {
14
- if (props.visible === undefined)
15
- return;
16
- !map().isStyleLoaded() && (await map().once('styledata'));
17
- map().setFog(props.visible ? props.style : null);
18
- });
19
- return props.children;
20
- };
21
- export default Fog;
@@ -1,139 +0,0 @@
1
- import { createSignal, createEffect, onMount, onCleanup, createContext, useContext, useTransition, createUniqueId, untrack, on, } from 'solid-js';
2
- import { mapEvents } from '../../events';
3
- import mapboxgl from 'mapbox-gl';
4
- import 'mapbox-gl/dist/mapbox-gl.css';
5
- const [pending, start] = useTransition();
6
- const [transitionType, setTransitionType] = createSignal('flyTo');
7
- const MapContext = createContext();
8
- const useMap = () => useContext(MapContext);
9
- const MapGL = props => {
10
- let map;
11
- let mapRef;
12
- let containerRef;
13
- props.id = props.id || createUniqueId();
14
- onMount(() => {
15
- map = new mapboxgl.Map({
16
- ...props.options,
17
- style: props.options?.style || { version: 8, sources: {}, layers: [] },
18
- container: mapRef,
19
- interactive: !!props.onViewportChange,
20
- bounds: props.viewport?.bounds,
21
- center: props.viewport?.center,
22
- zoom: props.viewport?.zoom || null,
23
- pitch: props.viewport?.pitch || null,
24
- bearing: props.viewport?.bearing || null,
25
- fitBoundsOptions: { padding: props.viewport?.padding },
26
- });
27
- map.container = containerRef;
28
- });
29
- onCleanup(() => map.remove());
30
- // Hook up events
31
- createEffect(() => mapEvents.forEach(item => {
32
- if (props[item]) {
33
- const event = item.slice(2).toLowerCase();
34
- const callback = e => props[item](e);
35
- map.on(event, callback);
36
- onCleanup(() => map.off(event, callback));
37
- }
38
- }));
39
- // Update debug features
40
- createEffect(() => (map.showTileBoundaries = props.showTileBoundaries));
41
- createEffect(() => (map.showTerrainWireframe = props.showTerrainWireframe));
42
- createEffect(() => (map.showPadding = props.showPadding));
43
- createEffect(() => (map.showCollisionBoxes = props.showCollisionBoxes));
44
- createEffect(() => (map.showOverdrawInspector = props.showOverdrawInspector));
45
- createEffect(() => (map.getCanvas().style.cursor = props.cursorStyle));
46
- // Update map style
47
- createEffect(on(() => props.options.style, () => {
48
- const oldStyle = map.getStyle();
49
- const oldLayers = oldStyle.layers.filter(l => l.id.startsWith('cl-'));
50
- const oldSources = Object.keys(oldStyle.sources)
51
- .filter(s => s.startsWith('cl-'))
52
- .reduce((obj, key) => ({ ...obj, [key]: oldStyle.sources[key] }), {});
53
- map.setStyle(props.options.style);
54
- map.once('styledata', () => {
55
- const newStyle = map.getStyle();
56
- map.setStyle({
57
- ...newStyle,
58
- sources: { ...newStyle.sources, ...oldSources },
59
- layers: [...newStyle.layers, ...oldLayers],
60
- });
61
- });
62
- }, { defer: true }));
63
- // Update projection
64
- createEffect(on(() => props.options.projection, () => map.setProjection(props.options.projection), { defer: true }));
65
- createEffect(() => setTransitionType(props.transitionType));
66
- // Hook up viewport events
67
- createEffect(() => {
68
- const viewport = {
69
- id: null,
70
- center: map.getCenter(),
71
- zoom: map.getZoom(),
72
- pitch: map.getPitch(),
73
- bearing: map.getBearing(),
74
- padding: props.viewport?.padding,
75
- bounds: props.viewport?.bounds,
76
- };
77
- const callMove = event => {
78
- if (event.originalEvent)
79
- props.onViewportChange &&
80
- props.onViewportChange({ ...viewport, id: props.id });
81
- setTransitionType('jumpTo');
82
- };
83
- const callEnd = event => {
84
- if (event.originalEvent)
85
- props.onViewportChange && props.onViewportChange(viewport);
86
- setTransitionType(props.transitionType);
87
- };
88
- map.on('move', callMove).on('moveend', callEnd);
89
- onCleanup(() => map.off('move', callMove).off('moveend', callEnd));
90
- });
91
- // Update boundaries
92
- createEffect(prev => {
93
- if (props.viewport?.bounds != prev)
94
- props.onViewportChange({
95
- ...props.viewport,
96
- ...map.cameraForBounds(props.viewport?.bounds, {
97
- padding: props.viewport?.padding,
98
- }),
99
- });
100
- return props.viewport?.bounds;
101
- }, props.viewport?.bounds);
102
- // Update Viewport
103
- createEffect(() => {
104
- if (props.id === props.viewport?.id)
105
- return;
106
- const viewport = {
107
- ...props.viewport,
108
- padding: props.viewport?.padding || 0,
109
- };
110
- switch (untrack(transitionType)) {
111
- case 'easeTo':
112
- map.stop().easeTo(viewport);
113
- case 'jumpTo':
114
- map.stop().jumpTo(viewport);
115
- default:
116
- map.stop().flyTo(viewport);
117
- }
118
- });
119
- let index = 0;
120
- createEffect(() => {
121
- if (props.triggerResize) {
122
- index = 0;
123
- window.requestAnimationFrame(function loop() {
124
- if (index < 15) {
125
- index++;
126
- window.requestAnimationFrame(loop);
127
- start(() => map.resize());
128
- }
129
- });
130
- }
131
- });
132
- return (<MapContext.Provider value={() => map}>
133
- <section ref={containerRef} style={{ position: 'absolute', 'z-index': 1 }}>
134
- {props.children}
135
- </section>
136
- <div ref={mapRef} class={props.class || ''} classList={props.classList} style={{ height: '100%', width: '100%', ...props.style }}/>
137
- </MapContext.Provider>);
138
- };
139
- export { MapGL as default, useMap };
@@ -1,22 +0,0 @@
1
- import { onMount, onCleanup, createEffect } from 'solid-js';
2
- import { useMap } from '../MapGL';
3
- const Sky = props => {
4
- const map = useMap();
5
- const layerId = '_sky';
6
- // Add Sky Layer
7
- onMount(async () => {
8
- !map().isStyleLoaded() && (await map().once('styledata'));
9
- !map().getLayer(layerId) && map().addLayer({ ...props.style, id: layerId });
10
- });
11
- // Remove Sky Layer
12
- onCleanup(() => map().getLayer(layerId) && map().removeLayer(layerId));
13
- // Update Visibility
14
- createEffect(async () => {
15
- if (props.visible === undefined)
16
- return;
17
- !map().isStyleLoaded() && (await map().once('styledata'));
18
- map().setLayoutProperty(layerId, 'visibility', props.visible ? 'visible' : 'none');
19
- });
20
- return props.children;
21
- };
22
- export default Sky;
@@ -1,32 +0,0 @@
1
- import { onMount, onCleanup, createEffect, createContext, useContext, createUniqueId, } from 'solid-js';
2
- import { useMap } from '../MapGL';
3
- const SourceContext = createContext();
4
- const useSource = () => useContext(SourceContext);
5
- const SourceComponent = props => {
6
- const map = useMap();
7
- props.id = props.id || createUniqueId();
8
- // Add Source
9
- onMount(async () => {
10
- !map().isStyleLoaded() && (await map().once('styledata'));
11
- !map().getSource(props.id) && map().addSource(props.id, props.source);
12
- });
13
- // Remove Source
14
- onCleanup(() => {
15
- map()
16
- .getStyle()
17
- .layers.forEach(layer => layer.source === props.id && map().removeLayer(layer.id));
18
- map().getSource(props.id) && map().removeSource(props.id);
19
- });
20
- // Update GeoJSON Data
21
- createEffect(async () => {
22
- if (props.source.type !== 'geojson' && !props.source.data)
23
- return;
24
- map().style &&
25
- map().getSource(props.id) &&
26
- map().getSource(props.id).setData(props.source.data);
27
- });
28
- return (<SourceContext.Provider value={{ id: props.id }}>
29
- {props.children}
30
- </SourceContext.Provider>);
31
- };
32
- export { SourceComponent as default, useSource };
@@ -1,23 +0,0 @@
1
- import { onMount, onCleanup, createEffect } from 'solid-js';
2
- import { useMap } from '../MapGL';
3
- import { useSource } from '../Source';
4
- const Terrain = props => {
5
- const map = useMap();
6
- const source = useSource();
7
- // Add Terrain Layer
8
- onMount(async () => {
9
- !map().isStyleLoaded() && (await map().once('styledata'));
10
- map().setTerrain({ ...props.style, source: source.id });
11
- });
12
- // Remove Terrain Layer
13
- onCleanup(() => map().setTerrain(null));
14
- // Update Visibility
15
- createEffect(async () => {
16
- if (props.visible === undefined)
17
- return;
18
- !map().isStyleLoaded() && (await map().once('styledata'));
19
- map().setTerrain(props.visible ? props.style : null);
20
- });
21
- return props.children;
22
- };
23
- export default Terrain;
@@ -1,10 +0,0 @@
1
- export { default, useMap } from './components/MapGL';
2
- export { default as Source } from './components/Source';
3
- export { default as Layer } from './components/Layer';
4
- export { default as Fog } from './components/Fog';
5
- export { default as Sky } from './components/Sky';
6
- export { default as Terrain } from './components/Terrain';
7
- export { default as Control } from './components/Control';
8
- export { default as Marker } from './components/Marker';
9
- export { default as Popup } from './components/Popup';
10
- export { default as Image } from './components/Image';
@@ -1,8 +0,0 @@
1
- import { Component } from 'solid-js';
2
- import type { SourceSpecification } from 'mapbox-gl/src/style-spec/types.js';
3
- declare const useSource: () => Source;
4
- declare const SourceComponent: Component<{
5
- id?: string;
6
- source: SourceSpecification;
7
- }>;
8
- export { SourceComponent as default, useSource };
@@ -1,11 +0,0 @@
1
- export { default, useMap } from './components/MapGL';
2
- export { default as Source } from './components/Source';
3
- export { default as Layer } from './components/Layer';
4
- export { default as Fog } from './components/Fog';
5
- export { default as Sky } from './components/Sky';
6
- export { default as Terrain } from './components/Terrain';
7
- export { default as Control } from './components/Control';
8
- export { default as Marker } from './components/Marker';
9
- export { default as Popup } from './components/Popup';
10
- export { default as Image } from './components/Image';
11
- export type { Viewport } from './components/MapGL';