Skip to content

Commit

Permalink
feat: save previous points in localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
tylercchase committed Aug 30, 2024
1 parent 06dea31 commit 01663e1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import * as uiStore from '@store/ui';
import * as searchStore from '@store/search';

import { Breakpoints, SearchType } from '@models';
import { DrawService, MapService, NetcdfService, PointHistoryService, ScreenSizeService } from '@services';
import { DrawService, MapService, NetcdfService, PointHistoryService, ScreenSizeService, WktService } from '@services';

import { SubSink } from 'subsink';

import { Point} from 'ol/geom';
import { WKT } from 'ol/format';
import moment2 from 'moment';
import { SetScenes } from '@store/scenes';
import {getPathRange} from '@store/filters';
// import {getPathRange} from '@store/filters';


@Component({
Expand Down Expand Up @@ -67,10 +67,13 @@ export class TimeseriesResultsMenuComponent implements OnInit, OnDestroy {
public pointHistoryService: PointHistoryService,
private drawService: DrawService,
private mapService: MapService,
private netcdfService: NetcdfService
private netcdfService: NetcdfService,
private wktService: WktService
) { }

ngOnInit(): void {
this.pointHistoryService.clearPoints();

this.subs.add(
this.screenSize.breakpoint$.subscribe(
point => this.breakpoint = point
Expand All @@ -88,6 +91,14 @@ export class TimeseriesResultsMenuComponent implements OnInit, OnDestroy {
this.mapService.setDisplacementLayer(history);
}));

let previous_points: any[] = localStorage.getItem('timeseries-points')?.split(';');
previous_points = previous_points?.map(value => {
return this.wktService.wktToFeature(value, 'EPSG:4326');
})
previous_points?.forEach(point => {
this.pointHistoryService.addPoint(point.getGeometry());
})

this.subs.add(this.drawService.polygon$.subscribe(polygon => {
if(polygon) {
let temp = polygon.getGeometry().clone() as Point;
Expand All @@ -100,9 +111,6 @@ export class TimeseriesResultsMenuComponent implements OnInit, OnDestroy {
}
}))

this.netcdfService.getTimeSeries(getPathRange).pipe(first()).subscribe(data => {
this.tsPath = data;
});
}

public onResizeEnd(event: ResizeEvent): void {
Expand Down Expand Up @@ -155,6 +163,7 @@ export class TimeseriesResultsMenuComponent implements OnInit, OnDestroy {
if (this.timeseries_subscription) {
this.timeseries_subscription.unsubscribe();
}
this.chartData.next(null);
this.timeseries_subscription = this.netcdfService.getTimeSeries(geometry).pipe(first()).subscribe(data => {
this.chartData.next(data);

Expand Down Expand Up @@ -235,6 +244,7 @@ export class TimeseriesResultsMenuComponent implements OnInit, OnDestroy {
}

ngOnDestroy() {
this.pointHistoryService.clearPoints();
this.subs.unsubscribe();
}
}
18 changes: 18 additions & 0 deletions src/app/services/point-history.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@angular/core';
import WKT from 'ol/format/WKT';

import { Point } from 'ol/geom';
import { Subject } from 'rxjs';
Expand All @@ -15,6 +16,8 @@ export class PointHistoryService {
public selectedPoint: number = 0;
constructor(
) {


}

public getHistory(): Point[] {
Expand All @@ -29,6 +32,21 @@ export class PointHistoryService {
}
this.history.push(point);
this.history$.next(this.history);
this.savePoints();
console.log(this.history)
}

public clearPoints() {
this.history = [];
this.history$.next(this.history);
}

private savePoints() {
let format = new WKT();
let converted = this.history.map((value) => {
return format.writeGeometry(value)
})
localStorage.setItem('timeseries-points', converted.join(';'))
}


Expand Down

0 comments on commit 01663e1

Please sign in to comment.