From bfba478af599d8c5bbd20ef26bf84580b87ad1eb Mon Sep 17 00:00:00 2001 From: andreeaceachir Date: Tue, 4 Jun 2024 12:54:28 +0200 Subject: [PATCH] feat: Expose the MapsIndoors Instance to be used from outside. --- packages/map-template/src/components/Map/Map.jsx | 16 +++++++++++++--- .../src/components/MapTemplate/MapTemplate.jsx | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/map-template/src/components/Map/Map.jsx b/packages/map-template/src/components/Map/Map.jsx index c975159e4..c7582119f 100644 --- a/packages/map-template/src/components/Map/Map.jsx +++ b/packages/map-template/src/components/Map/Map.jsx @@ -1,4 +1,4 @@ -import { useEffect } from "react"; +import { forwardRef, useEffect, useImperativeHandle } from "react"; import { useRecoilState, useRecoilValue } from 'recoil'; import { mapTypes } from "../../constants/mapTypes"; import useLiveData from '../../hooks/useLivedata'; @@ -39,7 +39,7 @@ let _tileStyle; * @param {function} onMapPositionKnown - Function that is run when the map position is known. * @returns */ -function Map({ onLocationClick, onVenueChangedOnMap, useMapProviderModule, onMapPositionKnown }) { +const Map = forwardRef(({ onLocationClick, onVenueChangedOnMap, useMapProviderModule, onMapPositionKnown }, ref) => { const apiKey = useRecoilValue(apiKeyState); const gmApiKey = useRecoilValue(gmApiKeyState); const mapboxAccessToken = useRecoilValue(mapboxAccessTokenState); @@ -264,10 +264,20 @@ function Map({ onLocationClick, onVenueChangedOnMap, useMapProviderModule, onMap onTileStyleChanged(mapsIndoorsInstance); }, [tileStyle]); + + /** + * Method that can be triggered on the element to get the MapsIndoors Instance. + */ + useImperativeHandle(ref, () => ({ + getMapsIndoorsInstance() { + return mapsIndoorsInstance; + } + })); + return (<> {mapType === mapTypes.Google && } {mapType === mapTypes.Mapbox && } ) -} +}); export default Map; diff --git a/packages/map-template/src/components/MapTemplate/MapTemplate.jsx b/packages/map-template/src/components/MapTemplate/MapTemplate.jsx index 5b78db16a..be8a2ba51 100644 --- a/packages/map-template/src/components/MapTemplate/MapTemplate.jsx +++ b/packages/map-template/src/components/MapTemplate/MapTemplate.jsx @@ -657,6 +657,7 @@ function MapTemplate({ apiKey, gmApiKey, mapboxAccessToken, venue, locationId, p } {window.mapsIndoorsInstance = mapsIndoorsInstance}} useMapProviderModule={useMapProviderModule} onVenueChangedOnMap={(venue) => venueChangedOnMap(venue)} onMapPositionKnown={() => setIsMapPositionKnown(true)}