aboutsummaryrefslogtreecommitdiffstats
path: root/app/models.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/models.js')
-rw-r--r--app/models.js23
1 files changed, 21 insertions, 2 deletions
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)) {
@@ -183,6 +183,24 @@ export class District {
}
/**
+ * 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
* @returns {District[]}
@@ -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",