AW-6046 Angular improvement
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good

This commit is contained in:
2024-04-15 10:29:47 +02:00
parent ede75f63f5
commit 84a1a04b19
104 changed files with 592 additions and 796 deletions

View File

@@ -1,25 +1,21 @@
import { Component, Host, Input, Output, EventEmitter,OnDestroy, OnInit, OnChanges, SimpleChanges, forwardRef } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, SimpleChanges, forwardRef } from '@angular/core';
import { AppConfig, IItem, ItemService } from '@farmmaps/common';
import { LayerGroupComponent, MapComponent } from 'ng-openlayers';
import { ItemService,IItem,AppConfig } from '@farmmaps/common';
import { IItemLayer, ITemporalItemLayer} from '../../../models/item.layer';
import { ILayerData} from '../../../models/layer.data';
import { IRenderoutputTiles,IRenderoutputImage,IGradientstop,ILayer,IHistogram,IColor} from '../../../models/color.map';
import {Extent} from 'ol/extent';
import Projection from 'ol/proj/Projection';
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,Source} from 'ol/source';
import {Vector as VectorSource} from 'ol/source';
import { Vector as VectorLayer } from 'ol/layer';
import { VectorImage as VectorImageLayer } 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 BaseLayer from 'ol/layer/Base';
import Feature from 'ol/Feature';
import { Extent } from 'ol/extent';
import { GeoJSON, MVT } from 'ol/format';
import { Geometry } from 'ol/geom';
import { Image, Layer, Tile, VectorImage as VectorImageLayer, Vector as VectorLayer } from 'ol/layer';
import VectorTileLayer from 'ol/layer/VectorTile';
import * as loadingstrategy from 'ol/loadingstrategy';
import * as proj from 'ol/proj';
import Projection from 'ol/proj/Projection';
import { BingMaps, ImageStatic, OSM, Source, TileArcGISRest, TileJSON, TileWMS, Vector as VectorSource, XYZ } from 'ol/source';
import VectorTileSource from 'ol/source/VectorTile';
import * as style from 'ol/style';
import { IColor, IGradientstop, IHistogram, ILayer, IRenderoutputImage, IRenderoutputTiles } from '../../../models/color.map';
import { IItemLayer, ITemporalItemLayer } from '../../../models/item.layer';
import { ILayerData } from '../../../models/layer.data';
@Component({
selector: 'fm-map-item-layers',
@@ -94,7 +90,7 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
return color;
}
getColor(item: IItem, layer: ILayer, feature): style.Style {
getColor(item: IItem, layer: any, feature): style.Style {
const value = layer.indexKey ? feature.get(layer.indexKey) : feature.get(layer.name);
const key = item.code + "_" + value;
if (!this.styleCache[key]) {
@@ -153,7 +149,7 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
const data = item.data;
const l:ILayer = (data && data.layers && data.layers.length > 0) ? data.layers[layerIndex] : null;
if (l && l.rendering && l.rendering.renderoutputType == "VectorTiles") {
var rt = l.rendering as IRenderoutputTiles;
const rt = l.rendering as IRenderoutputTiles;
layer = new VectorTileLayer({
declutter: true,
source: new VectorTileSource({
@@ -167,7 +163,7 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
}
})
} else if (l && l.rendering && l.rendering.renderoutputType == "Tiles") {
var rt = l.rendering as IRenderoutputTiles;
const rt = l.rendering as IRenderoutputTiles;
layer = new Tile({
source: new XYZ({
maxZoom: rt.maxzoom,
@@ -176,11 +172,12 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
})
});
} else {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const __this = this;
const format = new GeoJSON();
const source = new VectorSource({
strategy: loadingstrategy.bbox,
loader: function (extent: Extent, resolution: number, projection: Projection) {
loader: function (extent: Extent, _resolution: number, projection: Projection) {
const source = this as VectorSource<Feature<Geometry>>;
__this.itemService.getItemFeatures(item.code, extent, projection.getCode(), layerIndex).subscribe(function (data) {
const features = format.readFeatures(data).filter(feature => feature instanceof Feature) as Feature[];
@@ -237,7 +234,6 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
createSelectionLayer(itemLayer:IItemLayer):Layer<Source> {
let layerIndex = -1;
const layer: Layer<Source> = null;
layerIndex = itemLayer.layerIndex != -1 ? itemLayer.layerIndex : itemLayer.item.data.layers[0].index;
const data = itemLayer.item.data;
const l:ILayer = (data && data.layers && data.layers.length > 0) ? data.layers[layerIndex] : null;
@@ -265,7 +261,8 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
return null;
}
createExternalLayer(item:IItem,itemLayer:IItemLayer):Layer<Source> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
createExternalLayer(item:IItem,_itemLayer:IItemLayer):Layer<Source> {
const data = item.data as ILayerData;
let layer: Layer<Source> = null;
switch (data.interfaceType) {
@@ -319,7 +316,6 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
createLayer(itemLayer: IItemLayer): Layer<Source> {
let layer: Layer<Source> = null;
const layerIndex = -1;
if (itemLayer.item.itemType == 'vnd.farmmaps.itemtype.geotiff.processed') {
layer = this.createGeotiffLayer(itemLayer.item,itemLayer);
} else if (itemLayer.item.itemType == 'vnd.farmmaps.itemtype.shape.processed') {
@@ -379,10 +375,6 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
if(this.topLayerPrerenderEventhandlerInstalled && this.onPrerender.observers.length > 0 )
{
if(this.instance.getVisible()) {
const olLayers = this.instance.getLayers().getArray().forEach((l:any) => {
l.un('prerender',this.topLayerPrerenderEventhandler);
l.un('postrender',this.topLayerPostrenderEventhandler);
});
this.topLayerPrerenderEventhandlerInstalled = false;
}
}
@@ -415,17 +407,15 @@ export class ItemLayersComponent extends LayerGroupComponent implements OnChange
updateLayers(itemLayers: IItemLayer[] | IItemLayer) {
this.unInstallTopLayerPrerenderEventhandler();
let dataLayer = false;
let ils:IItemLayer[] = [];
if(Array.isArray(itemLayers)) {
ils = itemLayers;
} else {
dataLayer=true;
ils=[itemLayers];
}
const newLayers: Layer<Source>[] = [];
if (ils) {
ils.forEach((itemLayer, index) => {
ils.forEach((itemLayer) => {
if(itemLayer.item.itemType == 'vnd.farmmaps.itemtype.temporal') {
const il = itemLayer as ITemporalItemLayer;
const previousLayer = this.addOrUpdateOlLayer(il.previousItemLayer,newLayers.length);