-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexample.vue
79 lines (75 loc) · 1.94 KB
/
example.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<template>
<v-map :zoom=10 :center="initialLocation">
<v-tilelayer url="http://{s}.tile.osm.org/{z}/{x}/{y}.png"></v-tilelayer>
<v-rotated-marker v-for="l in locations" :key="l.id"
:lat-lng="l.latlng"
:icon="icon"
@click="handleMarkerClick(l)"
:rotationOrigin="l.origin"
:rotationAngle="l.yaw">
</v-rotated-marker>
</v-map>
</template>
<script>
import { Icon, LatLng } from 'leaflet'
import { LMap, LTileLayer, LMarker } from 'vue2-leaflet'
import Vue2LeafletRotatedMarker from './dist/Vue2LeafletRotatedMarker.js'
import iconUrl from 'leaflet/dist/images/marker-icon.png'
function rand(n) {
let max = n + 0.1
let min = n - 0.1
return Math.random() * (max - min) + min;
}
export default {
components: {
'v-map': LMap,
'v-tilelayer': LTileLayer,
'v-marker': LMarker,
'v-rotated-marker': Vue2LeafletRotatedMarker
},
methods: {
handleMarkerClick(l){
l.yaw+=20;
},
frame() {
this.locations[0].yaw+=2;
this.locations[1].yaw+=2;
this.locations[2].yaw+=2;
}
},
data () {
this.locations = []
for (let i = 0; i < 10; i++) {
this.locations.push({
id: i,
yaw: Math.random() * 360 - 180,
origin:'bottom center',
latlng: new LatLng(rand(-34.9205), rand(-57.953646)),
text: 'Hola ' + i
})
}
let icon = new Icon({iconUrl})
return {
locations:this.locations,
icon,
initialLocation: new LatLng(-34.9205, -57.953646)
}
},
mounted() {
setTimeout(() => {
console.log('done')
this.$nextTick(() =>{
this.clusterOptions = { disableClusteringAtZoom: 11 }
});
}, 5000);
this.intervalId = setInterval(this.frame, 100);
}
}
</script>
<style>
@import "~leaflet/dist/leaflet.css";
html, body {
height: 100%;
margin: 0;
}
</style>