@macrostrat/map-interface 2.1.0 → 2.2.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/CHANGELOG.md +6 -0
- package/dist/map-view.cjs +6 -9
- package/dist/map-view.cjs.map +1 -1
- package/dist/map-view.d.ts +1 -1
- package/dist/map-view.js +7 -10
- package/dist/map-view.js.map +1 -1
- package/package.json +3 -4
- package/src/map-view.ts +11 -8
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format
|
|
|
4
4
|
is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this
|
|
5
5
|
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [2.2.0] - 2026-02-13
|
|
8
|
+
|
|
9
|
+
- Add internal logic to `MapView` to manage the addition of custom style
|
|
10
|
+
fragments, based on updates to the `@macrostrat/mapbox-react` package
|
|
11
|
+
- Add new stories
|
|
12
|
+
|
|
7
13
|
## [2.1.0] - 2026-02-09
|
|
8
14
|
|
|
9
15
|
- Remove xDD info panel components
|
package/dist/map-view.cjs
CHANGED
|
@@ -71,9 +71,6 @@ function MapView(props) {
|
|
|
71
71
|
className,
|
|
72
72
|
...rest
|
|
73
73
|
} = props;
|
|
74
|
-
if (enableTerrain) {
|
|
75
|
-
terrainSourceID ??= "mapbox-3d-dem";
|
|
76
|
-
}
|
|
77
74
|
React.useEffect(() => {
|
|
78
75
|
if (id != null) {
|
|
79
76
|
console.warn(
|
|
@@ -90,6 +87,7 @@ function MapView(props) {
|
|
|
90
87
|
const ref = React.useRef();
|
|
91
88
|
const parentRef = React.useRef();
|
|
92
89
|
const [baseStyle, setBaseStyle] = React.useState(null);
|
|
90
|
+
const _ctxOverlayStyles = mapboxReact.useMapStyleFragments();
|
|
93
91
|
const estMapPosition = mapRef.current == null ? mapPosition : mapboxUtils.getMapPosition(mapRef.current);
|
|
94
92
|
const { mapUse3D, mapIsRotated } = mapboxUtils.mapViewInfo(estMapPosition);
|
|
95
93
|
const is3DAvailable = (mapUse3D ?? false) && enableTerrain;
|
|
@@ -97,9 +95,9 @@ function MapView(props) {
|
|
|
97
95
|
if (baseStyle == null) return;
|
|
98
96
|
let map = mapRef.current;
|
|
99
97
|
let newStyle = baseStyle;
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
102
|
-
newStyle = mapboxUtils.mergeStyles(newStyle, ...
|
|
98
|
+
const _overlayStyles = overlayStyles ?? [];
|
|
99
|
+
if (_overlayStyles.length > 0 || _ctxOverlayStyles.length > 0) {
|
|
100
|
+
newStyle = mapboxUtils.mergeStyles(newStyle, ..._overlayStyles, ..._ctxOverlayStyles);
|
|
103
101
|
}
|
|
104
102
|
if (is3DAvailable) {
|
|
105
103
|
const terrainStyle = mapboxReact.getTerrainLayerForStyle(newStyle, terrainSourceID);
|
|
@@ -123,7 +121,7 @@ function MapView(props) {
|
|
|
123
121
|
map2.setPadding(utils.getMapPadding(ref, parentRef), { animate: false });
|
|
124
122
|
onMapLoaded?.(map2);
|
|
125
123
|
}
|
|
126
|
-
}, [baseStyle, overlayStyles, transformStyle]);
|
|
124
|
+
}, [baseStyle, overlayStyles, _ctxOverlayStyles, transformStyle]);
|
|
127
125
|
uiComponents.useAsyncEffect(async () => {
|
|
128
126
|
let newStyle;
|
|
129
127
|
if (typeof style === "string") {
|
|
@@ -193,8 +191,7 @@ function StyleLoadedReporter({ onStyleLoaded = null }) {
|
|
|
193
191
|
}
|
|
194
192
|
function MapTerrainManager({
|
|
195
193
|
mapUse3D,
|
|
196
|
-
terrainSourceID
|
|
197
|
-
style
|
|
194
|
+
terrainSourceID
|
|
198
195
|
}) {
|
|
199
196
|
mapboxReact.use3DTerrain(mapUse3D, terrainSourceID);
|
|
200
197
|
return null;
|
package/dist/map-view.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-view.cjs","sources":["../src/map-view.ts"],"sourcesContent":["import hyper from \"@macrostrat/hyper\";\nimport {\n useMapRef,\n useMapDispatch,\n use3DTerrain,\n getTerrainLayerForStyle,\n useMapStatus,\n} from \"@macrostrat/mapbox-react\";\nimport React from \"react\";\nimport {\n mapViewInfo,\n MapPosition,\n setMapPosition,\n getMapPosition,\n getMapboxStyle,\n mergeStyles,\n} from \"@macrostrat/mapbox-utils\";\nimport classNames from \"classnames\";\nimport mapboxgl from \"mapbox-gl\";\nimport { useEffect, useRef, useState } from \"react\";\nimport styles from \"./main.module.sass\";\nimport {\n MapLoadingReporter,\n MapMovedReporter,\n MapPaddingManager,\n MapResizeManager,\n} from \"./helpers\";\nimport \"mapbox-gl/dist/mapbox-gl.css\";\nimport { getMapPadding } from \"./utils\";\nimport { useAsyncEffect } from \"@macrostrat/ui-components\";\n\nconst h = hyper.styled(styles);\n\ntype MapboxCoreOptions = Omit<mapboxgl.MapboxOptions, \"container\">;\n\nexport interface MapViewProps extends MapboxCoreOptions {\n showLineSymbols?: boolean;\n children?: React.ReactNode;\n mapboxToken?: string;\n // Deprecated\n accessToken?: string;\n terrainSourceID?: string;\n enableTerrain?: boolean;\n infoMarkerPosition?: mapboxgl.LngLatLike;\n mapPosition?: MapPosition;\n initializeMap?: (\n container: HTMLElement,\n args: MapboxOptionsExt,\n ) => mapboxgl.Map;\n onMapLoaded?: (map: mapboxgl.Map) => void;\n onStyleLoaded?: (map: mapboxgl.Map) => void;\n onMapMoved?: (mapPosition: MapPosition, map: mapboxgl.Map) => void;\n /** This map sets its own viewport, rather than being positioned by a parent.\n * This is a hack to ensure that the map can overflow its \"safe area\" when false */\n standalone?: boolean;\n /** Overlay styles to apply to the map: a list of mapbox style objects or fragments to\n * overlay on top of the main map style at runtime */\n overlayStyles?: Partial<mapboxgl.StyleSpecification>[];\n /** A function to transform the map style before it is loaded */\n transformStyle?: (\n style: mapboxgl.StyleSpecification,\n ) => mapboxgl.StyleSpecification;\n loadingIgnoredSources?: string[];\n id?: string;\n className?: string;\n}\n\nexport interface MapboxOptionsExt extends MapboxCoreOptions {\n mapPosition?: MapPosition;\n}\n\nfunction defaultInitializeMap(container, args: MapboxOptionsExt = {}) {\n const { mapPosition, ...rest } = args;\n\n const map = new mapboxgl.Map({\n container,\n maxZoom: 18,\n logoPosition: \"bottom-left\",\n trackResize: false,\n antialias: true,\n // This is a legacy option for Mapbox GL v2\n // @ts-ignore\n optimizeForTerrain: true,\n ...rest,\n });\n\n let _mapPosition = mapPosition;\n if (_mapPosition == null && rest.center == null && rest.bounds == null) {\n // If no map positioning information is provided, we use the default\n _mapPosition = defaultMapPosition;\n }\n\n // set initial map position\n if (_mapPosition != null) {\n setMapPosition(map, _mapPosition);\n }\n\n return map;\n}\n\nconst defaultMapPosition: MapPosition = {\n camera: {\n lat: 34,\n lng: -120,\n altitude: 300000,\n },\n};\n\nexport function MapView(props: MapViewProps) {\n let { terrainSourceID } = props;\n const {\n enableTerrain = true,\n style,\n mapPosition,\n initializeMap = defaultInitializeMap,\n children,\n mapboxToken,\n // Deprecated\n accessToken,\n infoMarkerPosition,\n transformRequest,\n projection,\n onMapLoaded = null,\n onStyleLoaded = null,\n onMapMoved = null,\n standalone = false,\n overlayStyles,\n transformStyle,\n trackResize = true,\n loadingIgnoredSources = [\"elevationMarker\", \"crossSectionEndpoints\"],\n id = \"map\",\n className,\n ...rest\n } = props;\n if (enableTerrain) {\n terrainSourceID ??= \"mapbox-3d-dem\";\n }\n\n useEffect(() => {\n if (id != null) {\n console.warn(\n \"Setting a specific element ID for the map is deprecated. Please use className instead.\",\n );\n }\n }, [id]);\n\n const _mapboxToken = mapboxToken ?? accessToken;\n\n if (_mapboxToken != null) {\n mapboxgl.accessToken = _mapboxToken;\n }\n\n const dispatch = useMapDispatch();\n let mapRef = useMapRef();\n const ref = useRef<HTMLDivElement>();\n const parentRef = useRef<HTMLDivElement>();\n\n const [baseStyle, setBaseStyle] = useState<mapboxgl.Style>(null);\n\n const estMapPosition: MapPosition | null =\n mapRef.current == null ? mapPosition : getMapPosition(mapRef.current);\n const { mapUse3D, mapIsRotated } = mapViewInfo(estMapPosition);\n const is3DAvailable = (mapUse3D ?? false) && enableTerrain;\n\n useEffect(() => {\n /** Manager to update map style */\n if (baseStyle == null) return;\n let map = mapRef.current;\n\n let newStyle: mapboxgl.StyleSpecification = baseStyle;\n\n const overlayStyles = props.overlayStyles ?? [];\n\n if (overlayStyles.length > 0) {\n newStyle = mergeStyles(newStyle, ...overlayStyles);\n }\n\n /** If we can, we try to update the map style with terrain information\n * immediately, before the style is loaded. This allows us to avoid a\n * flash of the map without terrain.\n *\n * To do this, we need to estimate the map position before load, which\n * doesn't always work.\n */\n if (is3DAvailable) {\n // We can update the style with terrain layers immediately\n const terrainStyle = getTerrainLayerForStyle(newStyle, terrainSourceID);\n newStyle = mergeStyles(newStyle, terrainStyle);\n }\n\n if (transformStyle != null) {\n newStyle = transformStyle(newStyle);\n }\n\n if (map != null) {\n dispatch({ type: \"set-style-loaded\", payload: false });\n map.setStyle(newStyle);\n } else {\n const map = initializeMap(ref.current, {\n style: newStyle,\n projection,\n mapPosition,\n transformRequest,\n ...rest,\n });\n dispatch({ type: \"set-map\", payload: map });\n map.setPadding(getMapPadding(ref, parentRef), { animate: false });\n onMapLoaded?.(map);\n }\n }, [baseStyle, overlayStyles, transformStyle]);\n\n useAsyncEffect(async () => {\n /** Manager to update map style */\n let newStyle: mapboxgl.StyleSpecification;\n if (typeof style === \"string\") {\n newStyle = await getMapboxStyle(style, {\n access_token: mapboxgl.accessToken,\n });\n } else {\n newStyle = style;\n }\n setBaseStyle(newStyle);\n }, [style]);\n\n // Get map projection\n const _projection = mapRef.current?.getProjection()?.name ?? \"mercator\";\n\n const mapClassName = classNames(\n {\n \"is-rotated\": mapIsRotated ?? false,\n \"is-3d-available\": is3DAvailable,\n },\n `${_projection}-projection`,\n );\n\n const parentClassName = classNames(\n {\n standalone,\n },\n className,\n );\n\n return h(\n \"div.map-view-container.main-view\",\n { ref: parentRef, className: parentClassName },\n [\n h(\"div.mapbox-map.map-view\", { ref, className: mapClassName, id }),\n h(MapLoadingReporter, {\n ignoredSources: loadingIgnoredSources,\n }),\n h(StyleLoadedReporter, { onStyleLoaded }),\n h(MapMovedReporter, { onMapMoved }),\n // Subsitute for trackResize: true that allows map resizing to\n // be tied to a specific ref component\n h.if(trackResize)(MapResizeManager, { containerRef: ref }),\n h(MapPaddingManager, {\n containerRef: ref,\n parentRef,\n infoMarkerPosition,\n }),\n h(MapTerrainManager, { mapUse3D: is3DAvailable, terrainSourceID, style }),\n children,\n ],\n );\n}\n\nfunction StyleLoadedReporter({ onStyleLoaded = null }) {\n /** Check back every 0.1 seconds to see if the map has loaded.\n * We do it this way because mapboxgl loading events are unreliable */\n const isStyleLoaded = useMapStatus((state) => state.isStyleLoaded);\n const mapRef = useMapRef();\n const dispatch = useMapDispatch();\n\n useEffect(() => {\n if (isStyleLoaded) return;\n const interval = setInterval(() => {\n const map = mapRef.current;\n if (map == null) return;\n if (map.isStyleLoaded()) {\n // Wait a tick before setting the style loaded state\n dispatch({ type: \"set-style-loaded\", payload: true });\n onStyleLoaded?.(map);\n clearInterval(interval);\n }\n }, 50);\n return () => clearInterval(interval);\n }, [isStyleLoaded]);\n\n return null;\n}\n\nexport function MapTerrainManager({\n mapUse3D,\n terrainSourceID,\n style,\n}: {\n mapUse3D?: boolean;\n terrainSourceID?: string;\n style?: mapboxgl.StyleSpecification | string;\n}) {\n use3DTerrain(mapUse3D, terrainSourceID);\n\n return null;\n}\n"],"names":["hyper","styles","mapboxgl","setMapPosition","useEffect","useMapDispatch","useMapRef","useRef","useState","getMapPosition","mapViewInfo","overlayStyles","mergeStyles","getTerrainLayerForStyle","map","getMapPadding","useAsyncEffect","getMapboxStyle","classNames","MapLoadingReporter","MapMovedReporter","MapResizeManager","MapPaddingManager","useMapStatus","use3DTerrain"],"mappings":";;;;;;;;;;;;;;;;;AA+BA,MAAM,IAAIA,WAAAA,QAAM,OAAOC,mBAAM;AAwC7B,SAAS,qBAAqB,WA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A;AAEjBD,QAAAA,UAAU,MAAM;AACd,QAAI,cAAe;AACnB,UAAM,WAAW,YAAY,MAAM;AACjC,YAAM,MAAM,OAAO;AACnB,UAAI,OAAO,KAAM;AACjB,UAAI,IAAI,iBAAiB;AAEvB,iBAAS,EAAE,MAAM,oBAAoB,SAAS,MAAM;AACpD,wBAAgB,GAAG;AACnB,sBAAc,QAAQ;AAAA,MACxB;AAAA,IACF,GAAG,EAAE;AACL,WAAO,MAAM,cAAc,QAAQ;AAAA,EACrC,GAAG,CAAC,aAAa,CAAC;AAElB,SAAO;AACT;AAEO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACDoB,cAAAA,aAAa,UAAU,eAAe;AAEtC,SAAO;AACT;;;"}
|
|
1
|
+
{"version":3,"file":"map-view.cjs","sources":["../src/map-view.ts"],"sourcesContent":["import hyper from \"@macrostrat/hyper\";\nimport {\n useMapRef,\n useMapDispatch,\n use3DTerrain,\n getTerrainLayerForStyle,\n useMapStatus,\n useMapStyleFragments,\n} from \"@macrostrat/mapbox-react\";\nimport React from \"react\";\nimport {\n mapViewInfo,\n MapPosition,\n setMapPosition,\n getMapPosition,\n getMapboxStyle,\n mergeStyles,\n} from \"@macrostrat/mapbox-utils\";\nimport classNames from \"classnames\";\nimport mapboxgl from \"mapbox-gl\";\nimport { useEffect, useRef, useState } from \"react\";\nimport styles from \"./main.module.sass\";\nimport {\n MapLoadingReporter,\n MapMovedReporter,\n MapPaddingManager,\n MapResizeManager,\n} from \"./helpers\";\nimport \"mapbox-gl/dist/mapbox-gl.css\";\nimport { getMapPadding } from \"./utils\";\nimport { useAsyncEffect } from \"@macrostrat/ui-components\";\n\nconst h = hyper.styled(styles);\n\ntype MapboxCoreOptions = Omit<mapboxgl.MapboxOptions, \"container\">;\n\nexport interface MapViewProps extends MapboxCoreOptions {\n showLineSymbols?: boolean;\n children?: React.ReactNode;\n mapboxToken?: string;\n // Deprecated\n accessToken?: string;\n terrainSourceID?: string;\n enableTerrain?: boolean;\n infoMarkerPosition?: mapboxgl.LngLatLike;\n mapPosition?: MapPosition;\n initializeMap?: (\n container: HTMLElement,\n args: MapboxOptionsExt,\n ) => mapboxgl.Map;\n onMapLoaded?: (map: mapboxgl.Map) => void;\n onStyleLoaded?: (map: mapboxgl.Map) => void;\n onMapMoved?: (mapPosition: MapPosition, map: mapboxgl.Map) => void;\n /** This map sets its own viewport, rather than being positioned by a parent.\n * This is a hack to ensure that the map can overflow its \"safe area\" when false */\n standalone?: boolean;\n /** Overlay styles to apply to the map: a list of mapbox style objects or fragments to\n * overlay on top of the main map style at runtime */\n overlayStyles?: Partial<mapboxgl.StyleSpecification>[];\n /** A function to transform the map style before it is loaded */\n transformStyle?: (\n style: mapboxgl.StyleSpecification,\n ) => mapboxgl.StyleSpecification;\n loadingIgnoredSources?: string[];\n id?: string;\n className?: string;\n}\n\nexport interface MapboxOptionsExt extends MapboxCoreOptions {\n mapPosition?: MapPosition;\n}\n\nfunction defaultInitializeMap(container, args: MapboxOptionsExt = {}) {\n const { mapPosition, ...rest } = args;\n\n const map = new mapboxgl.Map({\n container,\n maxZoom: 18,\n logoPosition: \"bottom-left\",\n trackResize: false,\n antialias: true,\n // This is a legacy option for Mapbox GL v2\n // @ts-ignore\n optimizeForTerrain: true,\n ...rest,\n });\n\n let _mapPosition = mapPosition;\n if (_mapPosition == null && rest.center == null && rest.bounds == null) {\n // If no map positioning information is provided, we use the default\n _mapPosition = defaultMapPosition;\n }\n\n // set initial map position\n if (_mapPosition != null) {\n setMapPosition(map, _mapPosition);\n }\n\n return map;\n}\n\nconst defaultMapPosition: MapPosition = {\n camera: {\n lat: 34,\n lng: -120,\n altitude: 300000,\n },\n};\n\nexport function MapView(props: MapViewProps) {\n let { terrainSourceID } = props;\n const {\n enableTerrain = true,\n style,\n mapPosition,\n initializeMap = defaultInitializeMap,\n children,\n mapboxToken,\n // Deprecated\n accessToken,\n infoMarkerPosition,\n transformRequest,\n projection,\n onMapLoaded = null,\n onStyleLoaded = null,\n onMapMoved = null,\n standalone = false,\n overlayStyles,\n transformStyle,\n trackResize = true,\n loadingIgnoredSources = [\"elevationMarker\", \"crossSectionEndpoints\"],\n id = \"map\",\n className,\n ...rest\n } = props;\n\n useEffect(() => {\n if (id != null) {\n console.warn(\n \"Setting a specific element ID for the map is deprecated. Please use className instead.\",\n );\n }\n }, [id]);\n\n const _mapboxToken = mapboxToken ?? accessToken;\n\n if (_mapboxToken != null) {\n mapboxgl.accessToken = _mapboxToken;\n }\n\n const dispatch = useMapDispatch();\n let mapRef = useMapRef();\n const ref = useRef<HTMLDivElement>();\n const parentRef = useRef<HTMLDivElement>();\n\n const [baseStyle, setBaseStyle] = useState<mapboxgl.Style>(null);\n\n /** Get overlay styles from map context. These are added after the base style is loaded, and can be used\n * to add layers to the map at runtime, even after initialization. They are merged with any overlay styles\n * passed in as props.\n */\n const _ctxOverlayStyles = useMapStyleFragments() as any[];\n\n const estMapPosition: MapPosition | null =\n mapRef.current == null ? mapPosition : getMapPosition(mapRef.current);\n const { mapUse3D, mapIsRotated } = mapViewInfo(estMapPosition);\n const is3DAvailable = (mapUse3D ?? false) && enableTerrain;\n\n useEffect(() => {\n /** Manager to update map style */\n if (baseStyle == null) return;\n let map = mapRef.current;\n\n let newStyle: mapboxgl.StyleSpecification = baseStyle;\n\n const _overlayStyles = overlayStyles ?? [];\n\n if (_overlayStyles.length > 0 || _ctxOverlayStyles.length > 0) {\n newStyle = mergeStyles(newStyle, ..._overlayStyles, ..._ctxOverlayStyles);\n }\n\n /** If we can, we try to update the map style with terrain information\n * immediately, before the style is loaded. This allows us to avoid a\n * flash of the map without terrain.\n *\n * To do this, we need to estimate the map position before load, which\n * doesn't always work.\n */\n if (is3DAvailable) {\n // We can update the style with terrain layers immediately\n const terrainStyle = getTerrainLayerForStyle(newStyle, terrainSourceID);\n newStyle = mergeStyles(newStyle, terrainStyle);\n }\n\n if (transformStyle != null) {\n newStyle = transformStyle(newStyle);\n }\n\n if (map != null) {\n dispatch({ type: \"set-style-loaded\", payload: false });\n map.setStyle(newStyle);\n } else {\n const map = initializeMap(ref.current, {\n style: newStyle,\n projection,\n mapPosition,\n transformRequest,\n ...rest,\n });\n dispatch({ type: \"set-map\", payload: map });\n map.setPadding(getMapPadding(ref, parentRef), { animate: false });\n onMapLoaded?.(map);\n }\n }, [baseStyle, overlayStyles, _ctxOverlayStyles, transformStyle]);\n\n useAsyncEffect(async () => {\n /** Manager to update map style */\n let newStyle: mapboxgl.StyleSpecification;\n if (typeof style === \"string\") {\n newStyle = await getMapboxStyle(style, {\n access_token: mapboxgl.accessToken,\n });\n } else {\n newStyle = style;\n }\n setBaseStyle(newStyle);\n }, [style]);\n\n // Get map projection\n const _projection = mapRef.current?.getProjection()?.name ?? \"mercator\";\n\n const mapClassName = classNames(\n {\n \"is-rotated\": mapIsRotated ?? false,\n \"is-3d-available\": is3DAvailable,\n },\n `${_projection}-projection`,\n );\n\n const parentClassName = classNames(\n {\n standalone,\n },\n className,\n );\n\n return h(\n \"div.map-view-container.main-view\",\n { ref: parentRef, className: parentClassName },\n [\n h(\"div.mapbox-map.map-view\", { ref, className: mapClassName, id }),\n h(MapLoadingReporter, {\n ignoredSources: loadingIgnoredSources,\n }),\n h(StyleLoadedReporter, { onStyleLoaded }),\n h(MapMovedReporter, { onMapMoved }),\n // Subsitute for trackResize: true that allows map resizing to\n // be tied to a specific ref component\n h.if(trackResize)(MapResizeManager, { containerRef: ref }),\n h(MapPaddingManager, {\n containerRef: ref,\n parentRef,\n infoMarkerPosition,\n }),\n h(MapTerrainManager, { mapUse3D: is3DAvailable, terrainSourceID, style }),\n children,\n ],\n );\n}\n\nfunction StyleLoadedReporter({ onStyleLoaded = null }) {\n /** Check back every 0.1 seconds to see if the map has loaded.\n * We do it this way because mapboxgl loading events are unreliable */\n const isStyleLoaded = useMapStatus((state) => state.isStyleLoaded);\n const mapRef = useMapRef();\n const dispatch = useMapDispatch();\n\n useEffect(() => {\n if (isStyleLoaded) return;\n const interval = setInterval(() => {\n const map = mapRef.current;\n if (map == null) return;\n if (map.isStyleLoaded()) {\n // Wait a tick before setting the style loaded state\n dispatch({ type: \"set-style-loaded\", payload: true });\n onStyleLoaded?.(map);\n clearInterval(interval);\n }\n }, 50);\n return () => clearInterval(interval);\n }, [isStyleLoaded]);\n\n return null;\n}\n\nexport function MapTerrainManager({\n mapUse3D,\n terrainSourceID,\n}: {\n mapUse3D?: boolean;\n terrainSourceID?: string;\n style?: mapboxgl.StyleSpecification | string;\n}) {\n use3DTerrain(mapUse3D, terrainSourceID);\n\n return null;\n}\n"],"names":["hyper","styles","mapboxgl","setMapPosition","useEffect","useMapDispatch","useMapRef","useRef","useState","useMapStyleFragments","getMapPosition","mapViewInfo","mergeStyles","getTerrainLayerForStyle","map","getMapPadding","useAsyncEffect","getMapboxStyle","classNames","MapLoadingReporter","MapMovedReporter","MapResizeManager","MapPaddingManager","useMapStatus","use3DTerrain"],"mappings":";;;;;;;;;;;;;;;;;AAgCA,MAAM,IAAIA,WAAAA,QAAM,OAAOC,mBAAM;AAwC7B,SAAS,qBAAqB,WAAW,OAAyB,IAAI;AACpE,QAAM,EAAE,aAAa,GAAG,KAAA,IAAS;AAEjC,QAAM,MAAM,IAAIC,kBAAAA,QAAS,IAAI;AAAA,IAC3B;AAAA,IACA,SAAS;AAAA,IACT,cAAc;AAAA,IACd,aAAa;AAAA,IACb,WAAW;AAAA;AAAA;AAAA,IAGX,oBAAoB;AAAA,IACpB,GAAG;AAAA,EAAA,CACJ;AAED,MAAI,eAAe;AACnB,MAAI,gBAAgB,QAAQ,KAAK,UAAU,QAAQ,KAAK,UAAU,MAAM;AAEtE,mBAAe;AAAA,EACjB;AAGA,MAAI,gBAAgB,MAAM;AACxBC,gBAAAA,eAAe,KAAK,YAAY;AAAA,EAClC;AAEA,SAAO;AACT;AAEA,MAAM,qBAAkC;AAAA,EACtC,QAAQ;AAAA,IACN,KAAK;AAAA,IACL,KAAK;AAAA,IACL,UAAU;AAAA,EA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MapView(props: MapViewProps): import('react').ReactEleme
|
|
|
33
33
|
ref: React.MutableRefObject<HTMLDivElement>;
|
|
34
34
|
className: string;
|
|
35
35
|
}, string | import('react').JSXElementConstructor<any>>;
|
|
36
|
-
export declare function MapTerrainManager({ mapUse3D, terrainSourceID,
|
|
36
|
+
export declare function MapTerrainManager({ mapUse3D, terrainSourceID, }: {
|
|
37
37
|
mapUse3D?: boolean;
|
|
38
38
|
terrainSourceID?: string;
|
|
39
39
|
style?: mapboxgl.StyleSpecification | string;
|
package/dist/map-view.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import h$1 from "@macrostrat/hyper";
|
|
2
|
-
import { use3DTerrain, useMapDispatch, useMapRef, getTerrainLayerForStyle, useMapStatus } from "@macrostrat/mapbox-react";
|
|
2
|
+
import { use3DTerrain, useMapDispatch, useMapRef, useMapStyleFragments, getTerrainLayerForStyle, useMapStatus } from "@macrostrat/mapbox-react";
|
|
3
3
|
import { getMapPosition, mapViewInfo, mergeStyles, getMapboxStyle, setMapPosition } from "@macrostrat/mapbox-utils";
|
|
4
4
|
import classNames from "classnames";
|
|
5
5
|
import mapboxgl from "mapbox-gl";
|
|
@@ -65,9 +65,6 @@ function MapView(props) {
|
|
|
65
65
|
className,
|
|
66
66
|
...rest
|
|
67
67
|
} = props;
|
|
68
|
-
if (enableTerrain) {
|
|
69
|
-
terrainSourceID ??= "mapbox-3d-dem";
|
|
70
|
-
}
|
|
71
68
|
useEffect(() => {
|
|
72
69
|
if (id != null) {
|
|
73
70
|
console.warn(
|
|
@@ -84,6 +81,7 @@ function MapView(props) {
|
|
|
84
81
|
const ref = useRef();
|
|
85
82
|
const parentRef = useRef();
|
|
86
83
|
const [baseStyle, setBaseStyle] = useState(null);
|
|
84
|
+
const _ctxOverlayStyles = useMapStyleFragments();
|
|
87
85
|
const estMapPosition = mapRef.current == null ? mapPosition : getMapPosition(mapRef.current);
|
|
88
86
|
const { mapUse3D, mapIsRotated } = mapViewInfo(estMapPosition);
|
|
89
87
|
const is3DAvailable = (mapUse3D ?? false) && enableTerrain;
|
|
@@ -91,9 +89,9 @@ function MapView(props) {
|
|
|
91
89
|
if (baseStyle == null) return;
|
|
92
90
|
let map = mapRef.current;
|
|
93
91
|
let newStyle = baseStyle;
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
newStyle = mergeStyles(newStyle, ...
|
|
92
|
+
const _overlayStyles = overlayStyles ?? [];
|
|
93
|
+
if (_overlayStyles.length > 0 || _ctxOverlayStyles.length > 0) {
|
|
94
|
+
newStyle = mergeStyles(newStyle, ..._overlayStyles, ..._ctxOverlayStyles);
|
|
97
95
|
}
|
|
98
96
|
if (is3DAvailable) {
|
|
99
97
|
const terrainStyle = getTerrainLayerForStyle(newStyle, terrainSourceID);
|
|
@@ -117,7 +115,7 @@ function MapView(props) {
|
|
|
117
115
|
map2.setPadding(getMapPadding(ref, parentRef), { animate: false });
|
|
118
116
|
onMapLoaded?.(map2);
|
|
119
117
|
}
|
|
120
|
-
}, [baseStyle, overlayStyles, transformStyle]);
|
|
118
|
+
}, [baseStyle, overlayStyles, _ctxOverlayStyles, transformStyle]);
|
|
121
119
|
useAsyncEffect(async () => {
|
|
122
120
|
let newStyle;
|
|
123
121
|
if (typeof style === "string") {
|
|
@@ -187,8 +185,7 @@ function StyleLoadedReporter({ onStyleLoaded = null }) {
|
|
|
187
185
|
}
|
|
188
186
|
function MapTerrainManager({
|
|
189
187
|
mapUse3D,
|
|
190
|
-
terrainSourceID
|
|
191
|
-
style
|
|
188
|
+
terrainSourceID
|
|
192
189
|
}) {
|
|
193
190
|
use3DTerrain(mapUse3D, terrainSourceID);
|
|
194
191
|
return null;
|
package/dist/map-view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-view.js","sources":["../src/map-view.ts"],"sourcesContent":["import hyper from \"@macrostrat/hyper\";\nimport {\n useMapRef,\n useMapDispatch,\n use3DTerrain,\n getTerrainLayerForStyle,\n useMapStatus,\n} from \"@macrostrat/mapbox-react\";\nimport React from \"react\";\nimport {\n mapViewInfo,\n MapPosition,\n setMapPosition,\n getMapPosition,\n getMapboxStyle,\n mergeStyles,\n} from \"@macrostrat/mapbox-utils\";\nimport classNames from \"classnames\";\nimport mapboxgl from \"mapbox-gl\";\nimport { useEffect, useRef, useState } from \"react\";\nimport styles from \"./main.module.sass\";\nimport {\n MapLoadingReporter,\n MapMovedReporter,\n MapPaddingManager,\n MapResizeManager,\n} from \"./helpers\";\nimport \"mapbox-gl/dist/mapbox-gl.css\";\nimport { getMapPadding } from \"./utils\";\nimport { useAsyncEffect } from \"@macrostrat/ui-components\";\n\nconst h = hyper.styled(styles);\n\ntype MapboxCoreOptions = Omit<mapboxgl.MapboxOptions, \"container\">;\n\nexport interface MapViewProps extends MapboxCoreOptions {\n showLineSymbols?: boolean;\n children?: React.ReactNode;\n mapboxToken?: string;\n // Deprecated\n accessToken?: string;\n terrainSourceID?: string;\n enableTerrain?: boolean;\n infoMarkerPosition?: mapboxgl.LngLatLike;\n mapPosition?: MapPosition;\n initializeMap?: (\n container: HTMLElement,\n args: MapboxOptionsExt,\n ) => mapboxgl.Map;\n onMapLoaded?: (map: mapboxgl.Map) => void;\n onStyleLoaded?: (map: mapboxgl.Map) => void;\n onMapMoved?: (mapPosition: MapPosition, map: mapboxgl.Map) => void;\n /** This map sets its own viewport, rather than being positioned by a parent.\n * This is a hack to ensure that the map can overflow its \"safe area\" when false */\n standalone?: boolean;\n /** Overlay styles to apply to the map: a list of mapbox style objects or fragments to\n * overlay on top of the main map style at runtime */\n overlayStyles?: Partial<mapboxgl.StyleSpecification>[];\n /** A function to transform the map style before it is loaded */\n transformStyle?: (\n style: mapboxgl.StyleSpecification,\n ) => mapboxgl.StyleSpecification;\n loadingIgnoredSources?: string[];\n id?: string;\n className?: string;\n}\n\nexport interface MapboxOptionsExt extends MapboxCoreOptions {\n mapPosition?: MapPosition;\n}\n\nfunction defaultInitializeMap(container, args: MapboxOptionsExt = {}) {\n const { mapPosition, ...rest } = args;\n\n const map = new mapboxgl.Map({\n container,\n maxZoom: 18,\n logoPosition: \"bottom-left\",\n trackResize: false,\n antialias: true,\n // This is a legacy option for Mapbox GL v2\n // @ts-ignore\n optimizeForTerrain: true,\n ...rest,\n });\n\n let _mapPosition = mapPosition;\n if (_mapPosition == null && rest.center == null && rest.bounds == null) {\n // If no map positioning information is provided, we use the default\n _mapPosition = defaultMapPosition;\n }\n\n // set initial map position\n if (_mapPosition != null) {\n setMapPosition(map, _mapPosition);\n }\n\n return map;\n}\n\nconst defaultMapPosition: MapPosition = {\n camera: {\n lat: 34,\n lng: -120,\n altitude: 300000,\n },\n};\n\nexport function MapView(props: MapViewProps) {\n let { terrainSourceID } = props;\n const {\n enableTerrain = true,\n style,\n mapPosition,\n initializeMap = defaultInitializeMap,\n children,\n mapboxToken,\n // Deprecated\n accessToken,\n infoMarkerPosition,\n transformRequest,\n projection,\n onMapLoaded = null,\n onStyleLoaded = null,\n onMapMoved = null,\n standalone = false,\n overlayStyles,\n transformStyle,\n trackResize = true,\n loadingIgnoredSources = [\"elevationMarker\", \"crossSectionEndpoints\"],\n id = \"map\",\n className,\n ...rest\n } = props;\n if (enableTerrain) {\n terrainSourceID ??= \"mapbox-3d-dem\";\n }\n\n useEffect(() => {\n if (id != null) {\n console.warn(\n \"Setting a specific element ID for the map is deprecated. Please use className instead.\",\n );\n }\n }, [id]);\n\n const _mapboxToken = mapboxToken ?? accessToken;\n\n if (_mapboxToken != null) {\n mapboxgl.accessToken = _mapboxToken;\n }\n\n const dispatch = useMapDispatch();\n let mapRef = useMapRef();\n const ref = useRef<HTMLDivElement>();\n const parentRef = useRef<HTMLDivElement>();\n\n const [baseStyle, setBaseStyle] = useState<mapboxgl.Style>(null);\n\n const estMapPosition: MapPosition | null =\n mapRef.current == null ? mapPosition : getMapPosition(mapRef.current);\n const { mapUse3D, mapIsRotated } = mapViewInfo(estMapPosition);\n const is3DAvailable = (mapUse3D ?? false) && enableTerrain;\n\n useEffect(() => {\n /** Manager to update map style */\n if (baseStyle == null) return;\n let map = mapRef.current;\n\n let newStyle: mapboxgl.StyleSpecification = baseStyle;\n\n const overlayStyles = props.overlayStyles ?? [];\n\n if (overlayStyles.length > 0) {\n newStyle = mergeStyles(newStyle, ...overlayStyles);\n }\n\n /** If we can, we try to update the map style with terrain information\n * immediately, before the style is loaded. This allows us to avoid a\n * flash of the map without terrain.\n *\n * To do this, we need to estimate the map position before load, which\n * doesn't always work.\n */\n if (is3DAvailable) {\n // We can update the style with terrain layers immediately\n const terrainStyle = getTerrainLayerForStyle(newStyle, terrainSourceID);\n newStyle = mergeStyles(newStyle, terrainStyle);\n }\n\n if (transformStyle != null) {\n newStyle = transformStyle(newStyle);\n }\n\n if (map != null) {\n dispatch({ type: \"set-style-loaded\", payload: false });\n map.setStyle(newStyle);\n } else {\n const map = initializeMap(ref.current, {\n style: newStyle,\n projection,\n mapPosition,\n transformRequest,\n ...rest,\n });\n dispatch({ type: \"set-map\", payload: map });\n map.setPadding(getMapPadding(ref, parentRef), { animate: false });\n onMapLoaded?.(map);\n }\n }, [baseStyle, overlayStyles, transformStyle]);\n\n useAsyncEffect(async () => {\n /** Manager to update map style */\n let newStyle: mapboxgl.StyleSpecification;\n if (typeof style === \"string\") {\n newStyle = await getMapboxStyle(style, {\n access_token: mapboxgl.accessToken,\n });\n } else {\n newStyle = style;\n }\n setBaseStyle(newStyle);\n }, [style]);\n\n // Get map projection\n const _projection = mapRef.current?.getProjection()?.name ?? \"mercator\";\n\n const mapClassName = classNames(\n {\n \"is-rotated\": mapIsRotated ?? false,\n \"is-3d-available\": is3DAvailable,\n },\n `${_projection}-projection`,\n );\n\n const parentClassName = classNames(\n {\n standalone,\n },\n className,\n );\n\n return h(\n \"div.map-view-container.main-view\",\n { ref: parentRef, className: parentClassName },\n [\n h(\"div.mapbox-map.map-view\", { ref, className: mapClassName, id }),\n h(MapLoadingReporter, {\n ignoredSources: loadingIgnoredSources,\n }),\n h(StyleLoadedReporter, { onStyleLoaded }),\n h(MapMovedReporter, { onMapMoved }),\n // Subsitute for trackResize: true that allows map resizing to\n // be tied to a specific ref component\n h.if(trackResize)(MapResizeManager, { containerRef: ref }),\n h(MapPaddingManager, {\n containerRef: ref,\n parentRef,\n infoMarkerPosition,\n }),\n h(MapTerrainManager, { mapUse3D: is3DAvailable, terrainSourceID, style }),\n children,\n ],\n );\n}\n\nfunction StyleLoadedReporter({ onStyleLoaded = null }) {\n /** Check back every 0.1 seconds to see if the map has loaded.\n * We do it this way because mapboxgl loading events are unreliable */\n const isStyleLoaded = useMapStatus((state) => state.isStyleLoaded);\n const mapRef = useMapRef();\n const dispatch = useMapDispatch();\n\n useEffect(() => {\n if (isStyleLoaded) return;\n const interval = setInterval(() => {\n const map = mapRef.current;\n if (map == null) return;\n if (map.isStyleLoaded()) {\n // Wait a tick before setting the style loaded state\n dispatch({ type: \"set-style-loaded\", payload: true });\n onStyleLoaded?.(map);\n clearInterval(interval);\n }\n }, 50);\n return () => clearInterval(interval);\n }, [isStyleLoaded]);\n\n return null;\n}\n\nexport function MapTerrainManager({\n mapUse3D,\n terrainSourceID,\n style,\n}: {\n mapUse3D?: boolean;\n terrainSourceID?: string;\n style?: mapboxgl.StyleSpecification | string;\n}) {\n use3DTerrain(mapUse3D, terrainSourceID);\n\n return null;\n}\n"],"names":["hyper","styles","overlayStyles","map"],"mappings":";;;;;;;;;;;AA+BA,MAAM,IAAIA,IAAM,OAAOC,GAAM;AAwC7B,SAAS,qBAAqB,WAAW,OAAyB,IAAI;AACpE,QAAM,EAAE,aAAa,GAAG,KAAA,IAAS;AAEjC,QAAM,MAAM,IAAI,SAAS,IAAI;AAAA,IAC3B;AAAA,IACA,SAAS;AAAA,IACT,cAAc;AAAA,IACd,aAAa;AAAA,IACb,WAAW;AAAA;AAAA;AAAA,IAGX,oBAAoB;AAAA,IACpB,GAAG;AAAA,EAAA,CACJ;AAED,MAAI,eAAe;AACnB,MAAI,gBAAgB,QAAQ,KAAK,U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per\";\nimport {\n useMapRef,\n useMapDispatch,\n use3DTerrain,\n getTerrainLayerForStyle,\n useMapStatus,\n useMapStyleFragments,\n} from \"@macrostrat/mapbox-react\";\nimport React from \"react\";\nimport {\n mapViewInfo,\n MapPosition,\n setMapPosition,\n getMapPosition,\n getMapboxStyle,\n mergeStyles,\n} from \"@macrostrat/mapbox-utils\";\nimport classNames from \"classnames\";\nimport mapboxgl from \"mapbox-gl\";\nimport { useEffect, useRef, useState } from \"react\";\nimport styles from \"./main.module.sass\";\nimport {\n MapLoadingReporter,\n MapMovedReporter,\n MapPaddingManager,\n MapResizeManager,\n} from \"./helpers\";\nimport \"mapbox-gl/dist/mapbox-gl.css\";\nimport { getMapPadding } from \"./utils\";\nimport { useAsyncEffect } from \"@macrostrat/ui-components\";\n\nconst h = hyper.styled(styles);\n\ntype MapboxCoreOptions = Omit<mapboxgl.MapboxOptions, \"container\">;\n\nexport interface MapViewProps extends MapboxCoreOptions {\n showLineSymbols?: boolean;\n children?: React.ReactNode;\n mapboxToken?: string;\n // Deprecated\n accessToken?: string;\n terrainSourceID?: string;\n enableTerrain?: boolean;\n infoMarkerPosition?: mapboxgl.LngLatLike;\n mapPosition?: MapPosition;\n initializeMap?: (\n container: HTMLElement,\n args: MapboxOptionsExt,\n ) => mapboxgl.Map;\n onMapLoaded?: (map: mapboxgl.Map) => void;\n onStyleLoaded?: (map: mapboxgl.Map) => void;\n onMapMoved?: (mapPosition: MapPosition, map: mapboxgl.Map) => void;\n /** This map sets its own viewport, rather than being positioned by a parent.\n * This is a hack to ensure that the map can overflow its \"safe area\" when false */\n standalone?: boolean;\n /** Overlay styles to apply to the map: a list of mapbox style objects or fragments to\n * overlay on top of the main map style at runtime */\n overlayStyles?: Partial<mapboxgl.StyleSpecification>[];\n /** A function to transform the map style before it is loaded */\n transformStyle?: (\n style: mapboxgl.StyleSpecification,\n ) => mapboxgl.StyleSpecification;\n loadingIgnoredSources?: string[];\n id?: string;\n className?: string;\n}\n\nexport interface MapboxOptionsExt extends MapboxCoreOptions {\n mapPosition?: MapPosition;\n}\n\nfunction defaultInitializeMap(container, args: MapboxOptionsExt = {}) {\n const { mapPosition, ...rest } = args;\n\n const map = new mapboxgl.Map({\n container,\n maxZoom: 18,\n logoPosition: \"bottom-left\",\n trackResize: false,\n antialias: true,\n // This is a legacy option for Mapbox GL v2\n // @ts-ignore\n optimizeForTerrain: true,\n ...rest,\n });\n\n let _mapPosition = mapPosition;\n if (_mapPosition == null && rest.center == null && rest.bounds == null) {\n // If no map positioning information is provided, we use the default\n _mapPosition = defaultMapPosition;\n }\n\n // set initial map position\n if (_mapPosition != null) {\n setMapPosition(map, _mapPosition);\n }\n\n return map;\n}\n\nconst defaultMapPosition: MapPosition = {\n camera: {\n lat: 34,\n lng: -120,\n altitude: 300000,\n },\n};\n\nexport function MapView(props: MapViewProps) {\n let { terrainSourceID } = props;\n const {\n enableTerrain = true,\n style,\n mapPosition,\n initializeMap = defaultInitializeMap,\n children,\n mapboxToken,\n // Deprecated\n accessToken,\n infoMarkerPosition,\n transformRequest,\n projection,\n onMapLoaded = null,\n onStyleLoaded = null,\n onMapMoved = null,\n standalone = false,\n overlayStyles,\n transformStyle,\n trackResize = true,\n loadingIgnoredSources = [\"elevationMarker\", \"crossSectionEndpoints\"],\n id = \"map\",\n className,\n ...rest\n } = props;\n\n useEffect(() => {\n if (id != null) {\n console.warn(\n \"Setting a specific element ID for the map is deprecated. Please use className instead.\",\n );\n }\n }, [id]);\n\n const _mapboxToken = mapboxToken ?? accessToken;\n\n if (_mapboxToken != null) {\n mapboxgl.accessToken = _mapboxToken;\n }\n\n const dispatch = useMapDispatch();\n let mapRef = useMapRef();\n const ref = useRef<HTMLDivElement>();\n const parentRef = useRef<HTMLDivElement>();\n\n const [baseStyle, setBaseStyle] = useState<mapboxgl.Style>(null);\n\n /** Get overlay styles from map context. These are added after the base style is loaded, and can be used\n * to add layers to the map at runtime, even after initialization. They are merged with any overlay styles\n * passed in as props.\n */\n const _ctxOverlayStyles = useMapStyleFragments() as any[];\n\n const estMapPosition: MapPosition | null =\n mapRef.current == null ? mapPosition : getMapPosition(mapRef.current);\n const { mapUse3D, mapIsRotated } = mapViewInfo(estMapPosition);\n const is3DAvailable = (mapUse3D ?? false) && enableTerrain;\n\n useEffect(() => {\n /** Manager to update map style */\n if (baseStyle == null) return;\n let map = mapRef.current;\n\n let newStyle: mapboxgl.StyleSpecification = baseStyle;\n\n const _overlayStyles = overlayStyles ?? [];\n\n if (_overlayStyles.length > 0 || _ctxOverlayStyles.length > 0) {\n newStyle = mergeStyles(newStyle, ..._overlayStyles, ..._ctxOverlayStyles);\n }\n\n /** If we can, we try to update the map style with terrain information\n * immediately, before the style is loaded. This allows us to avoid a\n * flash of the map without terrain.\n *\n * To do this, we need to estimate the map position before load, which\n * doesn't always work.\n */\n if (is3DAvailable) {\n // We can update the style with terrain layers immediately\n const terrainStyle = getTerrainLayerForStyle(newStyle, terrainSourceID);\n newStyle = mergeStyles(newStyle, terrainStyle);\n }\n\n if (transformStyle != null) {\n newStyle = transformStyle(newStyle);\n }\n\n if (map != null) {\n dispatch({ type: \"set-style-loaded\", payload: false });\n map.setStyle(newStyle);\n } else {\n const map = initializeMap(ref.current, {\n style: newStyle,\n projection,\n mapPosition,\n transformRequest,\n ...rest,\n });\n dispatch({ type: \"set-map\", payload: map });\n map.setPadding(getMapPadding(ref, parentRef), { animate: false });\n onMapLoaded?.(map);\n }\n }, [baseStyle, overlayStyles, _ctxOverlayStyles, transformStyle]);\n\n useAsyncEffect(async () => {\n /** Manager to update map style */\n let newStyle: mapboxgl.StyleSpecification;\n if (typeof style === \"string\") {\n newStyle = await getMapboxStyle(style, {\n access_token: mapboxgl.accessToken,\n });\n } else {\n newStyle = style;\n }\n setBaseStyle(newStyle);\n }, [style]);\n\n // Get map projection\n const _projection = mapRef.current?.getProjection()?.name ?? \"mercator\";\n\n const mapClassName = classNames(\n {\n \"is-rotated\": mapIsRotated ?? false,\n \"is-3d-available\": is3DAvailable,\n },\n `${_projection}-projection`,\n );\n\n const parentClassName = classNames(\n {\n standalone,\n },\n className,\n );\n\n return h(\n \"div.map-view-container.main-view\",\n { ref: parentRef, className: parentClassName },\n [\n h(\"div.mapbox-map.map-view\", { ref, className: mapClassName, id }),\n h(MapLoadingReporter, {\n ignoredSources: loadingIgnoredSources,\n }),\n h(StyleLoadedReporter, { onStyleLoaded }),\n h(MapMovedReporter, { onMapMoved }),\n // Subsitute for trackResize: true that allows map resizing to\n // be tied to a specific ref component\n h.if(trackResize)(MapResizeManager, { containerRef: ref }),\n h(MapPaddingManager, {\n containerRef: ref,\n parentRef,\n infoMarkerPosition,\n }),\n h(MapTerrainManager, { mapUse3D: is3DAvailable, terrainSourceID, style }),\n children,\n ],\n );\n}\n\nfunction StyleLoadedReporter({ onStyleLoaded = null }) {\n /** Check back every 0.1 seconds to see if the map has loaded.\n * We do it this way because mapboxgl loading events are unreliable */\n const isStyleLoaded = useMapStatus((state) => state.isStyleLoaded);\n const mapRef = useMapRef();\n const dispatch = useMapDispatch();\n\n useEffect(() => {\n if (isStyleLoaded) return;\n const interval = setInterval(() => {\n const map = mapRef.current;\n if (map == null) return;\n if (map.isStyleLoaded()) {\n // Wait a tick before setting the style loaded state\n dispatch({ type: \"set-style-loaded\", payload: true });\n onStyleLoaded?.(map);\n clearInterval(interval);\n }\n }, 50);\n return () => clearInterval(interval);\n }, [isStyleLoaded]);\n\n return null;\n}\n\nexport function MapTerrainManager({\n mapUse3D,\n terrainSourceID,\n}: {\n mapUse3D?: boolean;\n terrainSourceID?: string;\n style?: mapboxgl.StyleSpecification | string;\n}) {\n use3DTerrain(mapUse3D, terrainSourceID);\n\n return null;\n}\n"],"names":["hyper","styles","map"],"mappings":";;;;;;;;;;;AAgCA,MAAM,IAAIA,IAAM,OAAOC,GAAM;AAwC7B,SAAS,qBAAqB,WAAW,OAAyB,IAAI;AACpE,QAAM,EAAE,aAAa,GAAG,KAAA,IAAS;AAEjC,QAAM,MAAM,IAAI,SAAS,IAA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,CAAC,aAAa,CAAC;AAElB,SAAO;AACT;AAEO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AACF,GAIG;AACD,eAAa,UAAU,eAAe;AAEtC,SAAO;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@macrostrat/map-interface",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Map interface for Macrostrat",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -48,10 +48,9 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@blueprintjs/core": "^6.6.1",
|
|
50
50
|
"@macrostrat/color-utils": "^1.2.1",
|
|
51
|
-
"@macrostrat/data-components": "^1.1.
|
|
51
|
+
"@macrostrat/data-components": "^1.1.3",
|
|
52
52
|
"@macrostrat/hyper": "^3.0.6",
|
|
53
|
-
"@macrostrat/
|
|
54
|
-
"@macrostrat/mapbox-react": "^3.0.2",
|
|
53
|
+
"@macrostrat/mapbox-react": "^3.1.0",
|
|
55
54
|
"@macrostrat/mapbox-utils": "^1.7.2",
|
|
56
55
|
"@macrostrat/ui-components": "^5.0.5",
|
|
57
56
|
"@mapbox/tilebelt": "^2.0.0",
|
package/src/map-view.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
use3DTerrain,
|
|
6
6
|
getTerrainLayerForStyle,
|
|
7
7
|
useMapStatus,
|
|
8
|
+
useMapStyleFragments,
|
|
8
9
|
} from "@macrostrat/mapbox-react";
|
|
9
10
|
import React from "react";
|
|
10
11
|
import {
|
|
@@ -132,9 +133,6 @@ export function MapView(props: MapViewProps) {
|
|
|
132
133
|
className,
|
|
133
134
|
...rest
|
|
134
135
|
} = props;
|
|
135
|
-
if (enableTerrain) {
|
|
136
|
-
terrainSourceID ??= "mapbox-3d-dem";
|
|
137
|
-
}
|
|
138
136
|
|
|
139
137
|
useEffect(() => {
|
|
140
138
|
if (id != null) {
|
|
@@ -157,6 +155,12 @@ export function MapView(props: MapViewProps) {
|
|
|
157
155
|
|
|
158
156
|
const [baseStyle, setBaseStyle] = useState<mapboxgl.Style>(null);
|
|
159
157
|
|
|
158
|
+
/** Get overlay styles from map context. These are added after the base style is loaded, and can be used
|
|
159
|
+
* to add layers to the map at runtime, even after initialization. They are merged with any overlay styles
|
|
160
|
+
* passed in as props.
|
|
161
|
+
*/
|
|
162
|
+
const _ctxOverlayStyles = useMapStyleFragments() as any[];
|
|
163
|
+
|
|
160
164
|
const estMapPosition: MapPosition | null =
|
|
161
165
|
mapRef.current == null ? mapPosition : getMapPosition(mapRef.current);
|
|
162
166
|
const { mapUse3D, mapIsRotated } = mapViewInfo(estMapPosition);
|
|
@@ -169,10 +173,10 @@ export function MapView(props: MapViewProps) {
|
|
|
169
173
|
|
|
170
174
|
let newStyle: mapboxgl.StyleSpecification = baseStyle;
|
|
171
175
|
|
|
172
|
-
const
|
|
176
|
+
const _overlayStyles = overlayStyles ?? [];
|
|
173
177
|
|
|
174
|
-
if (
|
|
175
|
-
newStyle = mergeStyles(newStyle, ...
|
|
178
|
+
if (_overlayStyles.length > 0 || _ctxOverlayStyles.length > 0) {
|
|
179
|
+
newStyle = mergeStyles(newStyle, ..._overlayStyles, ..._ctxOverlayStyles);
|
|
176
180
|
}
|
|
177
181
|
|
|
178
182
|
/** If we can, we try to update the map style with terrain information
|
|
@@ -207,7 +211,7 @@ export function MapView(props: MapViewProps) {
|
|
|
207
211
|
map.setPadding(getMapPadding(ref, parentRef), { animate: false });
|
|
208
212
|
onMapLoaded?.(map);
|
|
209
213
|
}
|
|
210
|
-
}, [baseStyle, overlayStyles, transformStyle]);
|
|
214
|
+
}, [baseStyle, overlayStyles, _ctxOverlayStyles, transformStyle]);
|
|
211
215
|
|
|
212
216
|
useAsyncEffect(async () => {
|
|
213
217
|
/** Manager to update map style */
|
|
@@ -292,7 +296,6 @@ function StyleLoadedReporter({ onStyleLoaded = null }) {
|
|
|
292
296
|
export function MapTerrainManager({
|
|
293
297
|
mapUse3D,
|
|
294
298
|
terrainSourceID,
|
|
295
|
-
style,
|
|
296
299
|
}: {
|
|
297
300
|
mapUse3D?: boolean;
|
|
298
301
|
terrainSourceID?: string;
|