forked from jperelli/vue2-leaflet-markercluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.vue
78 lines (74 loc) · 2.18 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
<template>
<v-map :zoom=10 :center="initialLocation">
<v-icondefault></v-icondefault>
<v-tilelayer url="http://{s}.tile.osm.org/{z}/{x}/{y}.png"></v-tilelayer>
<v-marker-cluster :options="clusterOptions" @clusterclick="click()" @ready="ready">
<v-marker v-for="l in locations" :key="l.id" :lat-lng="l.latlng" :icon="icon">
<v-popup :content="l.text"></v-popup>
</v-marker>
</v-marker-cluster>
</v-map>
</template>
<script>
import * as Vue2Leaflet from 'vue2-leaflet'
import { latLng, Icon, icon } from 'leaflet'
import Vue2LeafletMarkercluster from './Vue2LeafletMarkercluster'
import iconUrl from 'leaflet/dist/images/marker-icon.png'
import shadowUrl from 'leaflet/dist/images/marker-shadow.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': Vue2Leaflet.LMap,
'v-tilelayer': Vue2Leaflet.LTileLayer,
'v-icondefault': Vue2Leaflet.LIconDefault,
'v-marker': Vue2Leaflet.LMarker,
'v-popup': Vue2Leaflet.LPopup,
'v-marker-cluster': Vue2LeafletMarkercluster
},
methods: {
click: (e) => console.log("clusterclick", e),
ready: (e) => console.log('ready', e),
},
data () {
let locations = []
for (let i = 0; i < 100; i++) {
locations.push({
id: i,
latlng: latLng(rand(-34.9205), rand(-57.953646)),
text: 'Hola ' + i
})
}
let customicon = icon(Object.assign({},
Icon.Default.prototype.options,
{iconUrl, shadowUrl}
))
return {
locations,
icon: customicon,
clusterOptions: {},
initialLocation: latLng(-34.9205, -57.953646)
}
},
mounted() {
setTimeout(() => {
console.log('done')
this.$nextTick(() =>{
this.clusterOptions = { disableClusteringAtZoom: 11 }
});
}, 5000);
}
}
</script>
<style>
@import "~leaflet/dist/leaflet.css";
@import "~leaflet.markercluster/dist/MarkerCluster.css";
@import "~leaflet.markercluster/dist/MarkerCluster.Default.css";
html, body {
height: 100%;
margin: 0;
}
</style>