Fix temporal layer selection
Some checks reported errors
FarmMaps.Develop/FarmMapsLib/pipeline/head Something is wrong with the build of this commit
Some checks reported errors
FarmMaps.Develop/FarmMapsLib/pipeline/head Something is wrong with the build of this commit
This commit is contained in:
parent
290d5d1d26
commit
e858ac778c
@ -28,8 +28,8 @@ import {GeoJSON,MVT} from 'ol/format';
|
||||
export class ItemLayersComponent extends LayerGroupComponent implements OnChanges, OnInit,OnDestroy {
|
||||
@Input() itemLayers: IItemLayer[];
|
||||
@Input() itemLayer: IItemLayer;
|
||||
@Output() onFeatureSelected: EventEmitter<string> = new EventEmitter<string>();
|
||||
@Output() onFeatureHover: EventEmitter<string> = new EventEmitter<string>();
|
||||
@Output() onFeatureSelected: EventEmitter<any> = new EventEmitter<any>();
|
||||
@Output() onFeatureHover: EventEmitter<any> = new EventEmitter<any>();
|
||||
private _apiEndPoint: string;
|
||||
private initialized:boolean = false;
|
||||
private mapEventHandlerInstalled = false;
|
||||
@ -310,7 +310,7 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
if(this.itemLayers) {
|
||||
this.updateLayers(this.itemLayers);
|
||||
} 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.updateLayers([this.itemLayer])
|
||||
@ -381,8 +381,8 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
olLayers.removeAt(newLayers.length);
|
||||
}
|
||||
this.selectionLayer=null;
|
||||
if(this.mapEventHandlerInstalled && itemLayers.length==1 && itemLayers[0].item.itemType == 'vnd.farmmaps.itemtype.shape.processed') {
|
||||
this.selectionLayer = this.createSelectionLayer(itemLayers[0]);
|
||||
if(this.mapEventHandlerInstalled && itemLayers.length==1 && this.getItemlayer(itemLayers[0]).item.itemType == 'vnd.farmmaps.itemtype.shape.processed') {
|
||||
this.selectionLayer = this.createSelectionLayer(this.getItemlayer(itemLayers[0]));
|
||||
olLayers.push(this.selectionLayer)
|
||||
}
|
||||
}
|
||||
@ -390,26 +390,27 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
|
||||
mapEventHandler = (event) => {
|
||||
// select only when having observers
|
||||
console.debug("Event");
|
||||
if(event.type === 'click' && !this.onFeatureSelected.observers.length) return;
|
||||
if(event.type === 'pointermove' && !this.onFeatureHover.observers.length) return;
|
||||
if(this.itemLayer && this.itemLayer.layer) {
|
||||
// if(event.type === 'click' && !this.onFeatureSelected.observers.length) return;
|
||||
//if(event.type === 'pointermove' && !this.onFeatureHover.observers.length) return;
|
||||
let itemLayer= this.getItemlayer(this.itemLayer);
|
||||
if(itemLayer && itemLayer.layer) {
|
||||
this.selectedFeatures = {};
|
||||
if(this.itemLayer.layer ) {
|
||||
let minZoom = this.itemLayer.layer.getMinZoom();
|
||||
if(itemLayer.layer ) {
|
||||
let minZoom = itemLayer.layer.getMinZoom();
|
||||
let currentZoom = this.map.instance.getView().getZoom();
|
||||
if(currentZoom>minZoom) {
|
||||
this.itemLayer.layer.getFeatures(event.pixel).then((features) => {
|
||||
itemLayer.layer.getFeatures(event.pixel).then((features) => {
|
||||
if(!features.length) {
|
||||
this.onFeatureHover.emit(null);
|
||||
return;
|
||||
}
|
||||
let fid = features[0].getId();
|
||||
let feature = features[0];
|
||||
if(event.type === 'pointermove') {
|
||||
this.selectedFeatures[fid] = features[0];
|
||||
this.onFeatureHover.emit(features[0]);
|
||||
this.onFeatureHover.emit({ "feature": feature,"itemCode":itemLayer.item.code });
|
||||
} else {
|
||||
this.onFeatureSelected.emit(features[0]);
|
||||
this.onFeatureSelected.emit({ "feature": feature,"itemCode":itemLayer.item.code });
|
||||
}
|
||||
})
|
||||
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) {
|
||||
if (this.instance && this.initialized) {
|
||||
if (changes['itemLayers']) {
|
||||
@ -428,7 +434,7 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
var itemLayer = changes['itemLayer'].currentValue as IItemLayer;
|
||||
this.itemLayer = 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.updateLayers([itemLayer]);
|
||||
|
Loading…
Reference in New Issue
Block a user