Fix location field not highlighting clicked location with marker opacity

This commit is contained in:
Jože Fortun
2024-07-17 16:30:20 +02:00
parent 7c177080ab
commit 62f8a81f93
2 changed files with 14 additions and 9 deletions
@@ -276,14 +276,14 @@ export default {
this.map.value = this.field.isMulti ? [...this.localValue] : this.localValue
this.localValueIndex = index
const firstCoordinates = (index >= 0 ? this.localValue[index] : this.localValue) || {}
firstCoordinates.coordinates = firstCoordinates.coordinates ? [...firstCoordinates.coordinates] : []
const areCoordinatesValid = firstCoordinates.coordinates && firstCoordinates.coordinates.length === 2 && firstCoordinates.coordinates.every(isNumber)
this.map.center = firstCoordinates.coordinates &&
firstCoordinates.coordinates.length === 2 &&
firstCoordinates.coordinates.every(isNumber) ? firstCoordinates.coordinates : this.field.options.center
firstCoordinates.coordinates = areCoordinatesValid ? [...firstCoordinates.coordinates] : []
this.map.zoom = index >= 0 ? 13 : this.field.options.zoom
this.map.center = areCoordinatesValid ? firstCoordinates.coordinates : this.field.options.center
this.map.zoom = areCoordinatesValid ? 13 : this.field.options.zoom
this.map.show = true
},
@@ -23,7 +23,6 @@
>
<c-map
:map="map"
:active-marker-index="localValueIndex"
:markers="localValue"
:hide-current-location-button="field.options.hideCurrentLocationButton"
:hide-geo-search="field.options.hideGeoSearch"
@@ -71,8 +70,11 @@ export default {
computed: {
localValue () {
if (this.field.isMulti) {
return this.value.map(v => {
return { value: JSON.parse(v || '{"coordinates":[]}').coordinates || [] }
return this.value.map((v, i) => {
return {
value: JSON.parse(v || '{"coordinates":[]}').coordinates || [],
opacity: this.localValueIndex === undefined || i === this.localValueIndex ? 1.0 : 0.6,
}
}).filter(c => c && c.value && c.value.length)
} else {
return [{ value: JSON.parse(this.value || '{"coordinates":[]}').coordinates || [] }].filter(c => c && c.value && c.value.length)
@@ -87,7 +89,10 @@ export default {
methods: {
openMap (index) {
this.localValueIndex = index
this.map.center = (this.localValue[index] && this.localValue[index].value) || this.field.options.center
const { value } = this.localValue[index] || {}
this.map.center = value || this.field.options.center
this.map.zoom = index >= 0 ? 13 : this.field.options.zoom
this.map.show = true
},