Skip to content

Commit aaa9cc6

Browse files
committed
camera retain
1 parent bab5b45 commit aaa9cc6

File tree

3 files changed

+4006
-22
lines changed

3 files changed

+4006
-22
lines changed

components/pano-app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default class PanoApp extends HTMLElement {
4141
let sceneOptions = {
4242
panoIcon: this.#map.getIcon(item),
4343
items: this.#items,
44-
heading: (activator == "scene" ? this.#scene.heading : null)
44+
retainCamera: (activator == "scene")
4545
}
4646
this.#scene.show(item, sceneOptions);
4747
}

components/pano-scene.js

+29-20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { NEAR_LIMIT } from "./config.js";
33

44

55
const DPR = devicePixelRatio;
6+
const YAW_KEY = "FlightYawDegree";
67

78
export default class PanoScene extends HTMLElement {
89
#lp;
@@ -16,10 +17,20 @@ export default class PanoScene extends HTMLElement {
1617
}
1718

1819
get heading() {
19-
return this.#lp.camera.lon + Number(this.#item["FlightYawDegree"]);
20+
return this.#lp.camera.lon + Number(this.#item[YAW_KEY]);
2021
}
2122

22-
show(item, options) {
23+
async show(item, options) {
24+
let camera = null;
25+
if (options.retainCamera && this.#lp) {
26+
let oldCamera = this.#lp.camera;
27+
camera = {
28+
lat: oldCamera.lat,
29+
lon: this.heading - Number(item[YAW_KEY]),
30+
fov: oldCamera.fov
31+
}
32+
}
33+
2334
this.#panoIcon && this.#panoIcon.hideFov();
2435
this.#panoIcon = options.panoIcon;
2536
this.#item = item;
@@ -43,13 +54,18 @@ export default class PanoScene extends HTMLElement {
4354
lp.src = item["SourceFile"];
4455
lp.addEventListener("change", e => this.#onPanoChange(e));
4556

46-
if (options.heading !== null) { // crossfade
57+
if (camera) { // crossfade
58+
let oldLp = this.#lp;
4759
lp.style.opacity = 0;
4860
this.append(lp, ...this.#near.values());
49-
setHeading(lp, options.heading-Number(item["FlightYawDegree"]), this.#lp);
61+
await lpLoaded(lp);
62+
lp.mode = "pano";
63+
lp.camera = camera;
64+
crossfade(oldLp, lp);
5065
} else { // hard replace
5166
this.replaceChildren(lp, ...this.#near.values());
5267
}
68+
5369
this.#lp = lp;
5470
this.#syncSize();
5571
}
@@ -72,14 +88,13 @@ export default class PanoScene extends HTMLElement {
7288
}
7389

7490
#onPanoChange(e) {
75-
if (!("FlightYawDegree" in this.#item)) { return; }
91+
if (!(YAW_KEY in this.#item)) { return; }
7692

7793
const { mode, camera } = e.target;
7894

7995
switch (mode) {
8096
case "pano":
81-
let angle = camera.lon + Number(this.#item["FlightYawDegree"]);
82-
this.#panoIcon.drawFov(angle, camera.fov);
97+
this.#panoIcon.drawFov(this.heading, camera.fov);
8398
break;
8499

85100
case "planet":
@@ -94,21 +109,15 @@ export default class PanoScene extends HTMLElement {
94109
}
95110
customElements.define("pano-scene", PanoScene);
96111

97-
function setHeading(lp, heading, oldLp) {
98-
lp.setAttribute("mode", "pano");
99-
let camera = {
100-
lat: 0,
101-
lon: heading,
102-
fov: oldLp.camera.fov
103-
}
104-
lp.addEventListener("load", _ => {
105-
lp.camera = camera;
106-
crossfade(oldLp, lp);
107-
});
108-
}
109-
110112
function crossfade(oldLp, newLp) {
111113
let duration = 1000;
112114
oldLp.animate({opacity: [1, 0]}, duration).finished.then(_ => oldLp.remove());
113115
newLp.animate({opacity: [0, 1]}, {duration, fill:"both"}).finished.then(a => a.commitStyles());
114116
}
117+
118+
function lpLoaded(lp) {
119+
return new Promise((resolve, reject) => {
120+
lp.addEventListener("load", resolve);
121+
lp.addEventListener("error", reject);
122+
});
123+
}

0 commit comments

Comments
 (0)