This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
google-streetview-pano.html
270 lines (226 loc) · 6.58 KB
/
google-streetview-pano.html
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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
180
181
182
183
184
185
186
187
188
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../google-apis/google-maps-api.html">
<link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html">
<!--
Element for generating a Google Maps Street View Panorama.
##### Example
<google-streetview-pano
pano-id="CWskcsTEZBNXaD8gG-zATA"
heading="330"
pitch="-2"
zoom="0.8"
disable-default-ui>
</google-streetview-pano>
There are tons of great panoramas on the [Google Maps | Views page](https://www.google.com/maps/views/home?gl=us)
To grab a panorama, look at its url in the address bar. For example:
google.com/maps/views/view/102684927602131521305/photo/**1szTnskrdKIAAAGuu3fZRw**
The hash in bold is the `pano-id`. You'll often need to dial in the `heading`, `pitch` and `zoom` manually.
You can also use the position attribute and set it to a position with a computed value. Example: { lat: 42.345573, lng: -71.098326 }
<google-streetview-pano
position="[[_myComputedPosition()]]"
heading="330"
pitch="-2"
zoom="0.8"
disable-default-ui>
</google-streetview-pano>
@demo
-->
<dom-module id="google-streetview-pano">
<style>
:host {
display: block;
}
#pano {
height: 100%;
}
</style>
<template>
<google-maps-api api-key="{{apiKey}}"
version="{{version}}"
client-id="{{clientId}}"
language="{{language}}"
client
on-api-load="_mapApiLoaded"></google-maps-api>
<div id="pano" on-mouseenter="_autoStop"
on-mouseleave="_autoUpdate"></div>
</template>
</dom-module>
<script>
(function() {
'use strict';
Polymer({
is: 'google-streetview-pano',
behaviors: [Polymer.IronResizableBehavior],
listeners: {
'iron-resize': '_onResize'
},
properties: {
/**
* A Maps API key. To obtain an API key, see developers.google.com/maps/documentation/javascript/tutorial#api_key.
*/
apiKey: String,
/**
* A Maps API for Business Client ID. To obtain a Maps API for Business Client ID, see developers.google.com/maps/documentation/business/.
* If set, a Client ID will take precedence over an API Key.
*/
clientId: String,
/**
* The localized language to load the Maps API with. For more information
* see https://developers.google.com/maps/documentation/javascript/basics#Language
*
* Note: the Maps API defaults to the preferred language setting of the browser.
* Use this parameter to override that behavior.
*
*/
language: String,
/**
* Version of the Google Maps API to use.
*
*/
version: {
type: String,
value: '3.exp'
},
/**
* Specifies which photosphere to load
*
*
*/
panoId: {
type: String,
observer: '_panoIdChanged'
},
/**
* Specifies which position to load
*
*
*/
position: {
type: Object,
observer: '_positionChanged'
},
/**
* The camera heading in degrees relative to true north. True north is 0°, east is 90°, south is 180°, west is 270°.
*/
heading: {
type: Number,
value: 45
},
/**
* The camera pitch in degrees, relative to the street view vehicle. Ranges from 90° (directly upwards) to -90° (directly downwards).
*/
pitch: {
type: Number,
value: -2
},
/**
* Sets the zoom level of the panorama. Fully zoomed-out is level 0, where the field of view is 180 degrees.
*/
zoom: {
type: Number,
value: 1
},
/**
* If true, disables all default UI.
*/
disableDefaultUi: {
type: Boolean,
value: false
},
/**
* If true, disables the auto panning animation
*/
disableAutoPan: {
type: Boolean,
value: false
}
},
pano: null,
rAFid: null,
/**
* Called when the Google Maps API has loaded.
*/
_mapApiLoaded: function() {
this.pano = new google.maps.StreetViewPanorama(this.$.pano, this._getPanoOptions());
this.pano.setVisible(true);
if (this.disableAutoPan) {
return;
}
// Kickoff the rotating animation
this.rAFid = requestAnimationFrame(this.update.bind(this));
},
/**
* Returns the an object with the current panorama configurations.
*/
_getPanoOptions: function() {
var panoOptions = {
pano: this.panoId,
position: this.position,
pov: {
heading: this.heading,
pitch: this.pitch
},
disableDefaultUI: this.disableDefaultUi,
zoom: this.zoom
};
return panoOptions;
},
/**
* Fired every rAF. Updates the heading to create a slow pan effect
* Will be canceled by mouse enter or calling stop()
*/
update: function() {
this.rAFid = requestAnimationFrame(this.update.bind(this));
var pov = this.pano.getPov();
pov.heading += 0.03;
this.pano.setPov(pov);
},
_autoUpdate: function() {
if (this.disableAutoPan) {
return;
}
this.update();
},
/**
* Reset the pov for the panorama.
* @method reset
*/
reset: function() {
var pov = this.pano.getPov();
pov.heading = this.heading;
pov.pitch = this.pitch;
this.pano.setPov(pov);
},
/**
* Cancel the slow panning animation.
* @method stop
*/
stop: function() {
cancelAnimationFrame(this.rAFid);
},
_autoStop: function() {
if (this.disableAutoPan) {
return;
}
this.stop();
},
_panoIdChanged: function(newVal, oldVal) {
if (this.pano) {
this.pano.setPano(newVal);
this.reset();
}
},
_positionChanged: function(newVal, oldVal) {
if (this.pano) {
this.pano.setPosition(newVal);
this.reset();
}
},
_onResize: function() {
if (window.google) {
google.maps.event.trigger(this.pano, 'resize');
}
}
});
}());
</script>