Skip to content

Commit

Permalink
Merge branch 'main' into feature/upgrade-sdk
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/map-template/CHANGELOG.md
  • Loading branch information
andreeaceachir142 committed Jan 8, 2025
2 parents ae1e52f + 810ce07 commit 1d9e742
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mapsindoors/components",
"version": "13.24.1",
"version": "13.25.0",
"description": "Web components for MapsIndoors",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
8 changes: 7 additions & 1 deletion packages/map-template/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.64.1] - 2025-01-07
## [1.65.1] - 2025-01-08

## Fixed

- Upgrade to SDK v4.38.3.

## [1.65.0] - 2025-01-08

## Added

- Added functionality to exit location details by clicking outside MapsIndoors data on the map for both Google Maps and Mapbox.

## [1.64.0] - 2025-01-02

## Added
Expand Down
2 changes: 1 addition & 1 deletion packages/map-template/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@mapsindoors/map-template",
"description": "Get a MapsIndoors map up and running in less than 10 mins.",
"version": "1.64.0",
"version": "1.65.0",
"private": false,
"files": [
"dist/*.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ function BottomSheet({ directionsFromLocation, directionsToLocation, pushAppView
onBack={() => closeLocationDetails()}
snapPointSwiped={locationDetailsSheetSwiped}
onStartDirections={() => pushAppView(appViews.DIRECTIONS)}
isOpen={currentAppView === appViews.LOCATION_DETAILS}
/>
</Sheet>,
<Sheet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import kioskLocationState from '../../atoms/kioskLocationState';
import accessibilityOnState from '../../atoms/accessibilityOnState';
import { useIsDesktop } from '../../hooks/useIsDesktop';
import showExternalIDsState from '../../atoms/showExternalIDsState';
import useOutsideMapsIndoorsDataClick from '../../hooks/useOutsideMapsIndoorsDataClick';

/**
* Shows details for a MapsIndoors Location.
Expand All @@ -26,9 +27,10 @@ import showExternalIDsState from '../../atoms/showExternalIDsState';
* @param {function} props.onSetSize - Callback that is fired when the toggle full description button is clicked and the Sheet size changes.
* @param {function} props.snapPointSwiped - Changes value when user has swiped a Bottom sheet to a new snap point.
* @param {function} props.onStartDirections - Callback that fires when user clicks the Start directions button.
* @param {boolean} props.isOpen - Whether the Location Details are open or not.
*
*/
function LocationDetails({ onBack, onStartWayfinding, onSetSize, snapPointSwiped, onStartDirections }) {
function LocationDetails({ onBack, onStartWayfinding, onSetSize, snapPointSwiped, onStartDirections, isOpen }) {
const { t } = useTranslation();

const locationInfoElement = useRef(null);
Expand Down Expand Up @@ -69,6 +71,8 @@ function LocationDetails({ onBack, onStartWayfinding, onSetSize, snapPointSwiped

const showExternalIDs = useRecoilValue(showExternalIDsState);

const clickedOutsideMapsIndoorsData = useOutsideMapsIndoorsDataClick(mapsIndoorsInstance, isOpen);

useEffect(() => {
return () => {
setLocationDisplayRule(null);
Expand Down Expand Up @@ -121,6 +125,12 @@ function LocationDetails({ onBack, onStartWayfinding, onSetSize, snapPointSwiped
}
}, [snapPointSwiped]); // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
if (clickedOutsideMapsIndoorsData) {
onBack();
}
}, [clickedOutsideMapsIndoorsData]);

/**
* Toggle the description.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/map-template/src/components/Sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function Sidebar({ directionsFromLocation, directionsToLocation, pushAppView, cu
onStartWayfinding={() => pushAppView(appViews.WAYFINDING)}
onBack={() => closeLocationDetails()}
onStartDirections={() => pushAppView(appViews.DIRECTIONS)}
isOpen={currentAppView === appViews.LOCATION_DETAILS}
/>
</Modal>,
<Modal isOpen={currentAppView === appViews.WAYFINDING} key="D">
Expand Down
93 changes: 93 additions & 0 deletions packages/map-template/src/hooks/useOutsideMapsIndoorsDataClick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { useEffect, useState } from 'react';
import mapTypeState from '../atoms/mapTypeState';
import { useRecoilValue } from 'recoil';
import { mapTypes } from '../constants/mapTypes';

/**
* Custom hook that handles map click events and determines whether the user clicked outside MapsIndoors data.
*
* @param {Object} mapsIndoorsInstance - The MapsIndoors instance.
* @param {boolean} isOpen - Whether the sidebar or bottom sheet is open or not.
* @returns {boolean} Returns `true` if the user clicked outside MapsIndoors data, `false` otherwise.
*/
export default function useOutsideMapsIndoorsDataClick(mapsIndoorsInstance, isOpen) {
const mapType = useRecoilValue(mapTypeState);
const [clickedOutside, setClickedOutside] = useState(false);
const map = mapsIndoorsInstance.getMap();

// Reset clickedOutside state when the sidebar or bottom sheet is opened
useEffect(() => {
if (isOpen) {
setClickedOutside(false);
}
}, [isOpen]);

/**
* Attaches click listeners to a Mapbox map instance to handle clicks on MapsIndoors data.
*
* @param {Object} map - The Mapbox map instance.
* @param {Object} mapsIndoorsInstance - The MapsIndoors instance.
* @param {boolean} isOpen - Whether the sidebar or bottom sheet is open or not.
* @param {Function} setClickedOutside - A function to set the state when a click occurs outside MapsIndoors data.
* @returns {Function} A cleanup function to remove the attached listeners.
*/
function attachMapboxClickListeners(map, mapsIndoorsInstance, isOpen, setClickedOutside) {
const mapboxClickHandler = (clickResult) => {
if (!isOpen) return;
const features = mapsIndoorsInstance.getMap().queryRenderedFeatures(clickResult.point);

if (features.length) {
setClickedOutside(false);
} else {
setClickedOutside(true);
}
};
map.on('click', mapboxClickHandler);

return () => {
map.off('click', mapboxClickHandler);
};
}

/**
* Attaches click listeners to the Google Maps and MapsIndoors instances.
*
* @param {object} map - The Google Maps instance.
* @param {object} mapsIndoorsInstance - The MapsIndoors instance.
* @param {boolean} isOpen - Whether the sidebar or bottom sheet is open or not.
* @param {function} setClickedOutside - A function to set the state when a click occurs outside MapsIndoors.
* @returns {function} A cleanup function to remove the attached listeners.
*/
function attachGoogleClickListeners(map, mapsIndoorsInstance, isOpen, setClickedOutside) {
const googleMapsClickHandler = (clickResult) => {
if (!isOpen) return;
setClickedOutside(false);
};

const googleMapsIndoorsClickHandler = (clickResult) => {
if (!isOpen) return;
setClickedOutside(true);
};

mapsIndoorsInstance.addListener('click', googleMapsClickHandler);
const mapListener = map.addListener('click', googleMapsIndoorsClickHandler);

return () => {
mapsIndoorsInstance.removeListener('click', googleMapsClickHandler);
mapListener.remove();
};
}

useEffect(() => {
let detachMapClickListeners;
if (mapType === mapTypes.Mapbox) {
detachMapClickListeners = attachMapboxClickListeners(map, mapsIndoorsInstance, isOpen, setClickedOutside);
}
if (mapType === mapTypes.Google) {
detachMapClickListeners = attachGoogleClickListeners(map, mapsIndoorsInstance, isOpen, setClickedOutside);
}
return () => detachMapClickListeners?.();
}, [mapsIndoorsInstance, isOpen]);

return clickedOutside;
}

0 comments on commit 1d9e742

Please sign in to comment.