| OLD | NEW |
| (Empty) | |
| 1 <!-- |
| 2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 3 This code may only be used under the BSD style license found at https://polymer.
github.io/LICENSE.txt |
| 4 The complete set of authors may be found at https://polymer.github.io/AUTHORS.tx
t |
| 5 The complete set of contributors may be found at https://polymer.github.io/CONTR
IBUTORS.txt |
| 6 Code distributed by Google as part of the polymer project is also |
| 7 subject to an additional IP rights grant found at https://polymer.github.io/PATE
NTS.txt |
| 8 --> |
| 9 |
| 10 <link rel="import" href="../polymer/polymer.html"> |
| 11 <link rel="import" href="../iron-jsonp-library/iron-jsonp-library.html"> |
| 12 |
| 13 <script> |
| 14 /** |
| 15 Dynamically loads the Google Maps JavaScript API, firing the `api-load` event wh
en ready. |
| 16 |
| 17 #### Example |
| 18 |
| 19 <google-maps-api apiKey="abc123" version="3.exp"></google-maps-api> |
| 20 <script> |
| 21 var mapsAPI = document.querySelector('google-maps-api'); |
| 22 mapsAPI.addEventListener('api-load', function(e) { |
| 23 // this.api === google.maps |
| 24 }); |
| 25 <script> |
| 26 |
| 27 Any number of components can use `<google-maps-api>` elements, and the library w
ill only be loaded once. |
| 28 |
| 29 @blurb Element wrapper around Google Maps API. |
| 30 |
| 31 */ |
| 32 Polymer({ |
| 33 |
| 34 is: 'google-maps-api', |
| 35 |
| 36 behaviors: [ |
| 37 Polymer.IronJsonpLibraryBehavior |
| 38 ], |
| 39 |
| 40 properties: { |
| 41 |
| 42 /** @private */ |
| 43 mapsUrl: { |
| 44 type: String, |
| 45 value: 'https://maps.googleapis.com/maps/api/js?callback=%%callback%%' |
| 46 }, |
| 47 |
| 48 /** |
| 49 * A Maps API key. To obtain an API key, see developers.google.com/maps/do
cumentation/javascript/tutorial#api_key. |
| 50 */ |
| 51 apiKey: { |
| 52 type: String, |
| 53 value: '' |
| 54 }, |
| 55 |
| 56 /** |
| 57 * A Maps API for Business Client ID. To obtain a Maps API for Business Cl
ient ID, see developers.google.com/maps/documentation/business/. |
| 58 * If set, a Client ID will take precedence over an API Key. |
| 59 */ |
| 60 clientId: { |
| 61 type: String, |
| 62 value: '' |
| 63 }, |
| 64 |
| 65 /** |
| 66 * The libraries to load with this map. Defaults to "places". For more inf
ormation |
| 67 * see https://developers.google.com/maps/documentation/javascript/librari
es. |
| 68 */ |
| 69 libraries: { |
| 70 type: String, |
| 71 value: 'places' |
| 72 }, |
| 73 |
| 74 /** |
| 75 * Version of the Maps API to use. |
| 76 */ |
| 77 version: { |
| 78 type: String, |
| 79 value: '3.exp' |
| 80 }, |
| 81 |
| 82 /** |
| 83 * The localized language to load the Maps API with. For more information |
| 84 * see https://developers.google.com/maps/documentation/javascript/basics#
Language |
| 85 * |
| 86 * Note: the Maps API defaults to the preffered language setting of the br
owser. |
| 87 * Use this parameter to override that behavior. |
| 88 */ |
| 89 language: { |
| 90 type: String, |
| 91 value: '' |
| 92 }, |
| 93 /** |
| 94 * If true, sign-in is enabled. |
| 95 * See https://developers.google.com/maps/documentation/javascript/signedi
n#enable_sign_in |
| 96 */ |
| 97 signedIn: { |
| 98 type: Boolean, |
| 99 value: false |
| 100 }, |
| 101 |
| 102 /** |
| 103 * Fired when the Maps API library is loaded and ready. |
| 104 * @event api-load |
| 105 */ |
| 106 /** |
| 107 * Name of event fired when library is loaded and available. |
| 108 */ |
| 109 notifyEvent: { |
| 110 type: String, |
| 111 value: 'api-load' |
| 112 }, |
| 113 |
| 114 /** @private */ |
| 115 libraryUrl: { |
| 116 type: String, |
| 117 computed: '_computeUrl(mapsUrl, version, libraries, apiKey, clientId, la
nguage, signedIn)' |
| 118 } |
| 119 }, |
| 120 |
| 121 _computeUrl: function(mapsUrl, version, libraries, apiKey, clientId, languag
e, signedIn) { |
| 122 var url = mapsUrl + '&v=' + version; |
| 123 url += "&libraries=" + libraries; |
| 124 |
| 125 if (apiKey && !clientId) { |
| 126 url += '&key=' + apiKey; |
| 127 } |
| 128 |
| 129 if (clientId) { |
| 130 url += '&client=' + clientId; |
| 131 } |
| 132 |
| 133 if (language) { |
| 134 url += '&language=' + language; |
| 135 } |
| 136 |
| 137 if (signedIn) { |
| 138 url += '&signed_in=' + signedIn; |
| 139 } |
| 140 return url; |
| 141 }, |
| 142 |
| 143 /** |
| 144 * Provides the google.maps JS API namespace. |
| 145 */ |
| 146 get api() { |
| 147 return google.maps; |
| 148 } |
| 149 }); |
| 150 </script> |
| OLD | NEW |