-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixedHtml2dMarkers.js
More file actions
39 lines (32 loc) · 1.13 KB
/
Copy pathfixedHtml2dMarkers.js
File metadata and controls
39 lines (32 loc) · 1.13 KB
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
const config = {
pixelToBlockRatio: 1,
idealHeightTodistanceRatio: 0.651613,
};
const camera = bluemap.mapViewer.camera
function update2dHtmlMarkers() {
const elements = document.getElementsByClassName("fixed-on-map");
if (!elements.length) return;
const distance = camera.distance;
const height = window.innerHeight;
const yaw = bluemap.mapViewer.controlsManager.rotation;
const expectedDistance = config.idealHeightTodistanceRatio * height * config.pixelToBlockRatio;
const scale = expectedDistance / distance;
const degrees = -yaw * (180 / Math.PI);
const ortho = camera.ortho;
for (const el of elements) {
if (el.classList.contains("hide-on-3d-view")) {
if (ortho == 0) {
el.style.display = "none";
continue;
} else {
el.style.display = "";
}
}
el.style.transform = `scale(${scale}) rotate(${degrees}deg)`;
el.style.transformOrigin = "top left";
}
}
(function loop() {
update2dHtmlMarkers();
requestAnimationFrame(loop);
})();