@macrostrat/map-interface 1.0.12 → 1.1.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/index.cjs.js +56 -67
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +57 -68
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +4 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/context-panel/index.ts +3 -4
- package/src/dev/map-page.ts +15 -9
- package/src/helpers.ts +15 -13
- package/src/map-view/index.ts +28 -32
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import "./index.css";
|
|
2
|
-
import {useMemo as $Zz0sd$useMemo, useState as $Zz0sd$useState, useEffect as $Zz0sd$useEffect, useCallback as $Zz0sd$useCallback, useRef as $Zz0sd$useRef} from "react";
|
|
3
2
|
import {Spinner as $Zz0sd$Spinner, Button as $Zz0sd$Button, Text as $Zz0sd$Text, Navbar as $Zz0sd$Navbar, Card as $Zz0sd$Card, Icon as $Zz0sd$Icon, Switch as $Zz0sd$Switch, Collapse as $Zz0sd$Collapse} from "@blueprintjs/core";
|
|
4
3
|
import $Zz0sd$macrostrathyper, {addClassNames as $Zz0sd$addClassNames} from "@macrostrat/hyper";
|
|
5
|
-
import {useMapStatus as $Zz0sd$useMapStatus, useFocusState as $Zz0sd$useFocusState, isCentered as $Zz0sd$isCentered, LocationFocusButton as $Zz0sd$LocationFocusButton, ZoomControl as $Zz0sd$ZoomControl, MapboxMapProvider as $Zz0sd$MapboxMapProvider, useMapPosition as $Zz0sd$useMapPosition, MapControlWrapper as $Zz0sd$MapControlWrapper, ThreeDControl as $Zz0sd$ThreeDControl, CompassControl as $Zz0sd$CompassControl, GlobeControl as $Zz0sd$GlobeControl, useMapRef as $Zz0sd$useMapRef, useMapEaseTo as $Zz0sd$useMapEaseTo, useMapDispatch as $Zz0sd$useMapDispatch, useMapConditionalStyle as $Zz0sd$useMapConditionalStyle} from "@macrostrat/mapbox-react";
|
|
4
|
+
import {useMapStatus as $Zz0sd$useMapStatus, useFocusState as $Zz0sd$useFocusState, isCentered as $Zz0sd$isCentered, LocationFocusButton as $Zz0sd$LocationFocusButton, ZoomControl as $Zz0sd$ZoomControl, MapboxMapProvider as $Zz0sd$MapboxMapProvider, useMapPosition as $Zz0sd$useMapPosition, MapControlWrapper as $Zz0sd$MapControlWrapper, ThreeDControl as $Zz0sd$ThreeDControl, CompassControl as $Zz0sd$CompassControl, GlobeControl as $Zz0sd$GlobeControl, useMapRef as $Zz0sd$useMapRef, useMapEaseTo as $Zz0sd$useMapEaseTo, useMapDispatch as $Zz0sd$useMapDispatch, useMapInitialized as $Zz0sd$useMapInitialized, useMapConditionalStyle as $Zz0sd$useMapConditionalStyle} from "@macrostrat/mapbox-react";
|
|
6
5
|
import {Spacer as $Zz0sd$Spacer, ErrorBoundary as $Zz0sd$ErrorBoundary, useToaster as $Zz0sd$useToaster, useDarkMode as $Zz0sd$useDarkMode, useStoredState as $Zz0sd$useStoredState, ToasterContext as $Zz0sd$ToasterContext, DevToolsButtonSlot as $Zz0sd$DevToolsButtonSlot, useInDarkMode as $Zz0sd$useInDarkMode, JSONView as $Zz0sd$JSONView, usePrevious as $Zz0sd$usePrevious} from "@macrostrat/ui-components";
|
|
7
6
|
import $Zz0sd$classnames from "classnames";
|
|
8
7
|
import {formatCoordForZoomLevel as $Zz0sd$formatCoordForZoomLevel, normalizeLng as $Zz0sd$normalizeLng, metersToFeet as $Zz0sd$metersToFeet, getMapboxStyle as $Zz0sd$getMapboxStyle, mergeStyles as $Zz0sd$mergeStyles, mapViewInfo as $Zz0sd$mapViewInfo, getMapPosition as $Zz0sd$getMapPosition, setMapPosition as $Zz0sd$setMapPosition} from "@macrostrat/mapbox-utils";
|
|
9
8
|
import {format as $Zz0sd$format} from "d3-format";
|
|
10
9
|
import $Zz0sd$mapboxgl, {ScaleControl as $Zz0sd$ScaleControl, GeolocateControl as $Zz0sd$GeolocateControl, Marker as $Zz0sd$Marker} from "mapbox-gl";
|
|
10
|
+
import {useState as $Zz0sd$useState, useEffect as $Zz0sd$useEffect, useCallback as $Zz0sd$useCallback, useRef as $Zz0sd$useRef, useMemo as $Zz0sd$useMemo} from "react";
|
|
11
11
|
import {asChromaColor as $Zz0sd$asChromaColor, toRGBAString as $Zz0sd$toRGBAString} from "@macrostrat/color-utils";
|
|
12
12
|
import {useTransition as $Zz0sd$useTransition} from "transition-hook";
|
|
13
13
|
import {debounce as $Zz0sd$debounce} from "underscore";
|
|
@@ -48,7 +48,6 @@ $parcel$export($6e914c81c8e053da$exports, "MapLoadingButton", () => $6e914c81c8e
|
|
|
48
48
|
$parcel$export($6e914c81c8e053da$exports, "FloatingNavbar", () => $6e914c81c8e053da$export$a8cc0062d02a3841);
|
|
49
49
|
|
|
50
50
|
|
|
51
|
-
|
|
52
51
|
var $fbe402416678c280$exports = {};
|
|
53
52
|
|
|
54
53
|
$parcel$export($fbe402416678c280$exports, "loading-button", () => $fbe402416678c280$export$fcaa8d3bc8e9cf1e, (v) => $fbe402416678c280$export$fcaa8d3bc8e9cf1e = v);
|
|
@@ -89,13 +88,10 @@ function $6e914c81c8e053da$export$4ec83e90d030b2f3({ isLoading: isLoading = fals
|
|
|
89
88
|
});
|
|
90
89
|
}
|
|
91
90
|
function $6e914c81c8e053da$export$9e3bae3c08bde368(props) {
|
|
92
|
-
const
|
|
93
|
-
const mapIsLoading = (0, $Zz0sd$useMemo)(()=>isLoading, [
|
|
94
|
-
isLoading
|
|
95
|
-
]);
|
|
91
|
+
const isLoading = (0, $Zz0sd$useMapStatus)((s)=>s.isLoading);
|
|
96
92
|
return $6e914c81c8e053da$var$h($6e914c81c8e053da$export$4ec83e90d030b2f3, {
|
|
97
93
|
...props,
|
|
98
|
-
isLoading:
|
|
94
|
+
isLoading: isLoading
|
|
99
95
|
});
|
|
100
96
|
}
|
|
101
97
|
function $6e914c81c8e053da$export$a8cc0062d02a3841({ className: className, children: children, headerElement: headerElement = null, title: title = null, statusElement: statusElement = null, rightElement: rightElement = null, height: height, width: width, style: style = {} }) {
|
|
@@ -1006,6 +1002,7 @@ function $4bc3dd5f0732eed3$export$2ab96428dea558d6({ containerRef: containerRef,
|
|
|
1006
1002
|
function $4bc3dd5f0732eed3$export$f6eeee399afc4e9a({ onMapMoved: onMapMoved = null }) {
|
|
1007
1003
|
const mapRef = (0, $Zz0sd$useMapRef)();
|
|
1008
1004
|
const dispatch = (0, $Zz0sd$useMapDispatch)();
|
|
1005
|
+
const isInitialized = (0, $Zz0sd$useMapInitialized)();
|
|
1009
1006
|
const mapMovedCallback = (0, $Zz0sd$useCallback)(()=>{
|
|
1010
1007
|
const map = mapRef.current;
|
|
1011
1008
|
if (map == null) return;
|
|
@@ -1016,9 +1013,9 @@ function $4bc3dd5f0732eed3$export$f6eeee399afc4e9a({ onMapMoved: onMapMoved = nu
|
|
|
1016
1013
|
});
|
|
1017
1014
|
onMapMoved?.(mapPosition, map);
|
|
1018
1015
|
}, [
|
|
1019
|
-
mapRef.current,
|
|
1020
1016
|
onMapMoved,
|
|
1021
|
-
dispatch
|
|
1017
|
+
dispatch,
|
|
1018
|
+
isInitialized
|
|
1022
1019
|
]);
|
|
1023
1020
|
(0, $Zz0sd$useEffect)(()=>{
|
|
1024
1021
|
// Get the current value of the map. Useful for gradually moving away
|
|
@@ -1041,6 +1038,7 @@ function $4bc3dd5f0732eed3$export$e57f9eaa51773f82({ ignoredSources: ignoredSour
|
|
|
1041
1038
|
const mapRef = (0, $Zz0sd$useMapRef)();
|
|
1042
1039
|
const loadingRef = (0, $Zz0sd$useRef)(false);
|
|
1043
1040
|
const dispatch = (0, $Zz0sd$useMapDispatch)();
|
|
1041
|
+
const isInitialized = (0, $Zz0sd$useMapInitialized)();
|
|
1044
1042
|
(0, $Zz0sd$useEffect)(()=>{
|
|
1045
1043
|
const map = mapRef.current;
|
|
1046
1044
|
const mapIsLoading = loadingRef.current;
|
|
@@ -1074,35 +1072,34 @@ function $4bc3dd5f0732eed3$export$e57f9eaa51773f82({ ignoredSources: ignoredSour
|
|
|
1074
1072
|
};
|
|
1075
1073
|
}, [
|
|
1076
1074
|
ignoredSources,
|
|
1077
|
-
|
|
1078
|
-
|
|
1075
|
+
mapIsLoading,
|
|
1076
|
+
isInitialized
|
|
1079
1077
|
]);
|
|
1080
1078
|
return null;
|
|
1081
1079
|
}
|
|
1082
1080
|
function $4bc3dd5f0732eed3$export$5c90a91c7455938c({ position: position, setPosition: setPosition, centerMarker: centerMarker = true }) {
|
|
1083
1081
|
const mapRef = (0, $Zz0sd$useMapRef)();
|
|
1084
1082
|
const markerRef = (0, $Zz0sd$useRef)(null);
|
|
1083
|
+
const isInitialized = (0, $Zz0sd$useMapInitialized)();
|
|
1085
1084
|
(0, $82fe09613877ffc2$export$278090850f6b3a9f)(mapRef, markerRef, position);
|
|
1086
|
-
const handleMapClick = (0, $Zz0sd$useCallback)((event)=>{
|
|
1087
|
-
setPosition(event.lngLat, event, mapRef.current);
|
|
1088
|
-
// We should integrate this with the "easeToCenter" hook
|
|
1089
|
-
if (centerMarker) mapRef.current?.flyTo({
|
|
1090
|
-
center: event.lngLat,
|
|
1091
|
-
duration: 800
|
|
1092
|
-
});
|
|
1093
|
-
}, [
|
|
1094
|
-
mapRef.current,
|
|
1095
|
-
setPosition
|
|
1096
|
-
]);
|
|
1097
1085
|
(0, $Zz0sd$useEffect)(()=>{
|
|
1098
1086
|
const map = mapRef.current;
|
|
1099
|
-
if (map
|
|
1087
|
+
if (map == null || setPosition == null) return;
|
|
1088
|
+
const handleMapClick = (event)=>{
|
|
1089
|
+
setPosition(event.lngLat, event, mapRef.current);
|
|
1090
|
+
// We should integrate this with the "easeToCenter" hook
|
|
1091
|
+
if (centerMarker) mapRef.current?.flyTo({
|
|
1092
|
+
center: event.lngLat,
|
|
1093
|
+
duration: 800
|
|
1094
|
+
});
|
|
1095
|
+
};
|
|
1096
|
+
map.on("click", handleMapClick);
|
|
1100
1097
|
return ()=>{
|
|
1101
1098
|
map?.off("click", handleMapClick);
|
|
1102
1099
|
};
|
|
1103
1100
|
}, [
|
|
1104
|
-
|
|
1105
|
-
|
|
1101
|
+
setPosition,
|
|
1102
|
+
isInitialized
|
|
1106
1103
|
]);
|
|
1107
1104
|
return null;
|
|
1108
1105
|
}
|
|
@@ -1216,54 +1213,46 @@ function $9e150e311a3261e9$export$ab1e7a67d6ec5ad8(props) {
|
|
|
1216
1213
|
let mapRef = (0, $Zz0sd$useMapRef)();
|
|
1217
1214
|
const ref = (0, $Zz0sd$useRef)();
|
|
1218
1215
|
const parentRef = (0, $Zz0sd$useRef)();
|
|
1219
|
-
// Keep track of map position for reloads
|
|
1220
|
-
(0, $Zz0sd$useEffect)(()=>{
|
|
1221
|
-
console.log("Map updated", mapRef.current);
|
|
1222
|
-
}, [
|
|
1223
|
-
mapRef.current
|
|
1224
|
-
]);
|
|
1225
1216
|
(0, $Zz0sd$useEffect)(()=>{
|
|
1226
1217
|
if (style == null) return;
|
|
1227
|
-
|
|
1218
|
+
let map = mapRef.current;
|
|
1219
|
+
if (map != null) {
|
|
1228
1220
|
console.log("Setting style", style);
|
|
1229
|
-
|
|
1230
|
-
|
|
1221
|
+
map.setStyle(style);
|
|
1222
|
+
} else {
|
|
1223
|
+
console.log("Initializing map", style);
|
|
1224
|
+
const map = initializeMap(ref.current, {
|
|
1225
|
+
style: style,
|
|
1226
|
+
projection: projection,
|
|
1227
|
+
mapPosition: mapPosition,
|
|
1228
|
+
...rest
|
|
1229
|
+
});
|
|
1230
|
+
dispatch({
|
|
1231
|
+
type: "set-map",
|
|
1232
|
+
payload: map
|
|
1233
|
+
});
|
|
1234
|
+
map.setPadding((0, $82fe09613877ffc2$export$bb78f9f01775eef1)(ref, parentRef), {
|
|
1235
|
+
animate: false
|
|
1236
|
+
});
|
|
1237
|
+
onMapLoaded?.(map);
|
|
1231
1238
|
}
|
|
1232
|
-
const
|
|
1233
|
-
style: style,
|
|
1234
|
-
projection: projection,
|
|
1235
|
-
mapPosition: mapPosition,
|
|
1236
|
-
...rest
|
|
1237
|
-
});
|
|
1238
|
-
map.setPadding((0, $82fe09613877ffc2$export$bb78f9f01775eef1)(ref, parentRef), {
|
|
1239
|
-
animate: false
|
|
1240
|
-
});
|
|
1241
|
-
map.on("style.load", ()=>{
|
|
1239
|
+
const loadCallback = ()=>{
|
|
1242
1240
|
onStyleLoaded?.(map);
|
|
1243
1241
|
dispatch({
|
|
1244
1242
|
type: "set-style-loaded",
|
|
1245
1243
|
payload: true
|
|
1246
1244
|
});
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1245
|
+
};
|
|
1246
|
+
map = mapRef.current;
|
|
1247
|
+
if (map.isStyleLoaded()) // Catch a race condition where the style is loaded before the callback is set
|
|
1248
|
+
loadCallback();
|
|
1249
|
+
map.on("style.load", loadCallback);
|
|
1250
|
+
return ()=>{
|
|
1251
|
+
map.off("style.load", loadCallback);
|
|
1252
|
+
};
|
|
1253
1253
|
}, [
|
|
1254
1254
|
style
|
|
1255
1255
|
]);
|
|
1256
|
-
// Map style updating
|
|
1257
|
-
// useEffect(() => {
|
|
1258
|
-
// if (mapRef?.current == null || style == null) return;
|
|
1259
|
-
// mapRef?.current?.setStyle(style);
|
|
1260
|
-
// }, [mapRef.current, style]);
|
|
1261
|
-
// Set map position if it changes
|
|
1262
|
-
// useEffect(() => {
|
|
1263
|
-
// const map = mapRef.current;
|
|
1264
|
-
// if (map == null || mapPosition == null) return;
|
|
1265
|
-
// setMapPosition(map, mapPosition);
|
|
1266
|
-
// }, [mapPosition]);
|
|
1267
1256
|
const _computedMapPosition = (0, $Zz0sd$useMapPosition)();
|
|
1268
1257
|
const { mapUse3D: mapUse3D, mapIsRotated: mapIsRotated } = (0, $Zz0sd$mapViewInfo)(_computedMapPosition);
|
|
1269
1258
|
// Get map projection
|
|
@@ -1810,7 +1799,7 @@ function $b8c84b63e75fe4f2$export$617d79dae526d2cf({ features: features }) {
|
|
|
1810
1799
|
|
|
1811
1800
|
|
|
1812
1801
|
const $a281a0612311d660$export$dda1d9f60106f0e9 = (0, $Zz0sd$macrostrathyper).styled((0, (/*@__PURE__*/$parcel$interopDefault($bfe9593b6c29b10b$exports))));
|
|
1813
|
-
function $a281a0612311d660$export$c5febf3ae8816972({ title: title = "Map inspector", headerElement: headerElement = null, transformRequest: transformRequest = null, mapPosition: mapPosition = null, mapboxToken: mapboxToken = null, overlayStyle: overlayStyle = null, children: children, style: style, bounds: bounds = null, focusedSource: focusedSource = null, focusedSourceTitle: focusedSourceTitle = null, fitViewport: fitViewport = true }) {
|
|
1802
|
+
function $a281a0612311d660$export$c5febf3ae8816972({ title: title = "Map inspector", headerElement: headerElement = null, transformRequest: transformRequest = null, mapPosition: mapPosition = null, mapboxToken: mapboxToken = null, overlayStyle: overlayStyle = null, children: children, style: style, bounds: bounds = null, focusedSource: focusedSource = null, focusedSourceTitle: focusedSourceTitle = null, fitViewport: fitViewport = true, styleType: styleType = "macrostrat" }) {
|
|
1814
1803
|
/* We apply a custom style to the panel container when we are interacting
|
|
1815
1804
|
with the search bar, so that we can block map interactions until search
|
|
1816
1805
|
bar focus is lost.
|
|
@@ -1819,15 +1808,15 @@ function $a281a0612311d660$export$c5febf3ae8816972({ title: title = "Map inspect
|
|
|
1819
1808
|
*/ const dark = (0, $Zz0sd$useDarkMode)();
|
|
1820
1809
|
const isEnabled = dark?.isEnabled;
|
|
1821
1810
|
if (mapboxToken != null) (0, $Zz0sd$mapboxgl).accessToken = mapboxToken;
|
|
1822
|
-
style ??= isEnabled ? "mapbox://styles/
|
|
1811
|
+
if (styleType == "macrostrat") style ??= isEnabled ? "mapbox://styles/jczaplewski/cl5uoqzzq003614o6url9ou9z?optimize=true" : "mapbox://styles/jczaplewski/clatdbkw4002q14lov8zx0bm0?optimize=true";
|
|
1812
|
+
else style ??= isEnabled ? "mapbox://styles/mapbox/dark-v10" : "mapbox://styles/mapbox/light-v10";
|
|
1823
1813
|
const [isOpen, setOpen] = (0, $Zz0sd$useState)(false);
|
|
1824
1814
|
const [state, setState] = (0, $Zz0sd$useStoredState)("macrostrat:dev-map-page", {
|
|
1825
1815
|
showTileExtent: false,
|
|
1826
1816
|
xRay: false
|
|
1827
1817
|
});
|
|
1828
1818
|
const { showTileExtent: showTileExtent, xRay: xRay } = state;
|
|
1829
|
-
const [actualStyle, setActualStyle] = (0, $Zz0sd$useState)(
|
|
1830
|
-
console.log("actualStyle", actualStyle);
|
|
1819
|
+
const [actualStyle, setActualStyle] = (0, $Zz0sd$useState)(null);
|
|
1831
1820
|
(0, $Zz0sd$useEffect)(()=>{
|
|
1832
1821
|
(0, $64ee2eed3ed5ffbc$export$e739dc8dfc0db9a6)(style, overlayStyle, {
|
|
1833
1822
|
mapboxToken: mapboxToken,
|
|
@@ -1892,6 +1881,7 @@ function $a281a0612311d660$export$c5febf3ae8816972({ title: title = "Map inspect
|
|
|
1892
1881
|
title: title
|
|
1893
1882
|
}),
|
|
1894
1883
|
contextPanel: $a281a0612311d660$export$dda1d9f60106f0e9((0, $4bdfa9cd8240b2fd$export$ec68dd77edbe678b), [
|
|
1884
|
+
children,
|
|
1895
1885
|
$a281a0612311d660$export$dda1d9f60106f0e9((0, $Zz0sd$Switch), {
|
|
1896
1886
|
checked: xRay,
|
|
1897
1887
|
label: "X-ray mode",
|
|
@@ -1901,8 +1891,7 @@ function $a281a0612311d660$export$c5febf3ae8816972({ title: title = "Map inspect
|
|
|
1901
1891
|
xRay: !xRay
|
|
1902
1892
|
});
|
|
1903
1893
|
}
|
|
1904
|
-
})
|
|
1905
|
-
children
|
|
1894
|
+
})
|
|
1906
1895
|
]),
|
|
1907
1896
|
detailPanel: detailElement,
|
|
1908
1897
|
contextPanelOpen: isOpen,
|