Implement device update event
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
This commit is contained in:
@@ -7,7 +7,7 @@ import { Effect, Actions,ofType } from '@ngrx/effects';
|
||||
import { Observable , of } from 'rxjs';
|
||||
import { withLatestFrom, switchMap, map, catchError, mergeMap, delay} from 'rxjs/operators';
|
||||
|
||||
import {GeoJSON} from 'ol/format';
|
||||
import {GeoJSON,WKT} from 'ol/format';
|
||||
import {Feature} from 'ol';
|
||||
import { getCenter, Extent, createEmpty, extend} from 'ol/extent';
|
||||
import {Point} from 'ol/geom'
|
||||
@@ -25,10 +25,15 @@ import { tassign } from 'tassign';
|
||||
|
||||
@Injectable()
|
||||
export class MapEffects {
|
||||
private _format: GeoJSON;
|
||||
private _geojsonFormat: GeoJSON;
|
||||
private _wktFormat: WKT;
|
||||
|
||||
private toPointFeature(feature: any): Feature {
|
||||
var f = this._format.readFeature(feature);
|
||||
private toPointFeature(updateEvent:commonActions.DeviceUpdateEvent): Feature {
|
||||
var f = this._wktFormat.readFeature(updateEvent.attributes["geometry"],{
|
||||
dataProjection: 'EPSG:4326',
|
||||
featureProjection: 'EPSG:3857'
|
||||
});
|
||||
f.setId(updateEvent.itemCode);
|
||||
var centroid = getCenter(f.getGeometry().getExtent());
|
||||
f.setGeometry(new Point(centroid));
|
||||
return f;
|
||||
@@ -83,7 +88,7 @@ export class MapEffects {
|
||||
f.id = f.properties["code"];
|
||||
}
|
||||
}
|
||||
return of(new mapActions.StartSearchSuccess(this._format.readFeatures(features), action.queryState));
|
||||
return of(new mapActions.StartSearchSuccess(this._geojsonFormat.readFeatures(features), action.queryState));
|
||||
}
|
||||
),
|
||||
catchError(error => of(new commonActions.Fail(error))));
|
||||
@@ -135,7 +140,11 @@ export class MapEffects {
|
||||
ofType(mapActions.SELECTITEMSUCCESS),
|
||||
switchMap((action:mapActions.SelectItemSuccess) => {
|
||||
return this.itemService$.getFeature(action.item.code, "EPSG:3857").pipe(
|
||||
map((feature: IItem) => new mapActions.AddFeatureSuccess(this._format.readFeature(feature) )),
|
||||
map((feature: any) => {
|
||||
let f = this._geojsonFormat.readFeature(feature);
|
||||
f.setId(action.item.code);
|
||||
return new mapActions.AddFeatureSuccess(f );
|
||||
}),
|
||||
catchError(error => of(new commonActions.Fail(error))));
|
||||
}
|
||||
));
|
||||
@@ -163,21 +172,19 @@ export class MapEffects {
|
||||
|
||||
@Effect()
|
||||
featureUpdate$: Observable<Action> = this.actions$.pipe(
|
||||
ofType(commonActions.ITEMCHANGEDEVENT),
|
||||
ofType(commonActions.DEVICEUPDATEEVENT),
|
||||
withLatestFrom(this.store$.select(mapReducers.selectGetFeatures)),
|
||||
mergeMap(([action, features]) => {
|
||||
let itemChangedAction = action as commonActions.ItemChangedEvent;
|
||||
let deviceUpdateEventAction = action as commonActions.DeviceUpdateEvent;
|
||||
var feature: Feature = null;
|
||||
for (let f of features) {
|
||||
if (f.get("code") == itemChangedAction.itemCode) {
|
||||
if (f.getId() == deviceUpdateEventAction.itemCode) {
|
||||
feature = f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (feature) {
|
||||
return this.itemService$.getFeature(itemChangedAction.itemCode, "EPSG:3857").pipe(
|
||||
map((feature: any) => new mapActions.UpdateFeatureSuccess(this.toPointFeature(feature))),
|
||||
catchError(error => of(new commonActions.Fail(error))));
|
||||
return of(new mapActions.UpdateFeatureSuccess(this.toPointFeature(deviceUpdateEventAction)));
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
@@ -225,6 +232,7 @@ export class MapEffects {
|
||||
}));
|
||||
|
||||
constructor(private actions$: Actions, private store$: Store<mapReducers.State>, private folderService$: FolderService, private itemService$: ItemService) {
|
||||
this._format = new GeoJSON();
|
||||
this._geojsonFormat = new GeoJSON();
|
||||
this._wktFormat = new WKT();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user