This repository has been archived by the owner on Apr 21, 2023. It is now read-only.
forked from pranavpandey/google-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle-map-drawing-tool.js
97 lines (86 loc) · 2.3 KB
/
google-map-drawing-tool.js
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
import { Polymer } from "@polymer/polymer/lib/legacy/polymer-fn.js";
import { html } from "@polymer/polymer/lib/utils/html-tag.js";
Polymer({
_template: html`
<dom-module id="google-map-drawing-tool">
<template>
<style>
:host {
display: none;
}
</style>
<content></content>
</template>
</dom-module>
`,
is: "google-map-drawing-tool",
properties: {
map: {
type: Object,
observer: "_mapLoaded",
},
polygonColor: {
type: String,
value: "#169FFF",
},
disabled: {
type: Object,
observer: "_disabledChanged",
},
},
detached: function () {
if (this.currentPolygon) {
this.currentPolygon.setMap(null);
this.currentPolygon = null;
}
},
_disabledChanged: function () {
// Clears fishined polygons
if (this.currentPolygon) {
this.currentPolygon.setMap(null);
this.currentPolygon = null;
}
if (this.manager) {
this.manager.setMap(this.disabled ? null : this.map);
// Clears unfishined polygons
this.manager.setDrawingMode(null);
this.manager.setDrawingMode(google.maps.drawing.OverlayType.POLYGON);
}
},
_mapLoaded: function () {
if (this.manager) {
return;
}
if (this.map !== null && !this.manager) {
this.manager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.POLYGON,
drawingControl: false,
drawingControlOptions: {},
polygonOptions: {
strokeColor: this.polygonColor,
strokeOpacity: 0.8,
strokeWeight: 4,
fillColor: this.polygonColor,
fillOpacity: 0.35,
},
});
this.manager.setMap(this.disabled ? null : this.map);
google.maps.event.addListener(
this.manager,
"polygoncomplete",
function (event) {
if (!this.disabled) {
this.currentPolygon = event;
console.log("vrau");
this.manager.setDrawingMode(null);
const result = event
.getPath()
.getArray()
.map((point) => ({ lat: point.lat(), lng: point.lng() }));
this.fire("on-polygon-completed", result);
}
}.bind(this)
);
}
},
});