diff --git a/client/wfnews-war/src/main/angular/src/app/components/saved/saved-location-full-details/saved-location-full-details.component.ts b/client/wfnews-war/src/main/angular/src/app/components/saved/saved-location-full-details/saved-location-full-details.component.ts index 75de3493a1..2273aa7068 100644 --- a/client/wfnews-war/src/main/angular/src/app/components/saved/saved-location-full-details/saved-location-full-details.component.ts +++ b/client/wfnews-war/src/main/angular/src/app/components/saved/saved-location-full-details/saved-location-full-details.component.ts @@ -95,6 +95,7 @@ export class SavedLocationFullDetailsComponent implements OnInit { } getFireCentre(location) { + try { const degreesPerPixel = 0.009; // rough estimation of the conversion factor from kilometers to degrees of latitude or longitude const distanceInDegrees = this.distanceInKm * degreesPerPixel; let latitude = location.point.coordinates[1]; @@ -110,7 +111,7 @@ export class SavedLocationFullDetailsComponent implements OnInit { { latitude: minLatitude, longitude: minLongitude }, // Bottom-left corner { latitude: maxLatitude, longitude: minLongitude } // Closing the polygon ]; - this.notificationService.getFireCentreByLocation(rectangleCoordinates).then( + this.notificationService.getFireCentreByLocation(rectangleCoordinates).subscribe( response => { if (response.features) { const fireCentre = response.features[0].properties.MOF_FIRE_CENTRE_NAME; @@ -118,9 +119,10 @@ export class SavedLocationFullDetailsComponent implements OnInit { this.cdr.markForCheck() } } - ).catch(error => { + ) + } catch(error) { console.error('Could not retrieve fire centre for saved location', error) - }) + } } diff --git a/client/wfnews-war/src/main/angular/src/app/components/saved/saved.component.ts b/client/wfnews-war/src/main/angular/src/app/components/saved/saved.component.ts index cef369f760..aaf48520ff 100644 --- a/client/wfnews-war/src/main/angular/src/app/components/saved/saved.component.ts +++ b/client/wfnews-war/src/main/angular/src/app/components/saved/saved.component.ts @@ -22,7 +22,6 @@ export class SavedComponent implements OnInit { public distanceInKm: number = 1; public wildFireWatchlist: any[] = []; public errorString: string; - public errorUrl: string; convertToStageOfControlDescription = convertToStageOfControlDescription convertToDateYear = convertToDateYear isMobileView = isMobileView @@ -86,21 +85,24 @@ export class SavedComponent implements OnInit { } getDangerRatings(locations) { - locations.forEach((location, outerIndex) => { - const rectangleCoordinates = this.bboxHelper(location) - this.notificationService.getDangerRatingByLocation( - rectangleCoordinates - ) - .then(dangerRatings => { - if (dangerRatings.features) { - const element = dangerRatings.features[0].properties.DANGER_RATING_DESC; - this.savedLocations[outerIndex].dangerRatings = (element) - this.cdr.markForCheck() - } - }).catch(error => { - console.error('can not get danger rating', error) - }); - }); + try { + locations.forEach((location, outerIndex) => { + const rectangleCoordinates = this.bboxHelper(location) + this.notificationService.getDangerRatingByLocation( + rectangleCoordinates + ) + .subscribe(dangerRatings => { + if (dangerRatings.features) { + const element = dangerRatings.features[0].properties.DANGER_RATING_DESC; + this.savedLocations[outerIndex].dangerRatings = (element) + this.cdr.markForCheck() + } + }) + }); + } catch (error) { + console.error('can not get danger rating', error) + } + } bboxHelper(location) { @@ -123,27 +125,22 @@ export class SavedComponent implements OnInit { } getFireCentre(locations) { - try { // const degreesPerPixel = 0.009; // rough estimation of the conversion factor from kilometers to degrees of latitude or longitude // const distanceInDegrees = this.distanceInKm * degreesPerPixel; - locations.forEach((location, outerIndex) => { - const rectangleCoordinates = this.bboxHelper(location) - this.errorUrl = this.notificationService.getFireCentreUrlByLocation(rectangleCoordinates) - this.notificationService.getFireCentreByLocation(rectangleCoordinates).then( - response => { - if (response.features) { - const fireCentre = response.features[0].properties.MOF_FIRE_CENTRE_NAME; - this.savedLocations[outerIndex].fireCentre = fireCentre; - this.cdr.markForCheck() - } - } - ).catch(error => { - this.errorString = JSON.stringify(error, ["message", "arguments", "type", "name"]) - console.error('can not get fire centre', error) - }) - }); - } catch (error) { - this.errorString = JSON.stringify(error, ["message", "arguments", "type", "name"]) + try { + locations.forEach((location, outerIndex) => { + const rectangleCoordinates = this.bboxHelper(location) + this.notificationService.getFireCentreByLocation(rectangleCoordinates).subscribe( + response => { + if (response.features) { + const fireCentre = response.features[0].properties.MOF_FIRE_CENTRE_NAME; + this.savedLocations[outerIndex].fireCentre = fireCentre; + this.cdr.markForCheck() + } + }) + }); + }catch (error) { + console.error('can not get fire centre', error) } } @@ -239,4 +236,4 @@ export class SavedComponent implements OnInit { } -} +} \ No newline at end of file diff --git a/client/wfnews-war/src/main/angular/src/app/services/notification.service.ts b/client/wfnews-war/src/main/angular/src/app/services/notification.service.ts index 4267e41747..d9cfd251d9 100644 --- a/client/wfnews-war/src/main/angular/src/app/services/notification.service.ts +++ b/client/wfnews-war/src/main/angular/src/app/services/notification.service.ts @@ -2,6 +2,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { CapacitorService } from '@app/services/capacitor-service'; import { AppConfigService } from "@wf1/core-ui"; +import { Observable } from 'rxjs'; export interface NotificationSettingRsrc { deviceType: string; @@ -93,33 +94,27 @@ export class NotificationService { }) } - public getFireCentreByLocation(bbox: BoundingBox[]): Promise { - const formattedString = bbox.map(pair => `${pair.longitude}%20${pair.latitude}`).join('%2C'); + public getFireCentreByLocation(bbox: BoundingBox[]): Observable { + const formattedString = bbox.map(pair => `${pair.longitude} ${pair.latitude}`).join(','); let url = (this.appConfigService.getConfig() as any).mapServices['openmapsBaseUrl'] as string - url += "?service=WFS&version=1.1.0&request=GetFeature&srsName=EPSG%3A4326&typename=pub%3AWHSE_LEGAL_ADMIN_BOUNDARIES.DRP_MOF_FIRE_CENTRES_SP&outputformat=application%2Fjson&cql_filter=INTERSECTS(GEOMETRY%2CSRID%3D4326%3BPOLYGON%20((" + url += "?service=WFS&version=1.1.0&request=GetFeature&srsName=EPSG:4326&typename=pub:WHSE_LEGAL_ADMIN_BOUNDARIES.DRP_MOF_FIRE_CENTRES_SP&outputformat=application/json&cql_filter=INTERSECTS(GEOMETRY,SRID=4326;POLYGON((" url += formattedString + ')))' let headers = new HttpHeaders(); headers.append('Access-Control-Allow-Origin','*'); headers.append('Accept','*/*'); - return this.http.get(url, { headers }).toPromise() + return this.http.get(encodeURI(url),{headers}) } - public getFireCentreUrlByLocation(bbox: BoundingBox[]) { - const formattedString = bbox.map(pair => `${pair.longitude}%20${pair.latitude}`).join('%2C'); + public getDangerRatingByLocation(bbox: BoundingBox[]): Observable { + const formattedString = bbox.map(pair => `${pair.longitude} ${pair.latitude}`).join(','); let url = (this.appConfigService.getConfig() as any).mapServices['openmapsBaseUrl'] as string - url += "?service=WFS&version=1.1.0&request=GetFeature&srsName=EPSG%3A4326&typename=pub%3AWHSE_LEGAL_ADMIN_BOUNDARIES.DRP_MOF_FIRE_CENTRES_SP&outputformat=application%2Fjson&cql_filter=INTERSECTS(GEOMETRY%2CSRID%3D4326%3BPOLYGON%20((" - url += formattedString + ')))' - return url - - } - - public getDangerRatingByLocation(bbox: BoundingBox[]): Promise { - const formattedString = bbox.map(pair => `${pair.longitude}%20${pair.latitude}`).join('%2C'); - let url = (this.appConfigService.getConfig() as any).mapServices['openmapsBaseUrl'] as string - url += "?service=WFS&version=1.1.0&request=GetFeature&srsName=EPSG%3A4326&typename=pub%3AWHSE_LAND_AND_NATURAL_RESOURCE.PROT_DANGER_RATING_SP&outputformat=application%2Fjson&cql_filter=INTERSECTS(SHAPE%2CSRID%3D4326%3BPOLYGON%20((" + url += "?service=WFS&version=1.1.0&request=GetFeature&srsName=EPSG:4326&typename=pub:WHSE_LAND_AND_NATURAL_RESOURCE.PROT_DANGER_RATING_SP&outputformat=application/json&cql_filter=INTERSECTS(SHAPE,SRID=4326;POLYGON((" url += formattedString +')))' - return this.http.get(url).toPromise() + let headers = new HttpHeaders(); + headers.append('Access-Control-Allow-Origin','*'); + headers.append('Accept','*/*'); + return this.http.get(encodeURI(url),{headers}) } }