Fix temporal layer selection
Some checks reported errors
FarmMaps.Develop/FarmMapsLib/pipeline/head Something is wrong with the build of this commit

This commit is contained in:
Willem Dantuma 2021-01-26 17:47:17 +01:00
parent 290d5d1d26
commit e858ac778c

View File

@ -28,8 +28,8 @@ import {GeoJSON,MVT} from 'ol/format';
export class ItemLayersComponent extends LayerGroupComponent implements OnChanges, OnInit,OnDestroy { export class ItemLayersComponent extends LayerGroupComponent implements OnChanges, OnInit,OnDestroy {
@Input() itemLayers: IItemLayer[]; @Input() itemLayers: IItemLayer[];
@Input() itemLayer: IItemLayer; @Input() itemLayer: IItemLayer;
@Output() onFeatureSelected: EventEmitter<string> = new EventEmitter<string>(); @Output() onFeatureSelected: EventEmitter<any> = new EventEmitter<any>();
@Output() onFeatureHover: EventEmitter<string> = new EventEmitter<string>(); @Output() onFeatureHover: EventEmitter<any> = new EventEmitter<any>();
private _apiEndPoint: string; private _apiEndPoint: string;
private initialized:boolean = false; private initialized:boolean = false;
private mapEventHandlerInstalled = false; private mapEventHandlerInstalled = false;
@ -310,7 +310,7 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
if(this.itemLayers) { if(this.itemLayers) {
this.updateLayers(this.itemLayers); this.updateLayers(this.itemLayers);
} else if(this.itemLayer) { } else if(this.itemLayer) {
if(this.itemLayer.item.itemType == 'vnd.farmmaps.itemtype.shape.processed' || (this.itemLayer as ITemporalItemLayer).temporalItems && (this.itemLayer as ITemporalItemLayer).temporalItems.length && (this.itemLayer as ITemporalItemLayer).temporalItems[0].itemType == 'vnd.farmmaps.itemtype.shape.processed' ) { if(this.getItemlayer(this.itemLayer).item.itemType == 'vnd.farmmaps.itemtype.shape.processed') {
this.installMapEventHandler(); this.installMapEventHandler();
} }
this.updateLayers([this.itemLayer]) this.updateLayers([this.itemLayer])
@ -381,8 +381,8 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
olLayers.removeAt(newLayers.length); olLayers.removeAt(newLayers.length);
} }
this.selectionLayer=null; this.selectionLayer=null;
if(this.mapEventHandlerInstalled && itemLayers.length==1 && itemLayers[0].item.itemType == 'vnd.farmmaps.itemtype.shape.processed') { if(this.mapEventHandlerInstalled && itemLayers.length==1 && this.getItemlayer(itemLayers[0]).item.itemType == 'vnd.farmmaps.itemtype.shape.processed') {
this.selectionLayer = this.createSelectionLayer(itemLayers[0]); this.selectionLayer = this.createSelectionLayer(this.getItemlayer(itemLayers[0]));
olLayers.push(this.selectionLayer) olLayers.push(this.selectionLayer)
} }
} }
@ -390,26 +390,27 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
mapEventHandler = (event) => { mapEventHandler = (event) => {
// select only when having observers // select only when having observers
console.debug("Event"); // if(event.type === 'click' && !this.onFeatureSelected.observers.length) return;
if(event.type === 'click' && !this.onFeatureSelected.observers.length) return; //if(event.type === 'pointermove' && !this.onFeatureHover.observers.length) return;
if(event.type === 'pointermove' && !this.onFeatureHover.observers.length) return; let itemLayer= this.getItemlayer(this.itemLayer);
if(this.itemLayer && this.itemLayer.layer) { if(itemLayer && itemLayer.layer) {
this.selectedFeatures = {}; this.selectedFeatures = {};
if(this.itemLayer.layer ) { if(itemLayer.layer ) {
let minZoom = this.itemLayer.layer.getMinZoom(); let minZoom = itemLayer.layer.getMinZoom();
let currentZoom = this.map.instance.getView().getZoom(); let currentZoom = this.map.instance.getView().getZoom();
if(currentZoom>minZoom) { if(currentZoom>minZoom) {
this.itemLayer.layer.getFeatures(event.pixel).then((features) => { itemLayer.layer.getFeatures(event.pixel).then((features) => {
if(!features.length) { if(!features.length) {
this.onFeatureHover.emit(null); this.onFeatureHover.emit(null);
return; return;
} }
let fid = features[0].getId(); let fid = features[0].getId();
let feature = features[0];
if(event.type === 'pointermove') { if(event.type === 'pointermove') {
this.selectedFeatures[fid] = features[0]; this.selectedFeatures[fid] = features[0];
this.onFeatureHover.emit(features[0]); this.onFeatureHover.emit({ "feature": feature,"itemCode":itemLayer.item.code });
} else { } else {
this.onFeatureSelected.emit(features[0]); this.onFeatureSelected.emit({ "feature": feature,"itemCode":itemLayer.item.code });
} }
}) })
if(this.selectionLayer) this.selectionLayer.changed(); if(this.selectionLayer) this.selectionLayer.changed();
@ -418,6 +419,11 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
} }
} }
getItemlayer(itemLayer:IItemLayer):IItemLayer {
if((itemLayer as ITemporalItemLayer).selectedItemLayer) return (itemLayer as ITemporalItemLayer).selectedItemLayer;
return itemLayer;
}
ngOnChanges(changes: SimpleChanges) { ngOnChanges(changes: SimpleChanges) {
if (this.instance && this.initialized) { if (this.instance && this.initialized) {
if (changes['itemLayers']) { if (changes['itemLayers']) {
@ -428,7 +434,7 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
var itemLayer = changes['itemLayer'].currentValue as IItemLayer; var itemLayer = changes['itemLayer'].currentValue as IItemLayer;
this.itemLayer = itemLayer this.itemLayer = itemLayer
if(itemLayer) { if(itemLayer) {
if(this.itemLayer.item.itemType == 'vnd.farmmaps.itemtype.shape.processed' || (this.itemLayer as ITemporalItemLayer).temporalItems && (this.itemLayer as ITemporalItemLayer).temporalItems.length && (this.itemLayer as ITemporalItemLayer).temporalItems[0].itemType == 'vnd.farmmaps.itemtype.shape.processed' ) { if(this.getItemlayer(this.itemLayer).item.itemType == 'vnd.farmmaps.itemtype.shape.processed') {
this.installMapEventHandler(); this.installMapEventHandler();
} }
this.updateLayers([itemLayer]); this.updateLayers([itemLayer]);