New tripmarkers field.

This commit is contained in:
2021-07-23 15:59:02 +02:00
parent fa01cc8014
commit 9aa381c11d
3 changed files with 159 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
<template>
<field-map :center="markers[0]" :field="field">
<l-marker v-for="pos in markers" :lat-lng="pos" :draggable="edit" @dragend="onDragEnd" @click="(event) => toggleMarker(event, Math.random())" />
<!-- :opacity="Math.random() > 0.5 ? 1 : 0.5"/> -->
</field-map>
</template>
<script>
import {LMarker} from 'vue2-leaflet'
export default {
props: {
value: {
type: Object,
default: null,
},
field: {
type: Object,
required: true,
},
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);
},
markers() {
let { selected_products, all_products } = this.field;
return selected_products.map(prod => L.latLng(prod.lat, prod.lng))
}
},
methods: {
toggleMarker(event, id) {
console.log('marker clicked!');
console.log("id:", id)
},
onDragEnd(evt) {
let latLng = evt.target.getLatLng();
this.$emit('input', {
lat: latLng.lat,
lng: latLng.lng,
});
},
registerWatchers() {
this.getGlobalFieldComponents().forEach(component => {
component.$watch('value', (value) => {
this.value['selected_products'] = value;
}, {immediate: true})
});
},
getGlobalFieldComponents(components = null) {
if (! components) {
components = this.$root.$children;
}
let returnArray = [];
components.forEach(component => {
if (component.field) {
return returnArray.push(component);
}
returnArray = returnArray.concat(this.getGlobalFieldComponents(component.$children));
});
return returnArray;
},
},
components: {
LMarker,
}
}
</script>

View File

@@ -5,6 +5,7 @@ Nova.booting((Vue, router) => {
Vue.component('field-map', require('./components/FieldMap'));
Vue.component('field-marker', require('./components/fields/Marker'));
Vue.component('field-markers', require('./components/fields/TripMarkers'));
Vue.component('field-polyline', require('./components/fields/Polyline'));
// Config leaflet images to load images from CDN