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:
parent
2e0b090fb7
commit
615872992f
12
package-lock.json
generated
12
package-lock.json
generated
@ -1943,9 +1943,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@farmmaps/common": {
|
"@farmmaps/common": {
|
||||||
"version": "0.0.1-prerelease.83",
|
"version": "0.0.1-prerelease.90",
|
||||||
"resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common/-/common-0.0.1-prerelease.83.tgz",
|
"resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common/-/common-0.0.1-prerelease.90.tgz",
|
||||||
"integrity": "sha512-JQryEA79ELg9hFYBYBIyEQD0bv5oHTX6Uch2nRaOlLhaiXbo6g/F4UYdRnLGTo7nzIPD1wcLcZQorfSMOhYPyQ==",
|
"integrity": "sha512-uSB9cJ06aJtfftQ/Yw6qR+LeeOAP1ly6JGxW6ubr/9hEqub38w+BPsQQYD5Sxn/oLjknRwhzEMZKYWTINF4zXw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"angular-oauth2-oidc": "^8.0.2",
|
"angular-oauth2-oidc": "^8.0.2",
|
||||||
"ngx-uploadx": "^3.3.2",
|
"ngx-uploadx": "^3.3.2",
|
||||||
@ -1953,9 +1953,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@farmmaps/common-map": {
|
"@farmmaps/common-map": {
|
||||||
"version": "0.0.1-prerelease.83",
|
"version": "0.0.1-prerelease.90",
|
||||||
"resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common-map/-/common-map-0.0.1-prerelease.83.tgz",
|
"resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common-map/-/common-map-0.0.1-prerelease.90.tgz",
|
||||||
"integrity": "sha512-tILDqqj+ucSipvxJws3tLlZ4ytewqfmZzTmS07O0YhTFqx7+4WzkW8kL8S8vx3t3rB/ZPoAMa9u+w6G2WQ6nCw==",
|
"integrity": "sha512-z1q8cHFNrrAQx8n8dXW2cn9d3wxG9oruPSoNgUrgz+YYJkxeDr0kd3SqloftPJrVxES0iIiqguweo0SRyBGVYA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"ngx-openlayers": "1.0.0-next.13",
|
"ngx-openlayers": "1.0.0-next.13",
|
||||||
"ol": "^6.0.0",
|
"ol": "^6.0.0",
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
"@angular/platform-browser-dynamic": "~8.2.14",
|
"@angular/platform-browser-dynamic": "~8.2.14",
|
||||||
"@angular/router": "~8.2.14",
|
"@angular/router": "~8.2.14",
|
||||||
"@aspnet/signalr": "^1.1.4",
|
"@aspnet/signalr": "^1.1.4",
|
||||||
"@farmmaps/common": ">=0.0.1-prerelease.83 <0.0.1",
|
"@farmmaps/common": ">=0.0.1-prerelease.90 <0.0.1",
|
||||||
"@farmmaps/common-map": ">=0.0.1-prerelease.83 <0.0.1",
|
"@farmmaps/common-map": ">=0.0.1-prerelease.90 <0.0.1",
|
||||||
"@ng-bootstrap/ng-bootstrap": "^4.2.1",
|
"@ng-bootstrap/ng-bootstrap": "^4.2.1",
|
||||||
"@ngrx/effects": "^8.2.0",
|
"@ngrx/effects": "^8.2.0",
|
||||||
"@ngrx/router-store": "^8.2.0",
|
"@ngrx/router-store": "^8.2.0",
|
||||||
|
@ -15,6 +15,6 @@
|
|||||||
"@ngrx/router-store": "^8.2",
|
"@ngrx/router-store": "^8.2",
|
||||||
"@ngrx/store": "^8.2",
|
"@ngrx/store": "^8.2",
|
||||||
"tassign": "^1.0.0",
|
"tassign": "^1.0.0",
|
||||||
"@farmmaps/common": ">=0.0.1-prerelease.82 <0.0.1"
|
"@farmmaps/common": ">=0.0.1-prerelease.90 <0.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import { Effect, Actions,ofType } from '@ngrx/effects';
|
|||||||
import { Observable , of } from 'rxjs';
|
import { Observable , of } from 'rxjs';
|
||||||
import { withLatestFrom, switchMap, map, catchError, mergeMap, delay} from 'rxjs/operators';
|
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 {Feature} from 'ol';
|
||||||
import { getCenter, Extent, createEmpty, extend} from 'ol/extent';
|
import { getCenter, Extent, createEmpty, extend} from 'ol/extent';
|
||||||
import {Point} from 'ol/geom'
|
import {Point} from 'ol/geom'
|
||||||
@ -25,10 +25,15 @@ import { tassign } from 'tassign';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MapEffects {
|
export class MapEffects {
|
||||||
private _format: GeoJSON;
|
private _geojsonFormat: GeoJSON;
|
||||||
|
private _wktFormat: WKT;
|
||||||
|
|
||||||
private toPointFeature(feature: any): Feature {
|
private toPointFeature(updateEvent:commonActions.DeviceUpdateEvent): Feature {
|
||||||
var f = this._format.readFeature(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());
|
var centroid = getCenter(f.getGeometry().getExtent());
|
||||||
f.setGeometry(new Point(centroid));
|
f.setGeometry(new Point(centroid));
|
||||||
return f;
|
return f;
|
||||||
@ -83,7 +88,7 @@ export class MapEffects {
|
|||||||
f.id = f.properties["code"];
|
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))));
|
catchError(error => of(new commonActions.Fail(error))));
|
||||||
@ -135,7 +140,11 @@ export class MapEffects {
|
|||||||
ofType(mapActions.SELECTITEMSUCCESS),
|
ofType(mapActions.SELECTITEMSUCCESS),
|
||||||
switchMap((action:mapActions.SelectItemSuccess) => {
|
switchMap((action:mapActions.SelectItemSuccess) => {
|
||||||
return this.itemService$.getFeature(action.item.code, "EPSG:3857").pipe(
|
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))));
|
catchError(error => of(new commonActions.Fail(error))));
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
@ -163,21 +172,19 @@ export class MapEffects {
|
|||||||
|
|
||||||
@Effect()
|
@Effect()
|
||||||
featureUpdate$: Observable<Action> = this.actions$.pipe(
|
featureUpdate$: Observable<Action> = this.actions$.pipe(
|
||||||
ofType(commonActions.ITEMCHANGEDEVENT),
|
ofType(commonActions.DEVICEUPDATEEVENT),
|
||||||
withLatestFrom(this.store$.select(mapReducers.selectGetFeatures)),
|
withLatestFrom(this.store$.select(mapReducers.selectGetFeatures)),
|
||||||
mergeMap(([action, features]) => {
|
mergeMap(([action, features]) => {
|
||||||
let itemChangedAction = action as commonActions.ItemChangedEvent;
|
let deviceUpdateEventAction = action as commonActions.DeviceUpdateEvent;
|
||||||
var feature: Feature = null;
|
var feature: Feature = null;
|
||||||
for (let f of features) {
|
for (let f of features) {
|
||||||
if (f.get("code") == itemChangedAction.itemCode) {
|
if (f.getId() == deviceUpdateEventAction.itemCode) {
|
||||||
feature = f;
|
feature = f;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (feature) {
|
if (feature) {
|
||||||
return this.itemService$.getFeature(itemChangedAction.itemCode, "EPSG:3857").pipe(
|
return of(new mapActions.UpdateFeatureSuccess(this.toPointFeature(deviceUpdateEventAction)));
|
||||||
map((feature: any) => new mapActions.UpdateFeatureSuccess(this.toPointFeature(feature))),
|
|
||||||
catchError(error => of(new commonActions.Fail(error))));
|
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -225,6 +232,7 @@ export class MapEffects {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
constructor(private actions$: Actions, private store$: Store<mapReducers.State>, private folderService$: FolderService, private itemService$: ItemService) {
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ export function reducer(state = initialState, action: mapActions.Actions | commo
|
|||||||
let features: any[] = [];
|
let features: any[] = [];
|
||||||
var index = -1;
|
var index = -1;
|
||||||
for (var i = 0; i < state.features.length; i++) {
|
for (var i = 0; i < state.features.length; i++) {
|
||||||
if (state.features[i].get("code") == a.feature.get("code")) {
|
if (state.features[i].getId() == a.feature.getId()) {
|
||||||
features.push(a.feature);
|
features.push(a.feature);
|
||||||
} else {
|
} else {
|
||||||
features.push(state.features[i]);
|
features.push(state.features[i]);
|
||||||
|
Loading…
Reference in New Issue
Block a user