From a4ed99a370930b1a0c0f065906ed99c15a015fd4 Mon Sep 17 00:00:00 2001 From: Petri Hienonen Date: Mon, 3 Nov 2025 11:19:15 +0200 Subject: Update documentation --- app/models.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'app/models.js') diff --git a/app/models.js b/app/models.js index 24dd5a8..d052f1c 100644 --- a/app/models.js +++ b/app/models.js @@ -1,4 +1,4 @@ -import { Collection, Feature, Geometry, LineString, Point, Polygon } from "geom"; +import { Bounds, Collection, Feature, LineString, Point, Polygon } from "geom"; /** @typedef {{ lat: number, lng: number }} GeoPointJson */ /** @typedef {{ date: string, price: number }} PriceUpdateJson */ @@ -172,7 +172,7 @@ export class District { * @returns {District} */ static fromFeature(feature) { - const name = feature.properties?.nimi_fi; + const name = "nimi_fi" in feature.properties ? feature.properties.nimi_fi : ""; const geometry = feature.geometry; if (name === undefined || !(geometry instanceof Polygon)) { @@ -182,6 +182,24 @@ export class District { return new District(name, geometry); } + /** + * Set houses data and render markers + * @param {District[]} districts + */ + static bounds(districts) { + const bounds = new Bounds(Infinity, Infinity, -Infinity, -Infinity); + + // Include districts in bounds + for (const district of districts) { + const districtBounds = district.polygon.bounds(); + bounds.minX = Math.min(districtBounds.minX, bounds.minX); + bounds.minY = Math.min(districtBounds.minY, bounds.minY); + bounds.maxX = Math.max(districtBounds.maxX, bounds.maxX); + bounds.maxY = Math.max(districtBounds.maxY, bounds.maxY); + } + return bounds; + } + /** * Convert Collection to District[] * @param {Collection} collection @@ -400,6 +418,7 @@ export class House { */ static getBuildingType(type) { // Basic mapping - can be expanded based on actual type values + /** @type {{[key: number]: string}} */ const typeMap = { 100: "House", 200: "Apartment", -- cgit v1.2.3-70-g09d2