forked from timeu/google-map-markerclusterer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
google-map-overlayview-marker-behavior.html
94 lines (87 loc) · 2.01 KB
/
google-map-overlayview-marker-behavior.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
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
<link rel="import" href="google-map-overlayview-behavior.html">
<script>
/**
* Use `GoogleMapOverlayViewMarkerBehavior` to implement elements that should be displayed as `Marker` on a `google-map` using an overlayview
* Users should either override the `_update` if they need to customize the positioning.
* @polymer
* @mixinFunction
*/
GoogleMapOverlayViewMarkerBehavior = function (superClass) {
return class extends GoogleMapOverlayViewBehavior(superClass) {
static get properties() {
return {
/**
* The position of the marker on the map
*/
position: {
type: Object,
value: null
},
/**
* The size of the marker
*/
size: {
type: Number,
value: 25,
},
/**
* Set to true if the marker should be draggable
*/
isDraggable: {
type: Boolean,
value: false
},
}
}
ready() {
super.ready();
this.style.position = 'absolute';
}
/**
* Returns the position of the marker
*/
getPosition() {
return this.position;
}
/**
* Returns whether marker is draggable.
*/
getDraggable() {
return this.isDraggable;
}
/**
* Returns the map instance.
*/
getMap() {
if (this.overlay) {
return this.overlay.getMap();
}
return null;
}
/**
* Sets the map instance
*/
setMap(map) {
if (this.overlay && this.overlay instanceof google.maps.OverlayView) {
this.overlay.setMap(map);
}
}
/**
* Draw callback forwarded to the function `update`.
*/
draw() {
this.update(this.position, this.size);
}
/**
* Override this function to implement custom positioning.
* By default will `left` and `top` CSS settings are used to position the element.
*/
update(position, size) {
var projection = this.overlay.getProjection();
var mapPos = projection.fromLatLngToDivPixel(position);
this.style.left = (mapPos.x - size / 2) + 'px';
this.style.top = (mapPos.y - size / 2) + 'px';
}
}
}
</script>