]> jcornell.net Git - ntbd-parcels.git/commitdiff
Separate parcel filter and render steps
authorJakob Cornell <jakob+gpg@jcornell.net>
Thu, 21 May 2026 04:28:15 +0000 (23:28 -0500)
committerJakob Cornell <jakob+gpg@jcornell.net>
Thu, 21 May 2026 04:28:15 +0000 (23:28 -0500)
main.js

diff --git a/main.js b/main.js
index 2fc1445edcbd40d89fa5a86397dce61e5ec0408c..39ae14d681667d3b2d00f5b681ec3acbb18c73b6 100644 (file)
--- a/main.js
+++ b/main.js
@@ -5,6 +5,14 @@ const PARCEL_JSON_PATH = "//jcornell.net/static/parcels/Tax_Parcels_(Assessor_Pr
 
 const PARCEL_LOAD_KEY = "parcelsLoaded";
 
+const PICK_ZONINGS = new Set([
+       "SR-C1", "SR-C2", "SR-C3", "SR-V1", "SR-V2", "TR-C1", "TR-C2", "TR-C3",
+       "TR-C4", "TR-V1", "TR-V2", "TR-U1", "TR-U2", "TR-R", "TR-P"
+]);
+
+const MIN_LOT_SIZE_ACRES = 0.5;
+const MAX_LOT_SIZE_ACRES = 1.5;
+
 function transposeCoordinates(coordList) {
        return coordList.map(
                poly => poly.map(
@@ -40,9 +48,8 @@ async function asyncMain() {
        }
 
        const store = db.query("features", "readonly");
-       const PICK_ZONINGS = new Set(["TR-V2", "TR-U1", "TR-U2"]);
-       overlay.innerText = "filtering & rendering parcels";
-       let matchCount = 0;
+       overlay.innerText = "filtering parcels";
+       const matches = [];
        let noZoningCount = 0;
        let noLotSizeCount = 0;
        // store.getAll doesn't work for some reason.
@@ -51,10 +58,8 @@ async function asyncMain() {
                        const zoningParts = (feature.properties.ZoningAll ?? "").split(", ");
                        const zoningMatch = zoningParts.length && new Set(zoningParts).intersection(PICK_ZONINGS).size;
                        const lotSizeAcres = feature.properties.LotSize / 43560;
-                       if (zoningMatch && lotSizeAcres >= 0.5 && lotSizeAcres <= 1.5) {
-                               const leafletCoords = transposeCoordinates(feature.geometry.coordinates);
-                               L.polygon(leafletCoords, {color: "blue", weight: 1}).addTo(map);
-                               matchCount += 1;
+                       if (zoningMatch && lotSizeAcres >= MIN_LOT_SIZE_ACRES && lotSizeAcres <= MAX_LOT_SIZE_ACRES) {
+                               matches.push(feature);
                        }
                        if (!zoningParts.length) {
                                noZoningCount += 1;
@@ -70,11 +75,17 @@ async function asyncMain() {
        console.log(
                "Searched %d parcels: %d matches, %d with no zoning, %d with no size",
                await store.count(),
-               matchCount,
+               matches.length,
                noZoningCount,
                noLotSizeCount,
        );
 
+       overlay.innerText = "rendering parcels";
+       for (const feature of matches) {
+               const leafletCoords = transposeCoordinates(feature.geometry.coordinates);
+               L.polygon(leafletCoords, {color: "blue", weight: 1}).addTo(map);
+       }
+
        overlay.style["display"] = "none";
 }