From 33641a08716ce51e871e33052a5e2928a6289d1a Mon Sep 17 00:00:00 2001 From: andrew nimmo Date: Fri, 9 Aug 2024 15:01:23 -0700 Subject: [PATCH] Improve Riparius handling --- .../controllers/autocompleter_controller.js | 15 ++++++++++----- app/javascript/controllers/geocode_controller.js | 16 ++++++++-------- app/javascript/controllers/map_controller.js | 12 ++++++------ 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/app/javascript/controllers/autocompleter_controller.js b/app/javascript/controllers/autocompleter_controller.js index ab1476779e..847081042e 100644 --- a/app/javascript/controllers/autocompleter_controller.js +++ b/app/javascript/controllers/autocompleter_controller.js @@ -286,11 +286,16 @@ export default class extends Controller { } // set the map type so box is editable this.mapOutlet.map_type = "hybrid"; // only if location_google - - let location - if (location = this.mapOutlet.validateLatLngInputs(false)) { - this.mapOutlet.geocodeLatLng(location); - } else if (this.mapOutlet.hasLockBoxBtnTarget) { + // set the map to stop ignoring place input + this.mapOutlet.ignorePlaceInput = false; + + // 2024-08-09: Don't geocode lat/lng when switching to location_google. + // This is for custom locations and should pay attention to place_name only. + // let location + // if (location = this.mapOutlet.validateLatLngInputs(false)) { + // this.mapOutlet.tryToGeocode(); + // } else + if (this.mapOutlet.hasLockBoxBtnTarget) { this.mapOutlet.lockBoxBtnTarget.classList.remove("d-none"); } } diff --git a/app/javascript/controllers/geocode_controller.js b/app/javascript/controllers/geocode_controller.js index fba70c52c8..1284151180 100644 --- a/app/javascript/controllers/geocode_controller.js +++ b/app/javascript/controllers/geocode_controller.js @@ -45,9 +45,9 @@ export default class extends Controller { } tryToGeocode() { - let location + const location = this.validateLatLngInputs(false) - if (location = this.validateLatLngInputs(false) && + if (location && JSON.stringify(location) !== JSON.stringify(this.lastGeocodedLatLng)) { this.geocodeLatLng(location) } @@ -75,10 +75,10 @@ export default class extends Controller { } tryToGeolocate() { - let address = this.placeInputTarget.value + const address = this.placeInputTarget.value - if (this.ignorePlaceInput === false && address !== "" - && address !== this.lastGeolocatedAddress) { + if (this.ignorePlaceInput === false && + address !== "" && address !== this.lastGeolocatedAddress) { this.geolocatePlaceName(address) } } @@ -449,9 +449,9 @@ export default class extends Controller { // ------------------------------- DEBUGGING ------------------------------ - helpDebug() { - debugger - } + // helpDebug() { + // debugger + // } verbose(str) { // console.log(str); diff --git a/app/javascript/controllers/map_controller.js b/app/javascript/controllers/map_controller.js index 770769439f..2a115b765b 100644 --- a/app/javascript/controllers/map_controller.js +++ b/app/javascript/controllers/map_controller.js @@ -398,11 +398,11 @@ export default class extends GeocodeController { let id if (this.hasLocationIdTarget && (id = this.locationIdTarget.value)) { this.mapLocationIdData() - // Only geocode lat/lng if we have no location_id and not ignoring place } else if (["location", "hybrid"].includes(this.map_type)) { + // Only geocode lat/lng if we have no location_id and not ignoring place + // ...and only geolocate placeName if we have no lat/lng if (this.ignorePlaceInput !== false) { this.tryToGeocode() // multiple possible results - // ...and only geolocate placeName if we have no lat/lng } else { this.tryToGeolocate() } @@ -499,7 +499,7 @@ export default class extends GeocodeController { // Action called by the "Open Map" button only. // open/close handled by BS collapse toggleMap() { - // this.verbose("map:toggleMap") + this.verbose("map:toggleMap") if (this.opened) { this.opened = false this.controlWrapTarget.classList.remove("map-open") @@ -627,9 +627,9 @@ export default class extends GeocodeController { // ------------------------------- DEBUGGING ------------------------------ - helpDebug() { - debugger - } + // helpDebug() { + // debugger + // } verbose(str) { // console.log(str);