Skip to content

Commit

Permalink
feat: Expose the MapsIndoors Instance to be used from outside.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreeaceachir142 committed Jun 4, 2024
1 parent 5c9ac63 commit bfba478
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/map-template/src/components/Map/Map.jsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 && <GoogleMapsMap onMapView={onMapView} onPositionControl={onPositionControlCreated} />}
{mapType === mapTypes.Mapbox && <MapboxMap onMapView={onMapView} onPositionControl={onPositionControlCreated} />}
</>)
}
});

export default Map;
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ function MapTemplate({ apiKey, gmApiKey, mapboxAccessToken, venue, locationId, p
</Fragment>
}
<MIMap
ref={(mapsIndoorsInstance) => {window.mapsIndoorsInstance = mapsIndoorsInstance}}
useMapProviderModule={useMapProviderModule}
onVenueChangedOnMap={(venue) => venueChangedOnMap(venue)}
onMapPositionKnown={() => setIsMapPositionKnown(true)}
Expand Down

0 comments on commit bfba478

Please sign in to comment.