|
|
@@ -14,7 +14,9 @@
|
|
|
:label="$t('where') + ' ?'"
|
|
|
outlined
|
|
|
append-icon="mdi-crosshairs-gps"
|
|
|
+ @click="onClick"
|
|
|
@change="$emit('change', $event ? $event.value : '')"
|
|
|
+ @click:append="geolocalizeUser"
|
|
|
/>
|
|
|
<v-snackbar :value="errorMsg !== ''">
|
|
|
{{ errorMsg }}
|
|
|
@@ -92,23 +94,17 @@ export default Vue.extend({
|
|
|
model: null as Address | null,
|
|
|
search: null,
|
|
|
features: [] as Array<Feature>,
|
|
|
+ items: [] as Array<Address>,
|
|
|
loading: false,
|
|
|
- errorMsg: ''
|
|
|
- }
|
|
|
- },
|
|
|
- computed: {
|
|
|
- items (): Array<Address> {
|
|
|
- return this.features.map((f: Feature) => {
|
|
|
- return {
|
|
|
- text: f.properties.name + ' (' + f.properties.postcode + ')',
|
|
|
- value: { longitude: f.geometry.coordinates[0] as number, latitude: f.geometry.coordinates[1] as number },
|
|
|
- disabled: false
|
|
|
- }
|
|
|
- })
|
|
|
+ errorMsg: '',
|
|
|
+ geolocalized: false
|
|
|
}
|
|
|
},
|
|
|
watch: {
|
|
|
search (val: string) {
|
|
|
+ if (this.geolocalized) {
|
|
|
+ return
|
|
|
+ }
|
|
|
if (!val) {
|
|
|
this.features = []
|
|
|
return
|
|
|
@@ -129,7 +125,13 @@ export default Vue.extend({
|
|
|
fetch(encodeURI(apiUrl))
|
|
|
.then(res => res.json())
|
|
|
.then(({ features }) => {
|
|
|
- this.features = features
|
|
|
+ this.items = features.map((f: Feature) => {
|
|
|
+ return {
|
|
|
+ text: f.properties.name + ' (' + f.properties.postcode + ')',
|
|
|
+ value: { longitude: f.geometry.coordinates[0] as number, latitude: f.geometry.coordinates[1] as number },
|
|
|
+ disabled: false
|
|
|
+ }
|
|
|
+ })
|
|
|
})
|
|
|
.catch((err) => {
|
|
|
// eslint-disable-next-line no-console
|
|
|
@@ -144,20 +146,28 @@ export default Vue.extend({
|
|
|
clear () {
|
|
|
this.model = null
|
|
|
this.search = null
|
|
|
- this.features = []
|
|
|
+ this.items = []
|
|
|
this.loading = false
|
|
|
this.errorMsg = ''
|
|
|
+ this.geolocalized = false
|
|
|
+ },
|
|
|
+ onClick () {
|
|
|
+ this.clear()
|
|
|
},
|
|
|
geolocalizeUser () {
|
|
|
if (navigator.geolocation) {
|
|
|
navigator.geolocation.getCurrentPosition(
|
|
|
(position: { coords: { longitude: number, latitude: number }}) => {
|
|
|
this.clear()
|
|
|
- this.model = {
|
|
|
+ const loc = {
|
|
|
text: this.$t('my_position') as string,
|
|
|
value: { longitude: position.coords.longitude, latitude: position.coords.latitude },
|
|
|
disabled: false
|
|
|
}
|
|
|
+ this.geolocalized = true
|
|
|
+ this.items = [loc]
|
|
|
+ this.model = loc
|
|
|
+ this.$emit('change', loc.value)
|
|
|
},
|
|
|
() => {
|
|
|
this.errorMsg = this.$t('geolocation_error') as string
|