Skip to content

Commit

Permalink
fixed the extractLevelsRangeAndBounds filter not properly working
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Aug 25, 2024
1 parent 1c9a687 commit 35d41d8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dist/*",
"src/"
],
"version": "0.0.13",
"version": "0.0.14",
"scripts": {
"test": "jest .",
"lint": "eslint src --fix && tsc --noEmit && prettier --write .",
Expand Down
5 changes: 3 additions & 2 deletions src/levelFromGeojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,16 @@ export function extractLevelsRangeAndBounds(
}
const levelRanges: LevelsRange[] = geojson.features
.filter(
(feat) => !feat.properties || typeof feat.properties.level !== "string",
(feat) => !!feat.properties && typeof feat.properties.level === "string",
)
.map((feat) => extractLevelRangeFromFeature(feat.properties?.level ?? ""))
.filter((r) => r !== null);

if (levelRanges.length == 0) {
console.debug(geojson);
throw new Error(
`the FeatureCollection does not contain a single level. cannot compute the range of levels to display`,
"the FeatureCollection does not contain a single level. " +
"Cannot compute the range of levels to display",
);
}
return {
Expand Down
48 changes: 48 additions & 0 deletions tests/GeojsonHelper.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,56 @@
import {
extractLevelRangeFromFeature,
parseLevelRange,
extractLevelsRangeAndBounds,
} from "../src/levelFromGeojson";
import type { FeatureCollection, Geometry } from "geojson";

describe("extractLevelRangeFromFeature", () => {
test("example-collection", () => {
const collection = {
features: [
{
geometry: {
coordinates: [
[11.6701479, 48.2668645],
[11.6701577, 48.2668634],
[11.6701702, 48.2668618],
],
type: "LineString",
},
id: 1290116452,
properties: {
indoor: "wall",
level: "0",
},
type: "Feature",
},
{
geometry: {
coordinates: [11.669933, 48.266857],
type: "Point",
},
id: 11976838772,
properties: {
door: "yes",
indoor: "yes",
level: "2",
},
type: "Feature",
},
],
type: "FeatureCollection",
} as FeatureCollection<Geometry>;
const expected = {
bounds: [11.669933, 48.266857, 11.6701702, 48.2668645],
levelsRange: {
max: 2,
min: 0,
},
};
expect(extractLevelsRangeAndBounds(collection)).toStrictEqual(expected);
});
});
describe("extractLevelRangeFromFeature", () => {
test("gibberish", () => {
expect(extractLevelRangeFromFeature("abc")).toStrictEqual(null);
Expand Down

0 comments on commit 35d41d8

Please sign in to comment.