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"
|
|
|
|
>
|
2020-11-30 10:24:11 +01:00
|
|
|
<l-tile-layer
|
|
|
|
:url="config.maps.tiles.endpoint"
|
|
|
|
:attribution="attribution"
|
|
|
|
>
|
|
|
|
</l-tile-layer>
|
2020-02-18 08:57:00 +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">
|
2020-11-30 10:24:11 +01:00
|
|
|
<span v-for="line in popupMultiLine" :key="line"
|
|
|
|
>{{ line }}<br
|
|
|
|
/></span>
|
2020-02-18 08:57:00 +01:00
|
|
|
</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
|
|
|
|
2020-11-30 10:24:11 +01:00
|
|
|
@Prop({ type: Object, required: false }) marker!: {
|
|
|
|
text: string | string[];
|
|
|
|
icon: string;
|
|
|
|
};
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
@Prop({ type: Object, required: false }) options!: Record<string, unknown>;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
@Prop({ type: Function, required: false })
|
2020-11-27 19:27:44 +01:00
|
|
|
updateDraggableMarkerCallback!: (latlng: LatLng, zoom: number) => void;
|
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-11-27 19:27:44 +01:00
|
|
|
openPopup(event: LeafletEvent): void {
|
2019-11-08 19:37:14 +01:00
|
|
|
this.$nextTick(() => {
|
|
|
|
event.target.openPopup();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
get mergedOptions(): Record<string, unknown> {
|
2019-04-03 17:29:03 +02:00
|
|
|
return { ...this.defaultOptions, ...this.options };
|
|
|
|
}
|
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
get lat(): number {
|
2020-02-18 08:57:00 +01:00
|
|
|
return this.$props.coords.split(";")[1];
|
|
|
|
}
|
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
get lon(): number {
|
2020-02-18 08:57:00 +01:00
|
|
|
return this.$props.coords.split(";")[0];
|
|
|
|
}
|
2019-11-08 19:37:14 +01:00
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
get popupMultiLine(): Array<string> {
|
2019-11-08 19:37:14 +01:00
|
|
|
if (Array.isArray(this.marker.text)) {
|
|
|
|
return this.marker.text;
|
|
|
|
}
|
|
|
|
return [this.marker.text];
|
|
|
|
}
|
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
clickMap(event: LeafletMouseEvent): void {
|
2019-11-08 19:37:14 +01:00
|
|
|
this.updateDraggableMarkerPosition(event.latlng);
|
|
|
|
}
|
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
updateDraggableMarkerPosition(e: LatLng): void {
|
2019-11-08 19:37:14 +01:00
|
|
|
this.updateDraggableMarkerCallback(e, this.zoom);
|
|
|
|
}
|
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
updateZoom(zoom: number): void {
|
2019-11-08 19:37:14 +01:00
|
|
|
this.zoom = zoom;
|
|
|
|
}
|
2019-11-20 13:49:57 +01:00
|
|
|
|
2020-11-27 19:27:44 +01:00
|
|
|
get attribution(): string {
|
|
|
|
return (
|
2020-11-30 10:24:11 +01:00
|
|
|
this.config.maps.tiles.attribution ||
|
|
|
|
(this.$t("© The OpenStreetMap Contributors") as string)
|
2020-11-27 19:27:44 +01:00
|
|
|
);
|
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>
|