aboutsummaryrefslogtreecommitdiffstats
path: root/app/map.js
diff options
context:
space:
mode:
authorPetri Hienonen <petri.hienonen@gmail.com>2025-11-15 19:12:48 +0200
committerPetri Hienonen <petri.hienonen@gmail.com>2025-11-15 19:14:02 +0200
commita44f2de806d0557b148dcdf36a3107cb4ecf31ce (patch)
tree9868794be4dbf2be820add96dae560f95369fce9 /app/map.js
parent64acc82b9634d948517ec5bb2ebe5a33cdf22df6 (diff)
downloadhousing-a44f2de806d0557b148dcdf36a3107cb4ecf31ce.tar.zst
Minor fixes
Diffstat (limited to 'app/map.js')
-rw-r--r--app/map.js37
1 files changed, 11 insertions, 26 deletions
diff --git a/app/map.js b/app/map.js
index 5976d92..e8e9098 100644
--- a/app/map.js
+++ b/app/map.js
@@ -79,8 +79,8 @@ export class MapEl {
#modalTimer;
/** @type {boolean} */
#persistentModal = false;
- /** @type {Bounds|null} */
- #fullBounds = null;
+ /** @type {Bounds} */
+ #fullBounds;
/** @type {Point|null} */
#centerPoint = null;
/** @type {number} */
@@ -150,29 +150,12 @@ export class MapEl {
// Calculate initial center point and view height
this.#centerPoint = new Point(bounds.minX + width / 2, bounds.minY + height / 2);
- this.#viewHeightMeters = this.#calculateViewHeightMeters(height);
- this.svg.setAttribute("viewBox", `${bounds.minX} ${-bounds.maxY} ${width} ${height}`);
- }
-
- /**
- * Calculate view height in meters based on latitude and view height in degrees
- * @param {number} heightDegrees
- * @returns {number}
- */
- #calculateViewHeightMeters(heightDegrees) {
// Approximate conversion: 1 degree latitude ≈ 111,000 meters
// 1 degree longitude varies by latitude: 111,000 * cos(latitude)
- return heightDegrees * 111000;
- }
+ this.#viewHeightMeters = height * 111000;
- /**
- * Calculate view height in degrees based on meters and latitude
- * @param {number} meters
- * @returns {number}
- */
- #calculateViewHeightDegrees(meters) {
- return meters / 111000;
+ this.svg.setAttribute("viewBox", `${bounds.minX} ${-bounds.maxY} ${width} ${height}`);
}
/**
@@ -191,7 +174,7 @@ export class MapEl {
this.#viewHeightMeters = MapMath.clamp(this.#viewHeightMeters, 100, 1000000);
// Calculate new view height in degrees
- const newHeightDegrees = this.#calculateViewHeightDegrees(this.#viewHeightMeters);
+ const newHeightDegrees = this.#viewHeightMeters / 11000;
// Calculate new width based on aspect ratio
const aspectRatio = vb.width / vb.height;
@@ -407,13 +390,15 @@ export class MapEl {
* @param {SVGSVGElement} svg
* @param {number} initVx - Initial velocity X
* @param {number} initVy - Initial velocity Y
+ * @param {Bounds} fullBounds
* @param {number} [friction=PanningConfig.DEFAULT_FRICTION]
* @param {number} [speedThreshold=PanningConfig.DEFAULT_SPEED_THRESHOLD]
*/
- #startInertia(
+ static #startInertia(
svg,
initVx,
initVy,
+ fullBounds,
friction = PanningConfig.DEFAULT_FRICTION,
speedThreshold = PanningConfig.DEFAULT_SPEED_THRESHOLD,
) {
@@ -440,7 +425,7 @@ export class MapEl {
vb.x -= deltaX;
vb.y -= deltaY;
- const { clampedX, clampedY } = MapEl.#clampViewBox(svg, this.#fullBounds);
+ const { clampedX, clampedY } = MapEl.#clampViewBox(svg, fullBounds);
if (clampedX) currVx = -currVx * PanningConfig.DEFAULT_BOUNCE_FACTOR;
if (clampedY) currVy = -currVy * PanningConfig.DEFAULT_BOUNCE_FACTOR;
@@ -650,7 +635,7 @@ export class MapEl {
const speed = Math.hypot(vx, vy);
if (speed > PanningConfig.DEFAULT_SPEED_THRESHOLD) {
- this.#startInertia(this.svg, vx, vy);
+ MapEl.#startInertia(this.svg, vx, vy, this.#fullBounds);
}
}
});
@@ -720,7 +705,7 @@ export class MapEl {
fill: "none", // Changed from semi-transparent blue to transparent
"pointer-events": "stroke",
stroke: "rgba(85, 85, 85, 1)",
- "stroke-width": "0.001",
+ "stroke-width": "0.0005",
},
}),
);