Some fixes and optimizations

This commit is contained in:
Willem Dantuma 2021-01-23 18:30:29 +01:00
parent 2f4e14ca1f
commit b30c29a5f1
2 changed files with 24 additions and 9 deletions

View File

@ -386,17 +386,31 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
}
mapEventHandler = (event) => {
//return;
//if(event.type === 'click' && !this.onFeatureSelected.observers.length) return;
//if(event.type === 'pointermode' && !this.onFeatureHover.observers.length) return;
// select only when having observers
if(event.type === 'click' && !this.onFeatureSelected.observers.length) return;
if(event.type === 'pointermove' && !this.onFeatureHover.observers.length) return;
if(this.itemLayer && this.itemLayer.layer) {
this.selectedFeatures = {};
this.itemLayer.layer.getFeatures(event.pixel).then((features) => {
if(!features.length) return;
let fid = features[0].getId();
this.selectedFeatures[fid] = features[0];
})
if(this.selectionLayer) this.selectionLayer.changed();
if(this.itemLayer.layer ) {
let minZoom = this.itemLayer.layer.getMinZoom();
let currentZoom = this.map.instance.getView().getZoom();
if(currentZoom>minZoom) {
this.itemLayer.layer.getFeatures(event.pixel).then((features) => {
if(!features.length) {
this.onFeatureHover.emit(null);
return;
}
let fid = features[0].getId();
if(event.type === 'pointermove') {
this.selectedFeatures[fid] = features[0];
this.onFeatureHover.emit(features[0]);
} else {
this.onFeatureSelected.emit(features[0]);
}
})
if(this.selectionLayer) this.selectionLayer.changed();
}
}
}
}

View File

@ -38,6 +38,7 @@
<aol-layer-vector>
<fm-map-item-source-vector [styles]="state.styles" [features]="state.features" (onFeatureSelected)="handleFeatureClick($event)" (onFeatureHover)="handleFeatureHover($event)" [selectedFeature]="state.selectedFeature" [selectedItem]="state.selectedItem"></fm-map-item-source-vector>
</aol-layer-vector>
<router-outlet name="map-layers"></router-outlet>
<!-- <fm-map-gps-location [position]="state.position" [headingTolerance]="20" [showHeading]="true" [heading]="state.compassHeading"></fm-map-gps-location> -->
<div class="control-container" >
<router-outlet name="map-controls"></router-outlet>