This commit is contained in:
2021-09-06 15:50:36 +02:00
parent c205e8bf23
commit 7545c4ffc9
7 changed files with 183 additions and 76 deletions

View File

@@ -1,11 +1,11 @@
<template>
<field-map :center="position" :field="field">
<l-marker :lat-lng="position" :draggable="edit" @dragend="onDragEnd"/>
<l-marker :lat-lng="position" :draggable="edit" @dragend="onDragEnd" />
</field-map>
</template>
<script>
import {LMarker} from 'vue2-leaflet'
import { LMarker } from "vue2-leaflet";
export default {
props: {
@@ -20,13 +20,16 @@ export default {
edit: {
type: Boolean,
default: false,
}
},
},
computed: {
position() {
return L.latLng(this.value.lat || this.field.map.center.latitude, this.value.lng || this.field.map.center.longitude);
}
return L.latLng(
this.value.lat || this.field.map.center.latitude,
this.value.lng || this.field.map.center.longitude
);
},
},
mounted() {
@@ -37,36 +40,46 @@ export default {
onDragEnd(evt) {
let latLng = evt.target.getLatLng();
this.$emit('input', {
this.$emit("input", {
lat: latLng.lat,
lng: latLng.lng,
});
},
registerWatchers() {
this.getGlobalFieldComponents().forEach(component => {
if ([this.field.latitudeField, this.field.longitudeField].includes(component.field.attribute)) {
component.$watch('value', (value) => {
this.value[component.field.attribute] = value;
}, {immediate: true})
this.getGlobalFieldComponents().forEach((component) => {
if (
[
this.field.latitudeField,
this.field.longitudeField,
].includes(component.field.attribute)
) {
component.$watch(
"value",
(value) => {
this.value[component.field.attribute] = value;
},
{ immediate: true }
);
}
});
},
getGlobalFieldComponents(components = null) {
if (! components) {
if (!components) {
components = this.$root.$children;
}
let returnArray = [];
components.forEach(component => {
components.forEach((component) => {
if (component.field) {
return returnArray.push(component);
}
returnArray = returnArray.concat(this.getGlobalFieldComponents(component.$children));
returnArray = returnArray.concat(
this.getGlobalFieldComponents(component.$children)
);
});
return returnArray;
@@ -75,6 +88,6 @@ export default {
components: {
LMarker,
}
}
},
};
</script>