Skip to content

Commit 914c411

Browse files
committed
use pano id for cube map camera position
1 parent 40d39a6 commit 914c411

File tree

1 file changed

+61
-57
lines changed
  • packages/sandcastle/gallery/google-streetview-panorama

1 file changed

+61
-57
lines changed

packages/sandcastle/gallery/google-streetview-panorama/main.js

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -75,69 +75,73 @@ function saveCameraView(viewer) {
7575

7676
function selectPanoCubeMap(position) {
7777
const carto = Cesium.Cartographic.fromCartesian(position);
78+
provider.getPanoIds(carto).then((panoIdList) => {
79+
const panoId = panoIdList[0];
80+
provider.getPanoIdMetadata(panoId).then((panoIdMetadata) => {
81+
const panoLat = panoIdMetadata.lat;
82+
const panoLng = panoIdMetadata.lng;
83+
const height = carto.height;
7884

79-
const panoLat = Cesium.Math.toDegrees(carto.latitude);
80-
const panoLng = Cesium.Math.toDegrees(carto.longitude);
81-
const height = carto.height;
82-
const pos = [panoLat, panoLng]; //lat,lng Aukland
83-
const posString = pos.join(",");
84-
const posObj = Cesium.Cartesian3.fromDegrees(pos[1], pos[0], 0);
85-
86-
const baseUrl = "https://maps.googleapis.com/maps/api/streetview";
87-
function pUrl(h, p) {
88-
const r = new Cesium.Resource({
89-
url: baseUrl,
90-
queryParameters: {
91-
size: "600x600",
92-
location: posString,
93-
heading: h,
94-
pitch: p,
95-
key: googleStreetViewStaticApiKey,
96-
},
97-
});
98-
return r.url;
99-
}
100-
101-
const positiveX = pUrl(0, 0);
102-
const negativeX = pUrl(180, 0);
103-
const positiveZ = pUrl(270, 0);
104-
const negativeZ = pUrl(90, 0);
105-
const positiveY = pUrl(-90, -90);
106-
const negativeY = pUrl(-90, 90);
107-
108-
const ndeToFixedFrameTransform =
109-
Cesium.Transforms.localFrameToFixedFrameGenerator("north", "down");
110-
111-
const transform = Cesium.Matrix4.getMatrix3(
112-
ndeToFixedFrameTransform(posObj, Cesium.Ellipsoid.default),
113-
new Cesium.Matrix3(),
114-
);
85+
const baseUrl = "https://maps.googleapis.com/maps/api/streetview";
86+
function pUrl(h, p) {
87+
const r = new Cesium.Resource({
88+
url: baseUrl,
89+
queryParameters: {
90+
size: "600x600",
91+
pano: panoId,
92+
heading: h,
93+
pitch: p,
94+
key: googleStreetViewStaticApiKey,
95+
},
96+
});
97+
return r.url;
98+
}
11599

116-
const cityPano = new Cesium.CubeMapPanorama({
117-
sources: {
118-
positiveX,
119-
negativeX,
120-
positiveY,
121-
negativeY,
122-
positiveZ,
123-
negativeZ,
124-
},
125-
transform: transform,
126-
});
100+
const positiveX = pUrl(0, 0);
101+
const negativeX = pUrl(180, 0);
102+
const positiveZ = pUrl(270, 0);
103+
const negativeZ = pUrl(90, 0);
104+
const positiveY = pUrl(-90, -90);
105+
const negativeY = pUrl(-90, 90);
106+
107+
const ndeToFixedFrameTransform =
108+
Cesium.Transforms.localFrameToFixedFrameGenerator("north", "down");
109+
110+
const pos = [panoLat, panoLng]; //lat,lng Aukland
111+
const posObj = Cesium.Cartesian3.fromDegrees(pos[1], pos[0], 0);
112+
113+
const transform = Cesium.Matrix4.getMatrix3(
114+
ndeToFixedFrameTransform(posObj, Cesium.Ellipsoid.default),
115+
new Cesium.Matrix3(),
116+
);
117+
118+
const cityPano = new Cesium.CubeMapPanorama({
119+
sources: {
120+
positiveX,
121+
negativeX,
122+
positiveY,
123+
negativeY,
124+
positiveZ,
125+
negativeZ,
126+
},
127+
transform: transform,
128+
});
127129

128-
viewer.scene.primitives.add(cityPano);
130+
viewer.scene.primitives.add(cityPano);
129131

130-
const lookPosition = Cesium.Cartesian3.fromDegrees(
131-
panoLng,
132-
panoLat,
133-
height + 2,
134-
);
132+
const lookPosition = Cesium.Cartesian3.fromDegrees(
133+
panoLng,
134+
panoLat,
135+
height + 2,
136+
);
135137

136-
const heading = Cesium.Math.toRadians(-90);
138+
const heading = Cesium.Math.toRadians(-90);
137139

138-
goToPanoView({
139-
position: lookPosition,
140-
heading,
140+
goToPanoView({
141+
position: lookPosition,
142+
heading,
143+
});
144+
});
141145
});
142146
}
143147

0 commit comments

Comments
 (0)