Refactoring types
This commit is contained in:
@@ -3,14 +3,14 @@ import { LayerVectorComponent, SourceVectorComponent, MapComponent } from 'ngx-o
|
||||
import { ItemService,ItemTypeService,IItem, IItemType } from '@farmmaps/common';
|
||||
|
||||
import { Feature } from 'ol';
|
||||
import { Point } from 'ol/geom';
|
||||
import { Point,Geometry } from 'ol/geom';
|
||||
import { MapBrowserEvent } from 'ol';
|
||||
import * as style from 'ol/style';
|
||||
import * as color from 'ol/color';
|
||||
import * as loadingstrategy from 'ol/loadingstrategy';
|
||||
import * as condition from 'ol/events/condition';
|
||||
import * as extent from 'ol/extent';
|
||||
import {Vector,Cluster} from 'ol/source';
|
||||
import {Vector,Cluster,Source} from 'ol/source';
|
||||
import {Layer} from 'ol/layer';
|
||||
import {GeoJSON} from 'ol/format';
|
||||
import {Select} from 'ol/interaction';
|
||||
@@ -25,17 +25,17 @@ import {FeatureIconService} from '../../../services/feature-icon.service';
|
||||
]
|
||||
})
|
||||
export class ItemVectorSourceComponent extends SourceVectorComponent implements OnInit, OnChanges {
|
||||
instance: Vector;
|
||||
instance: Vector<Geometry>;
|
||||
private _format: GeoJSON;
|
||||
private _select: Select;
|
||||
private _hoverSelect: Select;
|
||||
private _iconScale: number = 0.05;
|
||||
@Input() features: Array<Feature>;
|
||||
@Input() selectedFeature: Feature;
|
||||
@Input() features: Array<Feature<Geometry>>;
|
||||
@Input() selectedFeature: Feature<Geometry>;
|
||||
@Input() selectedItem: IItem;
|
||||
@Input() styles:IStyles;
|
||||
@Output() onFeatureSelected: EventEmitter<Feature> = new EventEmitter<Feature>();
|
||||
@Output() onFeatureHover: EventEmitter<Feature> = new EventEmitter<Feature>();
|
||||
@Output() onFeatureSelected: EventEmitter<Feature<Geometry>> = new EventEmitter<Feature<Geometry>>();
|
||||
@Output() onFeatureHover: EventEmitter<Feature<Geometry>> = new EventEmitter<Feature<Geometry>>();
|
||||
private stylesCache:IStyles = {};
|
||||
|
||||
constructor(@Host() private layer: LayerVectorComponent, private itemService: ItemService, private map: MapComponent, private itemTypeService: ItemTypeService,private featureIconService$:FeatureIconService) {
|
||||
@@ -43,7 +43,7 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements
|
||||
this._format = new GeoJSON();
|
||||
}
|
||||
|
||||
geometry(feature: Feature) {
|
||||
geometry(feature: Feature<Geometry>) {
|
||||
let view = this.map.instance.getView();
|
||||
let resolution = view.getResolution();
|
||||
var geometry = feature.getGeometry();
|
||||
@@ -55,9 +55,9 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements
|
||||
return geometry;
|
||||
}
|
||||
|
||||
getSelectedStyle(feature:Feature):style.Style {
|
||||
getSelectedStyle(feature:Feature<Geometry>):style.Style {
|
||||
let key = feature.get('itemType')+"_selected";
|
||||
let evaluatedStyle =null;
|
||||
let evaluatedStyle: style.Style | (Feature<Geometry>) =undefined;
|
||||
var styleEntry = this.stylesCache[key];
|
||||
if(styleEntry) {
|
||||
if(typeof styleEntry === 'function') {
|
||||
@@ -71,7 +71,7 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements
|
||||
if(evaluatedStyle ) {
|
||||
evaluatedStyle.setGeometry((feature) => this.geometry(feature));
|
||||
}
|
||||
return evaluatedStyle
|
||||
return evaluatedStyle as style.Style
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -80,17 +80,17 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements
|
||||
this._select = new Select({
|
||||
style:null,
|
||||
hitTolerance: 10,
|
||||
layers: [this.layer.instance as Layer]
|
||||
layers: [this.layer.instance as Layer<Source>]
|
||||
});
|
||||
this._hoverSelect = new Select({
|
||||
style: (feature) => {
|
||||
style: (feature:Feature<Geometry>) => {
|
||||
return this.getSelectedStyle(feature);
|
||||
},
|
||||
hitTolerance: 10,
|
||||
condition: (e: MapBrowserEvent) => {
|
||||
return e.type == 'pointermove';
|
||||
},
|
||||
layers: [this.layer.instance as Layer]
|
||||
layers: [this.layer.instance as Layer<Source>]
|
||||
});
|
||||
this.map.instance.addInteraction(this._select);
|
||||
this.map.instance.addInteraction(this._hoverSelect);
|
||||
@@ -132,7 +132,7 @@ export class ItemVectorSourceComponent extends SourceVectorComponent implements
|
||||
fill: new style.Fill({
|
||||
color: fillColor
|
||||
}),
|
||||
geometry:(feature) => this.geometry(feature)
|
||||
geometry:(feature:Feature<Geometry>) => this.geometry(feature)
|
||||
});
|
||||
} else {
|
||||
key = 'file';
|
||||
|
Reference in New Issue
Block a user