2019-03-22 17:35:07 +01:00
|
|
|
<template>
|
2019-04-03 17:29:03 +02:00
|
|
|
<div class="map-container">
|
2019-03-22 17:35:07 +01:00
|
|
|
<l-map
|
2019-04-03 17:29:03 +02:00
|
|
|
:zoom="mergedOptions.zoom"
|
|
|
|
:style="`height: ${mergedOptions.height}; width: ${mergedOptions.width}`"
|
|
|
|
class="leaflet-map"
|
2019-03-22 17:35:07 +01:00
|
|
|
:center="[lat, lon]"
|
2019-11-08 19:37:14 +01:00
|
|
|
@click="clickMap"
|
|
|
|
@update:zoom="updateZoom"
|
2019-03-22 17:35:07 +01:00
|
|
|
>
|
2019-04-24 14:13:52 +02:00
|
|
|
<l-tile-layer
|
2019-11-08 19:37:14 +01:00
|
|
|
url="https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png"
|
|
|
|
:attribution="$t('© The OpenStreetMap Contributors')"
|
2019-04-24 14:13:52 +02:00
|
|
|
>
|
|
|
|
|
|
|
|
</l-tile-layer>
|
2019-11-08 19:37:14 +01:00
|
|
|
<v-locatecontrol :options="{icon: 'mdi mdi-map-marker'}"/>
|
|
|
|
<l-marker :lat-lng="[lat, lon]" @add="openPopup" @update:latLng="updateDraggableMarkerPosition" :draggable="!readOnly">
|
|
|
|
<l-popup v-if="popupMultiLine">
|
|
|
|
<span v-for="line in popupMultiLine" :key="line">{{ line }}<br /></span>
|
|
|
|
</l-popup>
|
2019-03-22 17:35:07 +01:00
|
|
|
</l-marker>
|
|
|
|
</l-map>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-11-08 19:37:14 +01:00
|
|
|
import { Icon, LatLng, LeafletMouseEvent } from 'leaflet';
|
2019-03-22 17:35:07 +01:00
|
|
|
import 'leaflet/dist/leaflet.css';
|
|
|
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
2019-11-08 19:37:14 +01:00
|
|
|
import { LMap, LTileLayer, LMarker, LPopup, LIcon } from 'vue2-leaflet';
|
|
|
|
import Vue2LeafletLocateControl from '@/components/Map/Vue2LeafletLocateControl.vue';
|
2019-03-22 17:35:07 +01:00
|
|
|
|
|
|
|
@Component({
|
2019-11-08 19:37:14 +01:00
|
|
|
components: { LTileLayer, LMap, LMarker, LPopup, LIcon, 'v-locatecontrol': Vue2LeafletLocateControl },
|
2019-03-22 17:35:07 +01:00
|
|
|
})
|
2019-04-03 17:29:03 +02:00
|
|
|
export default class Map extends Vue {
|
2019-11-08 19:37:14 +01:00
|
|
|
@Prop({ type: Boolean, required: false, default: true }) readOnly!: boolean;
|
2019-03-22 17:35:07 +01:00
|
|
|
@Prop({ type: String, required: true }) coords!: string;
|
2019-11-08 19:37:14 +01:00
|
|
|
@Prop({ type: Object, required: false }) marker!: { text: String|String[], icon: String };
|
2019-04-03 17:29:03 +02:00
|
|
|
@Prop({ type: Object, required: false }) options!: object;
|
2019-11-08 19:37:14 +01:00
|
|
|
@Prop({ type: Function, required: false, default: () => {} }) updateDraggableMarkerCallback!: Function;
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2019-11-08 19:37:14 +01:00
|
|
|
defaultOptions: {
|
|
|
|
zoom: Number;
|
|
|
|
height: String;
|
|
|
|
width: String;
|
|
|
|
} = {
|
2019-04-03 17:29:03 +02:00
|
|
|
zoom: 15,
|
|
|
|
height: '100%',
|
|
|
|
width: '100%',
|
|
|
|
};
|
2019-03-22 17:35:07 +01:00
|
|
|
|
2019-11-08 19:37:14 +01:00
|
|
|
zoom = this.defaultOptions.zoom;
|
|
|
|
|
2019-03-22 17:35:07 +01:00
|
|
|
mounted() {
|
|
|
|
// this part resolve an issue where the markers would not appear
|
|
|
|
// @ts-ignore
|
|
|
|
delete Icon.Default.prototype._getIconUrl;
|
|
|
|
|
|
|
|
Icon.Default.mergeOptions({
|
|
|
|
iconRetinaUrl: require('leaflet/dist/images/marker-icon-2x.png'),
|
|
|
|
iconUrl: require('leaflet/dist/images/marker-icon.png'),
|
|
|
|
shadowUrl: require('leaflet/dist/images/marker-shadow.png'),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-11-08 19:37:14 +01:00
|
|
|
openPopup(event) {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
event.target.openPopup();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
get mergedOptions(): object {
|
|
|
|
return { ...this.defaultOptions, ...this.options };
|
|
|
|
}
|
|
|
|
|
2019-09-20 19:43:29 +02:00
|
|
|
get lat() { return this.$props.coords.split(';')[1]; }
|
|
|
|
get lon() { return this.$props.coords.split(';')[0]; }
|
2019-11-08 19:37:14 +01:00
|
|
|
|
|
|
|
get popupMultiLine() {
|
|
|
|
if (Array.isArray(this.marker.text)) {
|
|
|
|
return this.marker.text;
|
|
|
|
}
|
|
|
|
return [this.marker.text];
|
|
|
|
}
|
|
|
|
|
|
|
|
clickMap(event: LeafletMouseEvent) {
|
|
|
|
this.updateDraggableMarkerPosition(event.latlng);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateDraggableMarkerPosition(e: LatLng) {
|
|
|
|
console.log('updateDraggableMarkerPosition', e);
|
|
|
|
this.updateDraggableMarkerCallback(e, this.zoom);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateZoom(zoom: Number) {
|
|
|
|
this.zoom = zoom;
|
|
|
|
}
|
2019-03-22 17:35:07 +01:00
|
|
|
}
|
|
|
|
</script>
|
2019-04-03 17:29:03 +02:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
div.map-container {
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
.leaflet-map {
|
|
|
|
z-index: 20;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|