| OLD | NEW |
| 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 Provides the Google Maps API Directions Service to provide directions | 7 Provides the Google Maps API Directions Service to provide directions |
| 8 between a `startAddress` and `endAddress`. | 8 between a `startAddress` and `endAddress`. |
| 9 | 9 |
| 10 See https://developers.google.com/maps/documentation/javascript/directions for m
ore | 10 See https://developers.google.com/maps/documentation/javascript/directions for m
ore |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 <dom-module id="google-map-directions"> | 27 <dom-module id="google-map-directions"> |
| 28 <style> | 28 <style> |
| 29 :host { | 29 :host { |
| 30 display: none; | 30 display: none; |
| 31 } | 31 } |
| 32 </style> | 32 </style> |
| 33 <template> | 33 <template> |
| 34 <google-maps-api | 34 <google-maps-api |
| 35 api-key="[[apiKey]]" | 35 api-key="[[apiKey]]" |
| 36 libraries="[[libraries]]" | |
| 37 language="[[language]]" | 36 language="[[language]]" |
| 38 on-api-load="_mapApiLoaded"></google-maps-api> | 37 on-api-load="_mapApiLoaded"></google-maps-api> |
| 39 </template> | 38 </template> |
| 40 </dom-module> | 39 </dom-module> |
| 41 | 40 |
| 42 <script> | 41 <script> |
| 43 Polymer({ | 42 Polymer({ |
| 44 | 43 |
| 45 is: 'google-map-directions', | 44 is: 'google-map-directions', |
| 46 | 45 |
| 47 /** | 46 /** |
| 48 Fired whenever the directions service returns a result. | 47 Fired whenever the directions service returns a result. |
| 49 | 48 |
| 50 @event google-map-response | 49 @event google-map-response |
| 51 @param {Object} detail | 50 @param {{response: Object}}} detail |
| 52 @param {object} detail.response The directions service response. | |
| 53 */ | 51 */ |
| 54 properties: { | 52 properties: { |
| 55 /** | 53 /** |
| 56 * A Maps API key. To obtain an API key, see developers.google.com/maps/do
cumentation/javascript/tutorial#api_key. | 54 * A Maps API key. To obtain an API key, see developers.google.com/maps/do
cumentation/javascript/tutorial#api_key. |
| 57 */ | 55 */ |
| 58 apiKey: String, | 56 apiKey: String, |
| 59 | 57 |
| 60 /** | 58 /** |
| 61 * The Google map object. | 59 * The Google map object. |
| 62 * | 60 * |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 * Waypoints are not supported for transit directions. Optional. | 101 * Waypoints are not supported for transit directions. Optional. |
| 104 * | 102 * |
| 105 * @type google.maps.DirectionsWaypoint | 103 * @type google.maps.DirectionsWaypoint |
| 106 */ | 104 */ |
| 107 waypoints: { | 105 waypoints: { |
| 108 type: Array, | 106 type: Array, |
| 109 value: function() { return []; } | 107 value: function() { return []; } |
| 110 }, | 108 }, |
| 111 | 109 |
| 112 /** | 110 /** |
| 113 * A comma separated list (e.g. "places,geometry") of libraries to load | |
| 114 * with this map. Defaults to "places". For more information see | |
| 115 * https://developers.google.com/maps/documentation/javascript/libraries. | |
| 116 * | |
| 117 * Note, this needs to be set to the same value as the one used on <google
-map>. | |
| 118 * If you're overriding that element's `libraries` property, this one also | |
| 119 * needs to be set to the Maps API loads the library code. | |
| 120 */ | |
| 121 libraries: { | |
| 122 type: String, | |
| 123 value: 'places' | |
| 124 }, | |
| 125 | |
| 126 /** | |
| 127 * The localized language to load the Maps API with. For more information | 111 * The localized language to load the Maps API with. For more information |
| 128 * see https://developers.google.com/maps/documentation/javascript/basics#
Language | 112 * see https://developers.google.com/maps/documentation/javascript/basics#
Language |
| 129 * | 113 * |
| 130 * Note: the Maps API defaults to the preffered language setting of the br
owser. | 114 * Note: the Maps API defaults to the preffered language setting of the br
owser. |
| 131 * Use this parameter to override that behavior. | 115 * Use this parameter to override that behavior. |
| 132 */ | 116 */ |
| 133 language: { | 117 language: { |
| 134 type: String, | 118 type: String, |
| 135 value: null | 119 value: null |
| 136 }, | 120 }, |
| 137 | 121 |
| 138 /** | 122 /** |
| 123 * Options for the display of results |
| 124 */ |
| 125 rendererOptions: { |
| 126 type: Object, |
| 127 value: function() { return {}; } |
| 128 }, |
| 129 |
| 130 /** |
| 139 * The response from the directions service. | 131 * The response from the directions service. |
| 140 * | 132 * |
| 141 */ | 133 */ |
| 142 response: { | 134 response: { |
| 143 type: Object, | 135 type: Object, |
| 144 observer: '_responseChanged', | 136 observer: '_responseChanged', |
| 145 notify: true | 137 notify: true |
| 146 } | 138 } |
| 147 }, | 139 }, |
| 148 | 140 |
| 149 observers: [ | 141 observers: [ |
| 150 '_route(startAddress, endAddress, travelMode, waypoints)' | 142 '_route(startAddress, endAddress, travelMode, waypoints)' |
| 151 ], | 143 ], |
| 152 | 144 |
| 153 _mapApiLoaded: function() { | 145 _mapApiLoaded: function() { |
| 154 this._route(); | 146 this._route(); |
| 155 }, | 147 }, |
| 156 | 148 |
| 157 _responseChanged: function() { | 149 _responseChanged: function() { |
| 158 if (this.directionsRenderer && this.response) { | 150 if (this.directionsRenderer && this.response) { |
| 159 this.directionsRenderer.setDirections(this.response); | 151 this.directionsRenderer.setDirections(this.response); |
| 160 } | 152 } |
| 161 }, | 153 }, |
| 162 | 154 |
| 163 _mapChanged: function() { | 155 _mapChanged: function() { |
| 164 if (this.map && this.map instanceof google.maps.Map) { | 156 if (this.map && this.map instanceof google.maps.Map) { |
| 165 if (!this.directionsRenderer) { | 157 if (!this.directionsRenderer) { |
| 166 this.directionsRenderer = new google.maps.DirectionsRenderer(); | 158 this.directionsRenderer = new google.maps.DirectionsRenderer(this.rend
ererOptions); |
| 167 } | 159 } |
| 168 this.directionsRenderer.setMap(this.map); | 160 this.directionsRenderer.setMap(this.map); |
| 169 this._responseChanged(); | 161 this._responseChanged(); |
| 170 } else { | 162 } else { |
| 171 // If there is no more map, remove the directionsRenderer from the map a
nd delete it. | 163 // If there is no more map, remove the directionsRenderer from the map a
nd delete it. |
| 172 if (this.directionsRenderer) { | 164 if (this.directionsRenderer) { |
| 173 this.directionsRenderer.setMap(null); | 165 this.directionsRenderer.setMap(null); |
| 174 this.directionsRenderer = null; | 166 this.directionsRenderer = null; |
| 175 } | 167 } |
| 176 } | 168 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 198 }; | 190 }; |
| 199 this.directionsService.route(request, function(response, status) { | 191 this.directionsService.route(request, function(response, status) { |
| 200 if (status == google.maps.DirectionsStatus.OK) { | 192 if (status == google.maps.DirectionsStatus.OK) { |
| 201 this.response = response; | 193 this.response = response; |
| 202 this.fire('google-map-response', {response: response}); | 194 this.fire('google-map-response', {response: response}); |
| 203 } | 195 } |
| 204 }.bind(this)); | 196 }.bind(this)); |
| 205 } | 197 } |
| 206 }); | 198 }); |
| 207 </script> | 199 </script> |
| OLD | NEW |