-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.vue
94 lines (91 loc) · 2.39 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
<template>
<div style="height: 100%; width: 100%">
<l-map
style="height: 400px"
:center="mapCentre"
:zoom="mapZoom"
@polylinemeasure:toggle="handleToggle"
@polylinemeasure:start="handleStart"
@polylinemeasure:resume="handleResume"
@polylinemeasure:finish="handleFinish"
@polylinemeasure:clear="handleClear"
@polylinemeasure:add="handleAdd"
@polylinemeasure:insert="handleInsert"
@polylinemeasure:move="handleMove"
@polylinemeasure:remove="handleRemove"
>
<l-tile-layer
:url="tileUrl"
:attribution="tileAttribution"
/>
<l-control-polyline-measure />
</l-map>
<p
v-for="event in events"
:key="event.order"
>
{{ event.order }}. {{ event.desc }}
</p>
</div>
</template>
<script>
import L from 'leaflet';
import { LMap, LTileLayer } from 'vue2-leaflet';
import LControlPolylineMeasure from './LControlPolylineMeasure.vue';
export default {
components: {
LMap,
LTileLayer,
LControlPolylineMeasure,
},
data () {
return {
mapCentre: [51, -114],
mapZoom: 10,
tileUrl: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
tileAttribution: '© <a href="//osm.org/copyright">OpenStreetMap</a> contributors',
eventDescriptions: [],
};
},
computed: {
events () {
return this.eventDescriptions.map((desc, idx) => ({ order: idx + 1, desc })).reverse();
},
},
methods: {
addEvent (desc) {
this.eventDescriptions.push(desc);
},
handleToggle (e) {
this.addEvent(`Toggled: ${e.sttus}`);
},
handleStart (currentLine) {
this.addEvent(`Started: Initial distance ${currentLine.distance}`);
},
handleResume (currentLine) {
this.addEvent(`Resumed: Current distance ${currentLine.distance}`);
},
handleFinish (currentLine) {
this.addEvent(`Finished: Total distance ${currentLine.distance}`);
},
handleClear () {
this.addEvent('Cleared');
},
handleAdd (e) {
this.addEvent(`Added point: ${e.latlng}`);
},
handleInsert (e) {
this.addEvent(`Inserted point: ${e.latlng}`);
},
handleMove (e) {
this.addEvent(`Moved point: ${e.latlng} to ${e.sourceTarget._latlng}`);
},
handleRemove (e) {
this.addEvent(`Removed point: ${e.latlng}`);
},
},
};
</script>
<style>
@import '~leaflet/dist/leaflet.css';
</style>