2019-03-22 17:35:07 +01:00
|
|
|
<template>
|
2020-02-18 08:57:00 +01:00
|
|
|
<div class="map-container" v-if="config">
|
|
|
|
<l-map
|
|
|
|
:zoom="mergedOptions.zoom"
|
|
|
|
:style="`height: ${mergedOptions.height}; width: ${mergedOptions.width}`"
|
|
|
|
class="leaflet-map"
|
|
|
|
:center="[lat, lon]"
|
|
|
|
@click="clickMap"
|
|
|
|
@update:zoom="updateZoom"
|
|
|
|
>
|
|
|
|
<l-tile-layer :url="config.maps.tiles.endpoint" :attribution="attribution"> </l-tile-layer>
|
|
|
|
<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>
|
|
|
|
</l-marker>
|
|
|
|
</l-map>
|
|
|
|
</div>
|
2019-03-22 17:35:07 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-02-18 08:57:00 +01:00
|
|
|
import { Icon, LatLng, LeafletMouseEvent, LeafletEvent } from "leaflet";
|
|
|
|
import "leaflet/dist/leaflet.css";
|
|
|
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
|
|
|
import { LMap, LTileLayer, LMarker, LPopup, LIcon } from "vue2-leaflet";
|
|
|
|
import Vue2LeafletLocateControl from "@/components/Map/Vue2LeafletLocateControl.vue";
|
|
|
|
import { CONFIG } from "../graphql/config";
|
|
|
|
import { IConfig } from "../types/config.model";
|
2019-03-22 17:35:07 +01:00
|
|
|
|
|
|
|
@Component({
|
2020-02-18 08:57:00 +01:00
|
|
|
components: {
|
|
|
|
LTileLayer,
|
|
|
|
LMap,
|
|
|
|
LMarker,
|
|
|
|
LPopup,
|
|
|
|
LIcon,
|
|
|
|
"v-locatecontrol": Vue2LeafletLocateControl,
|
|
|
|
},
|
2019-11-20 13:49:57 +01:00
|
|
|
apollo: {
|
|
|
|
config: CONFIG,
|
|
|
|
},
|
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;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-03-22 17:35:07 +01:00
|
|
|
@Prop({ type: String, required: true }) coords!: string;
|
2020-02-18 08:57:00 +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;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
@Prop({ type: Function, required: false })
|
|
|
|
updateDraggableMarkerCallback!: Function;
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2019-11-08 19:37:14 +01:00
|
|
|
defaultOptions: {
|
2020-02-18 08:57:00 +01:00
|
|
|
zoom: number;
|
|
|
|
height: string;
|
|
|
|
width: string;
|
2019-11-08 19:37:14 +01:00
|
|
|
} = {
|
2019-04-03 17:29:03 +02:00
|
|
|
zoom: 15,
|
2020-02-18 08:57:00 +01:00
|
|
|
height: "100%",
|
|
|
|
width: "100%",
|
2019-04-03 17:29:03 +02:00
|
|
|
};
|
2019-03-22 17:35:07 +01:00
|
|
|
|
2019-11-08 19:37:14 +01:00
|
|
|
zoom = this.defaultOptions.zoom;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-11-20 13:49:57 +01:00
|
|
|
config!: IConfig;
|
2019-11-08 19:37:14 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
/* eslint-disable */
|
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({
|
2020-02-18 08:57:00 +01:00
|
|
|
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-03-22 17:35:07 +01:00
|
|
|
});
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
/* eslint-enable */
|
2019-03-22 17:35:07 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
openPopup(event: LeafletEvent) {
|
2019-11-08 19:37:14 +01:00
|
|
|
this.$nextTick(() => {
|
|
|
|
event.target.openPopup();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
get mergedOptions(): object {
|
|
|
|
return { ...this.defaultOptions, ...this.options };
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01: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) {
|
|
|
|
this.updateDraggableMarkerCallback(e, this.zoom);
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
updateZoom(zoom: number) {
|
2019-11-08 19:37:14 +01:00
|
|
|
this.zoom = zoom;
|
|
|
|
}
|
2019-11-20 13:49:57 +01:00
|
|
|
|
|
|
|
get attribution() {
|
2020-02-18 08:57:00 +01:00
|
|
|
return this.config.maps.tiles.attribution || this.$t("© The OpenStreetMap Contributors");
|
2019-11-20 13:49:57 +01:00
|
|
|
}
|
2019-03-22 17:35:07 +01:00
|
|
|
}
|
|
|
|
</script>
|
2019-04-03 17:29:03 +02:00
|
|
|
<style lang="scss" scoped>
|
2020-02-18 08:57:00 +01:00
|
|
|
div.map-container {
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.leaflet-map {
|
|
|
|
z-index: 20;
|
|
|
|
}
|
|
|
|
}
|
2019-04-03 17:29:03 +02:00
|
|
|
</style>
|