OLD | NEW |
(Empty) | |
| 1 <link rel="import" href="../polymer/polymer.html"> |
| 2 <link rel="import" href="../google-apis/google-maps-api.html"> |
| 3 |
| 4 <!-- |
| 5 Element for generating a Google Maps Street View Panorama. |
| 6 |
| 7 ##### Example |
| 8 |
| 9 <google-streetview-pano |
| 10 pano-id="CWskcsTEZBNXaD8gG-zATA" |
| 11 heading="330" |
| 12 pitch="-2" |
| 13 zoom="0.8" |
| 14 disable-default-ui> |
| 15 </google-streetview-pano> |
| 16 |
| 17 There are tons of great panoramas on the [Google Maps | Views page](https://www.
google.com/maps/views/home?gl=us) |
| 18 |
| 19 To grab a panorama, look at its url in the address bar. For example: |
| 20 |
| 21 google.com/maps/views/view/102684927602131521305/photo/**1szTnskrdKIAAAGuu3fZRw*
* |
| 22 |
| 23 The hash in bold is the `pano-id`. You'll often need to dial in the `heading`, `
pitch` and `zoom` manually. |
| 24 |
| 25 @demo |
| 26 --> |
| 27 |
| 28 <dom-module id="google-streetview-pano"> |
| 29 <style> |
| 30 :host { |
| 31 display: block; |
| 32 } |
| 33 #pano { |
| 34 height: 100%; |
| 35 } |
| 36 </style> |
| 37 <template> |
| 38 <google-maps-api api-key="{{apiKey}}" version="{{version}}" |
| 39 libraries="{{libraries}}" |
| 40 client-id="{{clientId}}" |
| 41 language="{{language}}" |
| 42 client |
| 43 on-api-load="_mapApiLoaded"></google-maps-api> |
| 44 <div id="pano" on-mouseenter="_autoStop" |
| 45 on-mouseleave="_autoUpdate"></div> |
| 46 </template> |
| 47 </dom-module> |
| 48 |
| 49 <script> |
| 50 "use strict"; |
| 51 |
| 52 Polymer({ |
| 53 is: 'google-streetview-pano', |
| 54 properties: { |
| 55 /** |
| 56 * A Maps API key. To obtain an API key, see developers.google.com/maps/do
cumentation/javascript/tutorial#api_key. |
| 57 */ |
| 58 apiKey: String, |
| 59 |
| 60 /** |
| 61 * A Maps API for Business Client ID. To obtain a Maps API for Business Cl
ient ID, see developers.google.com/maps/documentation/business/. |
| 62 * If set, a Client ID will take precedence over an API Key. |
| 63 */ |
| 64 clientId: String, |
| 65 |
| 66 /** |
| 67 * The localized language to load the Maps API with. For more information |
| 68 * see https://developers.google.com/maps/documentation/javascript/basics#
Language |
| 69 * |
| 70 * Note: the Maps API defaults to the preferred language setting of the br
owser. |
| 71 * Use this parameter to override that behavior. |
| 72 * |
| 73 */ |
| 74 language: String, |
| 75 |
| 76 /** |
| 77 * A comma separated list (e.g. "places,geometry") of libraries to load |
| 78 * with this map. Defaults to "places". For more information see |
| 79 * https://developers.google.com/maps/documentation/javascript/libraries. |
| 80 * |
| 81 */ |
| 82 libraries: { |
| 83 type: String, |
| 84 value: "places" |
| 85 }, |
| 86 |
| 87 /** |
| 88 * Version of the Google Maps API to use. |
| 89 * |
| 90 */ |
| 91 version: { |
| 92 type: String, |
| 93 value: '3.exp' |
| 94 }, |
| 95 |
| 96 /** |
| 97 * Specifies which photosphere to load |
| 98 * |
| 99 * **Required** |
| 100 */ |
| 101 panoId: { |
| 102 type: String, |
| 103 observer: '_panoIdChanged' |
| 104 }, |
| 105 |
| 106 /** |
| 107 * The camera heading in degrees relative to true north. True north is 0°,
east is 90°, south is 180°, west is 270°. |
| 108 */ |
| 109 heading: { |
| 110 type: Number, |
| 111 value: 45 |
| 112 }, |
| 113 |
| 114 /** |
| 115 * The camera pitch in degrees, relative to the street view vehicle. Range
s from 90° (directly upwards) to -90° (directly downwards). |
| 116 */ |
| 117 pitch: { |
| 118 type: Number, |
| 119 value: -2 |
| 120 }, |
| 121 |
| 122 /** |
| 123 * Sets the zoom level of the panorama. Fully zoomed-out is level 0, where
the field of view is 180 degrees. |
| 124 */ |
| 125 zoom: { |
| 126 type: Number, |
| 127 value: 1 |
| 128 }, |
| 129 |
| 130 /** |
| 131 * If true, disables all default UI. |
| 132 */ |
| 133 disableDefaultUi: { |
| 134 type: Boolean, |
| 135 value: false |
| 136 }, |
| 137 |
| 138 /** |
| 139 * If true, disables the auto panning animation |
| 140 */ |
| 141 disableAutoPan: { |
| 142 type: Boolean, |
| 143 value: false |
| 144 }, |
| 145 |
| 146 }, |
| 147 |
| 148 pano: null, |
| 149 rAFid: null, |
| 150 _mapApiLoaded: function() { |
| 151 this.pano = new google.maps.StreetViewPanorama( |
| 152 this.$.pano, |
| 153 this._getPanoOptions()); |
| 154 this.pano.setVisible(true); |
| 155 |
| 156 if (this.disableAutoPan) { |
| 157 return; |
| 158 } |
| 159 // Kickoff the rotating animation |
| 160 this.rAFid = requestAnimationFrame(this.update.bind(this)); |
| 161 }, |
| 162 |
| 163 /** |
| 164 * Returns the an object with the current panorama configurations. |
| 165 */ |
| 166 _getPanoOptions: function() { |
| 167 var panoOptions = { |
| 168 pano: this.panoId, |
| 169 pov: { |
| 170 heading: this.heading, |
| 171 pitch: this.pitch |
| 172 }, |
| 173 disableDefaultUI: this.disableDefaultUi, |
| 174 zoom: this.zoom |
| 175 }; |
| 176 |
| 177 return panoOptions; |
| 178 }, |
| 179 |
| 180 /** |
| 181 * Fired every rAF. Updates the heading to create a slow pan effect |
| 182 * Will be canceled by mouse enter or calling stop() |
| 183 */ |
| 184 update: function() { |
| 185 this.rAFid = requestAnimationFrame(this.update.bind(this)); |
| 186 var pov = this.pano.getPov(); |
| 187 pov.heading += 0.03; |
| 188 this.pano.setPov(pov); |
| 189 }, |
| 190 |
| 191 _autoUpdate: function() { |
| 192 if (this.disableAutoPan) { |
| 193 return; |
| 194 } |
| 195 |
| 196 this.update(); |
| 197 }, |
| 198 |
| 199 /** |
| 200 * Reset the pov for the panorama. |
| 201 * @method reset |
| 202 */ |
| 203 reset: function() { |
| 204 var pov = this.pano.getPov(); |
| 205 pov.heading = this.heading; |
| 206 pov.pitch = this.pitch; |
| 207 this.pano.setPov(pov); |
| 208 }, |
| 209 |
| 210 /** |
| 211 * Cancel the slow panning animation. |
| 212 * @method stop |
| 213 */ |
| 214 stop: function() { |
| 215 cancelAnimationFrame(this.rAFid); |
| 216 }, |
| 217 |
| 218 _autoStop: function() { |
| 219 if (this.disableAutoPan) { |
| 220 return; |
| 221 } |
| 222 |
| 223 this.stop(); |
| 224 }, |
| 225 |
| 226 _panoIdChanged: function(newVal, oldVal) { |
| 227 if (this.pano) { |
| 228 this.pano.setPano(newVal); |
| 229 this.reset(); |
| 230 } |
| 231 } |
| 232 }); |
| 233 </script> |
OLD | NEW |