Skip to content

Commit

Permalink
Fixes #2063 - Flter-out incompatible POI images
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Nov 5, 2024
1 parent ca3dbd1 commit d90a115
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
33 changes: 27 additions & 6 deletions IsraelHiking.Web/src/application/services/poi.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ describe("Poi Service", () => {
poiSource: "OSM",
poiId: "poiId",
identifier: "id",
imageUrl: "some-old-image-url",
imageUrl: "wikimedia.org/some-old-image-url",
website: "some-old-url"
} as any,
geometry: {
Expand Down Expand Up @@ -543,7 +543,7 @@ describe("Poi Service", () => {
expect(feature.properties.poiAddedUrls).toEqual(["some-new-url"]);
expect(feature.properties.poiRemovedUrls).toEqual(["some-old-url"]);
expect(feature.properties.poiAddedImages).toEqual(["some-new-image-url"]);
expect(feature.properties.poiRemovedImages).toEqual(["some-old-image-url"]);
expect(feature.properties.poiRemovedImages).toEqual(["wikimedia.org/some-old-image-url"]);
expect(feature.properties.poiIcon).toBe("icon-spring");
expect(feature.properties.poiGeolocation.lat).toBe(1);
expect(feature.properties.poiGeolocation.lon).toBe(2);
Expand All @@ -569,7 +569,7 @@ describe("Poi Service", () => {
poiSource: "OSM",
poiId: "poiId",
identifier: "id",
imageUrl: "some-image-url",
imageUrl: "wikimedia.org/some-image-url",
website: "some-url",
description: "description",
poiCategory: "natural",
Expand All @@ -595,7 +595,7 @@ describe("Poi Service", () => {
icon: "icon-spring",
iconColor: "blue",
description: "description",
imagesUrls: ["some-image-url"],
imagesUrls: ["wikimedia.org/some-image-url"],
title: "title",
urls: ["some-url"],
canEditTitle: true
Expand Down Expand Up @@ -701,7 +701,7 @@ describe("Poi Service", () => {
description: "description",
title: "title",
type: "some-type",
urls: [{mimeType: "image", url: "image-url", text: "text"}],
urls: [{mimeType: "image", url: "wikimedia.org/image-url", text: "text"}],
latlng: { lng: 1, lat: 2}
};

Expand All @@ -713,13 +713,34 @@ describe("Poi Service", () => {
expect(GeoJSONUtils.getLocation(featureAfterConverstion).lng).toBe(1);
expect(GeoJSONUtils.getDescription(featureAfterConverstion, "he")).toBe("description");
expect(GeoJSONUtils.getTitle(featureAfterConverstion, "he")).toBe("title");
expect(featureAfterConverstion.properties.image).toBe("image-url");
expect(featureAfterConverstion.properties.image).toBe("wikimedia.org/image-url");
expect(featureAfterConverstion.properties.image0).toBeUndefined();
expect(featureAfterConverstion.properties.poiIcon).toBe("icon-some-type");
}
)
);

it("Should filter out incompatible images",
inject([PoiService], (poiService: PoiService) => {
const feature = {
properties: {
poiSource: "OSM",
poiId: "poiId",
identifier: "id",
image: "invalid-image-url",
} as any,
geometry: {
type: "Point",
coordinates: [1, 2]
}
} as GeoJSON.Feature;

const info = poiService.getEditableDataFromFeature(feature);
expect(info.imagesUrls.length).toBe(0);
}
)
);

it("should get closest point from server", (inject([PoiService, HttpTestingController],
async (poiService: PoiService, mockBackend: HttpTestingController) => {

Expand Down
15 changes: 6 additions & 9 deletions IsraelHiking.Web/src/application/services/poi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,10 @@ export class PoiService {
title: GeoJSONUtils.getTitle(feature, language),
icon: feature.properties.poiIcon,
iconColor: feature.properties.poiIconColor,
imagesUrls: Object.keys(feature.properties).filter(k => k.startsWith("image")).map(k => feature.properties[k]),
imagesUrls: Object.keys(feature.properties)
.filter(k => k.startsWith("image"))
.map(k => feature.properties[k])
.filter(u => u.includes("wikimedia.org") || u.includes("inature.info") || u.includes("nakeb.co.il") || u.includes("jeepolog.com")),
urls: Object.keys(feature.properties).filter(k => k.startsWith("website")).map(k => feature.properties[k]),
isPoint: feature.geometry.type === "Point" || feature.geometry.type === "MultiPoint",
canEditTitle: !feature.properties.poiMerged && !feature.properties["mtb:name"],
Expand All @@ -787,17 +790,11 @@ export class PoiService {
poiIconColor: info.iconColor,
} as any
} as GeoJSON.Feature;
let index = 0;
for (const imageUrl of info.imagesUrls) {
const key = index === 0 ? "image" : `image${index}`;
feature.properties[key] = imageUrl;
index++;
GeoJSONUtils.setProperty(feature, "image", imageUrl);
}
index = 0;
for (const url of info.urls) {
const key = index === 0 ? "website" : `website${index}`;
feature.properties[key] = url;
index++;
GeoJSONUtils.setProperty(feature, "website", url);
}
const language = this.resources.getCurrentLanguageCodeSimplified();
GeoJSONUtils.setDescription(feature, info.description, language);
Expand Down

0 comments on commit d90a115

Please sign in to comment.