forked from jperelli/vue2-leaflet-markercluster
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.vue
116 lines (112 loc) · 2.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<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-pie
:options="clusterOptions"
:key-func="keyFunc"
:class-func="classFunc"
:title-func="titleFunc"
:style-func="styleFunc"
:rmax="rmax"
@clusterclick="click()">
<!-- require add data to marker -->
<v-marker v-for="l in locations" :key="l.id" :lat-lng="l.latlng" :icon="icon" :options="{marker_data: l}">
<v-popup :content="l.text"></v-popup>
</v-marker>
</v-marker-cluster-pie>
</v-map>
</template>
<script>
// import L from "leaflet";
import * as Vue2Leaflet from "vue2-leaflet";
import Vue2LeafletMarkerclusterPie from "./Vue2LeafletMarkerclusterPie";
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-pie": Vue2LeafletMarkerclusterPie
},
methods: {
click: function(e) {
alert("clusterclick");
},
keyFunc(d) {
return d.options.marker_data[this.iconStyleField];
},
classFunc(d) {
return "cluster-marker-segment-color_" + d.data.key;
},
titleFunc(d) {
return `count: ${d.data.values.length}`;
},
styleFunc(d) {
const color = this.colorMap[d.data.key];
return `
fill: ${color};
stroke: #444;
background: ${color};
border-color: #444;
`;
}
},
data() {
let locations = [];
for (let i = 0; i < 100; i++) {
locations.push({
id: i,
style_field: (Math.random() * 10) >> 0,
latlng: Vue2Leaflet.L.latLng(rand(-34.9205), rand(-57.953646)),
text: "Hola " + i
});
}
let icon = Vue2Leaflet.L.icon(
Object.assign({}, Vue2Leaflet.L.Icon.Default.prototype.options, {
iconUrl,
shadowUrl
})
);
return {
rmax: 35,
iconStyleField: "style_field",
locations,
icon,
clusterOptions: {},
initialLocation: Vue2Leaflet.L.latLng(-34.9205, -57.953646),
colorMap: {
"0": "black",
"1": "#F00000",
"2": "#FF0000",
"3": "#FFF000",
"4": "#FFFF00",
"5": "#FFFFF0",
"6": "#FFFFFF",
"7": "#0FFFFF",
"8": "#00FFFF",
"9": "#000FFF",
"10": "#0000FF"
}
};
}
};
</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>