@macrostrat/map-interface 0.2.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@macrostrat/map-interface",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Map interface for Macrostrat",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",
@@ -11,14 +11,14 @@
11
11
  "@macrostrat/hyper": "^2.2.1",
12
12
  "@macrostrat/mapbox-react": "^2.1.0",
13
13
  "@macrostrat/mapbox-utils": "^1.2.1",
14
- "@macrostrat/ui-components": "^3.0.0",
14
+ "@macrostrat/ui-components": "^3.1.0",
15
15
  "@mapbox/tilebelt": "^1.0.2",
16
16
  "@turf/bbox": "^6.5.0",
17
17
  "chroma-js": "^2.4.2",
18
18
  "classnames": "^2.3.2",
19
19
  "d3-array": "^3.2.4",
20
20
  "d3-format": "^3.1.0",
21
- "mapbox-gl": "^2.11.0",
21
+ "mapbox-gl": "^2.15.0",
22
22
  "transition-hook": "^1.5.2",
23
23
  "underscore": "^1.13.6",
24
24
  "use-resize-observer": "^9.1.0"
package/src/container.ts CHANGED
@@ -15,10 +15,6 @@ import { Card } from "@blueprintjs/core";
15
15
 
16
16
  import { ReactNode } from "react";
17
17
 
18
- export function MapInterface() {
19
- return h("div", "Hello world");
20
- }
21
-
22
18
  const h = hyper.styled(styles);
23
19
 
24
20
  type AnyElement = React.ReactNode | React.ReactElement | React.ReactFragment;
@@ -39,7 +35,6 @@ function _MapAreaContainer({
39
35
  mapControls = h(MapBottomControls),
40
36
  contextStackProps = null,
41
37
  detailStackProps = null,
42
- mapPosition = null,
43
38
  fitViewport = true,
44
39
  ...rest
45
40
  }: {
@@ -56,7 +51,6 @@ function _MapAreaContainer({
56
51
  contextPanelOpen?: boolean;
57
52
  contextStackProps?: HTMLDivProps;
58
53
  detailStackProps?: HTMLDivProps;
59
- mapPosition?: MapPosition;
60
54
  fitViewport?: boolean;
61
55
  }) {
62
56
  const _detailPanelOpen = detailPanelOpen ?? detailPanel != null;
@@ -88,7 +82,6 @@ function _MapAreaContainer({
88
82
  className: classNames("map-page", className, {
89
83
  "fit-viewport": fitViewport,
90
84
  }),
91
- mapPosition,
92
85
  },
93
86
  [
94
87
  h("div.main-ui", { className: mainUIClassName, ...rest }, [
@@ -121,7 +114,6 @@ export const MapAreaContainer = (props) =>
121
114
 
122
115
  interface MapContainerProps {
123
116
  className?: string;
124
- mapPosition?: MapPosition;
125
117
  children?: ReactNode;
126
118
  }
127
119
 
@@ -1,6 +1,6 @@
1
1
  .feature-panel
2
2
  position: relative
3
- overflow-x: hidden
3
+ margin: 0 -1em
4
4
 
5
5
  .key-value
6
6
  display: inline-block
@@ -27,9 +27,6 @@
27
27
 
28
28
  .feature-group
29
29
  border-bottom: 1px solid var(--panel-rule-inner)
30
- padding: 0 1em
31
- margin-left: -1em
32
- margin-right: -1em
33
30
  margin-bottom: 0.5em
34
31
  &:last-child
35
32
  border-bottom: none
@@ -38,7 +35,6 @@
38
35
  display: flex
39
36
  flex-direction: row
40
37
  align-items: baseline
41
- padding: 0 1em
42
38
  h3
43
39
  margin-right: 0.5em
44
40
 
@@ -48,7 +48,7 @@ export function DevMapPage({
48
48
  headerElement?: React.ReactElement;
49
49
  transformRequest?: mapboxgl.TransformRequestFunction;
50
50
  title?: string;
51
- style: mapboxgl.Style | string;
51
+ style?: mapboxgl.Style | string;
52
52
  children?: React.ReactNode;
53
53
  mapboxToken?: string;
54
54
  overlayStyle?: mapboxgl.Style | string;
@@ -131,8 +131,6 @@ export function DevMapPage({
131
131
  tile = { x: f._x, y: f._y, z: f._z };
132
132
  }
133
133
 
134
- console.log("Style", actualStyle);
135
-
136
134
  return h(
137
135
  MapAreaContainer,
138
136
  {
@@ -163,7 +161,8 @@ export function DevMapPage({
163
161
  style: actualStyle,
164
162
  transformRequest,
165
163
  mapPosition,
166
- projection: "globe",
164
+ projection: { name: "globe" },
165
+ mapboxToken,
167
166
  },
168
167
  [
169
168
  h(FeatureSelectionHandler, {
package/src/helpers.ts CHANGED
@@ -66,6 +66,7 @@ export function MapPaddingManager({
66
66
  },
67
67
  });
68
68
 
69
+ // Ideally, we would not have to do this when we know the infobox is loaded
69
70
  useMapEaseToCenter(infoMarkerPosition, padding);
70
71
 
71
72
  return null;
@@ -22,6 +22,7 @@ import {
22
22
  MapResizeManager,
23
23
  } from "../helpers";
24
24
  import "mapbox-gl/dist/mapbox-gl.css";
25
+ import { getMapPadding } from "../utils";
25
26
 
26
27
  const h = hyper.styled({ ...styles, ...rootStyles });
27
28
 
@@ -30,14 +31,19 @@ type MapboxCoreOptions = Omit<mapboxgl.MapboxOptions, "container">;
30
31
  export interface MapViewProps extends MapboxCoreOptions {
31
32
  showLineSymbols?: boolean;
32
33
  children?: React.ReactNode;
34
+ mapboxToken?: string;
35
+ // Deprecated
33
36
  accessToken?: string;
34
37
  terrainSourceID?: string;
35
38
  enableTerrain?: boolean;
36
39
  infoMarkerPosition?: mapboxgl.LngLatLike;
37
- //style: mapboxgl.Style | string;
38
- //transformRequest?: mapboxgl.TransformRequestFunction;
39
40
  mapPosition?: MapPosition;
40
- onMapLoad?: (map: mapboxgl.Map) => void;
41
+ initializeMap?: (
42
+ container: HTMLElement,
43
+ args: MapboxOptionsExt
44
+ ) => mapboxgl.Map;
45
+ onMapLoaded?: (map: mapboxgl.Map) => void;
46
+ onStyleLoaded?: (map: mapboxgl.Map) => void;
41
47
  }
42
48
 
43
49
  export interface MapboxOptionsExt extends MapboxCoreOptions {
@@ -83,6 +89,8 @@ export function MapView(props: MapViewProps) {
83
89
  mapPosition = defaultMapPosition,
84
90
  initializeMap = defaultInitializeMap,
85
91
  children,
92
+ mapboxToken,
93
+ // Deprecated
86
94
  accessToken,
87
95
  infoMarkerPosition,
88
96
  transformRequest,
@@ -95,8 +103,10 @@ export function MapView(props: MapViewProps) {
95
103
  terrainSourceID ??= "mapbox-3d-dem";
96
104
  }
97
105
 
98
- if (accessToken != null) {
99
- mapboxgl.accessToken = accessToken;
106
+ const _mapboxToken = mapboxToken ?? accessToken;
107
+
108
+ if (_mapboxToken != null) {
109
+ mapboxgl.accessToken = _mapboxToken;
100
110
  }
101
111
 
102
112
  const dispatch = useMapDispatch();
@@ -105,6 +115,9 @@ export function MapView(props: MapViewProps) {
105
115
  const parentRef = useRef<HTMLDivElement>();
106
116
 
107
117
  // Keep track of map position for reloads
118
+ useEffect(() => {
119
+ console.log("Map updated", mapRef.current);
120
+ }, [mapRef.current]);
108
121
 
109
122
  useEffect(() => {
110
123
  if (style == null) return;
@@ -119,6 +132,7 @@ export function MapView(props: MapViewProps) {
119
132
  mapPosition,
120
133
  ...rest,
121
134
  });
135
+ map.setPadding(getMapPadding(ref, parentRef), { animate: false });
122
136
  map.on("style.load", () => {
123
137
  onStyleLoaded?.(map);
124
138
  dispatch({ type: "set-style-loaded", payload: true });
@@ -9,6 +9,9 @@
9
9
  bottom: 0
10
10
  left: 0
11
11
  right: 0
12
+ &:global(.mapboxgl-map)
13
+ // override the default mapbox position: relative in all cases
14
+ position: absolute
12
15
 
13
16
  /* Desktop styling is necessarily much more complicated than mobile
14
17
  to handle a two-column layout. */