Handle nothing found for reverse geocode

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-10-15 16:48:11 +02:00
parent 93c79af4c2
commit 3d963cf3bc
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
2 changed files with 21 additions and 16 deletions

View file

@ -175,11 +175,13 @@ export default class AddressAutoComplete extends Vue {
}); });
this.addressData = result.data.reverseGeocode.map((address: IAddress) => new Address(address)); this.addressData = result.data.reverseGeocode.map((address: IAddress) => new Address(address));
if (this.addressData.length > 0) {
const defaultAddress = new Address(this.addressData[0]); const defaultAddress = new Address(this.addressData[0]);
this.selected = defaultAddress; this.selected = defaultAddress;
this.$emit("input", this.selected); this.$emit("input", this.selected);
this.queryText = `${defaultAddress.poiInfos.name} ${defaultAddress.poiInfos.alternativeName}`; this.queryText = `${defaultAddress.poiInfos.name} ${defaultAddress.poiInfos.alternativeName}`;
} }
}
checkCurrentPosition(e: LatLng): boolean { checkCurrentPosition(e: LatLng): boolean {
if (!this.selected || !this.selected.geom) return false; if (!this.selected || !this.selected.geom) return false;

View file

@ -151,7 +151,7 @@ export default class FullAddressAutoComplete extends Vue {
}; };
} }
async asyncData(query: string) { async asyncData(query: string): Promise<void> {
if (!query.length) { if (!query.length) {
this.addressData = []; this.addressData = [];
this.selected = new Address(); this.selected = new Address();
@ -178,7 +178,7 @@ export default class FullAddressAutoComplete extends Vue {
} }
@Watch("config") @Watch("config")
watchConfig(config: IConfig) { watchConfig(config: IConfig): void {
if (!config.geocoding.autocomplete) { if (!config.geocoding.autocomplete) {
// If autocomplete is disabled, we put a larger debounce value // If autocomplete is disabled, we put a larger debounce value
// so that we don't request with incomplete address // so that we don't request with incomplete address
@ -187,7 +187,7 @@ export default class FullAddressAutoComplete extends Vue {
} }
@Watch("value") @Watch("value")
updateEditing() { updateEditing(): void {
if (!(this.value && this.value.id)) return; if (!(this.value && this.value.id)) return;
this.selected = this.value; this.selected = this.value;
const address = new Address(this.selected); const address = new Address(this.selected);
@ -196,22 +196,22 @@ export default class FullAddressAutoComplete extends Vue {
} }
} }
updateSelected(option: IAddress) { updateSelected(option: IAddress): void {
if (option == null) return; if (option == null) return;
this.selected = option; this.selected = option;
this.$emit("input", this.selected); this.$emit("input", this.selected);
} }
resetPopup() { resetPopup(): void {
this.selected = new Address(); this.selected = new Address();
} }
openNewAddressModal() { openNewAddressModal(): void {
this.resetPopup(); this.resetPopup();
this.addressModalActive = true; this.addressModalActive = true;
} }
async reverseGeoCode(e: LatLng, zoom: number) { async reverseGeoCode(e: LatLng, zoom: number): Promise<void> {
// If the position has been updated through autocomplete selection, no need to geocode it! // If the position has been updated through autocomplete selection, no need to geocode it!
if (this.checkCurrentPosition(e)) return; if (this.checkCurrentPosition(e)) return;
const result = await this.$apollo.query({ const result = await this.$apollo.query({
@ -225,13 +225,15 @@ export default class FullAddressAutoComplete extends Vue {
}); });
this.addressData = result.data.reverseGeocode.map((address: IAddress) => new Address(address)); this.addressData = result.data.reverseGeocode.map((address: IAddress) => new Address(address));
if (this.addressData.length > 0) {
const defaultAddress = new Address(this.addressData[0]); const defaultAddress = new Address(this.addressData[0]);
this.selected = defaultAddress; this.selected = defaultAddress;
this.$emit("input", this.selected); this.$emit("input", this.selected);
this.queryText = `${defaultAddress.poiInfos.name} ${defaultAddress.poiInfos.alternativeName}`; this.queryText = `${defaultAddress.poiInfos.name} ${defaultAddress.poiInfos.alternativeName}`;
} }
}
checkCurrentPosition(e: LatLng) { checkCurrentPosition(e: LatLng): boolean {
if (!this.selected || !this.selected.geom) return false; if (!this.selected || !this.selected.geom) return false;
const lat = parseFloat(this.selected.geom.split(";")[1]); const lat = parseFloat(this.selected.geom.split(";")[1]);
const lon = parseFloat(this.selected.geom.split(";")[0]); const lon = parseFloat(this.selected.geom.split(";")[0]);
@ -259,6 +261,7 @@ export default class FullAddressAutoComplete extends Vue {
return this.label || (this.$t("Find an address") as string); return this.label || (this.$t("Find an address") as string);
} }
// eslint-disable-next-line class-methods-use-this
get canShowLocateMeButton(): boolean { get canShowLocateMeButton(): boolean {
return window.isSecureContext; return window.isSecureContext;
} }