Skip to content

Commit

Permalink
Fix initialization, Add iNature route support.
Browse files Browse the repository at this point in the history
  • Loading branch information
HarelM committed Sep 3, 2024
1 parent 9cef37a commit 5482567
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions IsraelHiking.Web/src/application/application.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import { OverpassTurboService } from "./services/overpass-turbo.service";
import { ImageAttributionService } from "./services/image-attribution.service";
import { PmTilesService } from "./services/pmtiles.service";
import { ApplicationUpdateService } from "./services/application-update.service";
import { INatureService } from "./services/inature.service";
// interactions
import { RouteEditPoiInteraction } from "./components/intercations/route-edit-poi.interaction";
import { RouteEditRouteInteraction } from "./components/intercations/route-edit-route.interaction";
Expand Down Expand Up @@ -309,6 +310,7 @@ const initializeApplication = (injector: Injector) => async () => {
ImageAttributionService,
PmTilesService,
ApplicationUpdateService,
INatureService,
AudioPlayerFactory,
FileSystemWrapper,
// eslint-disable-next-line
Expand Down
12 changes: 8 additions & 4 deletions IsraelHiking.Web/src/application/services/iNature.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class INatureService {
}
};
const lngLat = this.setLocation(content, feature);
this.setImageAndWebsite(content, feature, pageId);
this.setImageAndWebsite(content, feature, title);
feature.geometry = await this.getGeometryFromContent(content) ?? {
type: "Point",
coordinates: [lngLat.lng, lngLat.lat]
Expand Down Expand Up @@ -90,13 +90,17 @@ export class INatureService {
}

private async getGeometryFromContent(content: string): Promise<GeoJSON.Geometry> {
const shareRegexp = new RegExp("israelhiking\.osm\.org\.il/share/(.*?)");
const shareRegexp = new RegExp("israelhiking\\.osm\\.org\\.il/share/(.*?)[\"']");
const match = content.match(shareRegexp);
if (match == null) {
return null;
}
const shareId = match[1];
const geojson = await firstValueFrom(this.httpClient.get(`${Urls.urls}${shareId}?format=geojson`)) as GeoJSON.FeatureCollection;
return geojson.features.find(f => f.geometry.type === "LineString")?.geometry;
// HM TODO: replace this:
//let url = Urls.urls + shareId + "?format=geojson";
const url = "https://israelhiking.osm.org.il/api/urls/" + shareId + "?format=geojson";
const geojson = await firstValueFrom(this.httpClient.get(url)) as GeoJSON.FeatureCollection;
console.log(geojson);
return geojson.features.find(f => f.geometry.type !== "Point")?.geometry;
}
}

0 comments on commit 5482567

Please sign in to comment.