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-04-24 14:13:52 +02:00
|
|
|
<l-tile-layer
|
|
|
|
url="https://{s}.tile.osm.org/{z}/{x}/{y}.png"
|
|
|
|
attribution="© OpenStreetMap contributors"
|
|
|
|
>
|
|
|
|
|
|
|
|
</l-tile-layer>
|
2019-03-22 17:35:07 +01:00
|
|
|
<l-marker :lat-lng="[lat, lon]" >
|
|
|
|
<l-popup v-if="popup">{{ popup }}</l-popup>
|
|
|
|
</l-marker>
|
|
|
|
</l-map>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { Icon } from 'leaflet';
|
|
|
|
import 'leaflet/dist/leaflet.css';
|
|
|
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
|
|
|
import { LMap, LTileLayer, LMarker, LPopup } from 'vue2-leaflet';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: { LTileLayer, LMap, LMarker, LPopup },
|
|
|
|
})
|
2019-04-03 17:29:03 +02:00
|
|
|
export default class Map extends Vue {
|
2019-03-22 17:35:07 +01:00
|
|
|
@Prop({ type: String, required: true }) coords!: string;
|
|
|
|
@Prop({ type: String, required: false }) popup!: string;
|
2019-04-03 17:29:03 +02:00
|
|
|
@Prop({ type: Object, required: false }) options!: object;
|
|
|
|
|
|
|
|
defaultOptions: object = {
|
|
|
|
zoom: 15,
|
|
|
|
height: '100%',
|
|
|
|
width: '100%',
|
|
|
|
};
|
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-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-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>
|