Skip to content

Commit

Permalink
Update calls for fire bans and fire centre by location to Observable (#…
Browse files Browse the repository at this point in the history
…1507)

* Add temporrary alerts for fireCentre iOS debug

* Add temporrary alerts for fireCentre iOS debug

* Allow CORS for get fire centre by location call

* Remove alert and output error to saved html page

* Output error message content

* Try fetch as string rather than to string

* Try fetch as string rather than to string

* Try fetch as string rather than to string

* Output smaller font for error message

* Update calls for fire bans and fire centra by location to Observable for iOS
  • Loading branch information
ssylver93 authored Dec 14, 2023
1 parent 8adfaab commit 67c2d3f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -110,17 +111,18 @@ 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;
this.fireCentre = fireCentre;
this.cdr.markForCheck()
}
}
).catch(error => {
)
} catch(error) {
console.error('Could not retrieve fire centre for saved location', error)
})
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -239,4 +236,4 @@ export class SavedComponent implements OnInit {

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,33 +94,27 @@ export class NotificationService {
})
}

public getFireCentreByLocation(bbox: BoundingBox[]): Promise<any> {
const formattedString = bbox.map(pair => `${pair.longitude}%20${pair.latitude}`).join('%2C');
public getFireCentreByLocation(bbox: BoundingBox[]): Observable<any> {
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<any>(encodeURI(url),{headers})

}

public getFireCentreUrlByLocation(bbox: BoundingBox[]) {
const formattedString = bbox.map(pair => `${pair.longitude}%20${pair.latitude}`).join('%2C');
public getDangerRatingByLocation(bbox: BoundingBox[]): Observable<any> {
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<any> {
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<any>(encodeURI(url),{headers})

}
}
Expand Down

0 comments on commit 67c2d3f

Please sign in to comment.