22import { ref , shallowRef , watch } from ' vue'
33import { debounce } from ' vuetify/lib/util/helpers.mjs'
44import type { PlaceResult } from ' ../composables/useAreaOfInterest'
5+ import { mdiHelpCircleOutline } from ' @mdi/js'
56
67const emit = defineEmits <{
78 (e : ' location-selected' , place : PlaceResult ): void
@@ -18,8 +19,18 @@ watch(
1819
1920 isLoadingPlaces .value = true
2021 try {
22+ const referer = ' https://github.com/fieldsoftheworld/ftw-inference-app'
2123 const response = await fetch (
2224 ` https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent (newSearch )} ` ,
25+ // User-Agent or Referer are required by Nominatim's usage policy.
26+ // User-Agent is not working in Chrome, thus sending both.
27+ // Referer is usually set by the browser, but let's ensure it's set.
28+ {
29+ headers: {
30+ ' User-Agent' : referer ,
31+ Referer: referer ,
32+ },
33+ },
2334 )
2435 const data = await response .json ()
2536 suggestedPlaces .value = data ?.map ((place : any ) => ({
3142 } finally {
3243 isLoadingPlaces .value = false
3344 }
34- }, 500 ),
45+ }, 1000 ),
3546)
3647
3748const onLocationSelected = (item : { value: PlaceResult ; title: string } | null ) => {
@@ -42,16 +53,26 @@ const onLocationSelected = (item: { value: PlaceResult; title: string } | null)
4253 </script >
4354
4455<template >
45- <v-autocomplete
46- @update:model-value =" onLocationSelected"
47- v-model:search =" placeSearch"
48- :loading =" isLoadingPlaces"
49- :items =" suggestedPlaces"
50- label =" Search for a place"
51- item-title =" title"
52- return-object
53- hide-details
54- dense
55- variant =" outlined"
56- ></v-autocomplete >
56+ <div class =" d-flex align-center mb-2 ga-2" >
57+ <v-autocomplete
58+ @update:model-value =" onLocationSelected"
59+ v-model:search =" placeSearch"
60+ :loading =" isLoadingPlaces"
61+ :items =" suggestedPlaces"
62+ label =" Search for a place"
63+ item-title =" title"
64+ return-object
65+ hide-details
66+ dense
67+ variant =" outlined"
68+ ></v-autocomplete >
69+ <v-tooltip max-width =" 400" open-on-click >
70+ <template #activator =" { props } " >
71+ <v-icon class =" ml-1" :icon =" mdiHelpCircleOutline" size =" x-small" v-bind =" props" ></v-icon >
72+ </template >
73+ Geocoding provided by Nominatim.<br />
74+ © ; OpenStreetMap, https://openstreetmap.org<br />
75+ License: ODbL
76+ </v-tooltip >
77+ </div >
5778</template >
0 commit comments