Skip to content

Commit

Permalink
Use getMap method
Browse files Browse the repository at this point in the history
  • Loading branch information
hanbyul-here committed Jun 24, 2024
1 parent d17fbb0 commit dcd17f9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions app/scripts/components/common/blocks/scrollytelling/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function Scrollytelling(props) {
const { isHeaderHidden, headerHeight, wrapperHeight } =
useSlidingStickyHeaderProps();

const mapRef = useRef<MapRef>(null);
const mapRef = useRef<MapRef | null>(null);
const [isMapLoaded, setMapLoaded] = useState(false);

// Extract the props from the chapters.
Expand Down Expand Up @@ -273,8 +273,11 @@ function Scrollytelling(props) {
// Setup initial map state which will be the values on the first chapter.
const initialChapter = chapterProps[0];

mapRef.current?.setZoom(initialChapter.zoom);
mapRef.current?.setCenter(initialChapter.center);
// @NOTE: getMap method is needed to access hidden method
// https://visgl.github.io/react-map-gl/docs/api-reference/map#getmap
const currentMapRef = mapRef.current?.getMap();
currentMapRef?.setZoom(initialChapter.zoom);
currentMapRef?.setCenter(initialChapter.center);

setActiveChapter(initialChapter);

Expand All @@ -290,7 +293,7 @@ function Scrollytelling(props) {
const chapter = chapterProps[index];
setActiveChapter(chapter);

mapRef.current?.flyTo({
currentMapRef?.flyTo({
center: chapter.center,
zoom: chapter.zoom
});
Expand Down Expand Up @@ -411,7 +414,6 @@ function Scrollytelling(props) {
onMapLoad={() => {
setMapLoaded(true);
mapRef.current?.resize();
mapRef.current?.getMap().setProjection('globe');
}}
onStyleUpdate={() => {
mapRef.current?.resize();
Expand Down

0 comments on commit dcd17f9

Please sign in to comment.