forked from xkjyeah/vue-google-maps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
polygon-editing.html
57 lines (52 loc) · 1.66 KB
/
polygon-editing.html
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
<body>
<div id="root">
<gmap-map :center="{lat: 1.38, lng: 103.8}" :zoom="12" style="width: 100%; height: 500px">
<gmap-polygon :paths="paths" :editable="true" @paths_changed="updateEdited($event)">
</gmap-polygon>
</gmap-map>
<ul v-if="edited" @click="edited = null">
<li v-for="path in edited">
<ol>
<li v-for="point in path">
{{point.lat}}, {{point.lng}}
</li>
</ol>
</li>
</ul>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.0/vue.js"></script>
<script src="vue-google-maps.js"></script>
<script>
Vue.use(VueGoogleMaps, {
load: {
key: 'AIzaSyDf43lPdwlF98RCBsJOFNKOkoEjkwxb5Sc'
},
});
document.addEventListener('DOMContentLoaded', function() {
window.XXX = new Vue({
el: '#root',
data: {
edited: null,
paths: [
[ {lat: 1.380, lng: 103.800}, {lat:1.380, lng: 103.810}, {lat: 1.390, lng: 103.810}, {lat: 1.390, lng: 103.800} ],
[ {lat: 1.382, lng: 103.802}, {lat:1.382, lng: 103.808}, {lat: 1.388, lng: 103.808}, {lat: 1.388, lng: 103.802} ],
]
},
methods: {
updateEdited(mvcArray) {
let paths = [];
for (let i=0; i<mvcArray.getLength(); i++) {
let path = [];
for (let j=0; j<mvcArray.getAt(i).getLength(); j++) {
let point = mvcArray.getAt(i).getAt(j);
path.push({lat: point.lat(), lng: point.lng()});
}
paths.push(path);
}
this.edited = paths;
}
}
});
});
</script>
</body>