From 15d1f14ee166c944e24a1e846e930489754ba146 Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Fri, 18 Sep 2020 14:20:33 +0200 Subject: [PATCH] More or less working now --- angular.json | 7 +++-- custom-webpack.config.js | 10 +++++++ .../gps-location/gps-location.component.ts | 8 ++++-- .../aol/item-layers/item-layers.component.ts | 11 ++------ .../aol/switch2d3d/switch2d3d.component.ts | 28 +++++++++++++++---- .../fm-map/components/map/map.component.html | 2 +- .../selected-item-cropfield.component.ts | 15 +++------- src/main.ts | 2 +- 8 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 custom-webpack.config.js diff --git a/angular.json b/angular.json index e346a4f..bd5deca 100644 --- a/angular.json +++ b/angular.json @@ -11,8 +11,11 @@ "schematics": {}, "architect": { "build": { - "builder": "@angular-devkit/build-angular:browser", + "builder": "@angular-builders/custom-webpack:browser", "options": { + "customWebpackConfig": { + "path": "./custom-webpack.config.js" + }, "aot": true, "outputPath": "dist/farmmaps-lib-app", "index": "src/index.html", @@ -85,7 +88,7 @@ } }, "serve": { - "builder": "@angular-devkit/build-angular:dev-server", + "builder": "@angular-builders/custom-webpack:dev-server", "options": { "browserTarget": "farmmaps-lib-app:build" }, diff --git a/custom-webpack.config.js b/custom-webpack.config.js new file mode 100644 index 0000000..70173ee --- /dev/null +++ b/custom-webpack.config.js @@ -0,0 +1,10 @@ +module.exports = { + node: { + // Resolve node module use of fs + fs: "empty", + Buffer: false, + http: "empty", + https: "empty", + zlib: "empty" + } + }; \ No newline at end of file diff --git a/projects/common-map/src/fm-map/components/aol/gps-location/gps-location.component.ts b/projects/common-map/src/fm-map/components/aol/gps-location/gps-location.component.ts index 2bb45fc..1428028 100644 --- a/projects/common-map/src/fm-map/components/aol/gps-location/gps-location.component.ts +++ b/projects/common-map/src/fm-map/components/aol/gps-location/gps-location.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Input, ViewChild, ElementRef, OnChanges, SimpleChanges } from '@angular/core'; +import { Component, OnInit, Input, ViewChild, ElementRef, OnChanges, SimpleChanges ,Host} from '@angular/core'; import { MapComponent } from 'ngx-openlayers'; import Overlay from 'ol/Overlay'; import { fromLonLat, toLonLat } from 'ol/proj'; @@ -23,9 +23,10 @@ export class GpsLocation implements OnInit,OnChanges{ public path: string = ""; public rotate: string = ""; private resolution: number = 0; + initialized:boolean = false; @ViewChild('location', { static: true }) locationElement: ElementRef; - constructor(private map: MapComponent) { + constructor(@Host() private map: MapComponent) { } @@ -54,12 +55,13 @@ export class GpsLocation implements OnInit,OnChanges{ this.resolution = evt.target.get('resolution'); this.recalcLocationTolerance(); }); + this.initialized = true; } ngOnChanges(changes: SimpleChanges) { if (changes.position && this.instance) { var p = changes.position.currentValue as Position; - if(p) { + if(p && this.initialized) { this.instance.setPosition(fromLonLat([p.coords.longitude, p.coords.latitude])); this.locationTolerance = p.coords.accuracy; this.recalcLocationTolerance(); diff --git a/projects/common-map/src/fm-map/components/aol/item-layers/item-layers.component.ts b/projects/common-map/src/fm-map/components/aol/item-layers/item-layers.component.ts index 29266b1..bed4b90 100644 --- a/projects/common-map/src/fm-map/components/aol/item-layers/item-layers.component.ts +++ b/projects/common-map/src/fm-map/components/aol/item-layers/item-layers.component.ts @@ -99,17 +99,12 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange var l = (data && data.layers && data.layers.length > 0) ? data.layers[0] : null; if (l && l.rendering && l.rendering.renderoutputType == "Tiles") { var rt = l.rendering as IRenderoutputTiles; - let source = new XYZ({ maxZoom: rt.maxzoom, minZoom: rt.minzoom, url: `${this._apiEndPoint}/api/v1/items/${item.code}/tiles/${layerIndex}/{z}/{x}/{y}.png?v=${Date.parse(item.updated)}` }); + let source = new XYZ({crossOrigin: 'use-credentials', maxZoom: rt.maxzoom, minZoom: rt.minzoom, url: `${this._apiEndPoint}/api/v1/items/${item.code}/tiles/${layerIndex}/{z}/{x}/{y}.png?v=${Date.parse(item.updated)}` }); layer = new Tile({ source: source }); } if (l && l.rendering && l.rendering.renderoutputType == "Image") { - var ri = l.rendering as IRenderoutputImage; - let projection = new Projection({ - code: 'image', - units: 'pixels', - extent: ri.extent - }); - let source = new ImageStatic({ imageExtent: ri.extent, projection: projection, url: `${this._apiEndPoint}/api/v1/items/${item.code}/mapimage/${layerIndex}?v=${Date.parse(item.updated)}` }); + var ri = l.rendering as IRenderoutputImage; + let source = new ImageStatic({ imageExtent: ri.extent, crossOrigin: 'use-credentials',projection: "EPSG:3857", url: `${this._apiEndPoint}/api/v1/items/${item.code}/mapimage/${layerIndex}?v=${Date.parse(item.updated)}` }); layer = new Image({ source: source }); } return layer; diff --git a/projects/common-map/src/fm-map/components/aol/switch2d3d/switch2d3d.component.ts b/projects/common-map/src/fm-map/components/aol/switch2d3d/switch2d3d.component.ts index 090e5ea..7c11286 100644 --- a/projects/common-map/src/fm-map/components/aol/switch2d3d/switch2d3d.component.ts +++ b/projects/common-map/src/fm-map/components/aol/switch2d3d/switch2d3d.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit,Input,Host } from '@angular/core'; import { MapComponent } from 'ngx-openlayers'; import OLCesium from 'ol-cesium'; +declare var olcs: any; @Component({ selector: 'fm-map-switch2d3d', @@ -21,20 +22,35 @@ export class Switch2D3DComponent { @Input() enable:boolean; public label: string = "3D"; private ol3d: OLCesium; + private synchronizers:any[]; constructor(@Host() private map: MapComponent) { } - ngOnInit() { - this.ol3d = new OLCesium({ map: this.map.instance }); // ol2dMap is the ol.Map instance + ngOnInit() { + this.ol3d = new OLCesium({ map: this.map.instance,createSynchronizers: (map,scene) => { + this.synchronizers = [ + new olcs.RasterSynchronizer(map,scene), + new olcs.VectorSynchronizer(map,scene) + ]; + return this.synchronizers; + },stopOpenLayersEventsPropagation:true}); + } + + synchronize() { + this.synchronizers.forEach((synchronizer) => { + synchronizer.synchronize(); + }); } handleClick(event) { - this.enable = !this.enable; - if (this.enable) - this.ol3d.setEnabled(this.enable); - this.label = this.enable?"2D":"3D"; + this.enable = !this.enable; + if(this.enable) { + this.synchronize(); + } + this.ol3d.setEnabled(this.enable); + this.label = this.enable?"2D":"3D"; } } diff --git a/projects/common-map/src/fm-map/components/map/map.component.html b/projects/common-map/src/fm-map/components/map/map.component.html index 8b807a6..45854c4 100644 --- a/projects/common-map/src/fm-map/components/map/map.component.html +++ b/projects/common-map/src/fm-map/components/map/map.component.html @@ -37,7 +37,7 @@ - +
diff --git a/projects/common-map/src/fm-map/components/selected-item-cropfield/selected-item-cropfield.component.ts b/projects/common-map/src/fm-map/components/selected-item-cropfield/selected-item-cropfield.component.ts index 79f17f4..c6da727 100644 --- a/projects/common-map/src/fm-map/components/selected-item-cropfield/selected-item-cropfield.component.ts +++ b/projects/common-map/src/fm-map/components/selected-item-cropfield/selected-item-cropfield.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, Injectable, OnInit, ComponentFactoryResolver, Inject, ComponentFactory } from '@angular/core'; +import { Component, Input, Injectable, OnInit } from '@angular/core'; import { Location } from '@angular/common'; import { Feature } from 'ol'; import { Store } from '@ngrx/store'; @@ -11,7 +11,6 @@ import { Observable,of } from 'rxjs'; import {GeoJSON} from 'ol/format'; import {getArea} from 'ol/sphere'; import { withLatestFrom,switchMap,combineLatest } from 'rxjs/operators'; -import { AbstractItemListItemComponent, ItemListItemComponent } from '../item-list-item/item-list-item.component'; @ForItemType("vnd.farmmaps.itemtype.cropfield") @@ -25,8 +24,7 @@ export class SelectedItemCropfieldComponent extends AbstractSelectedItemComponen public items: Observable; - constructor(store: Store, itemTypeService: ItemTypeService, location: Location, router: Router, private itemService$: ItemService,private folderService$: FolderService, - private componentFactoryResolver: ComponentFactoryResolver, @Inject(AbstractItemListItemComponent) public itemComponentList: AbstractItemListItemComponent[] ) { + constructor(store: Store, itemTypeService: ItemTypeService, location: Location, router: Router, private itemService$: ItemService,private folderService$: FolderService) { super(store, itemTypeService,location,router); } @@ -41,7 +39,6 @@ export class SelectedItemCropfieldComponent extends AbstractSelectedItemComponen } ngOnInit() { - var componentFactory: ComponentFactory = this.componentFactoryResolver.resolveComponentFactory(ItemListItemComponent); // default var childItems = this.folderService$.getItems(this.item.code, 0, 1000); var atLocationItems = this.itemService$.getItemList(null,null,null,this.item.code,true); this.items = childItems.pipe( @@ -50,12 +47,8 @@ export class SelectedItemCropfieldComponent extends AbstractSelectedItemComponen let retVal:IListItem[] = []; let codes = {}; ci.forEach((listItem) => { - if (this.itemComponentList.findIndex(i => - i.item['forItemType'].indexOf(this.item.itemType) >= 0 && - i.item['forSourceTask'].indexOf(this.item.sourceTask) >= 0) >= 0) { - retVal.push(listItem); - codes[listItem.code]=listItem; - } + retVal.push(listItem); + codes[listItem.code]=listItem; }); ali.forEach((atlocationitem) => { let listItem = atlocationitem as IListItem; diff --git a/src/main.ts b/src/main.ts index 9a03fb3..c10fd29 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,4 @@ -import * as Cesium from 'cesium' +import * as Cesium from 'cesium'; import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';