2018-06-25 18:29:57 +02:00
|
|
|
<template>
|
|
|
|
<div class="fill-height fill-width">
|
2018-06-28 14:40:56 +02:00
|
|
|
<v-lmap :center="latlng" :zoom="this.zoom" :minZoom="this.minZoom" :maxZoom="this.maxZoom" :options="{ zoomControl: false }" @contextmenu="handleLongPress">
|
2018-06-25 18:29:57 +02:00
|
|
|
<v-ltilelayer :url="tileServer" :attribution="attribution"></v-ltilelayer>
|
2018-06-27 11:17:38 +02:00
|
|
|
|
|
|
|
<v-lts v-if="heading" :lat-lng="latlng" :options="markerOptions"></v-lts>
|
|
|
|
<v-lcirclemarker v-else :lat-lng="latlng" :color="markerOptions.color" :fillColor="markerOptions.fillColor" :fillOpacity="1.0" :weight="markerOptions.weight" :radius="markerRadius"></v-lcirclemarker>
|
|
|
|
|
|
|
|
<v-lcircle v-if="shouldDisplayAccuracy" :lat-lng="latlng" :radius="radiusFromAccuracy"></v-lcircle>
|
|
|
|
|
2018-06-27 14:59:45 +02:00
|
|
|
<ReportMarker v-for="marker in markers" :key="marker.id" :marker="marker"></ReportMarker>
|
2018-06-25 18:29:57 +02:00
|
|
|
</v-lmap>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import L from 'leaflet';
|
|
|
|
import iconRetinaUrl from 'leaflet/dist/images/marker-icon-2x.png';
|
|
|
|
import iconUrl from 'leaflet/dist/images/marker-icon.png';
|
|
|
|
import shadowUrl from 'leaflet/dist/images/marker-shadow.png';
|
|
|
|
|
2018-06-27 14:59:45 +02:00
|
|
|
import * as constants from '@/constants';
|
|
|
|
import ReportMarker from './ReportMarker.vue';
|
2018-06-27 11:17:38 +02:00
|
|
|
|
2018-06-25 18:29:57 +02:00
|
|
|
// Fix for a bug in Leaflet default icon
|
|
|
|
// see https://github.com/PaulLeCam/react-leaflet/issues/255#issuecomment-261904061
|
|
|
|
delete L.Icon.Default.prototype._getIconUrl;
|
|
|
|
L.Icon.Default.mergeOptions({
|
|
|
|
iconRetinaUrl,
|
|
|
|
iconUrl,
|
|
|
|
shadowUrl,
|
|
|
|
});
|
|
|
|
|
|
|
|
export default {
|
2018-06-27 14:59:45 +02:00
|
|
|
components: {
|
|
|
|
ReportMarker,
|
|
|
|
},
|
2018-06-25 18:29:57 +02:00
|
|
|
props: {
|
2018-06-27 11:17:38 +02:00
|
|
|
accuracy: {
|
|
|
|
type: Number,
|
|
|
|
default: null,
|
|
|
|
},
|
2018-06-25 18:29:57 +02:00
|
|
|
heading: Number,
|
|
|
|
lat: Number,
|
|
|
|
lng: Number,
|
2018-06-26 11:04:23 +02:00
|
|
|
markers: Array,
|
2018-06-28 14:40:56 +02:00
|
|
|
onLongPress: Function,
|
2018-06-25 18:29:57 +02:00
|
|
|
},
|
|
|
|
computed: {
|
2018-06-27 11:17:38 +02:00
|
|
|
radiusFromAccuracy() {
|
|
|
|
if (this.accuracy) {
|
|
|
|
return this.accuracy / (
|
2018-06-27 22:45:03 +02:00
|
|
|
(constants.EARTH_RADIUS * 2 * Math.PI * Math.cos(this.lat * (Math.PI / 180))) /
|
2018-06-27 11:17:38 +02:00
|
|
|
(2 ** (this.zoom + 8))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
shouldDisplayAccuracy() {
|
|
|
|
return (
|
|
|
|
this.accuracy &&
|
|
|
|
this.accuracy < 100 &&
|
|
|
|
this.radiusFromAccuracy > this.markerRadius
|
|
|
|
);
|
|
|
|
},
|
2018-06-25 18:29:57 +02:00
|
|
|
latlng() {
|
|
|
|
return [this.lat, this.lng];
|
|
|
|
},
|
|
|
|
markerOptions() {
|
|
|
|
return {
|
|
|
|
fillColor: '#00ff00',
|
2018-06-27 11:17:38 +02:00
|
|
|
color: '#000000',
|
2018-06-25 18:29:57 +02:00
|
|
|
heading: this.heading,
|
2018-06-27 11:17:38 +02:00
|
|
|
weight: 1,
|
2018-06-25 18:29:57 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors',
|
2018-06-27 14:59:45 +02:00
|
|
|
zoom: constants.DEFAULT_ZOOM,
|
2018-06-27 11:17:38 +02:00
|
|
|
markerRadius: 10.0,
|
2018-06-27 14:59:45 +02:00
|
|
|
minZoom: constants.MIN_ZOOM,
|
|
|
|
maxZoom: constants.MAX_ZOOM,
|
|
|
|
tileServer: constants.TILE_SERVER,
|
2018-06-25 18:29:57 +02:00
|
|
|
};
|
|
|
|
},
|
2018-06-28 14:40:56 +02:00
|
|
|
methods: {
|
|
|
|
handleLongPress(event) {
|
|
|
|
if (this.onLongPress) {
|
|
|
|
this.onLongPress(event.latlng);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2018-06-25 18:29:57 +02:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.application .leaflet-bar a {
|
|
|
|
color: black;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.fill-width {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
</style>
|