73bcce88
luigser
COMPONENTS
|
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
|
<!-- Copyright (c) 2015 Google Inc. All rights reserved. -->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../google-apis/google-maps-api.html">
<!--
The `google-map-marker` element represents a map marker. It is used as a
child of `google-map`.
<b>Example</b>:
<google-map latitude="37.77493" longitude="-122.41942">
<google-map-marker latitude="37.779" longitude="-122.3892"
title="Go Giants!"></google-map-marker>
</google-map>
<b>Example</b> - marker with info window (children create the window content):
<google-map-marker latitude="37.77493" longitude="-122.41942">
<img src="image.png">
</google-map-marker>
<b>Example</b> - a draggable marker:
<google-map-marker latitude="37.77493" longitude="-122.41942"
draggable="true"></google-map-marker>
<b>Example</b> - hide a marker:
<google-map-marker latitude="37.77493" longitude="-122.41942"
hidden></google-map-marker>
-->
<dom-module id="google-map-marker">
<style>
:host {
display: none;
}
</style>
<template><content></content></template>
</dom-module>
<script>
|
73bcce88
luigser
COMPONENTS
|
45
|
(function() {
|
e619a3b0
Luigi Serra
Controllet cross ...
|
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
function setupDragHandler_() {
if (this.draggable) {
this.dragHandler_ = google.maps.event.addListener(
this.marker, 'dragend', onDragEnd_.bind(this));
} else {
google.maps.event.removeListener(this.dragHandler_);
this.dragHandler_ = null;
}
}
function onDragEnd_(e, details, sender) {
this.latitude = e.latLng.lat();
this.longitude = e.latLng.lng();
}
|
73bcce88
luigser
COMPONENTS
|
62
63
64
65
66
67
68
69
70
|
Polymer({
is: 'google-map-marker',
/**
* Fired when the marker icon was clicked. Requires the clickEvents attribute to be true.
* @param {google.maps.MouseEvent} event The mouse event.
* @event google-map-marker-click
*/
|
e619a3b0
Luigi Serra
Controllet cross ...
|
71
|
|
73bcce88
luigser
COMPONENTS
|
72
73
74
75
76
|
/**
* Fired when the marker icon was double clicked. Requires the clickEvents attribute to be true.
* @param {google.maps.MouseEvent} event The mouse event.
* @event google-map-marker-dblclick
*/
|
e619a3b0
Luigi Serra
Controllet cross ...
|
77
|
|
73bcce88
luigser
COMPONENTS
|
78
|
/**
|
a1a3bc73
Luigi Serra
graphs updates
|
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
* Fired repeatedly while the user drags the marker. Requires the dragEvents attribute to be true.
* @event google-map-marker-drag
*/
/**
* Fired when the user stops dragging the marker. Requires the dragEvents attribute to be true.
* @event google-map-marker-dragend
*/
/**
* Fired when the user starts dragging the marker. Requires the dragEvents attribute to be true.
* @event google-map-marker-dragstart
*/
/**
|
73bcce88
luigser
COMPONENTS
|
94
95
96
97
|
* Fired for a mousedown on the marker. Requires the mouseEvents attribute to be true.
* @event google-map-marker-mousedown
* @param {google.maps.MouseEvent} event The mouse event.
*/
|
e619a3b0
Luigi Serra
Controllet cross ...
|
98
|
|
73bcce88
luigser
COMPONENTS
|
99
100
101
102
103
104
|
/**
* Fired when the DOM `mousemove` event is fired on the marker. Requires the mouseEvents
* attribute to be true.
* @event google-map-marker-mousemove
* @param {google.maps.MouseEvent} event The mouse event.
*/
|
e619a3b0
Luigi Serra
Controllet cross ...
|
105
|
|
73bcce88
luigser
COMPONENTS
|
106
107
108
109
110
111
|
/**
* Fired when the mouse leaves the area of the marker icon. Requires the mouseEvents attribute to be
* true.
* @event google-map-marker-mouseout
* @param {google.maps.MouseEvent} event The mouse event.
*/
|
e619a3b0
Luigi Serra
Controllet cross ...
|
112
|
|
73bcce88
luigser
COMPONENTS
|
113
114
115
116
117
118
|
/**
* Fired when the mouse enters the area of the marker icon. Requires the mouseEvents attribute to be
* true.
* @event google-map-marker-mouseover
* @param {google.maps.MouseEvent} event The mouse event.
*/
|
e619a3b0
Luigi Serra
Controllet cross ...
|
119
|
|
73bcce88
luigser
COMPONENTS
|
120
121
122
123
124
125
|
/**
* Fired for a mouseup on the marker. Requires the mouseEvents attribute to be true.
*
* @event google-map-marker-mouseup
* @param {google.maps.MouseEvent} event The mouse event.
*/
|
e619a3b0
Luigi Serra
Controllet cross ...
|
126
|
|
73bcce88
luigser
COMPONENTS
|
127
128
129
130
131
|
/**
* Fired for a rightclick on the marker. Requires the clickEvents attribute to be true.
* @event google-map-marker-rightclick
* @param {google.maps.MouseEvent} event The mouse event.
*/
|
e619a3b0
Luigi Serra
Controllet cross ...
|
132
|
|
eb240478
Luigi Serra
public room cards...
|
133
134
135
136
137
138
139
140
141
142
|
/**
* Fired when an infowindow is opened.
* @event google-map-marker-open
*/
/**
* Fired when the close button of the infowindow is pressed.
* @event google-map-marker-close
*/
|
73bcce88
luigser
COMPONENTS
|
143
144
145
146
147
|
properties: {
/**
* A Google Maps marker object.
* @type google.maps.Marker
*/
|
a1a3bc73
Luigi Serra
graphs updates
|
148
149
150
151
|
marker: {
type: Object,
notify: true
},
|
73bcce88
luigser
COMPONENTS
|
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/**
* The Google map object.
* @type google.maps.Map
*/
map: {
type: Object,
observer: '_mapChanged'
},
/**
* A Google Map Infowindow object.
*/
info: {
type: Object,
value: null
},
/**
* When true, marker *click events are automatically registered.
*/
clickEvents: {
type: Boolean,
value: false,
observer: '_clickEventsChanged'
},
/**
|
a1a3bc73
Luigi Serra
graphs updates
|
180
181
182
183
184
185
186
187
188
|
* When true, marker drag* events are automatically registered.
*/
dragEvents: {
type: Boolean,
value: false,
observer: '_dragEventsChanged'
},
/**
|
73bcce88
luigser
COMPONENTS
|
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
* Image URL for the marker icon.
* @type string|google.maps.Icon|google.maps.Symbol
*/
icon: {
type: Object,
value: null,
observer: '_iconChanged'
},
/**
* When true, marker mouse* events are automatically registered.
*/
mouseEvents: {
type: Boolean,
value: false,
observer: '_mouseEventsChanged'
},
/**
* Z-index for the marker icon.
*/
zIndex: {
type: Number,
value: 0,
observer: '_zIndexChanged'
},
/**
* The marker's longitude coordinate.
*/
longitude: {
type: Number,
value: null,
|
a1a3bc73
Luigi Serra
graphs updates
|
222
|
notify: true
|
73bcce88
luigser
COMPONENTS
|
223
|
},
|
e619a3b0
Luigi Serra
Controllet cross ...
|
224
|
|
73bcce88
luigser
COMPONENTS
|
225
226
227
228
229
230
|
/**
* The marker's latitude coordinate.
*/
latitude: {
type: Number,
value: null,
|
a1a3bc73
Luigi Serra
graphs updates
|
231
|
notify: true
|
e619a3b0
Luigi Serra
Controllet cross ...
|
232
233
234
235
236
237
238
239
240
241
|
},
/**
* A animation for the marker. "DROP" or "BOUNCE". See
* https://developers.google.com/maps/documentation/javascript/examples/marker-animations.
*/
animation: {
type: String,
value: null,
observer: '_animationChanged'
|
eb240478
Luigi Serra
public room cards...
|
242
243
244
245
246
247
248
249
250
|
},
/**
* Specifies whether the InfoWindow is open or not
*/
open: {
type: Boolean,
value: false,
observer: '_openChanged'
|
73bcce88
luigser
COMPONENTS
|
251
252
253
254
255
256
257
258
259
|
}
},
observers: [
'_updatePosition(latitude, longitude)'
],
detached: function() {
if (this.marker) {
|
a1a3bc73
Luigi Serra
graphs updates
|
260
261
|
google.maps.event.clearInstanceListeners(this.marker);
this._listeners = {};
|
73bcce88
luigser
COMPONENTS
|
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
this.marker.setMap(null);
}
if (this._contentObserver)
this._contentObserver.disconnect();
},
attached: function() {
// If element is added back to DOM, put it back on the map.
if (this.marker) {
this.marker.setMap(this.map);
}
},
_updatePosition: function() {
if (this.marker && this.latitude != null && this.longitude != null) {
this.marker.setPosition({
lat: parseFloat(this.latitude),
lng: parseFloat(this.longitude)
});
}
},
_clickEventsChanged: function() {
if (this.map) {
if (this.clickEvents) {
this._forwardEvent('click');
this._forwardEvent('dblclick');
this._forwardEvent('rightclick');
} else {
this._clearListener('click');
this._clearListener('dblclick');
this._clearListener('rightclick');
}
}
},
|
a1a3bc73
Luigi Serra
graphs updates
|
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
_dragEventsChanged: function() {
if (this.map) {
if (this.dragEvents) {
this._forwardEvent('drag');
this._forwardEvent('dragend');
this._forwardEvent('dragstart');
} else {
this._clearListener('drag');
this._clearListener('dragend');
this._clearListener('dragstart');
}
}
},
|
73bcce88
luigser
COMPONENTS
|
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
_mouseEventsChanged: function() {
if (this.map) {
if (this.mouseEvents) {
this._forwardEvent('mousedown');
this._forwardEvent('mousemove');
this._forwardEvent('mouseout');
this._forwardEvent('mouseover');
this._forwardEvent('mouseup');
} else {
this._clearListener('mousedown');
this._clearListener('mousemove');
this._clearListener('mouseout');
this._clearListener('mouseover');
this._clearListener('mouseup');
}
}
},
|
e619a3b0
Luigi Serra
Controllet cross ...
|
330
331
332
333
334
335
|
_animationChanged: function() {
if (this.marker) {
this.marker.setAnimation(google.maps.Animation[this.animation]);
}
},
|
73bcce88
luigser
COMPONENTS
|
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
_iconChanged: function() {
if (this.marker) {
this.marker.setIcon(this.icon);
}
},
_zIndexChanged: function() {
if (this.marker) {
this.marker.setZIndex(this.zIndex);
}
},
_mapChanged: function() {
// Marker will be rebuilt, so disconnect existing one from old map and listeners.
if (this.marker) {
this.marker.setMap(null);
google.maps.event.clearInstanceListeners(this.marker);
}
if (this.map && this.map instanceof google.maps.Map) {
this._mapReady();
}
},
_contentChanged: function() {
if (this._contentObserver)
this._contentObserver.disconnect();
// Watch for future updates.
this._contentObserver = new MutationObserver( this._contentChanged.bind(this));
this._contentObserver.observe( this, {
childList: true,
subtree: true
});
var content = this.innerHTML.trim();
if (content) {
if (!this.info) {
// Create a new infowindow
this.info = new google.maps.InfoWindow();
|
eb240478
Luigi Serra
public room cards...
|
375
376
377
378
379
380
|
this.openInfoHandler_ = google.maps.event.addListener(this.marker, 'click', function() {
this.open = true;
}.bind(this));
this.closeInfoHandler_ = google.maps.event.addListener(this.info, 'closeclick', function() {
this.open = false;
|
73bcce88
luigser
COMPONENTS
|
381
382
383
384
385
386
|
}.bind(this));
}
this.info.setContent(content);
} else {
if (this.info) {
// Destroy the existing infowindow. It doesn't make sense to have an empty one.
|
eb240478
Luigi Serra
public room cards...
|
387
388
|
google.maps.event.removeListener(this.openInfoHandler_);
google.maps.event.removeListener(this.closeInfoHandler_);
|
73bcce88
luigser
COMPONENTS
|
389
390
391
392
393
|
this.info = null;
}
}
},
|
eb240478
Luigi Serra
public room cards...
|
394
395
396
397
398
399
400
401
402
403
404
405
|
_openChanged: function() {
if (this.info) {
if (this.open) {
this.info.open(this.map, this.marker);
this.fire('google-map-marker-open');
} else {
this.info.close();
this.fire('google-map-marker-close');
}
}
},
|
73bcce88
luigser
COMPONENTS
|
406
407
408
409
|
_mapReady: function() {
this._listeners = {};
this.marker = new google.maps.Marker({
map: this.map,
|
e619a3b0
Luigi Serra
Controllet cross ...
|
410
411
412
413
|
position: {
lat: parseFloat(this.latitude),
lng: parseFloat(this.longitude)
},
|
73bcce88
luigser
COMPONENTS
|
414
|
title: this.title,
|
e619a3b0
Luigi Serra
Controllet cross ...
|
415
|
animation: google.maps.Animation[this.animation],
|
73bcce88
luigser
COMPONENTS
|
416
417
418
419
420
421
422
|
draggable: this.draggable,
visible: !this.hidden,
icon: this.icon,
zIndex: this.zIndex
});
this._contentChanged();
this._clickEventsChanged();
|
a1a3bc73
Luigi Serra
graphs updates
|
423
|
this._dragEventsChanged();
|
73bcce88
luigser
COMPONENTS
|
424
|
this._mouseEventsChanged();
|
eb240478
Luigi Serra
public room cards...
|
425
|
this._openChanged();
|
73bcce88
luigser
COMPONENTS
|
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
|
setupDragHandler_.bind(this)();
},
_clearListener: function(name) {
if (this._listeners[name]) {
google.maps.event.removeListener(this._listeners[name]);
this._listeners[name] = null;
}
},
_forwardEvent: function(name) {
this._listeners[name] = google.maps.event.addListener(this.marker, name, function(event) {
this.fire('google-map-marker-' + name, event);
}.bind(this));
},
attributeChanged: function(attrName, oldVal, newVal) {
if (!this.marker) {
return;
}
// Cannot use *Changed watchers for native properties.
switch (attrName) {
case 'hidden':
this.marker.setVisible(!this.hidden);
break;
case 'draggable':
this.marker.setDraggable(this.draggable);
setupDragHandler_.bind(this)();
break;
case 'title':
this.marker.setTitle(this.title);
break;
}
}
});
|
73bcce88
luigser
COMPONENTS
|
463
464
|
})();
</script>
|