Handle nothing found for reverse geocode
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
93c79af4c2
commit
3d963cf3bc
|
@ -175,10 +175,12 @@ 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));
|
||||||
const defaultAddress = new Address(this.addressData[0]);
|
if (this.addressData.length > 0) {
|
||||||
this.selected = defaultAddress;
|
const defaultAddress = new Address(this.addressData[0]);
|
||||||
this.$emit("input", this.selected);
|
this.selected = defaultAddress;
|
||||||
this.queryText = `${defaultAddress.poiInfos.name} ${defaultAddress.poiInfos.alternativeName}`;
|
this.$emit("input", this.selected);
|
||||||
|
this.queryText = `${defaultAddress.poiInfos.name} ${defaultAddress.poiInfos.alternativeName}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkCurrentPosition(e: LatLng): boolean {
|
checkCurrentPosition(e: LatLng): boolean {
|
||||||
|
|
|
@ -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));
|
||||||
const defaultAddress = new Address(this.addressData[0]);
|
if (this.addressData.length > 0) {
|
||||||
this.selected = defaultAddress;
|
const defaultAddress = new Address(this.addressData[0]);
|
||||||
this.$emit("input", this.selected);
|
this.selected = defaultAddress;
|
||||||
this.queryText = `${defaultAddress.poiInfos.name} ${defaultAddress.poiInfos.alternativeName}`;
|
this.$emit("input", this.selected);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue