Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Fix: preserve geopicker zoom, center map on user location on load, no error clicking pin #905

Merged
merged 3 commits into from
Jun 14, 2022

Conversation

eyelidlessness
Copy link
Contributor

@eyelidlessness eyelidlessness commented Jun 7, 2022

Closes #902. Grouping these together, initially for visibility/feedback because they all affect the Leaflet UI and would be challenging to test and I want to get a sense of how much interest there is in adding those tests anyway.

This was a regression in the original `setgeopoint` work, when abstracting the geolocation code into `getCurrentPosition`
Also fixes the pin's width so it's no longer distorted
@@ -40,15 +40,15 @@ let searchSource =
'https://maps.googleapis.com/maps/api/geocode/json?address={address}&sensor=true&key={api_key}';
const googleApiKey = config.googleApiKey || config.google_api_key;
const iconSingle = L.divIcon({
iconSize: 24,
iconSize: [16, 24],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does two things:

  1. Correct the width of map pins
  2. Prevent an error when clicking on the pin, where Leaflet's internal state calculating the pin's offset has NaN for the left side.

@@ -773,7 +773,6 @@ class Geopicker extends Widget {
// update last requested map coordinates to be used to initialize map in mobile fullscreen view
if (latLng) {
this.lastLatLng = latLng;
this.lastZoom = zoom;
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'm not certain this isn't guarded here for a reason, but it seems like the event handler more likely is the expected behavior.

@@ -841,6 +840,16 @@ class Geopicker extends Widget {
}
});

this.map.on('load', () => {
this.map.on('zoomend', (event) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this is wrapped in the load event to ensure the initial zoom isn't treated as a user-initiated state change.

@lognaturel lognaturel merged commit 6936b39 into enketo:master Jun 14, 2022
@lognaturel
Copy link
Contributor

how much interest there is in adding those tests

Seems ok to continue with this being untested for now.

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

Successfully merging this pull request may close these issues.

2 participants