Skip to content
Snippets Groups Projects
Commit f07db3c3 authored by zdenko.vuk@ijs.si's avatar zdenko.vuk@ijs.si
Browse files

if user selects for the second time the same geojson it shouldnt be downloaded...

if user selects for the second time the same geojson it shouldnt be downloaded once again. Has to be tested thorughly yet.

one of the resets is not working fine.

if user selects for the second time the same geojson it shouldnt be downloaded once again working fine.
parent 690a96a3
No related branches found
No related tags found
No related merge requests found
......@@ -14,16 +14,15 @@
<div id="loadGeojsonButtonsContainer">
<button
nbButton
status="primary"
size="small"
(click)="onLoad(l)"
(click)="onLoadClick(l.buttonLabel)"
nbTooltip="Select a simulation in order to use this button. GET http://localhost:8083/dss/geojson/{id}/selectedKpi"
[disabled]="selectedSimulation == undefined"
[nbSpinner]="geojsonLoading"
[status]="selectedGeojson == l ? 'control' : 'primary'"
*ngFor="let l of loadGeojsonButtons"
[status]="selectedGeojson == l.buttonLabel ? 'control' : 'primary'"
*ngFor="let l of loadGeojsons"
>
load {{ l }} geojson
load {{ l.buttonLabel }} geojson
</button>
<button
nbButton
......
......@@ -25,11 +25,23 @@ export class ResultsMapComponent implements OnChanges {
};
mapLegend = new L.Control({ position: "bottomright" });
radioButtonLayersControl: any;
loadGeojsonButtons: string[] = [
"bikeability",
"bikeIntensity",
"bikeSafety",
"pollution",
loadGeojsons: Object[] = [
{
response: undefined,
buttonLabel: "bikeability",
},
{
response: undefined,
buttonLabel: "bikeIntensity",
},
{
response: undefined,
buttonLabel: "bikeSafety",
},
{
response: undefined,
buttonLabel: "pollution",
},
];
checkedRadioButton: string = "";
geoJsonStyleWeight: number = 5;
......@@ -73,7 +85,7 @@ export class ResultsMapComponent implements OnChanges {
// }, 1000);
}
onLoad(selectedKpi: string) {
onLoadClick(selectedKpi: string) {
this.selectedGeojson = selectedKpi;
this.resetLayersAndButton();
this.setMapZoom();
......@@ -81,14 +93,49 @@ export class ResultsMapComponent implements OnChanges {
if (this.radioButtonLayersControl)
this.radioButtonLayersControl.remove(this.map);
this.loadGeojsons.forEach((geojson, index) => {
if (geojson["buttonLabel"] == selectedKpi) {
if (this.loadGeojsons[index]["response"] == undefined) {
this.toastrService.show("This might take a while", "Info", {
status: "info",
});
this.geojsonLoading = true;
this.simulationService
.getGeojson(this.selectedSimulation["id"].toString(), selectedKpi)
.subscribe(
(res) => {
.subscribe((res) => {
this.loadGeojsons[index]["response"] = res;
this.handleResponse(
selectedKpi,
this.loadGeojsons[index]["response"]
);
}),
(error) => {
this.toastrService.show(
error["message"],
"Error Getting Geojson",
{
status: "danger",
}
);
this.geojsonLoading = false;
};
} else {
this.handleResponse(
selectedKpi,
this.loadGeojsons[index]["response"]
);
}
}
});
}
handleResponse(selectedKpi, res) {
this.loadGeojsons.forEach((geojson, index) => {
if (geojson["buttonLabel"] == selectedKpi) {
this.loadGeojsons[index]["response"] = res;
}
});
if (res["message"] == "Calculating...") {
this.toastrService.show(
"Server says: Calculating the KPI visualization. GEOJSON loading will not be completed.",
......@@ -155,14 +202,6 @@ export class ResultsMapComponent implements OnChanges {
this.map.addControl(this.radioButtonLayersControl);
this.addListenerToRadioButtonLayersControl();
this.geojsonLoading = false;
},
(error) => {
this.toastrService.show(error["message"], "Error Getting Geojson", {
status: "danger",
});
this.geojsonLoading = false;
}
);
}
setLegend(legendType) {
......@@ -628,5 +667,9 @@ export class ResultsMapComponent implements OnChanges {
ngOnChanges() {
this.resetLayersAndButton();
this.selectedGeojson = "";
Object.entries(this.loadGeojsons).forEach((entry) => {
entry[1]["response"] = undefined;
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment