Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add center prop and logic around it #436

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

matbmapspeople
Copy link
Contributor

I added possibility to read center's value from the URL.

Based on this value and other URL prop values I created a logic where the map should be centred.

@andreeaceachir142
Copy link
Contributor

@ammapspeople I've added a few comments here which stood out at a first glance, to save you some time 😄

Copy link
Contributor

@ammapspeople ammapspeople left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll pause reviewing this until the build error mentioned in the Jira ticket is resolved.

@@ -553,6 +556,13 @@ function MapTemplate({ apiKey, gmApiKey, mapboxAccessToken, venue, locationId, p
setSearchExternalLocations(searchExternalLocations);
}, [searchExternalLocations]);

/*
* TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do 😁

@@ -92,8 +93,9 @@ defineCustomElements();
* @param {boolean} [props.showRoadNames] - A boolean parameter that dictates whether Mapbox road names should be shown. By default, Mapbox road names are hidden when MapsIndoors data is shown. It is dictated by `mi-transition-level` which default value is 17.
* @param {boolean} [props.showExternalIDs] - Determine whether the location details on the map should have an external ID visible. The default value is set to false.
* @param {boolean} [props.searchExternalLocations] - If you want to perform search for external locations in the Wayfinding mode. If set to true, Mapbox/Google places will be displayed depending on the Map Provider you are using. If set to false, the results returned will only be MapsIndoors results. The default is true.
* @param {string} [props.center] - TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs explanation

@@ -36,6 +36,7 @@ import getBooleanValue from "../../helpers/GetBooleanValue.js";
* @param {boolean} [props.showExternalIDs] - Determine whether the location details on the map should have an external ID visible. The default value is set to false.
* @param {boolean} [props.showRoadNames] - A boolean parameter that dictates whether Mapbox road names should be shown. By default, Mapbox road names are hidden when MapsIndoors data is shown. It is dictated by `mi-transition-level` which default value is 17.
* @param {boolean} [props.searchExternalLocations] - If you want to perform search for external results in the Wayfinding mode. If set to true, Mapbox/Google places will be displayed depending on the Map Provider you are using. If set to false, the results returned will only be MapsIndoors results. The default is true.
* @param {string} [props.center] - TODO
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs explanation.

const venuesInSolution = useRecoilValue(venuesInSolutionState);
const currentPitch = useRecoilValue(currentPitchSelector);
const venueWasSelected = useRecoilValue(venueWasSelectedState);
const [kioskLocationDisplayRuleWasChanged, setKioskLocationDisplayRuleWasChanged] = useState(false);
let centerValue = useRecoilValue(centerState);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name it center to follow the existing pattern?

Comment on lines 106 to 116
getDesktopPaddingBottom().then(desktopPaddingBottom => {
desktopPadBottom = desktopPaddingBottom;
});

getMobilePaddingBottom().then(mobilePaddingBottom => {
mobilePadBottom = mobilePaddingBottom
});

getDesktopPaddingLeft().then(desktopPaddingLeft => {
desktopPadLeft = desktopPaddingLeft;
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Promise.all() instead of running them one by one. Then you'll get an array with all the values when all have resolved. See for example the onLocationClicked function in the Search component.

@matbmapspeople
Copy link
Contributor Author

I now addressed all your comments @andreeaceachir142 and @ammapspeople

const zoomLevel = startZoomLevel ?? 16;


Promise.all([getDesktopPaddingBottom(), getDesktopPaddingLeft(), getMobilePaddingBottom()]).then(([desktopPaddingBottom, desktopPaddingLeft, mobilePaddingBottom]) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't we risk that the "pad" variables are null since this is asynchronous and the code following it is immediately executed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reversed the code as it was before. Because version before works.

@ammapspeople
Copy link
Contributor

The bounds are not fit to venue when no center prop provided:

image

@ammapspeople
Copy link
Contributor

The center prop is not reacting to changes runtime. It should.

Kapture.2025-01-10.at.09.36.53.mp4

@matbmapspeople
Copy link
Contributor Author

I believe I addressed all your comments @ammapspeople
I would appreciate @andreeaceachir142 if you can resolve yours if I managed to fix your issues :)

@@ -36,6 +36,7 @@ import getBooleanValue from "../../helpers/GetBooleanValue.js";
* @param {boolean} [props.showExternalIDs] - Determine whether the location details on the map should have an external ID visible. The default value is set to false.
* @param {boolean} [props.showRoadNames] - A boolean parameter that dictates whether Mapbox road names should be shown. By default, Mapbox road names are hidden when MapsIndoors data is shown. It is dictated by `mi-transition-level` which default value is 17.
* @param {boolean} [props.searchExternalLocations] - If you want to perform search for external results in the Wayfinding mode. If set to true, Mapbox/Google places will be displayed depending on the Map Provider you are using. If set to false, the results returned will only be MapsIndoors results. The default is true.
* @param {string} [props.center] - Specifies the coordinates where the map should load, represented as latitude and longitude values separated by a comma. If the specified coordinates intersect with a Venue, that Venue will be selected in the Venue Selector.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use the same phrasing pattern as for the venue and locationId prop: "If you want the map to center on a specific coordinate, provide [...]"

const centerPoint = { geometry: { type: 'Point', coordinates: [latitude, longitude] } };

// Returns Venue that intersects with center prop.
const intersectingVenueWithCenterPoint = venuesInSolution.find(venue => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary to calculate at this point in time, since the value is only used in some cases. Postpone to be calculated only when we know it's going to be used.

if (venueWasSelected) {
// If switching Venues, while having center prop defined, set center prop to undefined.
// It is required to be able to switch between Venues inside Venue Selector.
center = undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not set Recoil atoms to undefined. I guess that would stop the reactivity of it. Instead use a useRecoilState instead of a useRecoilValue hook for the center atom to get access to a setter function.

@matbmapspeople
Copy link
Contributor Author

I applied your suggestions @ammapspeople

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants