Skip to content

Commit 3332f3c

Browse files
committed
panoIcon sharing
1 parent 7d0a608 commit 3332f3c

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

components/pano-app.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ export default class PanoApp extends HTMLElement {
1414
this.show(e.detail.item, {center:false, popup:false});
1515
});
1616

17+
this.#scene.addEventListener("pano-click", e => {
18+
this.show(e.detail.item, {center:true, popup:true});
19+
});
20+
1721
this.#map.addEventListener("pano-over", e => this.#highlight(e.detail.item));
1822
this.#map.addEventListener("pano-out", e => this.#highlight(null));
23+
24+
this.#scene.addEventListener("pano-over", e => this.#highlight(e.detail.item));
25+
this.#scene.addEventListener("pano-out", e => this.#highlight(null));
1926
}
2027

2128
connectedCallback() {
@@ -25,7 +32,8 @@ export default class PanoApp extends HTMLElement {
2532

2633
show(item, options) {
2734
this.#map.activate(item, options);
28-
this.#scene.show(item, this.#items);
35+
let panoIcon = this.#map.getIcon(item);
36+
this.#scene.show(item, this.#items, panoIcon);
2937
}
3038

3139
#highlight(item) {

components/pano-icon.css

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
pano-icon {
22
display: block;
33
position: relative;
4+
--color: dodgerblue;
5+
&.active { --color: orange; }
6+
transition: opacity 300ms;
47

58
.fov {
69
position: absolute;
@@ -14,13 +17,13 @@ pano-icon {
1417
}
1518

1619
.icon {
17-
position: relative;
1820
display: block;
1921
path {
20-
stroke: rgba(0, 0, 0, 0.75);
21-
fill: dodgerblue;
22+
stroke: #000;
23+
fill: var(--color);
24+
transition: all 300ms;
2225
}
2326
}
2427

25-
&.active .icon path { fill: orange; }
28+
&:not(.highlight):not(.active) { opacity: 0.7; }
2629
}

components/pano-map.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export default class PanoMap extends HTMLElement {
6464
}
6565
}
6666

67+
getIcon(item) { return this.#panoIcons.get(item); }
68+
6769
activate(item, options) {
6870
if (options.center) { this.#map.setView([item["GPSLatitude"], item["GPSLongitude"]], 17); }
6971

@@ -115,7 +117,6 @@ export default class PanoMap extends HTMLElement {
115117
let icon = L.divIcon({html:panoIcon, popupAnchor, iconSize, className:""});
116118
let marker = L.marker([item["GPSLatitude"], item["GPSLongitude"]], {title:item["ImageDescription"] || "", icon});
117119

118-
item.panoIcon = panoIcon;
119120
marker.bindPopup(() => this.#buildPopup(item));
120121

121122
panoIcon.addEventListener("mouseenter", _ => this.#dispatch("pano-over", item));

components/pano-near.css

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ pano-near {
33
position: absolute;
44
translate: -50% -50%;
55
cursor: pointer;
6+
--color: dodgerblue;
7+
transition: opacity 300ms;
68

79
.icon {
810
display: block;
911
path {
10-
stroke: rgba(0, 0, 0, 0.75);
11-
fill: dodgerblue;
12-
.leaflet-marker-icon.active & { fill: orange; }
12+
stroke: #000;
13+
fill: var(--color);
1314
}
1415
}
1516

16-
&:hover .icon path { fill: orange; }
17+
&:not(.highlight):not(.active) { opacity: 0.7; }
1718
}

components/pano-scene.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ const NEAR_LIMIT = 5000;
77
export default class PanoScene extends HTMLElement {
88
#lp;
99
#item;
10+
#panoIcon;
1011
#near = new Map();
1112

1213
constructor() {
1314
super();
1415
new ResizeObserver(_ => this.#lp && this.#syncSize()).observe(this);
1516
}
1617

17-
show(item, allItems) {
18+
show(item, allItems, panoIcon) {
1819
let littlePlanet = document.createElement("little-planet");
1920
littlePlanet.src = item["SourceFile"];
2021
this.#lp = littlePlanet;
22+
this.#panoIcon = panoIcon;
2123

2224
// fixme odebrat
2325
littlePlanet.addEventListener("change", e => this.#onPanoChange(e));
@@ -46,18 +48,18 @@ export default class PanoScene extends HTMLElement {
4648
this.#syncSize();
4749
}
4850

49-
#syncSize() { // fixme resizeobserver
50-
const lp = this.#lp;
51-
lp.width = lp.clientWidth * DPR;
52-
lp.height = lp.clientHeight * DPR;
53-
}
54-
5551
highlight(item) {
5652
for (let [i, near] of this.#near.entries()) {
5753
near.classList.toggle("highlight", i == item);
5854
}
5955
}
6056

57+
#syncSize() {
58+
const lp = this.#lp;
59+
lp.width = lp.clientWidth * DPR;
60+
lp.height = lp.clientHeight * DPR;
61+
}
62+
6163
#dispatch(type, item) {
6264
let event = new CustomEvent(type, {detail:{item}});
6365
this.dispatchEvent(event);
@@ -71,11 +73,11 @@ export default class PanoScene extends HTMLElement {
7173
switch (mode) {
7274
case "pano":
7375
let angle = camera.lon + Number(this.#item["FlightYawDegree"]);
74-
this.#item.panoIcon.drawFov(angle, camera.fov);
76+
this.#panoIcon.drawFov(angle, camera.fov);
7577
break;
7678

7779
case "planet":
78-
this.#item.panoIcon.hideFov();
80+
this.#panoIcon.hideFov();
7981
break;
8082
}
8183

0 commit comments

Comments
 (0)