solid-map-gl 1.8.0 → 1.8.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.
@@ -1,13 +1,13 @@
1
1
  import { onCleanup, createEffect, createContext, useContext, createUniqueId, } from 'solid-js';
2
- import { useMap } from '../MapProvider';
2
+ import { useMapContext } from '../MapProvider';
3
3
  import { rasterStyleList } from '../../mapStyles';
4
4
  const SourceContext = createContext();
5
5
  export const useSourceId = () => useContext(SourceContext);
6
6
  export const Source = props => {
7
- const [map] = useMap();
7
+ const [ctx] = useMapContext();
8
8
  props.id ??= createUniqueId();
9
9
  const debug = (text, value) => {
10
- map().debug &&
10
+ ctx.map.debug &&
11
11
  console.debug('%c[MapGL]', 'color: #ec4899', text, value || '');
12
12
  };
13
13
  const lookup = url => {
@@ -30,16 +30,16 @@ export const Source = props => {
30
30
  return source;
31
31
  };
32
32
  // Add Source
33
- map().addSource(props.id, lookup(props.source.url));
34
- map().sourceIdList.push(props.id);
33
+ ctx.map.addSource(props.id, lookup(props.source.url));
34
+ ctx.map.sourceIdList.push(props.id);
35
35
  debug('Add Source:', props.id);
36
36
  // Update Data
37
- const source = map().getSource(props.id);
37
+ const source = ctx.map.getSource(props.id);
38
38
  switch (props.source.type) {
39
39
  case 'geojson':
40
40
  createEffect(() => {
41
41
  const data = props.source.data;
42
- if (!map().isSourceLoaded(props.id))
42
+ if (!ctx.map.isSourceLoaded(props.id))
43
43
  return;
44
44
  source.setData(data || {});
45
45
  debug('Update GeoJSON Data:', props.id);
@@ -49,7 +49,7 @@ export const Source = props => {
49
49
  createEffect(() => {
50
50
  const url = props.source.url;
51
51
  const coords = props.source.coordinates;
52
- if (!map().isSourceLoaded(props.id))
52
+ if (!ctx.map.isSourceLoaded(props.id))
53
53
  return;
54
54
  source.updateImage(url, coords);
55
55
  debug('Update Image Data:', props.id);
@@ -59,7 +59,7 @@ export const Source = props => {
59
59
  createEffect(() => {
60
60
  const url = props.source.url;
61
61
  const tiles = props.source.tiles;
62
- if (!map().isSourceLoaded(props.id))
62
+ if (!ctx.map.isSourceLoaded(props.id))
63
63
  return;
64
64
  url ? source.setUrl(url) : source.setTiles(tiles);
65
65
  debug('Update Vector Data:', props.id);
@@ -68,7 +68,7 @@ export const Source = props => {
68
68
  case 'raster':
69
69
  createEffect(() => {
70
70
  const src = lookup(props.source.url);
71
- if (!map().isSourceLoaded(props.id))
71
+ if (!ctx.map.isSourceLoaded(props.id))
72
72
  return;
73
73
  src.url ? source.setUrl(src.url) : source.setTiles(src.tiles);
74
74
  debug('Update Raster Data:', props.id);
@@ -77,10 +77,10 @@ export const Source = props => {
77
77
  }
78
78
  // Remove Source
79
79
  onCleanup(() => {
80
- map()
80
+ ctx.map
81
81
  ?.getStyle()
82
- .layers.forEach(layer => layer.source === props.id && map().removeLayer(layer.id));
83
- map()?.getSource(props.id) && map()?.removeSource(props.id);
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
84
  debug('Remove Source:', props.id);
85
85
  });
86
86
  return (<SourceContext.Provider value={props.id}>
@@ -1,25 +1,25 @@
1
1
  import { createEffect, createUniqueId } from 'solid-js';
2
- import { useMap } from '../MapProvider';
2
+ import { useMapContext } from '../MapProvider';
3
3
  import { useSourceId } from '../Source';
4
4
  export const Terrain = (props) => {
5
- const [map] = useMap();
5
+ const [ctx] = useMapContext();
6
6
  let sourceId = useSourceId();
7
7
  // Add Terrain Source if not already defined
8
8
  if (!sourceId && !props.source) {
9
9
  sourceId = createUniqueId();
10
- map().addSource(sourceId, {
10
+ ctx.map.addSource(sourceId, {
11
11
  type: 'raster-dem',
12
- url: map().isMapLibre
12
+ url: ctx.map.isMapLibre
13
13
  ? 'https://demotiles.maplibre.org/terrain-tiles/tiles.json'
14
14
  : 'mapbox://mapbox.terrain-rgb',
15
- tileSize: map().isMapLibre ? 256 : 512,
16
- maxzoom: map().isMapLibre ? undefined : 14
15
+ tileSize: ctx.map.isMapLibre ? 256 : 512,
16
+ maxzoom: ctx.map.isMapLibre ? undefined : 14
17
17
  });
18
- map().sourceIdList.push(sourceId);
18
+ ctx.map.sourceIdList.push(sourceId);
19
19
  }
20
20
  // Add or Update Terrain Layer
21
21
  createEffect(() => {
22
- map().setTerrain({
22
+ ctx.map.setTerrain({
23
23
  exaggeration: props.exaggeration || 1,
24
24
  source: props.source || sourceId,
25
25
  });
@@ -1,5 +1,5 @@
1
1
  export { MapGL as default } from './components/MapGL';
2
- export { MapProvider, useMap } from './components/MapProvider';
2
+ export { MapProvider, useMapContext } from './components/MapProvider';
3
3
  export { Source, useSourceId } from './components/Source';
4
4
  export { Layer } from './components/Layer';
5
5
  export { Atmosphere } from './components/Atmosphere';
@@ -4,8 +4,9 @@ import type { Options as FullscreenOptions } from 'mapbox-gl/src/ui/control/full
4
4
  import type { Options as GeolocateOptions } from 'mapbox-gl/src/ui/control/geolocate_control';
5
5
  import type { Options as NavigationOptions } from 'mapbox-gl/src/ui/control/navigation_control';
6
6
  import type { Options as ScaleOptions } from 'mapbox-gl/src/ui/control/scale_control';
7
+ type ControlType = 'navigation' | 'scale' | 'attribution' | 'fullscreen' | 'geolocate';
7
8
  type Props = {
8
- type?: 'navigation' | 'scale' | 'attribution' | 'fullscreen' | 'geolocate';
9
+ type?: ControlType;
9
10
  /** a string that specifies the type of control to be displayed. It can be one of 'navigation', 'scale', 'attribution', 'fullscreen', or 'geolocate' */
10
11
  options?: NavigationOptions | ScaleOptions | AttributionOptions | FullscreenOptions | GeolocateOptions | object;
11
12
  /** an optional object that contains options specific to the control type */
@@ -1,8 +1,11 @@
1
- import { ParentComponent } from "solid-js";
1
+ import { ParentComponent } from 'solid-js';
2
2
  import type { Map } from '../MapGL';
3
- export declare const MapContext: import("solid-js").Context<import("solid-js").Accessor<any>[]>;
4
- export declare const useMap: () => import("solid-js").Accessor<any>[];
3
+ export declare const MapContext: import("solid-js").Context<{
4
+ map: any;
5
+ }[]>;
6
+ export declare const useMapContext: () => {
7
+ map: any;
8
+ }[];
5
9
  export declare const MapProvider: ParentComponent<{
6
10
  map?: Map;
7
- userInteraction?: boolean;
8
11
  }>;
@@ -1,5 +1,5 @@
1
1
  export { MapGL as default } from './components/MapGL';
2
- export { MapProvider, useMap } from './components/MapProvider';
2
+ export { MapProvider, useMapContext } from './components/MapProvider';
3
3
  export { Source, useSourceId } from './components/Source';
4
4
  export { Layer } from './components/Layer';
5
5
  export { Atmosphere } from './components/Atmosphere';
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.8.0",
2
+ "version": "1.8.2",
3
3
  "name": "solid-map-gl",
4
4
  "description": "Solid Component Library for Mapbox GL JS",
5
5
  "info": "Solid Component Library for 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.",
@@ -56,7 +56,7 @@
56
56
  "canvas": "^2.11.2",
57
57
  "jsdom": "^22.1.0",
58
58
  "mapbox-gl": "^2.15.0",
59
- "rollup": "^3.24.0",
59
+ "rollup": "^3.25.1",
60
60
  "rollup-plugin-import-css": "^3.2.1",
61
61
  "rollup-preset-solid": "^2.0.1",
62
62
  "solid-js": "^1.7.6",