Refactoring types
This commit is contained in:
@@ -4,7 +4,7 @@ import { MapComponent } from 'ngx-openlayers';
|
||||
import * as proj from 'ol/proj';
|
||||
import {Point,Geometry} from 'ol/geom';
|
||||
import { GeoJSON } from 'ol/format';
|
||||
import { Feature } from 'ol';
|
||||
import { Feature} from 'ol';
|
||||
|
||||
export interface IDroppedFile {
|
||||
files: any,
|
||||
@@ -21,7 +21,7 @@ export class FileDropTargetComponent implements OnInit, OnDestroy {
|
||||
element: Element;
|
||||
@Output() onFileDropped = new EventEmitter<IDroppedFile>();
|
||||
@Input() parentCode: string;
|
||||
@Input() features: Array<Feature>;
|
||||
@Input() features: Array<Feature<Geometry>>;
|
||||
|
||||
constructor(private map: MapComponent) {
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { Component, OnInit, Input, ViewChild, ElementRef, OnChanges, SimpleChanges ,Host} from '@angular/core';
|
||||
import { MapComponent } from 'ngx-openlayers';
|
||||
import Overlay from 'ol/Overlay';
|
||||
import Overlay from 'ol/Overlay';
|
||||
import { fromLonLat, toLonLat } from 'ol/proj';
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ export class GpsLocation implements OnInit,OnChanges{
|
||||
this.rotate = "rotate(" + Math.round(this.heading) + " 500 500)";
|
||||
this.locTolerancePixels = this.locationTolerance;
|
||||
this.map.instance.addOverlay(this.instance);
|
||||
this.map.instance.getView().on('change:resolution', (evt) => {
|
||||
this.map.instance.getView().on('change:resolution', (evt:any) => {
|
||||
this.resolution = evt.target.get('resolution');
|
||||
this.recalcLocationTolerance();
|
||||
});
|
||||
|
@@ -10,12 +10,14 @@ import * as proj from 'ol/proj';
|
||||
import * as loadingstrategy from 'ol/loadingstrategy';
|
||||
import * as style from 'ol/style';
|
||||
import {Tile,Layer,Image} from 'ol/layer';
|
||||
import {XYZ,ImageStatic,OSM,BingMaps,TileWMS,TileArcGISRest,TileJSON} from 'ol/source';
|
||||
import {XYZ,ImageStatic,OSM,BingMaps,TileWMS,TileArcGISRest,TileJSON,Source} from 'ol/source';
|
||||
import {Vector as VectorSource} from 'ol/source';
|
||||
import { Vector as VectorLayer } from 'ol/layer';
|
||||
import VectorTileSource from 'ol/source/VectorTile';
|
||||
import VectorTileLayer from 'ol/layer/VectorTile';
|
||||
import {GeoJSON,MVT} from 'ol/format';
|
||||
import { Geometry } from 'ol/geom';
|
||||
import TileSource from 'ol/source/Tile';
|
||||
|
||||
@Component({
|
||||
selector: 'fm-map-item-layers',
|
||||
@@ -34,7 +36,7 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
private initialized:boolean = false;
|
||||
private mapEventHandlerInstalled = false;
|
||||
private selectedFeatures = {};
|
||||
private selectionLayer:Layer = null;
|
||||
private selectionLayer:Layer<Source> = null;
|
||||
|
||||
constructor(private itemService: ItemService, private map: MapComponent, public appConfig: AppConfig) {
|
||||
super(map);
|
||||
@@ -119,9 +121,9 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
return this.styleCache[key];
|
||||
}
|
||||
|
||||
createGeotiffLayer(item:IItem,itemLayer:IItemLayer):Layer {
|
||||
createGeotiffLayer(item:IItem,itemLayer:IItemLayer):Layer<Source> {
|
||||
var layerIndex = -1;
|
||||
var layer: Layer = null;
|
||||
var layer: Layer<Source> = null;
|
||||
layerIndex = itemLayer.layerIndex != -1 ? itemLayer.layerIndex : item.data.layers[0].index;
|
||||
let source = new XYZ({ maxZoom: 19, minZoom: 1, url: `${this._apiEndPoint}/api/v1/items/${item.code}/tiles/${layerIndex}/{z}/{x}/{y}.png?v=${Date.parse(item.updated)}` });
|
||||
layer = new Tile({ source: source });
|
||||
@@ -142,9 +144,9 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
return layer;
|
||||
}
|
||||
|
||||
createShapeLayer(item:IItem,itemLayer:IItemLayer):Layer {
|
||||
createShapeLayer(item:IItem,itemLayer:IItemLayer):Layer<Source> {
|
||||
var layerIndex = -1;
|
||||
var layer: Layer = null;
|
||||
var layer: Layer<Source> = null;
|
||||
layerIndex = itemLayer.layerIndex != -1 ? itemLayer.layerIndex : item.data.layers[0].index;
|
||||
var data = item.data;
|
||||
var l:ILayer = (data && data.layers && data.layers.length > 0) ? data.layers[layerIndex] : null;
|
||||
@@ -177,7 +179,7 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
let source = new VectorSource({
|
||||
strategy: loadingstrategy.bbox,
|
||||
loader: function (extent: Extent, resolution: number, projection: Projection) {
|
||||
var source = this as VectorSource;
|
||||
var source = this as VectorSource<Geometry>;
|
||||
__this.itemService.getItemFeatures(item.code, extent, projection.getCode(), layerIndex).subscribe(function (data) {
|
||||
var features = format.readFeatures(data);
|
||||
for (let f of features) {
|
||||
@@ -230,16 +232,16 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
return layer;
|
||||
}
|
||||
|
||||
createSelectionLayer(itemLayer:IItemLayer):Layer {
|
||||
createSelectionLayer(itemLayer:IItemLayer):Layer<Source> {
|
||||
var layerIndex = -1;
|
||||
var layer: Layer = null;
|
||||
var layer: Layer<Source> = null;
|
||||
layerIndex = itemLayer.layerIndex != -1 ? itemLayer.layerIndex : itemLayer.item.data.layers[0].index;
|
||||
var data = itemLayer.item.data;
|
||||
var l:ILayer = (data && data.layers && data.layers.length > 0) ? data.layers[layerIndex] : null;
|
||||
if (l && l.rendering && l.rendering.renderoutputType == "VectorTiles") {
|
||||
return new VectorTileLayer({
|
||||
renderMode: 'vector',
|
||||
source: itemLayer.layer.getSource(),
|
||||
source: (itemLayer.layer as VectorTileLayer).getSource(),
|
||||
style: (feature) => {
|
||||
if (feature.getId() in this.selectedFeatures) {
|
||||
|
||||
@@ -260,9 +262,9 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
return null;
|
||||
}
|
||||
|
||||
createExternalLayer(item:IItem,itemLayer:IItemLayer):Layer {
|
||||
createExternalLayer(item:IItem,itemLayer:IItemLayer):Layer<Source> {
|
||||
let data = item.data as ILayerData;
|
||||
var layer: Layer = null;
|
||||
var layer: Layer<Source> = null;
|
||||
switch (data.interfaceType) {
|
||||
case 'OSM': {
|
||||
let source = new OSM();
|
||||
@@ -312,8 +314,8 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
return layer;
|
||||
}
|
||||
|
||||
createLayer(itemLayer: IItemLayer): Layer {
|
||||
var layer: Layer = null;
|
||||
createLayer(itemLayer: IItemLayer): Layer<Source> {
|
||||
var layer: Layer<Source> = null;
|
||||
var layerIndex = -1;
|
||||
if (itemLayer.item.itemType == 'vnd.farmmaps.itemtype.geotiff.processed') {
|
||||
layer = this.createGeotiffLayer(itemLayer.item,itemLayer);
|
||||
@@ -360,7 +362,7 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
}
|
||||
}
|
||||
|
||||
addOrUpdateOlLayer(itemLayer:IItemLayer,index:number):Layer {
|
||||
addOrUpdateOlLayer(itemLayer:IItemLayer,index:number):Layer<Source> {
|
||||
if(!itemLayer) return null;
|
||||
var olLayers = this.instance.getLayers();
|
||||
var layer = itemLayer.layer;
|
||||
@@ -385,7 +387,7 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
|
||||
}
|
||||
|
||||
updateLayers(itemLayers: IItemLayer[]) {
|
||||
let newLayers: IItemLayer[] = [];
|
||||
let newLayers: Layer<Source>[] = [];
|
||||
if (itemLayers) {
|
||||
itemLayers.forEach((itemLayer, index) => {
|
||||
if(itemLayer.item.itemType == 'vnd.farmmaps.itemtype.temporal') {
|
||||
|
@@ -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';
|
||||
|
@@ -1,8 +1,5 @@
|
||||
import { Component, OnDestroy, OnInit, Input, Optional, OnChanges, SimpleChanges } from '@angular/core';
|
||||
import { Vector } from 'ol/layer';
|
||||
import { Style } from 'ol/style';
|
||||
import { StyleFunction } from 'ol/style/Style';
|
||||
import { LayerVectorComponent, LayerGroupComponent, MapComponent } from 'ngx-openlayers';
|
||||
import { Component, OnDestroy, OnInit, Input, OnChanges, SimpleChanges } from '@angular/core';
|
||||
import { LayerVectorComponent, MapComponent } from 'ngx-openlayers';
|
||||
import { RenderType } from 'ol/layer/Vector';
|
||||
|
||||
@Component({
|
||||
@@ -12,7 +9,7 @@ import { RenderType } from 'ol/layer/Vector';
|
||||
`,
|
||||
})
|
||||
export class LayerVectorImageComponent extends LayerVectorComponent implements OnInit, OnDestroy, OnChanges {
|
||||
public source: Vector;
|
||||
//public source: Vector;
|
||||
|
||||
@Input()
|
||||
renderMode: RenderType | string = "image";
|
||||
|
Reference in New Issue
Block a user