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

Commit

Permalink
Merge pull request #905 from eyelidlessness/fix/geopicker-ui
Browse files Browse the repository at this point in the history
Fix: preserve geopicker zoom, center map on user location on load, no error clicking pin
  • Loading branch information
lognaturel authored Jun 14, 2022
2 parents 484eb18 + 9d3c67d commit 6936b39
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/widget/geo/geopicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
className: 'enketo-geopoint-marker',
});
const iconMulti = L.divIcon({
iconSize: 16,
iconSize: [16, 16],
className: 'enketo-geopoint-circle-marker',
});
const iconMultiActive = L.divIcon({
iconSize: 16,
iconSize: [16, 16],
className: 'enketo-geopoint-circle-marker-active',
});

Expand Down Expand Up @@ -325,7 +325,7 @@ class Geopicker extends Widget {
this._updateMap([0, 0], 1);
if (this.props.detect) {
getCurrentPosition()
.then((position) => {
.then(({ position }) => {
that._updateMap(
[
position.coords.latitude,
Expand Down Expand Up @@ -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;
}

// update the map if it is visible
Expand Down Expand Up @@ -841,6 +840,16 @@ class Geopicker extends Widget {
}
});

this.map.on('load', () => {
this.map.on('zoomend', (event) => {
const zoom = event.target.getZoom();

if (zoom != null) {
this.lastZoom = zoom;
}
});
});

// watch out, default "Leaflet" link clicks away from page, loosing all data
that.map.attributionControl.setPrefix('');

Expand Down

0 comments on commit 6936b39

Please sign in to comment.