solid-map-gl 1.1.3 → 1.1.7

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 CHANGED
@@ -2,10 +2,11 @@
2
2
 
3
3
  # Solid Mapbox GL JS
4
4
 
5
- ![npm-version](https://badgen.net/npm/v/solid-map-gl)
6
- ![licence](https://badgen.net/badge/license/MIT/blue)
7
- ![types](https://badgen.net/npm/types/solid-map-gl)
8
- ![downloads](https://badgen.net/npm/dt/solid-map-gl)
5
+ [![npm](https://badgen.net/npm/v/solid-map-gl)
6
+ ![downloads](https://badgen.net/npm/dt/solid-map-gl)](https://www.npmjs.com/package/solid-map-gl)
7
+ [![licence](https://badgen.net/badge/license/MIT/blue)](./LICENSE)
8
+ [![zip](https://badgen.net/bundlephobia/minzip/solid-map-gl)
9
+ ![treeshaking](https://badgen.net/bundlephobia/tree-shaking/solid-map-gl)](https://bundlephobia.com/package/solid-map-gl@1.1.6)
9
10
 
10
11
  [Solid](https://www.solidjs.com/) Component Library for [Mapbox GL JS.](https://github.com/mapbox/mapbox-gl-js) Mapbox GL JS is a JavaScript library that renders interactive maps from vector tiles and Mapbox styles using WebGL. This project is intended to be as close as possible to the [Mapbox GL JS API.](https://docs.mapbox.com/mapbox-gl-js/api/)
11
12
 
@@ -17,7 +18,7 @@
17
18
  - [Map with Source and Layer](#map-with-source-and-layer)
18
19
  - [Map with GeoJSON Source](#map-with-geojson-source)
19
20
  - [Examples](#examples)
20
- - [Changelog](#changelog)
21
+ - [Roadmap](#roadmap)
21
22
 
22
23
  <br>
23
24
 
@@ -70,17 +71,15 @@ By default, `MapGL` component renders in a static mode. That means that the user
70
71
 
71
72
  ```jsx
72
73
  import MapGL from 'solid-map-gl'
73
-
74
- <MapGL
75
- options={{
76
- accessToken: { MAPBOX_ACCESS_TOKEN },
77
- style: 'mapbox://styles/mapbox/light-v10',
78
- }}
79
- viewport={{
80
- center: [-122.41, 37.78]
81
- zoom: 11,
82
- }}>
83
- </MapGL>
74
+ ;<MapGL
75
+ options={{
76
+ accessToken: { MAPBOX_ACCESS_TOKEN },
77
+ style: 'mapbox://styles/mapbox/light-v10',
78
+ }}
79
+ viewport={{
80
+ center: [-122.41, 37.78],
81
+ zoom: 11,
82
+ }}></MapGL>
84
83
  ```
85
84
 
86
85
  ### Interactive Map
@@ -92,14 +91,14 @@ import { createSignal } from 'solid-js'
92
91
  import MapGL, { Viewport } from 'solid-map-gl'
93
92
 
94
93
  const [viewport, setViewport] = createSignal({
95
- center: [-122.41, 37.78]
96
- zoom: 11,
97
- } as Viewport)
94
+ center: [-122.41, 37.78],
95
+ zoom: 11
96
+ } as Viewport);
98
97
 
99
98
  <MapGL
100
99
  options={{
101
100
  accessToken: { MAPBOX_ACCESS_TOKEN },
102
- style: 'mapbox://styles/mapbox/light-v10',
101
+ style: 'mapbox://styles/mapbox/light-v10'
103
102
  }}
104
103
  viewport={viewport()}
105
104
  onViewportChange={evt => setViewport(evt)}>
@@ -115,12 +114,12 @@ const [viewport, setViewport] = createSignal({
115
114
  Except for layers of the `background` type, each layer needs to refer to a source. Either buy referencing the `id` in `sourceId` or by nesting the layer within the source component. Layers take the data that they get from a source, optionally filter features, and then define how those features are styled.
116
115
 
117
116
  ```jsx
118
- import MapGL, { Source, Layer } from 'solid-map-gl'
117
+ import MapGL, { Source, Layer } from 'solid-map-gl';
119
118
 
120
119
  <MapGL
121
120
  options={{
122
121
  accessToken: { MAPBOX_ACCESS_TOKEN },
123
- style: 'mapbox://styles/mapbox/light-v10',
122
+ style: 'mapbox://styles/mapbox/light-v10'
124
123
  }}>
125
124
  <Source
126
125
  source={{
@@ -148,8 +147,8 @@ import { createSignal } from 'solid-js'
148
147
  import MapGL, { Source, Layer } from 'solid-map-gl'
149
148
 
150
149
  const [viewport, setViewport] = createSignal({
151
- center: [-122.486052, 37.830348],
152
- zoom: 15,
150
+ center: [-122.486052, 37.830348],
151
+ zoom: 15,
153
152
  })
154
153
 
155
154
  const data = {
@@ -182,30 +181,32 @@ const data = {
182
181
  },
183
182
  }
184
183
 
185
- <MapGL
186
- options={{
187
- accessToken: { MAPBOX_ACCESS_TOKEN },
188
- style: 'mapbox://styles/mapbox/light-v10',
189
- }}
190
- viewport={viewport()}
191
- onViewportChange={evt => setViewport(evt)}>
192
- <Source
193
- source={{
194
- type: 'geojson',
195
- data: {data}
184
+ ;<MapGL
185
+ options={{
186
+ accessToken: { MAPBOX_ACCESS_TOKEN },
187
+ style: 'mapbox://styles/mapbox/light-v10',
188
+ }}
189
+ viewport={viewport()}
190
+ onViewportChange={evt => setViewport(evt)}>
191
+ <Source
192
+ source={{
193
+ type: 'geojson',
194
+ data: { data },
196
195
  }}>
197
- <Layer style={{
198
- type: 'line',
199
- layout: {
200
- 'line-join': 'round',
201
- 'line-cap': 'round',
202
- }
203
- paint: {
204
- 'line-color': '#888',
205
- 'line-width': 8,
206
- }
207
- }} />
208
- </Source>
196
+ <Layer
197
+ style={{
198
+ type: 'line',
199
+ layout: {
200
+ 'line-join': 'round',
201
+ 'line-cap': 'round',
202
+ },
203
+ paint: {
204
+ 'line-color': '#888',
205
+ 'line-width': 8,
206
+ },
207
+ }}
208
+ />
209
+ </Source>
209
210
  </MapGL>
210
211
  ```
211
212
 
@@ -222,8 +223,8 @@ import { MapboxLayer } from '@deck.gl/mapbox'
222
223
  import { ScatterplotLayer } from '@deck.gl/layers'
223
224
 
224
225
  const [viewport, setViewport] = createSignal({
225
- center: [-74.5, 40],
226
- zoom: 9,
226
+ center: [-74.5, 40],
227
+ zoom: 9,
227
228
  })
228
229
 
229
230
  const myDeckLayer = new MapboxLayer({
@@ -235,23 +236,29 @@ const myDeckLayer = new MapboxLayer({
235
236
  getColor: [255, 0, 0],
236
237
  })
237
238
 
238
- <MapGL
239
- options={{
240
- accessToken: { MAPBOX_ACCESS_TOKEN },
241
- style: 'mapbox://styles/mapbox/light-v10',
242
- }}
243
- viewport={viewport()}
244
- onViewportChange={evt => setViewport(evt)}>
245
- <Layer customLayer={myDeckLayer} />
239
+ ;<MapGL
240
+ options={{
241
+ accessToken: { MAPBOX_ACCESS_TOKEN },
242
+ style: 'mapbox://styles/mapbox/light-v10',
243
+ }}
244
+ viewport={viewport()}
245
+ onViewportChange={evt => setViewport(evt)}>
246
+ <Layer customLayer={myDeckLayer} />
246
247
  </MapGL>
247
248
  ```
248
249
 
249
250
  ## Examples
250
251
 
251
- ### Coming Soon
252
+ #### Coming Soon
253
+
254
+ <br>
252
255
 
253
- ## Changelog
256
+ ## Roadmap
254
257
 
255
- - 1.0.0 - Initial release
256
- - 1.1.0 - Bug fixing
257
- - 1.2.0 - Bug fixing
258
+ - [x] Basic Mapbox GL Functionality
259
+ - [x] Include Map Controls
260
+ - [x] Include Fog, Sky, and Terrain
261
+ - [x] Include Popup and Markers
262
+ - [x] Minify bundle & reduce size
263
+ - [ ] Add basemap switching
264
+ - [ ] Add edit functionality
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{template,createComponent,insert,effect,classList}from"solid-js/web";import{useTransition,createContext,onCleanup,onMount,createEffect,useContext,createUniqueId,createSignal}from"solid-js";import mapboxgl from"mapbox-gl";const _tmpl$$2=template("<main></main>",2),[pending,start]=useTransition(),MapContext=createContext(),useMap=()=>useContext(MapContext),MapGL=n=>{let t,o;onCleanup(()=>t.remove()),onMount(()=>{t=new mapboxgl.Map({...n.options,container:o,bounds:n.viewport.bounds,center:n.viewport.center,zoom:n.viewport.zoom||null,pitch:n.viewport.pitch||null,bearing:n.viewport.bearing||null,fitBoundsOptions:{padding:n.viewport.padding}})}),createEffect(()=>n.onMouseMove&&t.on("mousemove",e=>n.onMouseMove(e.lngLat)));const e=()=>{var e={center:t.getCenter(),zoom:t.getZoom(),pitch:t.getPitch(),bearing:t.getBearing(),padding:n.viewport.padding};n.onViewportChange(e)};createEffect(()=>n.onViewportChange&&t.on("dragend",e).on("moveend",e).on("zoomend",e).on("rotateend",e).on("pitchend",e).on("boxzoomend",e)),createEffect(async()=>{n.viewport.bounds&&t.fitBounds(n.viewport.bounds,{padding:n.viewport.padding})});let a=0;return createEffect(()=>{n.triggerResize&&(a=0,window.requestAnimationFrame(function e(){a<15&&(a++,window.requestAnimationFrame(e),start(()=>t.resize()))}))}),createComponent(MapContext.Provider,{value:()=>t,get children(){const a=_tmpl$$2.cloneNode(!0),e=o;return"function"==typeof e?e(a):o=a,a.style.setProperty("height","100%"),a.style.setProperty("width","100%"),insert(a,()=>n.children),effect(e=>{var t=n.class||"",o=n.classList;return t!==e._v$&&(a.className=e._v$=t),e._v$2=classList(a,o,e._v$2),e},{_v$:void 0,_v$2:void 0}),a}})},SourceContext=createContext(),useSource=()=>useContext(SourceContext),SourceComponent=t=>{const o=useMap();return t.id=t.id||createUniqueId(),onMount(async()=>{o().isStyleLoaded()||await o().once("styledata"),o().getSource(t.id)||o().addSource(t.id,t.source)}),onCleanup(()=>{o().getStyle().layers.forEach(e=>e.source===t.id&&o().removeLayer(e.id)),o().getSource(t.id)&&o().removeSource(t.id)}),createEffect(async()=>{("geojson"===t.source.type||t.source.data)&&o().getSource(t.id)&&o().getSource(t.id).setData(t.source.data)}),createComponent(SourceContext.Provider,{get value(){return{source:t.id}},get children(){return t.children}})},diff=(a={},n={})=>{return[...new Set([...Object.keys(a),...Object.keys(n)])].reduce((e,t)=>{var o=a[t];return o!==n[t]&&e.push([t,o]),e},[])},Layer=o=>{const a=useMap(),e=useSource();return o.id=o.id||createUniqueId(),onMount(async()=>{a().isStyleLoaded()||await a().once("styledata"),a().getLayer(o.id)||a().addLayer(o.layer||{...o.style,id:o.id,source:e.source},o.beforeType?a().getStyle().layers.find(e=>e.type===o.beforeType).id:o.beforeId)}),createEffect(e=>{if(o.style||!a().getLayer(o.id))return diff(o.style.paint,e.paint).forEach(([e,t])=>a().setPaintProperty(o.id,e,t)),diff(o.style.layout,e.layout).forEach(([e,t])=>a().setLayoutProperty(o.id,e,t)),o.style.minzoom===e.minzoom&&o.style.maxzoom===e.max||a().setLayerZoomRange(o.id,o.style.minzoom,o.style.maxzoom),o.style},o.style),createEffect(async()=>{void 0!==o.visible&&(a().isStyleLoaded()||await a().once("styledata"),a().setLayoutProperty(o.id,"visibility",o.visible?"visible":"none",{validate:!1}))}),createEffect(async()=>{o.filter&&(a().isStyleLoaded()||await a().once("styledata"),a().setFilter(o.id,o.filter))}),createEffect(async()=>{o.featureState&&o.featureState.id&&(a().loaded()||await a().once("render"),a().removeFeatureState({source:e.source,sourceLayer:o.style["source-layer"]}),a().setFeatureState({source:e.source,sourceLayer:o.style["source-layer"],id:o.featureState.id},o.featureState.state))}),o.children},Fog=e=>{const t=useMap();return onMount(async()=>{t().isStyleLoaded()||await t().once("styledata"),t().setFog(e.style)}),onCleanup(()=>t().setFog(null)),createEffect(async()=>{void 0!==e.visible&&(t().isStyleLoaded()||await t().once("styledata"),t().setFog(e.visible?e.style:null))}),e.children},Sky=e=>{const t=useMap(),o="_sky";return onMount(async()=>{t().isStyleLoaded()||await t().once("styledata"),t().getLayer(o)||t().addLayer({...e.style,id:o})}),onCleanup(()=>t().getLayer(o)&&t().removeLayer(o)),createEffect(async()=>{void 0!==e.visible&&(t().isStyleLoaded()||await t().once("styledata"),t().setLayoutProperty(o,"visibility",e.visible?"visible":"none"))}),e.children},Terrain=e=>{const t=useMap(),o=useSource();return onMount(async()=>{t().isStyleLoaded()||await t().once("styledata"),t().setTerrain({...e.style,source:o.source})}),onCleanup(()=>t().setTerrain(null)),createEffect(async()=>{void 0!==e.visible&&(t().isStyleLoaded()||await t().once("styledata"),t().setTerrain(e.visible?e.style:null))}),e.children},Control=t=>{const o=useMap(),[e,a]=createSignal(null);return onMount(async()=>{let e;switch(t.type){case"navigation":e=new mapboxgl.NavigationControl(t.options);break;case"scale":e=new mapboxgl.ScaleControl(t.options);break;case"attribution":e=new mapboxgl.AttributionControl(t.options);break;case"fullscreen":e=new mapboxgl.FullscreenControl(t.options);break;case"geolocate":e=new mapboxgl.GeolocateControl(t.options)}e&&o().addControl(e,t.position),a(e)}),onCleanup(()=>o().removeControl(e())),t.children},_tmpl$$1=template("<div></div>",2),Marker=t=>{const o=useMap();let a=null;return onMount(async()=>{var e;a=new mapboxgl.Marker(t.options).setLngLat(t.lnglat).setPopup(t.children?(new mapboxgl.Popup).setDOMContent((e=_tmpl$$1.cloneNode(!0),insert(e,()=>t.children),e)):null).addTo(o())}),onCleanup(()=>a.remove()),createEffect(()=>a.setLngLat(t.lnglat)),[]},_tmpl$=template("<div></div>",2),Popup=t=>{const o=useMap();let a=null;return onMount(async()=>{var e;a=new mapboxgl.Popup(t.options).setLngLat(t.lnglat).setDOMContent((e=_tmpl$.cloneNode(!0),insert(e,()=>t.children),e)).addTo(o())}),onCleanup(()=>a.remove()),createEffect(()=>a.setLngLat(t.lnglat)),createEffect(()=>a.setDOMContent((()=>{var e=_tmpl$.cloneNode(!0);return insert(e,()=>t.children),e})())),[]},Image=o=>{const a=useMap();return onMount(async()=>{a().isStyleLoaded()||await a().once("styledata"),o.url?a().loadImage(o.url,(e,t)=>{if(e)throw e;a().hasImage(o.id)||a().addImage(o.id,t)}):a().hasImage(o.id)||a().addImage(o.id,o.image,o.options)}),onCleanup(()=>a().hasImage(o.id)&&a().removeImage(o.id)),createEffect(async()=>{o.image&&o.url||(o.url?a().loadImage(o.url,(e,t)=>{if(e)throw e;a().hasImage(o.id)||a().updateImage(o.id,t)}):a().hasImage(o.id)&&a().updateImage(o.id,o.image))}),[]};export{Control,Fog,Image,Layer,Marker,Popup,Sky,SourceComponent as Source,Terrain,MapGL as default};
1
+ import{template,createComponent,insert,effect,classList}from"solid-js/web";import{useTransition,createContext,onCleanup,onMount,createEffect,useContext,createUniqueId,createSignal}from"solid-js";import mapboxgl from"mapbox-gl";const _tmpl$$2=template("<main></main>",2);var Type;!function(e){e.flyTo="flyTo",e.easeTo="easeTo",e.jumpTo="jumpTo"}(Type=Type||{});const[pending,start]=useTransition(),MapContext=createContext(),useMap=()=>useContext(MapContext),MapGL=n=>{let a,t;onCleanup(()=>a.remove()),onMount(()=>{a=new mapboxgl.Map({...n.options,container:t,bounds:n.viewport.bounds,center:n.viewport.center,zoom:n.viewport.zoom||null,pitch:n.viewport.pitch||null,bearing:n.viewport.bearing||null,fitBoundsOptions:{padding:n.viewport.padding}})}),createEffect(()=>n.onMouseMove&&a.on("mousemove",e=>n.onMouseMove(e.lngLat)));const e=e=>{e.isInternal||(e={center:a.getCenter(),zoom:a.getZoom(),pitch:a.getPitch(),bearing:a.getBearing(),padding:n.viewport.padding,bounds:n.viewport.bounds},n.onViewportChange(e))};createEffect(()=>n.onViewportChange&&a.on("dragend",e).on("moveend",e).on("zoomend",e).on("rotateend",e).on("pitchend",e).on("boxzoomend",e)),createEffect(e=>{return n.viewport.bounds!=e&&(e=a.cameraForBounds(n.viewport.bounds,{padding:n.viewport.padding}),n.onViewportChange({...n.viewport,...e})),n.viewport.bounds},n.viewport.bounds),createEffect(async e=>{var t=n.viewport,o={...t.zoom!=e.zoom&&{zoom:t.zoom},...t.padding!=e.padding&&{padding:t.padding},...t.bearing!=e.bearing&&{bearing:t.bearing},...t.pitch!=e.pitch&&{pitch:t.pitch},...t.center!=e.center&&{center:t.center.lng?[t.center.lng,t.center.lat]:t.center}};if(Object.keys(o).length)switch(a.stop(),n.transitionType){case"easeTo":a.easeTo(o,{isInternal:!0});case"jumpTo":a.jumpTo(o,{isInternal:!0});default:a.flyTo(o,{isInternal:!0})}return t},n.viewport);let o=0;return createEffect(()=>{n.triggerResize&&(o=0,window.requestAnimationFrame(function e(){o<15&&(o++,window.requestAnimationFrame(e),start(()=>a.resize()))}))}),createComponent(MapContext.Provider,{value:()=>a,get children(){const a=_tmpl$$2.cloneNode(!0),e=t;return"function"==typeof e?e(a):t=a,a.style.setProperty("height","100%"),a.style.setProperty("width","100%"),insert(a,()=>n.children),effect(e=>{var t=n.class||"",o=n.classList;return t!==e._v$&&(a.className=e._v$=t),e._v$2=classList(a,o,e._v$2),e},{_v$:void 0,_v$2:void 0}),a}})},SourceContext=createContext(),useSource=()=>useContext(SourceContext),SourceComponent=t=>{const o=useMap();return t.id=t.id||createUniqueId(),onMount(async()=>{o().isStyleLoaded()||await o().once("styledata"),o().getSource(t.id)||o().addSource(t.id,t.source)}),onCleanup(()=>{o().getStyle().layers.forEach(e=>e.source===t.id&&o().removeLayer(e.id)),o().getSource(t.id)&&o().removeSource(t.id)}),createEffect(async()=>{("geojson"===t.source.type||t.source.data)&&o().getSource(t.id)&&o().getSource(t.id).setData(t.source.data)}),createComponent(SourceContext.Provider,{get value(){return{id:t.id}},get children(){return t.children}})},diff=(a={},n={})=>{return[...new Set([...Object.keys(a),...Object.keys(n)])].reduce((e,t)=>{var o=a[t];return o!==n[t]&&e.push([t,o]),e},[])},Layer=o=>{const a=useMap(),t=useSource();return o.id=o.id||createUniqueId(),onMount(async()=>{a().isStyleLoaded()||await a().once("styledata"),a().getLayer(o.id)||a().addLayer(o.layer||{...o.style,id:o.id,source:t.id},o.beforeType?a().getStyle().layers.find(e=>e.type===o.beforeType).id:o.beforeId)}),createEffect(e=>{if(o.style&&a().getSource(t.id)&&a().getLayer(o.id))return o.style.layout!==e?.layout&&diff(o.style.layout,e?.layout).forEach(([e,t])=>a().setLayoutProperty(o.id,e,t,{validate:!1})),o.style.paint!==e?.paint&&diff(o.style.paint,e?.paint).forEach(([e,t])=>a().setPaintProperty(o.id,e,t,{validate:!1})),o.style.minzoom===e?.minzoom&&o.style.maxzoom===e?.maxzoom||a().setLayerZoomRange(o.id,o.style.minzoom,o.style.maxzoom),o.style.filter!==e?.filter&&a().setFilter(o.id,o.style.filter,{validate:!1}),o.style},o.style),createEffect(e=>{if(void 0!==o.visible&&o.visible!==e&&a().getSource(t.id)&&a().getLayer(o.id))return a().setLayoutProperty(o.id,"visibility",o.visible?"visible":"none",{validate:!1}),o.visible},o.visible),createEffect(async()=>{o.filter&&(a().isStyleLoaded()||await a().once("styledata"),a().setFilter(o.id,o.filter))}),createEffect(async()=>{o.featureState&&o.featureState.id&&(a().isStyleLoaded()||await a().once("styledata"),a().removeFeatureState({source:t.id,sourceLayer:o.style["source-layer"]}),a().setFeatureState({source:t.id,sourceLayer:o.style["source-layer"],id:o.featureState.id},o.featureState.state))}),o.children},Fog=e=>{const t=useMap();return onMount(async()=>{t().isStyleLoaded()||await t().once("styledata"),t().setFog(e.style)}),onCleanup(()=>t().setFog(null)),createEffect(async()=>{void 0!==e.visible&&(t().isStyleLoaded()||await t().once("styledata"),t().setFog(e.visible?e.style:null))}),e.children},Sky=e=>{const t=useMap(),o="_sky";return onMount(async()=>{t().isStyleLoaded()||await t().once("styledata"),t().getLayer(o)||t().addLayer({...e.style,id:o})}),onCleanup(()=>t().getLayer(o)&&t().removeLayer(o)),createEffect(async()=>{void 0!==e.visible&&(t().isStyleLoaded()||await t().once("styledata"),t().setLayoutProperty(o,"visibility",e.visible?"visible":"none"))}),e.children},Terrain=e=>{const t=useMap(),o=useSource();return onMount(async()=>{t().isStyleLoaded()||await t().once("styledata"),t().setTerrain({...e.style,source:o.id})}),onCleanup(()=>t().setTerrain(null)),createEffect(async()=>{void 0!==e.visible&&(t().isStyleLoaded()||await t().once("styledata"),t().setTerrain(e.visible?e.style:null))}),e.children},Control=t=>{const o=useMap(),[e,a]=createSignal(null);return onMount(async()=>{let e;switch(t.type){case"navigation":e=new mapboxgl.NavigationControl(t.options);break;case"scale":e=new mapboxgl.ScaleControl(t.options);break;case"attribution":e=new mapboxgl.AttributionControl(t.options);break;case"fullscreen":e=new mapboxgl.FullscreenControl(t.options);break;case"geolocate":e=new mapboxgl.GeolocateControl(t.options)}e&&o().addControl(e,t.position),a(e)}),onCleanup(()=>o().removeControl(e())),t.children},_tmpl$$1=template("<div></div>",2),Marker=t=>{const o=useMap();let a=null;return onMount(async()=>{var e;a=new mapboxgl.Marker(t.options).setLngLat(t.lnglat).setPopup(t.children?(new mapboxgl.Popup).setDOMContent((e=_tmpl$$1.cloneNode(!0),insert(e,()=>t.children),e)):null).addTo(o())}),onCleanup(()=>a.remove()),createEffect(()=>a.setLngLat(t.lnglat)),[]},_tmpl$=template("<div></div>",2),Popup=t=>{const o=useMap();let a=null;return onMount(async()=>{var e;a=new mapboxgl.Popup(t.options).setLngLat(t.lnglat).setDOMContent((e=_tmpl$.cloneNode(!0),insert(e,()=>t.children),e)).addTo(o())}),onCleanup(()=>a.remove()),createEffect(()=>a.setLngLat(t.lnglat)),createEffect(()=>a.setDOMContent((()=>{var e=_tmpl$.cloneNode(!0);return insert(e,()=>t.children),e})())),[]},Image=o=>{const a=useMap();return onMount(async()=>{a().isStyleLoaded()||await a().once("styledata"),o.url?a().loadImage(o.url,(e,t)=>{if(e)throw e;a().hasImage(o.id)||a().addImage(o.id,t)}):a().hasImage(o.id)||a().addImage(o.id,o.image,o.options)}),onCleanup(()=>a().hasImage(o.id)&&a().removeImage(o.id)),createEffect(async()=>{o.image&&o.url||(o.url?a().loadImage(o.url,(e,t)=>{if(e)throw e;a().hasImage(o.id)||a().updateImage(o.id,t)}):a().hasImage(o.id)&&a().updateImage(o.id,o.image))}),[]};export{Control,Fog,Image,Layer,Marker,Popup,Sky,SourceComponent as Source,Terrain,MapGL as default};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/components/MapGL/index.tsx","../../src/components/Source/index.tsx","../../src/components/Layer/index.tsx","../../src/components/Fog/index.tsx","../../src/components/Sky/index.tsx","../../src/components/Terrain/index.tsx","../../src/components/Control/index.tsx","../../src/components/Marker/index.tsx","../../src/components/Popup/index.tsx","../../src/components/Image/index.tsx"],"sourcesContent":["import {\n createEffect,\n onMount,\n onCleanup,\n createContext,\n useContext,\n Component,\n useTransition,\n} from 'solid-js'\nimport mapboxgl from 'mapbox-gl'\nimport 'mapbox-gl/dist/mapbox-gl.css'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type MapboxOptions from 'mapbox-gl/src/ui/map'\nimport type MapMouseEvent from 'mapbox-gl/src/ui/events'\nimport type { LngLatLike } from 'mapbox-gl/src/geo/lng_lat.js'\nimport type { LngLatBounds } from 'mapbox-gl/src/geo/lng_lat_bounds.js'\n\nexport type Viewport = {\n center?: LngLatLike\n bounds?: LngLatBounds\n zoom?: number\n pitch?: number\n bearing?: number\n padding?: number\n}\n\nconst [pending, start] = useTransition()\n\nconst MapContext = createContext<MapboxMap>()\nconst useMap = () => useContext(MapContext)\n\nconst MapGL: Component<{\n class?: string\n classList?: {\n [k: string]: boolean | undefined\n }\n viewport?: Viewport\n options?: MapboxOptions\n children?: Component[] | Component\n triggerResize?: boolean\n onMouseMove?: (event: MapMouseEvent) => void\n onViewportChange?: (viewport: Viewport) => void\n}> = props => {\n let map: MapboxMap\n let mapRef: HTMLElement\n\n onCleanup(() => map.remove())\n\n onMount(() => {\n map = new mapboxgl.Map({\n ...props.options,\n container: mapRef,\n bounds: props.viewport.bounds,\n center: props.viewport.center,\n zoom: props.viewport.zoom || null,\n pitch: props.viewport.pitch || null,\n bearing: props.viewport.bearing || null,\n fitBoundsOptions: { padding: props.viewport.padding },\n } as MapboxOptions)\n })\n\n createEffect(\n () =>\n props.onMouseMove &&\n map.on('mousemove', event => props.onMouseMove(event.lngLat))\n )\n\n const _onViewportChange = () => {\n const viewport: Viewport = {\n center: map.getCenter(),\n zoom: map.getZoom(),\n pitch: map.getPitch(),\n bearing: map.getBearing(),\n padding: props.viewport.padding,\n }\n props.onViewportChange(viewport)\n }\n\n createEffect(\n () =>\n props.onViewportChange &&\n map\n .on('dragend', _onViewportChange)\n .on('moveend', _onViewportChange)\n .on('zoomend', _onViewportChange)\n .on('rotateend', _onViewportChange)\n .on('pitchend', _onViewportChange)\n .on('boxzoomend', _onViewportChange)\n )\n\n createEffect(async () => {\n if (!props.viewport.bounds) return\n\n map.fitBounds(props.viewport.bounds, {\n padding: props.viewport.padding,\n })\n })\n\n let index = 0\n\n createEffect(() => {\n if (props.triggerResize) {\n index = 0\n window.requestAnimationFrame(function loop() {\n if (index < 15) {\n index++\n window.requestAnimationFrame(loop)\n start(() => map.resize())\n }\n })\n }\n })\n\n return (\n <MapContext.Provider value={() => map}>\n <main\n ref={mapRef}\n class={props.class || ''}\n classList={props.classList}\n style={{ height: '100%', width: '100%' }}>\n {props.children}\n </main>\n </MapContext.Provider>\n )\n}\n\nexport { MapGL as default, useMap }\n","import {\n onMount,\n onCleanup,\n createEffect,\n Component,\n createContext,\n useContext,\n createUniqueId,\n} from 'solid-js'\nimport { useMap } from '../MapGL'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type {\n Source,\n SourceSpecification,\n} from 'mapbox-gl/src/style-spec/types.js'\n\nconst SourceContext = createContext<Source>()\n\nconst useSource = (): Source => useContext(SourceContext)\n\nconst SourceComponent: Component<{\n id?: string\n source: SourceSpecification\n}> = props => {\n const map: MapboxMap = useMap()\n props.id = props.id || createUniqueId()\n // Add Source\n onMount(async () => {\n !map().isStyleLoaded() && (await map().once('styledata'))\n !map().getSource(props.id) && map().addSource(props.id, props.source)\n })\n\n // Remove Source\n onCleanup(() => {\n map()\n .getStyle()\n .layers.forEach(\n layer => layer.source === props.id && map().removeLayer(layer.id)\n )\n map().getSource(props.id) && map().removeSource(props.id)\n })\n\n // Update GeoJSON Data\n createEffect(async () => {\n if (props.source.type !== 'geojson' && !props.source.data) return\n\n map().getSource(props.id) &&\n map().getSource(props.id).setData(props.source.data)\n })\n\n return (\n <SourceContext.Provider value={{ source: props.id }}>\n {props.children}\n </SourceContext.Provider>\n )\n}\n\nexport { SourceComponent as default, useSource }\n","import { onMount, createEffect, Component, createUniqueId } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport { useSource } from '../Source'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type {\n FilterSpecification,\n StyleSpecification,\n SourceSpecification,\n} from 'mapbox-gl/src/style-spec/types.js'\nimport type { CustomLayerInterface } from 'mapbox-gl/src/style/style_layer/custom_style_layer'\n\nconst diff = (\n newProps: StyleSpecification = {},\n prevProps: StyleSpecification = {}\n) => {\n const keys = new Set([...Object.keys(newProps), ...Object.keys(prevProps)])\n return [...keys].reduce((acc, key: string) => {\n const value = newProps[key]\n if (value !== prevProps[key]) {\n acc.push([key, value])\n }\n return acc\n }, [])\n}\n\nconst Layer: Component<{\n id?: string\n style?: StyleSpecification\n layer?: CustomLayerInterface\n filter?: FilterSpecification\n visible?: boolean\n sourceId?: string\n beforeType?:\n | 'background'\n | 'fill'\n | 'line'\n | 'symbol'\n | 'raster'\n | 'circle'\n | 'fill-extrusion'\n | 'heatmap'\n | 'hillshade'\n | 'sky'\n beforeId?: string\n featureState?: { id: number | string; state: object }\n}> = props => {\n const map: MapboxMap = useMap()\n const source: SourceSpecification = useSource()\n props.id = props.id || createUniqueId()\n // Add Layer\n onMount(async () => {\n !map().isStyleLoaded() && (await map().once('styledata'))\n\n if (map().getLayer(props.id)) return\n\n map().addLayer(\n props.layer || {\n ...props.style,\n id: props.id,\n source: source.source,\n },\n props.beforeType\n ? map()\n .getStyle()\n .layers.find(l => l.type === props.beforeType).id\n : props.beforeId\n )\n })\n\n // Update Style\n createEffect((prev: StyleSpecification) => {\n if (!props.style && map().getLayer(props.id)) return\n\n diff(props.style.paint, prev.paint).forEach(([key, value]) =>\n map().setPaintProperty(props.id, key, value)\n )\n\n diff(props.style.layout, prev.layout).forEach(([key, value]) =>\n map().setLayoutProperty(props.id, key, value)\n )\n\n if (\n props.style.minzoom !== prev.minzoom ||\n props.style.maxzoom !== prev.max\n )\n map().setLayerZoomRange(\n props.id,\n props.style.minzoom,\n props.style.maxzoom\n )\n\n return props.style\n }, props.style)\n\n // Update Visibility\n createEffect(async () => {\n if (props.visible === undefined) return\n\n !map().isStyleLoaded() && (await map().once('styledata'))\n map().setLayoutProperty(\n props.id,\n 'visibility',\n props.visible ? 'visible' : 'none',\n { validate: false }\n )\n })\n\n // Update Filter\n createEffect(async () => {\n if (!props.filter) return\n\n !map().isStyleLoaded() && (await map().once('styledata'))\n map().setFilter(props.id, props.filter)\n })\n\n // Update Feature State\n createEffect(async () => {\n if (!props.featureState || !props.featureState.id) return\n\n map().loaded() ? null : await map().once('render')\n\n map().removeFeatureState({\n source: source.source,\n sourceLayer: props.style['source-layer'],\n })\n map().setFeatureState(\n {\n source: source.source,\n sourceLayer: props.style['source-layer'],\n id: props.featureState.id,\n },\n props.featureState.state\n )\n })\n\n return props.children\n}\n\nexport default Layer\n","import { onMount, onCleanup, createEffect, Component } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type { FogSpecification } from 'mapbox-gl/src/style-spec/types.js'\n\nconst Fog: Component<{\n style: FogSpecification\n visible?: boolean\n}> = props => {\n const map: MapboxMap = useMap()\n // Add Fog Layer\n onMount(async () => {\n !map().isStyleLoaded() && (await map().once('styledata'))\n map().setFog(props.style)\n })\n // Remove Fog Layer\n onCleanup(() => map().setFog(null))\n\n // Update Visibility\n createEffect(async () => {\n if (props.visible === undefined) return\n\n !map().isStyleLoaded() && (await map().once('styledata'))\n map().setFog(props.visible ? props.style : null)\n })\n\n return props.children\n}\n\nexport default Fog\n","import { onMount, onCleanup, createEffect, Component } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type { StyleSpecification } from 'mapbox-gl/src/style-spec/types.js'\n\nconst Sky: Component<{\n style: StyleSpecification\n visible?: boolean\n}> = props => {\n const map: MapboxMap = useMap()\n const layerId = '_sky'\n // Add Sky Layer\n onMount(async () => {\n !map().isStyleLoaded() && (await map().once('styledata'))\n !map().getLayer(layerId) && map().addLayer({ ...props.style, id: layerId })\n })\n\n // Remove Sky Layer\n onCleanup(() => map().getLayer(layerId) && map().removeLayer(layerId))\n\n // Update Visibility\n createEffect(async () => {\n if (props.visible === undefined) return\n\n !map().isStyleLoaded() && (await map().once('styledata'))\n map().setLayoutProperty(\n layerId,\n 'visibility',\n props.visible ? 'visible' : 'none'\n )\n })\n\n return props.children\n}\n\nexport default Sky\n","import { onMount, onCleanup, createEffect, Component } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport { useSource } from '../Source'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type {\n TerrainSpecification,\n SourceSpecification,\n} from 'mapbox-gl/src/style-spec/types.js'\n\nconst Terrain: Component<{\n style: TerrainSpecification\n visible?: boolean\n}> = props => {\n const map: MapboxMap = useMap()\n const source: SourceSpecification = useSource()\n\n // Add Terrain Layer\n onMount(async () => {\n !map().isStyleLoaded() && (await map().once('styledata'))\n map().setTerrain({ ...props.style, source: source.source })\n })\n\n // Remove Terrain Layer\n onCleanup(() => map().setTerrain(null))\n\n // Update Visibility\n createEffect(async () => {\n if (props.visible === undefined) return\n\n !map().isStyleLoaded() && (await map().once('styledata'))\n map().setTerrain(props.visible ? props.style : null)\n })\n\n return props.children\n}\n\nexport default Terrain\n","import { onMount, onCleanup, createSignal, Component, lazy } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport mapboxgl from 'mapbox-gl'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type { Options as AttributionOptions } from 'mapbox-gl/src/ui/control/attribution_control'\nimport type { Options as FullscreenOptions } from 'mapbox-gl/src/ui/control/fullscreen_control'\nimport type { Options as GeolocateOptions } from 'mapbox-gl/src/ui/control/geolocate_control'\nimport type { Options as NavigationOptions } from 'mapbox-gl/src/ui/control/navigation_control'\nimport type { Options as ScaleOptions } from 'mapbox-gl/src/ui/control/scale_control'\n\nconst Control: Component<{\n type:\n | 'navigation'\n | 'scale'\n | 'attribution'\n | 'fullscreen'\n | 'geolocate'\n | 'language'\n | 'traffic'\n options?:\n | NavigationOptions\n | ScaleOptions\n | AttributionOptions\n | FullscreenOptions\n | GeolocateOptions\n position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'\n}> = props => {\n const map: MapboxMap = useMap()\n const [control, setControl] = createSignal(null)\n // Add Control\n onMount(async () => {\n let control\n\n switch (props.type) {\n case 'navigation':\n control = new mapboxgl.NavigationControl(props.options)\n break\n case 'scale':\n control = new mapboxgl.ScaleControl(props.options)\n break\n case 'attribution':\n control = new mapboxgl.AttributionControl(props.options)\n break\n case 'fullscreen':\n control = new mapboxgl.FullscreenControl(props.options)\n break\n case 'geolocate':\n control = new mapboxgl.GeolocateControl(props.options)\n break\n // case 'language':\n // const MapboxLanguage = (await import('@mapbox/mapbox-gl-language'))\n // .default\n // control = new MapboxLanguage(props.options)\n // break\n // case 'traffic':\n // const MapboxTraffic = (await import('@mapbox/mapbox-gl-traffic'))\n // .default\n // await import('@mapbox/mapbox-gl-traffic/mapbox-gl-traffic.css')\n // control = new MapboxTraffic(props.options)\n // break\n }\n control && map().addControl(control, props.position)\n setControl(control)\n })\n\n onCleanup(() => map().removeControl(control()))\n\n return props.children\n}\n\nexport default Control\n","import { onMount, onCleanup, createEffect, Component, children } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport mapboxgl from 'mapbox-gl'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type { MarkerSpecification } from 'mapbox-gl/src/style-spec/types.js'\nimport type { LngLatLike } from 'mapbox-gl/src/geo/lng_lat.js'\n\nconst Marker: Component<{\n options?: MarkerSpecification\n lnglat: LngLatLike\n}> = props => {\n const map: MapboxMap = useMap()\n let marker = null\n\n // Add Marker\n onMount(async () => {\n marker = new mapboxgl.Marker(props.options)\n .setLngLat(props.lnglat)\n .setPopup(\n props.children\n ? new mapboxgl.Popup().setDOMContent(<div>{props.children}</div>)\n : null\n )\n .addTo(map())\n })\n // Remove Marker\n onCleanup(() => marker.remove())\n\n // Update Position\n createEffect(() => marker.setLngLat(props.lnglat))\n\n return <></>\n}\n\nexport default Marker\n","import { onMount, onCleanup, createEffect, Component } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport mapboxgl from 'mapbox-gl'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type { PopupSpecification } from 'mapbox-gl/src/style-spec/types.js'\nimport type { LngLatLike } from 'mapbox-gl/src/geo/lng_lat.js'\n\nconst Popup: Component<{\n options?: PopupSpecification\n lnglat: LngLatLike\n}> = props => {\n const map: MapboxMap = useMap()\n let popup = null\n\n // Add Popup\n onMount(async () => {\n popup = new mapboxgl.Popup(props.options)\n .setLngLat(props.lnglat)\n .setDOMContent(<div>{props.children}</div>)\n .addTo(map())\n })\n // Remove Popup\n onCleanup(() => popup.remove())\n\n // Update Position\n createEffect(() => popup.setLngLat(props.lnglat))\n\n // Update Content\n createEffect(() => popup.setDOMContent(<div>{props.children}</div>))\n\n return <></>\n}\n\nexport default Popup\n","import { onMount, onCleanup, createEffect, Component } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type {\n StyleImageInterface,\n StyleImageMetadata,\n} from 'mapbox-gl/src/style/style_image'\n\nconst Image: Component<{\n id: string\n url?: string\n image?:\n | HTMLImageElement\n | ImageBitmap\n | ImageData\n | { width: number; height: number; data: Uint8Array | Uint8ClampedArray }\n | StyleImageInterface\n options?: StyleImageMetadata\n}> = props => {\n const map: MapboxMap = useMap()\n // Add Image\n onMount(async () => {\n !map().isStyleLoaded() && (await map().once('styledata'))\n if (props.url) {\n map().loadImage(props.url, (error, image) => {\n if (error) throw error\n !map().hasImage(props.id) && map().addImage(props.id, image)\n })\n } else {\n !map().hasImage(props.id) &&\n map().addImage(props.id, props.image, props.options)\n }\n })\n // Remove Image\n onCleanup(() => map().hasImage(props.id) && map().removeImage(props.id))\n\n // Update Image\n createEffect(async () => {\n if (props.image && props.url) return\n\n if (props.url) {\n map().loadImage(props.url, (error, image) => {\n if (error) throw error\n !map().hasImage(props.id) && map().updateImage(props.id, image)\n })\n } else {\n map().hasImage(props.id) && map().updateImage(props.id, props.image)\n }\n })\n\n return <></>\n}\n\nexport default Image\n"],"names":["pending","start","useTransition","MapContext","createContext","useMap","useContext","MapGL","props","map","mapRef","onCleanup","remove","onMount","mapboxgl","Map","options","container","bounds","viewport","center","zoom","pitch","bearing","fitBoundsOptions","padding","createEffect","onMouseMove","on","event","lngLat","_onViewportChange","getCenter","getZoom","getPitch","getBearing","onViewportChange","async","fitBounds","index","triggerResize","window","requestAnimationFrame","loop","resize","children","class","classList","SourceContext","useSource","SourceComponent","id","createUniqueId","isStyleLoaded","once","getSource","addSource","source","getStyle","layers","forEach","layer","removeLayer","removeSource","type","data","setData","diff","newProps","prevProps","Set","Object","keys","reduce","acc","key","value","push","Layer","getLayer","addLayer","style","beforeType","find","l","beforeId","prev","paint","setPaintProperty","layout","setLayoutProperty","minzoom","maxzoom","max","setLayerZoomRange","undefined","visible","validate","filter","setFilter","featureState","loaded","removeFeatureState","sourceLayer","setFeatureState","state","Fog","setFog","Sky","layerId","Terrain","setTerrain","Control","control","setControl","createSignal","NavigationControl","ScaleControl","AttributionControl","FullscreenControl","GeolocateControl","addControl","position","removeControl","Marker","marker","setLngLat","lnglat","setPopup","Popup","setDOMContent","addTo","popup","Image","url","loadImage","error","image","hasImage","addImage","removeImage","updateImage"],"mappings":"8QA0BM,CAACA,QAASC,OAASC,gBAEnBC,WAAaC,gBACbC,OAAS,IAAMC,WAAWH,YAE1BI,MAWDC,QACCC,EACAC,EAEJC,UAAU,IAAMF,EAAIG,UAEpBC,QAAQ,KACNJ,EAAM,IAAIK,SAASC,IAAI,IAClBP,EAAMQ,QACTC,UAAWP,EACXQ,OAAQV,EAAMW,SAASD,OACvBE,OAAQZ,EAAMW,SAASC,OACvBC,KAAMb,EAAMW,SAASE,MAAQ,KAC7BC,MAAOd,EAAMW,SAASG,OAAS,KAC/BC,QAASf,EAAMW,SAASI,SAAW,KACnCC,iBAAkB,CAAEC,QAASjB,EAAMW,SAASM,aAIhDC,aACE,IACElB,EAAMmB,aACNlB,EAAImB,GAAG,YAAaC,GAASrB,EAAMmB,YAAYE,EAAMC,gBAGnDC,EAAoB,SAClBZ,EAAqB,CACzBC,OAAQX,EAAIuB,YACZX,KAAMZ,EAAIwB,UACVX,MAAOb,EAAIyB,WACXX,QAASd,EAAI0B,aACbV,QAASjB,EAAMW,SAASM,SAE1BjB,EAAM4B,iBA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EAAiBJ,aACnB+H,EAAQ,YAGZvH,QAAQwB,gBACN+F,EAAQ,IAAItH,SAASmH,MAAMzH,EAAMQ,SAC9B8G,UAAUtH,EAAMuH,QAChBG,mDAAoB1H,EAAMqC,cAC1BsF,MAAM1H,OAGXE,UAAU,IAAMyH,EAAMxH,UAGtBc,aAAa,IAAM0G,EAAMN,UAAUtH,EAAMuH,SAGzCrG,aAAa,IAAM0G,EAAMF,mEAAoB1H,EAAMqC,sBCpB/CwF,MAUD7H,UACGC,EAAiBJ,gBAEvBQ,QAAQwB,UACL5B,IAAM4C,uBAA0B5C,IAAM6C,KAAK,aACxC9C,EAAM8H,IACR7H,IAAM8H,UAAU/H,EAAM8H,IAAK,CAACE,EAAOC,QAC7BD,EAAO,MAAMA,EAChB/H,IAAMiI,SAASlI,EAAM2C,KAAO1C,IAAMkI,SAASnI,EAAM2C,GAAIsF,KAGvDhI,IAAMiI,SAASlI,EAAM2C,KACpB1C,IAAMkI,SAASnI,EAAM2C,GAAI3C,EAAMiI,MAAOjI,EAAMQ,WAIlDL,UAAU,IAAMF,IAAMiI,SAASlI,EAAM2C,KAAO1C,IAAMmI,YAAYpI,EAAM2C,KAGpEzB,aAAaW,UACP7B,EAAMiI,OAASjI,EAAM8H,MAErB9H,EAAM8H,IACR7H,IAAM8H,UAAU/H,EAAM8H,IAAK,CAACE,EAAOC,QAC7BD,EAAO,MAAMA,EAChB/H,IAAMiI,SAASlI,EAAM2C,KAAO1C,IAAMoI,YAAYrI,EAAM2C,GAAIsF,KAG3DhI,IAAMiI,SAASlI,EAAM2C,KAAO1C,IAAMoI,YAAYrI,EAAM2C,GAAI3C,EAAMiI"}
1
+ {"version":3,"file":"index.js","sources":["../../src/components/MapGL/index.tsx","../../src/components/Source/index.tsx","../../src/components/Layer/index.tsx","../../src/components/Fog/index.tsx","../../src/components/Sky/index.tsx","../../src/components/Terrain/index.tsx","../../src/components/Control/index.tsx","../../src/components/Marker/index.tsx","../../src/components/Popup/index.tsx","../../src/components/Image/index.tsx"],"sourcesContent":["import {\n createEffect,\n onMount,\n onCleanup,\n createContext,\n useContext,\n Component,\n useTransition,\n} from 'solid-js'\nimport mapboxgl from 'mapbox-gl'\nimport 'mapbox-gl/dist/mapbox-gl.css'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type MapboxOptions from 'mapbox-gl/src/ui/map'\nimport type MapMouseEvent from 'mapbox-gl/src/ui/events'\nimport type { LngLatLike } from 'mapbox-gl/src/geo/lng_lat.js'\nimport type { LngLatBounds } from 'mapbox-gl/src/geo/lng_lat_bounds.js'\n\nexport type Viewport = {\n center?: LngLatLike\n bounds?: LngLatBounds\n zoom?: number\n pitch?: number\n bearing?: number\n padding?: number\n}\n\nenum Type {\n flyTo = 'flyTo',\n easeTo = 'easeTo',\n jumpTo = 'jumpTo',\n}\n\nconst [pending, start] = useTransition()\n\nconst MapContext = createContext<MapboxMap>()\nconst useMap = () => useContext(MapContext)\n\nconst MapGL: Component<{\n class?: string\n classList?: {\n [k: string]: boolean | undefined\n }\n viewport?: Viewport\n options?: MapboxOptions\n children?: Element[]\n triggerResize?: boolean\n transitionType?: Type\n onMouseMove?: (event: MapMouseEvent) => void\n onViewportChange?: (viewport: Viewport) => void\n}> = props => {\n let map: MapboxMap\n let mapRef: HTMLElement\n\n onCleanup(() => map.remove())\n\n onMount(() => {\n map = new mapboxgl.Map({\n ...props.options,\n container: mapRef,\n bounds: props.viewport.bounds,\n center: props.viewport.center,\n zoom: props.viewport.zoom || null,\n pitch: props.viewport.pitch || null,\n bearing: props.viewport.bearing || null,\n fitBoundsOptions: { padding: props.viewport.padding },\n } as MapboxOptions)\n })\n\n createEffect(\n () =>\n props.onMouseMove &&\n map.on('mousemove', event => props.onMouseMove(event.lngLat))\n )\n\n const _onViewportChange = evt => {\n if (evt.isInternal) return\n const viewport: Viewport = {\n center: map.getCenter(),\n zoom: map.getZoom(),\n pitch: map.getPitch(),\n bearing: map.getBearing(),\n padding: props.viewport.padding,\n bounds: props.viewport.bounds,\n }\n props.onViewportChange(viewport)\n }\n\n createEffect(\n () =>\n props.onViewportChange &&\n map\n .on('dragend', _onViewportChange)\n .on('moveend', _onViewportChange)\n .on('zoomend', _onViewportChange)\n .on('rotateend', _onViewportChange)\n .on('pitchend', _onViewportChange)\n .on('boxzoomend', _onViewportChange)\n )\n\n createEffect(prev => {\n if (props.viewport.bounds != prev) {\n const camera = map.cameraForBounds(props.viewport.bounds, {\n padding: props.viewport.padding,\n })\n props.onViewportChange({\n ...props.viewport,\n ...camera,\n })\n }\n return props.viewport.bounds\n }, props.viewport.bounds)\n\n createEffect(async (prev: Viewport) => {\n const vp: Viewport = props.viewport\n const nvp: Viewport = {\n ...(vp.zoom != prev.zoom && { zoom: vp.zoom }),\n ...(vp.padding != prev.padding && { padding: vp.padding }),\n ...(vp.bearing != prev.bearing && { bearing: vp.bearing }),\n ...(vp.pitch != prev.pitch && { pitch: vp.pitch }),\n ...(vp.center != prev.center && {\n center: vp.center.lng ? [vp.center.lng, vp.center.lat] : vp.center,\n }),\n }\n if (Object.keys(nvp).length) {\n map.stop()\n switch (props.transitionType) {\n case 'easeTo':\n map.easeTo(nvp, { isInternal: true })\n case 'jumpTo':\n map.jumpTo(nvp, { isInternal: true })\n default:\n map.flyTo(nvp, { isInternal: true })\n }\n }\n return vp\n }, props.viewport)\n\n let index = 0\n\n createEffect(() => {\n if (props.triggerResize) {\n index = 0\n window.requestAnimationFrame(function loop() {\n if (index < 15) {\n index++\n window.requestAnimationFrame(loop)\n start(() => map.resize())\n }\n })\n }\n })\n\n return (\n <MapContext.Provider value={() => map}>\n <main\n ref={mapRef}\n class={props.class || ''}\n classList={props.classList}\n style={{ height: '100%', width: '100%' }}>\n {props.children}\n </main>\n </MapContext.Provider>\n )\n}\n\nexport { MapGL as default, useMap }\n","import {\n onMount,\n onCleanup,\n createEffect,\n Component,\n createContext,\n useContext,\n createUniqueId,\n} from 'solid-js'\nimport { useMap } from '../MapGL'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type {\n Source,\n SourceSpecification,\n} from 'mapbox-gl/src/style-spec/types.js'\n\nconst SourceContext = createContext<Source>()\n\nconst useSource = (): Source => useContext(SourceContext)\n\nconst SourceComponent: Component<{\n id?: string\n source: SourceSpecification\n}> = props => {\n const map: MapboxMap = useMap()\n props.id = props.id || createUniqueId()\n // Add Source\n onMount(async () => {\n !map().isStyleLoaded() && (await map().once('styledata'))\n !map().getSource(props.id) && map().addSource(props.id, props.source)\n })\n\n // Remove Source\n onCleanup(() => {\n map()\n .getStyle()\n .layers.forEach(\n layer => layer.source === props.id && map().removeLayer(layer.id)\n )\n map().getSource(props.id) && map().removeSource(props.id)\n })\n\n // Update GeoJSON Data\n createEffect(async () => {\n if (props.source.type !== 'geojson' && !props.source.data) return\n\n map().getSource(props.id) &&\n map().getSource(props.id).setData(props.source.data)\n })\n\n return (\n <SourceContext.Provider value={{ id: props.id }}>\n {props.children}\n </SourceContext.Provider>\n )\n}\n\nexport { SourceComponent as default, useSource }\n","import { onMount, createEffect, Component, createUniqueId } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport { useSource } from '../Source'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type {\n FilterSpecification,\n StyleSpecification,\n SourceSpecification,\n} from 'mapbox-gl/src/style-spec/types.js'\nimport type { CustomLayerInterface } from 'mapbox-gl/src/style/style_layer/custom_style_layer'\n\nconst diff = (\n newProps: StyleSpecification = {},\n prevProps: StyleSpecification = {}\n) => {\n const keys = new Set([...Object.keys(newProps), ...Object.keys(prevProps)])\n return [...keys].reduce((acc, key: string) => {\n const value = newProps[key]\n if (value !== prevProps[key]) {\n acc.push([key, value])\n }\n return acc\n }, [])\n}\n\nconst Layer: Component<{\n id?: string\n style?: StyleSpecification\n layer?: CustomLayerInterface\n filter?: FilterSpecification\n visible?: boolean\n sourceId?: string\n beforeType?:\n | 'background'\n | 'fill'\n | 'line'\n | 'symbol'\n | 'raster'\n | 'circle'\n | 'fill-extrusion'\n | 'heatmap'\n | 'hillshade'\n | 'sky'\n beforeId?: string\n featureState?: { id: number | string; state: object }\n}> = props => {\n const map: MapboxMap = useMap()\n const source: SourceSpecification = useSource()\n props.id = props.id || createUniqueId()\n // Add Layer\n onMount(async () => {\n !map().isStyleLoaded() && (await map().once('styledata'))\n\n if (map().getLayer(props.id)) return\n\n map().addLayer(\n props.layer || {\n ...props.style,\n id: props.id,\n source: source.id,\n },\n props.beforeType\n ? map()\n .getStyle()\n .layers.find(l => l.type === props.beforeType).id\n : props.beforeId\n )\n })\n\n // Update Style\n createEffect((prev: StyleSpecification) => {\n if (\n !props.style ||\n !map().getSource(source.id) ||\n !map().getLayer(props.id)\n )\n return\n\n if (props.style.layout !== prev?.layout)\n diff(props.style.layout, prev?.layout).forEach(([key, value]) =>\n map().setLayoutProperty(props.id, key, value, { validate: false })\n )\n\n if (props.style.paint !== prev?.paint)\n diff(props.style.paint, prev?.paint).forEach(([key, value]) =>\n map().setPaintProperty(props.id, key, value, { validate: false })\n )\n\n if (\n props.style.minzoom !== prev?.minzoom ||\n props.style.maxzoom !== prev?.maxzoom\n )\n map().setLayerZoomRange(\n props.id,\n props.style.minzoom,\n props.style.maxzoom\n )\n\n if (props.style.filter !== prev?.filter)\n map().setFilter(props.id, props.style.filter, { validate: false })\n\n return props.style\n }, props.style)\n\n // Update Visibility\n createEffect((prev: boolean) => {\n if (\n props.visible === undefined ||\n props.visible === prev ||\n !map().getSource(source.id) ||\n !map().getLayer(props.id)\n )\n return\n\n map().setLayoutProperty(\n props.id,\n 'visibility',\n props.visible ? 'visible' : 'none',\n { validate: false }\n )\n return props.visible\n }, props.visible)\n\n // Update Filter\n createEffect(async () => {\n if (!props.filter) return\n\n !map().isStyleLoaded() && (await map().once('styledata'))\n map().setFilter(props.id, props.filter)\n })\n\n // Update Feature State\n createEffect(async () => {\n if (!props.featureState || !props.featureState.id) return\n\n !map().isStyleLoaded() && (await map().once('styledata'))\n\n map().removeFeatureState({\n source: source.id,\n sourceLayer: props.style['source-layer'],\n })\n map().setFeatureState(\n {\n source: source.id,\n sourceLayer: props.style['source-layer'],\n id: props.featureState.id,\n },\n props.featureState.state\n )\n })\n\n return props.children\n}\n\nexport default Layer\n","import { onMount, onCleanup, createEffect, Component } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type { FogSpecification } from 'mapbox-gl/src/style-spec/types.js'\n\nconst Fog: Component<{\n style: FogSpecification\n visible?: boolean\n}> = props => {\n const map: MapboxMap = useMap()\n // Add Fog Layer\n onMount(async () => {\n !map().isStyleLoaded() && (await map().once('styledata'))\n map().setFog(props.style)\n })\n // Remove Fog Layer\n onCleanup(() => map().setFog(null))\n\n // Update Visibility\n createEffect(async () => {\n if (props.visible === undefined) return\n\n !map().isStyleLoaded() && (await map().once('styledata'))\n map().setFog(props.visible ? props.style : null)\n })\n\n return props.children\n}\n\nexport default Fog\n","import { onMount, onCleanup, createEffect, Component } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type { StyleSpecification } from 'mapbox-gl/src/style-spec/types.js'\n\nconst Sky: Component<{\n style: StyleSpecification\n visible?: boolean\n}> = props => {\n const map: MapboxMap = useMap()\n const layerId = '_sky'\n // Add Sky Layer\n onMount(async () => {\n !map().isStyleLoaded() && (await map().once('styledata'))\n !map().getLayer(layerId) && map().addLayer({ ...props.style, id: layerId })\n })\n\n // Remove Sky Layer\n onCleanup(() => map().getLayer(layerId) && map().removeLayer(layerId))\n\n // Update Visibility\n createEffect(async () => {\n if (props.visible === undefined) return\n\n !map().isStyleLoaded() && (await map().once('styledata'))\n map().setLayoutProperty(\n layerId,\n 'visibility',\n props.visible ? 'visible' : 'none'\n )\n })\n\n return props.children\n}\n\nexport default Sky\n","import { onMount, onCleanup, createEffect, Component } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport { useSource } from '../Source'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type {\n TerrainSpecification,\n SourceSpecification,\n} from 'mapbox-gl/src/style-spec/types.js'\n\nconst Terrain: Component<{\n style: TerrainSpecification\n visible?: boolean\n}> = props => {\n const map: MapboxMap = useMap()\n const source: SourceSpecification = useSource()\n\n // Add Terrain Layer\n onMount(async () => {\n !map().isStyleLoaded() && (await map().once('styledata'))\n map().setTerrain({ ...props.style, source: source.id })\n })\n\n // Remove Terrain Layer\n onCleanup(() => map().setTerrain(null))\n\n // Update Visibility\n createEffect(async () => {\n if (props.visible === undefined) return\n\n !map().isStyleLoaded() && (await map().once('styledata'))\n map().setTerrain(props.visible ? props.style : null)\n })\n\n return props.children\n}\n\nexport default Terrain\n","import { onMount, onCleanup, createSignal, Component, lazy } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport mapboxgl from 'mapbox-gl'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type { Options as AttributionOptions } from 'mapbox-gl/src/ui/control/attribution_control'\nimport type { Options as FullscreenOptions } from 'mapbox-gl/src/ui/control/fullscreen_control'\nimport type { Options as GeolocateOptions } from 'mapbox-gl/src/ui/control/geolocate_control'\nimport type { Options as NavigationOptions } from 'mapbox-gl/src/ui/control/navigation_control'\nimport type { Options as ScaleOptions } from 'mapbox-gl/src/ui/control/scale_control'\n\nconst Control: Component<{\n type:\n | 'navigation'\n | 'scale'\n | 'attribution'\n | 'fullscreen'\n | 'geolocate'\n | 'language'\n | 'traffic'\n options?:\n | NavigationOptions\n | ScaleOptions\n | AttributionOptions\n | FullscreenOptions\n | GeolocateOptions\n position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'\n}> = props => {\n const map: MapboxMap = useMap()\n const [control, setControl] = createSignal(null)\n // Add Control\n onMount(async () => {\n let control\n\n switch (props.type) {\n case 'navigation':\n control = new mapboxgl.NavigationControl(props.options)\n break\n case 'scale':\n control = new mapboxgl.ScaleControl(props.options)\n break\n case 'attribution':\n control = new mapboxgl.AttributionControl(props.options)\n break\n case 'fullscreen':\n control = new mapboxgl.FullscreenControl(props.options)\n break\n case 'geolocate':\n control = new mapboxgl.GeolocateControl(props.options)\n break\n // case 'language':\n // // @ts-ignore\n // const MapboxLanguage = (await import('@mapbox/mapbox-gl-language'))\n // .default\n // control = new MapboxLanguage(props.options)\n // break\n // case 'traffic':\n // // @ts-ignore\n // const MapboxTraffic = (await import('@mapbox/mapbox-gl-traffic'))\n // .default\n // // @ts-ignore\n // await import('@mapbox/mapbox-gl-traffic/mapbox-gl-traffic.css')\n // control = new MapboxTraffic(props.options)\n // break\n }\n control && map().addControl(control, props.position)\n setControl(control)\n })\n\n onCleanup(() => map().removeControl(control()))\n\n return props.children\n}\n\nexport default Control\n","import { onMount, onCleanup, createEffect, Component, children } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport mapboxgl from 'mapbox-gl'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type { MarkerSpecification } from 'mapbox-gl/src/style-spec/types.js'\nimport type { LngLatLike } from 'mapbox-gl/src/geo/lng_lat.js'\n\nconst Marker: Component<{\n options?: MarkerSpecification\n lnglat: LngLatLike\n}> = props => {\n const map: MapboxMap = useMap()\n let marker = null\n\n // Add Marker\n onMount(async () => {\n marker = new mapboxgl.Marker(props.options)\n .setLngLat(props.lnglat)\n .setPopup(\n props.children\n ? new mapboxgl.Popup().setDOMContent(<div>{props.children}</div>)\n : null\n )\n .addTo(map())\n })\n // Remove Marker\n onCleanup(() => marker.remove())\n\n // Update Position\n createEffect(() => marker.setLngLat(props.lnglat))\n\n return <></>\n}\n\nexport default Marker\n","import { onMount, onCleanup, createEffect, Component } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport mapboxgl from 'mapbox-gl'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type { PopupSpecification } from 'mapbox-gl/src/style-spec/types.js'\nimport type { LngLatLike } from 'mapbox-gl/src/geo/lng_lat.js'\n\nconst Popup: Component<{\n options?: PopupSpecification\n lnglat: LngLatLike\n}> = props => {\n const map: MapboxMap = useMap()\n let popup = null\n\n // Add Popup\n onMount(async () => {\n popup = new mapboxgl.Popup(props.options)\n .setLngLat(props.lnglat)\n .setDOMContent(<div>{props.children}</div>)\n .addTo(map())\n })\n // Remove Popup\n onCleanup(() => popup.remove())\n\n // Update Position\n createEffect(() => popup.setLngLat(props.lnglat))\n\n // Update Content\n createEffect(() => popup.setDOMContent(<div>{props.children}</div>))\n\n return <></>\n}\n\nexport default Popup\n","import { onMount, onCleanup, createEffect, Component } from 'solid-js'\nimport { useMap } from '../MapGL'\nimport type MapboxMap from 'mapbox-gl/src/ui/map'\nimport type {\n StyleImageInterface,\n StyleImageMetadata,\n} from 'mapbox-gl/src/style/style_image'\n\nconst Image: Component<{\n id: string\n url?: string\n image?:\n | HTMLImageElement\n | ImageBitmap\n | ImageData\n | { width: number; height: number; data: Uint8Array | Uint8ClampedArray }\n | StyleImageInterface\n options?: StyleImageMetadata\n}> = props => {\n const map: MapboxMap = useMap()\n // Add Image\n onMount(async () => {\n !map().isStyleLoaded() && (await map().once('styledata'))\n if (props.url) {\n map().loadImage(props.url, (error, image) => {\n if (error) throw error\n !map().hasImage(props.id) && map().addImage(props.id, image)\n })\n } else {\n !map().hasImage(props.id) &&\n map().addImage(props.id, props.image, props.options)\n }\n })\n // Remove Image\n onCleanup(() => map().hasImage(props.id) && map().removeImage(props.id))\n\n // Update Image\n createEffect(async () => {\n if (props.image && props.url) return\n\n if (props.url) {\n map().loadImage(props.url, (error, image) => {\n if (error) throw error\n !map().hasImage(props.id) && map().updateImage(props.id, image)\n })\n } else {\n map().hasImage(props.id) && map().updateImage(props.id, props.image)\n }\n })\n\n return <></>\n}\n\nexport default Image\n"],"names":["Type","pending","start","useTransition","MapContext","createContext","useMap","useContext","MapGL","props","map","mapRef","onCleanup","remove","onMount","mapboxgl","Map","options","container","bounds","viewport","center","zoom","pitch","bearing","fitBoundsOptions","padding","createEffect","onMouseMove","on","event","lngLat","_onViewportChange","evt","isInternal","getCenter","getZoom","getPitch","getBearing","onViewportChange","prev","camera","cameraForBounds","vp","nvp","lng","lat","Object","keys","length","stop","transitionType","easeTo","jumpTo","flyTo","index","triggerResize","window","requestAnimationFrame","loop","resize","Provider","value","children","class","classList","SourceContext","useSource","SourceComponent","id","createUniqueId","async","isStyleLoaded","once","getSource","addSource","source","getStyle","layers","forEach","layer","removeLayer","removeSource","type","data","setData","diff","newProps","prevProps","Set","reduce","acc","key","push","Layer","getLayer","addLayer","style","beforeType","find","l","beforeId","layout","setLayoutProperty","validate","paint","setPaintProperty","minzoom","maxzoom","setLayerZoomRange","filter","setFilter","undefined","visible","featureState","removeFeatureState","sourceLayer","setFeatureState","state","Fog","setFog","Sky","layerId","Terrain","setTerrain","Control","control","setControl","createSignal","NavigationControl","ScaleControl","AttributionControl","FullscreenControl","GeolocateControl","addControl","position","removeControl","Marker","marker","setLngLat","lnglat","setPopup","Popup","setDOMContent","addTo","popup","Image","url","loadImage","error","image","hasImage","addImage","removeImage","updateImage"],"mappings":"kRA0BKA,eAAAA,GAAAA,gBAAAA,kBAAAA,mBAAAA,KAAAA,UAML,KAAM,CAACC,QAASC,OAASC,gBAEnBC,WAAaC,gBACbC,OAAS,IAAMC,WAAWH,YAE1BI,MAYDC,QACCC,EACAC,EAEJC,UAAU,IAAMF,EAAIG,UAEpBC,QAAQ,KACNJ,EAAM,IAAIK,SAASC,IAAI,IAClBP,EAAMQ,QACTC,UAAWP,EACXQ,OAAQV,EAAMW,SAASD,OACvBE,OAAQZ,EAAMW,SAASC,OACvBC,KAAMb,EAAMW,SAASE,MAAQ,KAC7BC,MAAOd,EAAMW,SAASG,OAAS,KAC/BC,QAASf,EAAMW,SAASI,SAAW,KACnCC,iBAAkB,CAAEC,QAASjB,EAAMW,SAASM,aAIhDC,aACE,IACElB,EAAMmB,aACNlB,EAAImB,GAAG,YAAaC,GAASrB,EAAMmB,YAAYE,EAAMC,gBAGnDC,EAAoBC,IACpBA,EAAIC,aACFd,EAAqB,CACzBC,OAAQX,EAAIyB,YACZb,KAAMZ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l(props.options);
25
25
  break;
26
26
  // case 'language':
27
+ // // @ts-ignore
27
28
  // const MapboxLanguage = (await import('@mapbox/mapbox-gl-language'))
28
29
  // .default
29
30
  // control = new MapboxLanguage(props.options)
30
31
  // break
31
32
  // case 'traffic':
33
+ // // @ts-ignore
32
34
  // const MapboxTraffic = (await import('@mapbox/mapbox-gl-traffic'))
33
35
  // .default
36
+ // // @ts-ignore
34
37
  // await import('@mapbox/mapbox-gl-traffic/mapbox-gl-traffic.css')
35
38
  // control = new MapboxTraffic(props.options)
36
39
  // break
@@ -23,7 +23,7 @@ const Layer = props => {
23
23
  map().addLayer(props.layer || {
24
24
  ...props.style,
25
25
  id: props.id,
26
- source: source.source,
26
+ source: source.id,
27
27
  }, props.beforeType
28
28
  ? map()
29
29
  .getStyle()
@@ -32,22 +32,31 @@ const Layer = props => {
32
32
  });
33
33
  // Update Style
34
34
  createEffect((prev) => {
35
- if (!props.style && map().getLayer(props.id))
35
+ if (!props.style ||
36
+ !map().getSource(source.id) ||
37
+ !map().getLayer(props.id))
36
38
  return;
37
- diff(props.style.paint, prev.paint).forEach(([key, value]) => map().setPaintProperty(props.id, key, value));
38
- diff(props.style.layout, prev.layout).forEach(([key, value]) => map().setLayoutProperty(props.id, key, value));
39
- if (props.style.minzoom !== prev.minzoom ||
40
- props.style.maxzoom !== prev.max)
39
+ if (props.style.layout !== prev?.layout)
40
+ diff(props.style.layout, prev?.layout).forEach(([key, value]) => map().setLayoutProperty(props.id, key, value, { validate: false }));
41
+ if (props.style.paint !== prev?.paint)
42
+ diff(props.style.paint, prev?.paint).forEach(([key, value]) => map().setPaintProperty(props.id, key, value, { validate: false }));
43
+ if (props.style.minzoom !== prev?.minzoom ||
44
+ props.style.maxzoom !== prev?.maxzoom)
41
45
  map().setLayerZoomRange(props.id, props.style.minzoom, props.style.maxzoom);
46
+ if (props.style.filter !== prev?.filter)
47
+ map().setFilter(props.id, props.style.filter, { validate: false });
42
48
  return props.style;
43
49
  }, props.style);
44
50
  // Update Visibility
45
- createEffect(async () => {
46
- if (props.visible === undefined)
51
+ createEffect((prev) => {
52
+ if (props.visible === undefined ||
53
+ props.visible === prev ||
54
+ !map().getSource(source.id) ||
55
+ !map().getLayer(props.id))
47
56
  return;
48
- !map().isStyleLoaded() && (await map().once('styledata'));
49
57
  map().setLayoutProperty(props.id, 'visibility', props.visible ? 'visible' : 'none', { validate: false });
50
- });
58
+ return props.visible;
59
+ }, props.visible);
51
60
  // Update Filter
52
61
  createEffect(async () => {
53
62
  if (!props.filter)
@@ -59,13 +68,13 @@ const Layer = props => {
59
68
  createEffect(async () => {
60
69
  if (!props.featureState || !props.featureState.id)
61
70
  return;
62
- map().loaded() ? null : await map().once('render');
71
+ !map().isStyleLoaded() && (await map().once('styledata'));
63
72
  map().removeFeatureState({
64
- source: source.source,
73
+ source: source.id,
65
74
  sourceLayer: props.style['source-layer'],
66
75
  });
67
76
  map().setFeatureState({
68
- source: source.source,
77
+ source: source.id,
69
78
  sourceLayer: props.style['source-layer'],
70
79
  id: props.featureState.id,
71
80
  }, props.featureState.state);
@@ -1,6 +1,12 @@
1
1
  import { createEffect, onMount, onCleanup, createContext, useContext, useTransition, } from 'solid-js';
2
2
  import mapboxgl from 'mapbox-gl';
3
3
  import 'mapbox-gl/dist/mapbox-gl.css';
4
+ var Type;
5
+ (function (Type) {
6
+ Type["flyTo"] = "flyTo";
7
+ Type["easeTo"] = "easeTo";
8
+ Type["jumpTo"] = "jumpTo";
9
+ })(Type || (Type = {}));
4
10
  const [pending, start] = useTransition();
5
11
  const MapContext = createContext();
6
12
  const useMap = () => useContext(MapContext);
@@ -22,13 +28,16 @@ const MapGL = props => {
22
28
  });
23
29
  createEffect(() => props.onMouseMove &&
24
30
  map.on('mousemove', event => props.onMouseMove(event.lngLat)));
25
- const _onViewportChange = () => {
31
+ const _onViewportChange = evt => {
32
+ if (evt.isInternal)
33
+ return;
26
34
  const viewport = {
27
35
  center: map.getCenter(),
28
36
  zoom: map.getZoom(),
29
37
  pitch: map.getPitch(),
30
38
  bearing: map.getBearing(),
31
39
  padding: props.viewport.padding,
40
+ bounds: props.viewport.bounds,
32
41
  };
33
42
  props.onViewportChange(viewport);
34
43
  };
@@ -40,13 +49,42 @@ const MapGL = props => {
40
49
  .on('rotateend', _onViewportChange)
41
50
  .on('pitchend', _onViewportChange)
42
51
  .on('boxzoomend', _onViewportChange));
43
- createEffect(async () => {
44
- if (!props.viewport.bounds)
45
- return;
46
- map.fitBounds(props.viewport.bounds, {
47
- padding: props.viewport.padding,
48
- });
49
- });
52
+ createEffect(prev => {
53
+ if (props.viewport.bounds != prev) {
54
+ const camera = map.cameraForBounds(props.viewport.bounds, {
55
+ padding: props.viewport.padding,
56
+ });
57
+ props.onViewportChange({
58
+ ...props.viewport,
59
+ ...camera,
60
+ });
61
+ }
62
+ return props.viewport.bounds;
63
+ }, props.viewport.bounds);
64
+ createEffect(async (prev) => {
65
+ const vp = props.viewport;
66
+ const nvp = {
67
+ ...(vp.zoom != prev.zoom && { zoom: vp.zoom }),
68
+ ...(vp.padding != prev.padding && { padding: vp.padding }),
69
+ ...(vp.bearing != prev.bearing && { bearing: vp.bearing }),
70
+ ...(vp.pitch != prev.pitch && { pitch: vp.pitch }),
71
+ ...(vp.center != prev.center && {
72
+ center: vp.center.lng ? [vp.center.lng, vp.center.lat] : vp.center,
73
+ }),
74
+ };
75
+ if (Object.keys(nvp).length) {
76
+ map.stop();
77
+ switch (props.transitionType) {
78
+ case 'easeTo':
79
+ map.easeTo(nvp, { isInternal: true });
80
+ case 'jumpTo':
81
+ map.jumpTo(nvp, { isInternal: true });
82
+ default:
83
+ map.flyTo(nvp, { isInternal: true });
84
+ }
85
+ }
86
+ return vp;
87
+ }, props.viewport);
50
88
  let index = 0;
51
89
  createEffect(() => {
52
90
  if (props.triggerResize) {
@@ -24,7 +24,7 @@ const SourceComponent = props => {
24
24
  map().getSource(props.id) &&
25
25
  map().getSource(props.id).setData(props.source.data);
26
26
  });
27
- return (<SourceContext.Provider value={{ source: props.id }}>
27
+ return (<SourceContext.Provider value={{ id: props.id }}>
28
28
  {props.children}
29
29
  </SourceContext.Provider>);
30
30
  };
@@ -7,7 +7,7 @@ const Terrain = props => {
7
7
  // Add Terrain Layer
8
8
  onMount(async () => {
9
9
  !map().isStyleLoaded() && (await map().once('styledata'));
10
- map().setTerrain({ ...props.style, source: source.source });
10
+ map().setTerrain({ ...props.style, source: source.id });
11
11
  });
12
12
  // Remove Terrain Layer
13
13
  onCleanup(() => map().setTerrain(null));
@@ -12,6 +12,11 @@ export declare type Viewport = {
12
12
  bearing?: number;
13
13
  padding?: number;
14
14
  };
15
+ declare enum Type {
16
+ flyTo = "flyTo",
17
+ easeTo = "easeTo",
18
+ jumpTo = "jumpTo"
19
+ }
15
20
  declare const useMap: () => MapboxMap;
16
21
  declare const MapGL: Component<{
17
22
  class?: string;
@@ -20,8 +25,9 @@ declare const MapGL: Component<{
20
25
  };
21
26
  viewport?: Viewport;
22
27
  options?: MapboxOptions;
23
- children?: Component[] | Component;
28
+ children?: Element[];
24
29
  triggerResize?: boolean;
30
+ transitionType?: Type;
25
31
  onMouseMove?: (event: MapMouseEvent) => void;
26
32
  onViewportChange?: (viewport: Viewport) => void;
27
33
  }>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.3",
2
+ "version": "1.1.7",
3
3
  "name": "solid-map-gl",
4
4
  "description": "Solid Component Library for Mapbox GL JS",
5
5
  "author": "kaihuebner",
@@ -33,16 +33,20 @@
33
33
  "solidjs"
34
34
  ],
35
35
  "homepage": "https://github.com/gishub4/solid-map-gl#readme",
36
+ "browserList": [
37
+ "defaults",
38
+ "not ie 11"
39
+ ],
36
40
  "dependencies": {
37
41
  "mapbox-gl": "^2.6.1",
38
- "solid-js": "^1.2.6"
42
+ "solid-js": "^1.3.3"
39
43
  },
40
44
  "devDependencies": {
41
45
  "@types/mapbox-gl": "^2.4.2",
42
- "rollup": "^2.59.0",
46
+ "rollup": "^2.65.0",
43
47
  "rollup-plugin-import-css": "^3.0.2",
44
48
  "rollup-plugin-uglify": "^6.0.4",
45
- "rollup-preset-solid": "^1.0.1",
46
- "typescript": "^4.4.4"
49
+ "rollup-preset-solid": "^1.1.0",
50
+ "typescript": "^4.5.5"
47
51
  }
48
52
  }