Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: catch missing glofas dynamic data better AB#25411 #1477

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export class DynamicPointPopupComponent implements OnInit {
public glofasFooterStyle: string;

public eapAlertClass: EapAlertClass;
private defautEapAlertClass: EapAlertClass = {
label: 'No action',
color: 'ibf-no-alert-primary',
};

private allowedLayers = [
IbfLayerName.gauges,
Expand Down Expand Up @@ -76,9 +80,10 @@ export class DynamicPointPopupComponent implements OnInit {
this.layerName === IbfLayerName.glofasStations &&
this.glofasData.eapAlertClasses
) {
this.eapAlertClass = this.glofasData.eapAlertClasses[
this.glofasData.station.dynamicData.eapAlertClass
];
this.eapAlertClass =
this.glofasData.eapAlertClasses[
this.glofasData.station.dynamicData?.eapAlertClass
] || this.defautEapAlertClass;
}

this.title = this.getTitle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,46 @@ export class GlofasStationPopupContentComponent implements OnInit {
public barBackgroundColor: string;
public barTextColor: string;
private eapAlertClass: EapAlertClass;
private defautEapAlertClass: EapAlertClass = {
label: 'No action',
color: 'ibf-no-alert-primary',
};

ngOnInit(): void {
if (!this.data) {
return;
}

const difference =
Number(this.data.station.dynamicData.forecastLevel) -
Number(this.data.station.dynamicData.triggerLevel);
Number(this.data.station.dynamicData?.forecastLevel) -
Number(this.data.station.dynamicData?.triggerLevel);
const closeMargin = 0.05;
const tooClose =
Math.abs(difference) / this.data.station.triggerLevel < closeMargin;

this.barValue =
difference === 0 || !tooClose
? Number(this.data.station.dynamicData.forecastLevel)
: Number(this.data.station.dynamicData.triggerLevel) +
? Number(this.data.station.dynamicData?.forecastLevel)
: Number(this.data.station.dynamicData?.triggerLevel) +
Math.sign(difference) *
Number(this.data.station.dynamicData.triggerLevel) *
Number(this.data.station.dynamicData?.triggerLevel) *
closeMargin;

this.triggerWidth = Math.max(
Math.min(
Math.round(
(this.barValue / Number(this.data.station.dynamicData.triggerLevel)) *
(this.barValue /
Number(this.data.station.dynamicData?.triggerLevel)) *
100,
),
115,
),
0,
);

this.eapAlertClass = this.data.eapAlertClasses[
this.data.station.dynamicData.eapAlertClass
];
this.eapAlertClass =
this.data.eapAlertClasses[this.data.station.dynamicData?.eapAlertClass] ||
this.defautEapAlertClass;

this.barBackgroundColor = `var(--ion-color-${this.eapAlertClass.color})`;
this.barTextColor = `var(--ion-color-${this.eapAlertClass.color}-contrast)`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,16 @@ export class PointMarkerService {

const markerIcon: IconOptions = {
...LEAFLET_MARKER_ICON_OPTIONS_BASE,
iconUrl: `assets/markers/glofas-station-${markerProperties.dynamicData?.eapAlertClass}-trigger.svg`,
iconRetinaUrl: `assets/markers/glofas-station-${markerProperties.dynamicData?.eapAlertClass}-trigger.svg`,
iconUrl: `assets/markers/glofas-station-${
markerProperties.dynamicData?.eapAlertClass || 'no'
}-trigger.svg`,
iconRetinaUrl: `assets/markers/glofas-station-${
markerProperties.dynamicData?.eapAlertClass || 'no'
}-trigger.svg`,
};
const className = `trigger-popup-${markerProperties.dynamicData?.eapAlertClass}`;
const className = `trigger-popup-${
markerProperties.dynamicData?.eapAlertClass || 'no'
}`;

const markerInstance = marker(markerLatLng, {
title: markerTitle,
Expand Down
Loading