Skip to content

Commit

Permalink
small updates to map components
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed Nov 14, 2024
1 parent 7359980 commit 9d00934
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
8 changes: 3 additions & 5 deletions packages/map-interface/src/dev/map-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import hyper from "@macrostrat/hyper";
import { Spacer, useDarkMode, useStoredState } from "@macrostrat/ui-components";
import mapboxgl from "mapbox-gl";
import { useCallback, useState, useEffect } from "react";
import { buildInspectorStyle, buildXRayStyle } from "./xray";
import { buildInspectorStyle } from "./xray";
import { MapAreaContainer, PanelCard } from "../container";
import { FloatingNavbar, MapLoadingButton } from "../context-panel";
import { MapMarker } from "../helpers";
Expand Down Expand Up @@ -75,9 +75,7 @@ export function MapInspector({
});
const { showTileExtent, xRay } = state;

const [actualStyle, setActualStyle] = useState(style);

console.log("actualStyle", actualStyle);
const [actualStyle, setActualStyle] = useState(null);

useEffect(() => {
buildInspectorStyle(style, overlayStyle, {
Expand Down Expand Up @@ -141,14 +139,14 @@ export function MapInspector({
title,
}),
contextPanel: h(PanelCard, [
children,
h(Switch, {
checked: xRay,
label: "X-ray mode",
onChange() {
setState({ ...state, xRay: !xRay });
},
}),
children,
]),
detailPanel: detailElement,
contextPanelOpen: isOpen,
Expand Down
21 changes: 3 additions & 18 deletions packages/map-interface/src/map-view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
useMapRef,
useMapDispatch,
useMapPosition,
useMapStatus,
} from "@macrostrat/mapbox-react";
import {
mapViewInfo,
Expand Down Expand Up @@ -116,18 +117,15 @@ export function MapView(props: MapViewProps) {
const ref = useRef<HTMLDivElement>();
const parentRef = useRef<HTMLDivElement>();

// Keep track of map position for reloads
useEffect(() => {
console.log("Map updated", mapRef.current);
}, [mapRef.current]);

useEffect(() => {
if (style == null) return;
if (mapRef.current != null) {
console.log("Setting style", style);
mapRef.current.setStyle(style);
return;
}

console.log("Initializing map", style);
const map = initializeMap(ref.current, {
style,
projection,
Expand All @@ -143,19 +141,6 @@ export function MapView(props: MapViewProps) {
dispatch({ type: "set-map", payload: map });
}, [style]);

// Map style updating
// useEffect(() => {
// if (mapRef?.current == null || style == null) return;
// mapRef?.current?.setStyle(style);
// }, [mapRef.current, style]);

// Set map position if it changes
// useEffect(() => {
// const map = mapRef.current;
// if (map == null || mapPosition == null) return;
// setMapPosition(map, mapPosition);
// }, [mapPosition]);

const _computedMapPosition = useMapPosition();
const { mapUse3D, mapIsRotated } = mapViewInfo(_computedMapPosition);

Expand Down

0 comments on commit 9d00934

Please sign in to comment.