Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: lib/src/google-map/google-map-marker.html

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/google-map/google-map-directions.html ('k') | lib/src/google-map/google-map-point.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- Copyright (c) 2015 Google Inc. All rights reserved. --> 1 <!-- Copyright (c) 2015 Google Inc. All rights reserved. -->
2 2
3 <link rel="import" href="../polymer/polymer.html"> 3 <link rel="import" href="../polymer/polymer.html">
4 <link rel="import" href="../google-apis/google-maps-api.html"> 4 <link rel="import" href="../google-apis/google-maps-api.html">
5 5
6 <!-- 6 <!--
7 The `google-map-marker` element represents a map marker. It is used as a 7 The `google-map-marker` element represents a map marker. It is used as a
8 child of `google-map`. 8 child of `google-map`.
9 9
10 <b>Example</b>: 10 <b>Example</b>:
(...skipping 24 matching lines...) Expand all
35 <dom-module id="google-map-marker"> 35 <dom-module id="google-map-marker">
36 <style> 36 <style>
37 :host { 37 :host {
38 display: none; 38 display: none;
39 } 39 }
40 </style> 40 </style>
41 <template><content></content></template> 41 <template><content></content></template>
42 </dom-module> 42 </dom-module>
43 43
44 <script> 44 <script>
45 (function() {
45 46
46 (function() { 47 function setupDragHandler_() {
48 if (this.draggable) {
49 this.dragHandler_ = google.maps.event.addListener(
50 this.marker, 'dragend', onDragEnd_.bind(this));
51 } else {
52 google.maps.event.removeListener(this.dragHandler_);
53 this.dragHandler_ = null;
54 }
55 }
56
57 function onDragEnd_(e, details, sender) {
58 this.latitude = e.latLng.lat();
59 this.longitude = e.latLng.lng();
60 }
61
47 Polymer({ 62 Polymer({
48 63
49 is: 'google-map-marker', 64 is: 'google-map-marker',
50 65
51 /** 66 /**
52 * Fired when the marker icon was clicked. Requires the clickEvents attribut e to be true. 67 * Fired when the marker icon was clicked. Requires the clickEvents attribut e to be true.
53 * @param {google.maps.MouseEvent} event The mouse event. 68 * @param {google.maps.MouseEvent} event The mouse event.
54 * @event google-map-marker-click 69 * @event google-map-marker-click
55 */ 70 */
71
56 /** 72 /**
57 * Fired when the marker icon was double clicked. Requires the clickEvents a ttribute to be true. 73 * Fired when the marker icon was double clicked. Requires the clickEvents a ttribute to be true.
58 * @param {google.maps.MouseEvent} event The mouse event. 74 * @param {google.maps.MouseEvent} event The mouse event.
59 * @event google-map-marker-dblclick 75 * @event google-map-marker-dblclick
60 */ 76 */
77
61 /** 78 /**
62 * Fired for a mousedown on the marker. Requires the mouseEvents attribute t o be true. 79 * Fired for a mousedown on the marker. Requires the mouseEvents attribute t o be true.
63 * @event google-map-marker-mousedown 80 * @event google-map-marker-mousedown
64 * @param {google.maps.MouseEvent} event The mouse event. 81 * @param {google.maps.MouseEvent} event The mouse event.
65 */ 82 */
83
66 /** 84 /**
67 * Fired when the DOM `mousemove` event is fired on the marker. Requires the mouseEvents 85 * Fired when the DOM `mousemove` event is fired on the marker. Requires the mouseEvents
68 * attribute to be true. 86 * attribute to be true.
69 * @event google-map-marker-mousemove 87 * @event google-map-marker-mousemove
70 * @param {google.maps.MouseEvent} event The mouse event. 88 * @param {google.maps.MouseEvent} event The mouse event.
71 */ 89 */
90
72 /** 91 /**
73 * Fired when the mouse leaves the area of the marker icon. Requires the mou seEvents attribute to be 92 * Fired when the mouse leaves the area of the marker icon. Requires the mou seEvents attribute to be
74 * true. 93 * true.
75 * @event google-map-marker-mouseout 94 * @event google-map-marker-mouseout
76 * @param {google.maps.MouseEvent} event The mouse event. 95 * @param {google.maps.MouseEvent} event The mouse event.
77 */ 96 */
97
78 /** 98 /**
79 * Fired when the mouse enters the area of the marker icon. Requires the mou seEvents attribute to be 99 * Fired when the mouse enters the area of the marker icon. Requires the mou seEvents attribute to be
80 * true. 100 * true.
81 * @event google-map-marker-mouseover 101 * @event google-map-marker-mouseover
82 * @param {google.maps.MouseEvent} event The mouse event. 102 * @param {google.maps.MouseEvent} event The mouse event.
83 */ 103 */
104
84 /** 105 /**
85 * Fired for a mouseup on the marker. Requires the mouseEvents attribute to be true. 106 * Fired for a mouseup on the marker. Requires the mouseEvents attribute to be true.
86 * 107 *
87 * @event google-map-marker-mouseup 108 * @event google-map-marker-mouseup
88 * @param {google.maps.MouseEvent} event The mouse event. 109 * @param {google.maps.MouseEvent} event The mouse event.
89 */ 110 */
111
90 /** 112 /**
91 * Fired for a rightclick on the marker. Requires the clickEvents attribute to be true. 113 * Fired for a rightclick on the marker. Requires the clickEvents attribute to be true.
92 * @event google-map-marker-rightclick 114 * @event google-map-marker-rightclick
93 * @param {google.maps.MouseEvent} event The mouse event. 115 * @param {google.maps.MouseEvent} event The mouse event.
94 */ 116 */
117
118 /**
119 * Fired when an infowindow is opened.
120 * @event google-map-marker-open
121 */
122
123 /**
124 * Fired when the close button of the infowindow is pressed.
125 * @event google-map-marker-close
126 */
127
95 properties: { 128 properties: {
96 /** 129 /**
97 * A Google Maps marker object. 130 * A Google Maps marker object.
98 * @type google.maps.Marker 131 * @type google.maps.Marker
99 */ 132 */
100 marker: Object, 133 marker: Object,
101 134
102 /** 135 /**
103 * The Google map object. 136 * The Google map object.
104 * @type google.maps.Map 137 * @type google.maps.Map
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 }, 187 },
155 188
156 /** 189 /**
157 * The marker's longitude coordinate. 190 * The marker's longitude coordinate.
158 */ 191 */
159 longitude: { 192 longitude: {
160 type: Number, 193 type: Number,
161 value: null, 194 value: null,
162 reflectToAttribute: true 195 reflectToAttribute: true
163 }, 196 },
197
164 /** 198 /**
165 * The marker's latitude coordinate. 199 * The marker's latitude coordinate.
166 */ 200 */
167 latitude: { 201 latitude: {
168 type: Number, 202 type: Number,
169 value: null, 203 value: null,
170 reflectToAttribute: true 204 reflectToAttribute: true
205 },
206
207 /**
208 * A animation for the marker. "DROP" or "BOUNCE". See
209 * https://developers.google.com/maps/documentation/javascript/examples/ma rker-animations.
210 */
211 animation: {
212 type: String,
213 value: null,
214 observer: '_animationChanged'
215 },
216
217 /**
218 * Specifies whether the InfoWindow is open or not
219 */
220 open: {
221 type: Boolean,
222 value: false,
223 observer: '_openChanged'
171 } 224 }
172 }, 225 },
173 226
174 observers: [ 227 observers: [
175 '_updatePosition(latitude, longitude)' 228 '_updatePosition(latitude, longitude)'
176 ], 229 ],
177 230
178 detached: function() { 231 detached: function() {
179 if (this.marker) { 232 if (this.marker) {
180 this.marker.setMap(null); 233 this.marker.setMap(null);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } else { 277 } else {
225 this._clearListener('mousedown'); 278 this._clearListener('mousedown');
226 this._clearListener('mousemove'); 279 this._clearListener('mousemove');
227 this._clearListener('mouseout'); 280 this._clearListener('mouseout');
228 this._clearListener('mouseover'); 281 this._clearListener('mouseover');
229 this._clearListener('mouseup'); 282 this._clearListener('mouseup');
230 } 283 }
231 } 284 }
232 }, 285 },
233 286
287 _animationChanged: function() {
288 if (this.marker) {
289 this.marker.setAnimation(google.maps.Animation[this.animation]);
290 }
291 },
292
234 _iconChanged: function() { 293 _iconChanged: function() {
235 if (this.marker) { 294 if (this.marker) {
236 this.marker.setIcon(this.icon); 295 this.marker.setIcon(this.icon);
237 } 296 }
238 }, 297 },
239 298
240 _zIndexChanged: function() { 299 _zIndexChanged: function() {
241 if (this.marker) { 300 if (this.marker) {
242 this.marker.setZIndex(this.zIndex); 301 this.marker.setZIndex(this.zIndex);
243 } 302 }
(...skipping 19 matching lines...) Expand all
263 this._contentObserver.observe( this, { 322 this._contentObserver.observe( this, {
264 childList: true, 323 childList: true,
265 subtree: true 324 subtree: true
266 }); 325 });
267 326
268 var content = this.innerHTML.trim(); 327 var content = this.innerHTML.trim();
269 if (content) { 328 if (content) {
270 if (!this.info) { 329 if (!this.info) {
271 // Create a new infowindow 330 // Create a new infowindow
272 this.info = new google.maps.InfoWindow(); 331 this.info = new google.maps.InfoWindow();
273 this.infoHandler_ = google.maps.event.addListener(this.marker, 'click' , function() { 332 this.openInfoHandler_ = google.maps.event.addListener(this.marker, 'cl ick', function() {
274 this.info.open(this.map, this.marker); 333 this.open = true;
334 }.bind(this));
335
336 this.closeInfoHandler_ = google.maps.event.addListener(this.info, 'clo seclick', function() {
337 this.open = false;
275 }.bind(this)); 338 }.bind(this));
276 } 339 }
277 this.info.setContent(content); 340 this.info.setContent(content);
278 } else { 341 } else {
279 if (this.info) { 342 if (this.info) {
280 // Destroy the existing infowindow. It doesn't make sense to have an empty one. 343 // Destroy the existing infowindow. It doesn't make sense to have an empty one.
281 google.maps.event.removeListener(this.infoHandler_); 344 google.maps.event.removeListener(this.openInfoHandler_);
345 google.maps.event.removeListener(this.closeInfoHandler_);
282 this.info = null; 346 this.info = null;
283 } 347 }
284 } 348 }
285 }, 349 },
286 350
351 _openChanged: function() {
352 if (this.info) {
353 if (this.open) {
354 this.info.open(this.map, this.marker);
355 this.fire('google-map-marker-open');
356 } else {
357 this.info.close();
358 this.fire('google-map-marker-close');
359 }
360 }
361 },
362
287 _mapReady: function() { 363 _mapReady: function() {
288 this._listeners = {}; 364 this._listeners = {};
289 this.marker = new google.maps.Marker({ 365 this.marker = new google.maps.Marker({
290 map: this.map, 366 map: this.map,
291 position: { 367 position: {
292 lat: parseFloat(this.latitude), 368 lat: parseFloat(this.latitude),
293 lng: parseFloat(this.longitude) 369 lng: parseFloat(this.longitude)
294 }, 370 },
295 title: this.title, 371 title: this.title,
372 animation: google.maps.Animation[this.animation],
296 draggable: this.draggable, 373 draggable: this.draggable,
297 visible: !this.hidden, 374 visible: !this.hidden,
298 icon: this.icon, 375 icon: this.icon,
299 zIndex: this.zIndex 376 zIndex: this.zIndex
300 }); 377 });
301 this._contentChanged(); 378 this._contentChanged();
302 this._clickEventsChanged(); 379 this._clickEventsChanged();
303 this._contentChanged(); 380 this._contentChanged();
304 this._mouseEventsChanged(); 381 this._mouseEventsChanged();
382 this._openChanged();
305 setupDragHandler_.bind(this)(); 383 setupDragHandler_.bind(this)();
306 }, 384 },
307 385
308 _clearListener: function(name) { 386 _clearListener: function(name) {
309 if (this._listeners[name]) { 387 if (this._listeners[name]) {
310 google.maps.event.removeListener(this._listeners[name]); 388 google.maps.event.removeListener(this._listeners[name]);
311 this._listeners[name] = null; 389 this._listeners[name] = null;
312 } 390 }
313 }, 391 },
314 392
(...skipping 17 matching lines...) Expand all
332 this.marker.setDraggable(this.draggable); 410 this.marker.setDraggable(this.draggable);
333 setupDragHandler_.bind(this)(); 411 setupDragHandler_.bind(this)();
334 break; 412 break;
335 case 'title': 413 case 'title':
336 this.marker.setTitle(this.title); 414 this.marker.setTitle(this.title);
337 break; 415 break;
338 } 416 }
339 } 417 }
340 }); 418 });
341 419
342 function setupDragHandler_() {
343 if (this.draggable) {
344 this.dragHandler_ = google.maps.event.addListener(
345 this.marker, 'dragend', onDragEnd_.bind(this));
346 } else {
347 google.maps.event.removeListener(this.dragHandler_);
348 this.dragHandler_ = null;
349 }
350 }
351
352 function onDragEnd_(e, details, sender) {
353 this.latitude = e.latLng.lat();
354 this.longitude = e.latLng.lng();
355 }
356 })(); 420 })();
357 </script> 421 </script>
OLDNEW
« no previous file with comments | « lib/src/google-map/google-map-directions.html ('k') | lib/src/google-map/google-map-point.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698