From 63508dbb67776eb4a5eb5c04ee6ffbcba40965f4 Mon Sep 17 00:00:00 2001 From: HarelM Date: Sat, 9 Nov 2024 22:52:04 +0200 Subject: [PATCH] Add inature support to osm-tags service --- .../services/osm-tags.service.spec.ts | 446 ++++-------------- .../application/services/osm-tags.service.ts | 9 +- 2 files changed, 97 insertions(+), 358 deletions(-) diff --git a/IsraelHiking.Web/src/application/services/osm-tags.service.spec.ts b/IsraelHiking.Web/src/application/services/osm-tags.service.spec.ts index 80ffb7817..a358ff5a7 100644 --- a/IsraelHiking.Web/src/application/services/osm-tags.service.spec.ts +++ b/IsraelHiking.Web/src/application/services/osm-tags.service.spec.ts @@ -1,25 +1,31 @@ -import { OsmTagsService } from "./osm-tags.service"; +import { OsmTagsService, PoiProperties } from "./osm-tags.service"; + +function createFeature(properties: any): GeoJSON.Feature { + return { + type: "Feature", + properties: properties, + geometry: { + type: "Point", + coordinates: [0 ,0] + } + }; +} + +function createPoi(properties: any = {}): GeoJSON.Feature { + return { + properties + } as any; +} describe("OsmTagsService", () => { it("Should not set icon color category if already set", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - boundary: "protected_area" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: { - poiIconColor: "black", - poiIcon: "icon-bike", - poiCategory: "Bicycle" - } - } as any; + const feature = createFeature({ boundary: "protected_area" }); + const poi = createPoi({ + poiIconColor: "black", + poiIcon: "icon-bike", + poiCategory: "Bicycle" + }); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -30,19 +36,8 @@ describe("OsmTagsService", () => { it("Should set§ icon color category for protected_area", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - boundary: "protected_area" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({boundary: "protected_area" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -53,19 +48,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for network lcn", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - network: "lcn" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({network: "lcn" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -76,19 +60,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for network lwn", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - network: "lwn" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({network: "lwn" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -99,19 +72,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for route hiking", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - route: "hiking" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({route: "hiking" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -122,19 +84,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for route bicycle", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - route: "bicycle" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({route: "bicycle" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -145,19 +96,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for historic ruins", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - historic: "ruins" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({historic: "ruins" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -168,19 +108,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for historic archaeological_site", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - historic: "archaeological_site" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({historic: "archaeological_site" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -191,19 +120,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for historic memorial", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - historic: "memorial" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({historic: "memorial" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -214,19 +132,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for historic tomb", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - historic: "tomb" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({historic: "tomb" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -236,19 +143,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for picnic table", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - leisure: "picnic_table" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({leisure: "picnic_table" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -259,19 +155,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for cave entrance", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - natural: "cave_entrance" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({natural: "cave_entrance" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -282,19 +167,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for spring", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - natural: "spring" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({natural: "spring" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -305,19 +179,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for tree", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - natural: "tree" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({natural: "tree" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -328,19 +191,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for flowers", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - natural: "flowers" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({natural: "flowers" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -351,19 +203,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for waterhole", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - natural: "waterhole" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({natural: "waterhole" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -374,19 +215,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for reservoir", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - water: "reservoir" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({water: "reservoir" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -397,19 +227,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for water_well", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - man_made: "water_well" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({ man_made: "water_well" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -420,19 +239,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for cistern", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - man_made: "cistern" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({ man_made: "cistern" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -443,19 +251,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for waterfall", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - waterway: "waterfall" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({ waterway: "waterfall" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -466,19 +263,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for place", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - place: "village" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({ place: "village" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -489,19 +275,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for viewpoint", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - tourism: "viewpoint" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({tourism: "viewpoint" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -512,19 +287,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for picnic_site", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - tourism: "camp_site" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({tourism: "camp_site" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -535,19 +299,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for attraction", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - tourism: "attraction" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({tourism: "attraction" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -558,19 +311,8 @@ describe("OsmTagsService", () => { it("Should set icon color category for mtb route", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - "mtb:name": "route" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({ "mtb:name": "route" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -581,42 +323,20 @@ describe("OsmTagsService", () => { it("Should set icon color category for natural peak", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - natural: "peak" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({natural: "peak" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert - expect(poi.properties.poiCategory).toBe("Other"); + expect(poi.properties.poiCategory).toBe("Natural"); expect(poi.properties.poiIcon).toBe("icon-peak"); expect(poi.properties.poiIconColor).toBe("black"); }); it("Should set icon color category for wikipedia", () => { // Arrange - const feature: GeoJSON.Feature = { - type: "Feature", - properties: { - wikipedia: "page" - }, - geometry: { - type: "Point", - coordinates: [0 ,0] - } - }; - const poi = { - properties: {} - } as any; + const feature = createFeature({ wikipedia: "page" }); + const poi = createPoi(); // Act OsmTagsService.setIconColorCategory(feature, poi); // Assert @@ -624,4 +344,16 @@ describe("OsmTagsService", () => { expect(poi.properties.poiIcon).toBe("icon-wikipedia-w"); expect(poi.properties.poiIconColor).toBe("black"); }); + + it("Should set icon color category for inature and wikidata and prefer inture", () => { + // Arrange + const feature = createFeature({ wikipedia: "page", "ref:IL:inature": "inature" }); + const poi = createPoi(); + // Act + OsmTagsService.setIconColorCategory(feature, poi); + // Assert + expect(poi.properties.poiCategory).toBe("iNature"); + expect(poi.properties.poiIcon).toBe("icon-inature"); + expect(poi.properties.poiIconColor).toBe("#116C00"); + }); }); \ No newline at end of file diff --git a/IsraelHiking.Web/src/application/services/osm-tags.service.ts b/IsraelHiking.Web/src/application/services/osm-tags.service.ts index 23c1f0b88..a5ccb8ae2 100644 --- a/IsraelHiking.Web/src/application/services/osm-tags.service.ts +++ b/IsraelHiking.Web/src/application/services/osm-tags.service.ts @@ -184,7 +184,14 @@ export class OsmTagsService { if (feature.properties.natural === "peak") { poi.properties.poiIconColor = "black"; poi.properties.poiIcon = "icon-peak"; - poi.properties.poiCategory = "Other"; + poi.properties.poiCategory = "Natural"; + return; + } + + if (feature.properties["ref:IL:inature"]) { + poi.properties.poiIconColor = "#116C00"; + poi.properties.poiIcon = "icon-inature"; + poi.properties.poiCategory = "iNature"; return; }