Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(geo): add saveable options for layers and datasources #1696

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Tool } from '@igo2/common/tool';
import { Message } from '@igo2/core/message';
import {
AnyDataSourceOptions,
LayerOptions,
MapAttributionOptions,
MapExtent,
Expand Down Expand Up @@ -98,3 +99,13 @@ export interface ContextProfils {
title: string;
childs?: ContextProfils[];
}

export interface IContextLayer {
id?: string;
layerId?: number;
contextId?: number;
layerOptions?:
| LayerOptions
| Pick<LayerOptions, 'title' | 'zIndex' | 'visible' | 'security'>;
sourceOptions?: AnyDataSourceOptions;
}
22 changes: 5 additions & 17 deletions packages/context/src/lib/context-manager/shared/context.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import {
ContextServiceOptions,
ContextsList,
DetailedContext,
ExtraFeatures
ExtraFeatures,
IContextLayer
} from './context.interface';

@Injectable({
Expand Down Expand Up @@ -481,24 +482,11 @@ export class ContextService {
.sort((a, b) => a.zIndex - b.zIndex);
}

let i = 0;
for (const layer of layers) {
const layerOptions: AnyLayerOptions = {
title: layer.options.title,
zIndex: ++i,
visible: layer.visible,
security: layer.options.security,
opacity: layer.opacity
};
const opts = {
const opts: IContextLayer = {
id: layer.options.id ? String(layer.options.id) : undefined,
layerOptions,
sourceOptions: {
type: layer.dataSource.options.type,
params: layer.dataSource.options.params,
url: layer.dataSource.options.url,
queryable: layer.queryable
}
layerOptions: layer.saveableOptions,
sourceOptions: layer.dataSource.saveableOptions
};
if (opts.sourceOptions.type) {
context.layers.push(opts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ export class ArcGISRestDataSource extends DataSource {
public declare ol: olSourceVector;
public declare options: ArcGISRestDataSourceOptions;

get saveableOptions(): Partial<ArcGISRestDataSourceOptions> {
const baseOptions = super.saveableOptions;
return {
...baseOptions,
params: this.options.params,
url: this.options.url
};
}

protected createOlSource(): olSourceVector {
const esrijsonFormat = new olFormatEsriJSON();
return new olSourceVector({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import olSourceCarto from 'ol/source/CartoDB';

import { DataSourceOptions } from './datasource.interface';

export interface CartoDataSourceOptions extends DataSourceOptions {
Expand All @@ -13,6 +11,4 @@ export interface CartoDataSourceOptions extends DataSourceOptions {
projection?: string;
config?: any;
map?: string;

ol?: olSourceCarto;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export class CartoDataSource extends DataSource {
: QueryHtmlTarget.BLANK;
}

get saveableOptions(): Partial<CartoDataSourceOptions> {
const baseOptions = super.saveableOptions;
return {
...baseOptions,
params: this.options.params
};
}

protected createOlSource(): olSourceCarto {
const crossOrigin = this.options.crossOrigin
? this.options.crossOrigin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import olSourceVector from 'ol/source/Vector';
import { FeatureDataSourceOptions } from './feature-datasource.interface';

export interface ClusterDataSourceOptions extends FeatureDataSourceOptions {
// type?: 'cluster';
distance?: number;
source?: olSourceVector;
ol?: olSourceVector;
pathOffline?: string;
excludeAttribute?: string[];
excludeAttributeOffline?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ export class ClusterDataSource extends FeatureDataSource {
public declare options: ClusterDataSourceOptions;
public declare ol: olSourceCluster;

get saveableOptions(): Partial<ClusterDataSourceOptions> {
const baseOptions = super.saveableOptions;
return {
...baseOptions,
params: this.options.params
};
}

protected createOlSource(): olSourceCluster {
this.options.format = this.getSourceFormatFromOptions(this.options);
this.options.source = super.createOlSource();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Type } from 'ol/geom/Geometry';
import olSource from 'ol/source/Source';

import { Encoders, Preset, Tokenizer } from 'flexsearch';

Expand All @@ -25,8 +24,8 @@ export interface DataSourceOptions {
optionsFromCapabilities?: boolean;
optionsFromApi?: boolean;
_layerOptionsFromSource?: Record<string, string>;
url?: string;
id?: string;
ol?: olSource;
minZoom?: number;
maxZoom?: number;
minDate?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export abstract class DataSource {
public ol: olSource | olVectorSource | olClusterSource;
private legend: Legend[];

get saveableOptions(): Partial<DataSourceOptions> {
return {
type: this.options.type,
url: this.options.url
};
}

constructor(
public options: DataSourceOptions = {},
protected dataService?: DataService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import olFeature from 'ol/Feature';
import olFormatFeature from 'ol/format/Feature';
import olSource from 'ol/source/Source';
import olSourceVector from 'ol/source/Vector';

import { DataSourceOptions } from './datasource.interface';

export interface FeatureDataSourceOptions extends DataSourceOptions {
// type?: 'vector' | 'wfs';
formatType?: string;
formatOptions?: any;

Expand All @@ -18,8 +15,6 @@ export interface FeatureDataSourceOptions extends DataSourceOptions {
preload?: PreloadOptions;
excludeAttribute?: string[];
excludeAttributeOffline?: string[];

ol?: olSourceVector | olSource;
}

export interface PreloadOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import { FeatureDataSourceOptions } from './feature-datasource.interface';
export class FeatureDataSource extends DataSource {
public declare options: FeatureDataSourceOptions;
public declare ol: olSourceVector;

get saveableOptions(): Partial<FeatureDataSourceOptions> {
const baseOptions = super.saveableOptions;
return {
...baseOptions,
params: this.options.params
};
}

protected createOlSource(): olSourceVector {
const sourceOptions = {
format: this.getSourceFormatFromOptions(this.options)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import olAttribution from 'ol/control/Attribution';
import ImageArcGISRest from 'ol/source/ImageArcGISRest';

import { DataSourceOptions } from './datasource.interface';

Expand All @@ -12,7 +11,6 @@ export interface ArcGISRestImageDataSourceOptions extends DataSourceOptions {
attributions?: olAttribution;
projection?: string;
url?: string;
ol?: ImageArcGISRest;
idColumn?: string;
options?: any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export class ImageArcGISRestDataSource extends DataSource {
: QueryHtmlTarget.BLANK;
}

get saveableOptions(): Partial<ArcGISRestImageDataSourceOptions> {
const baseOptions = super.saveableOptions;
return {
...baseOptions,
params: this.options.params
};
}

protected createOlSource(): ImageArcGISRest {
const params =
this.options.layer === undefined
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import olSourceVectorTile from 'ol/source/VectorTile';

import { DataSourceOptions } from './datasource.interface';

export interface MVTDataSourceOptions extends DataSourceOptions {
// type?: 'mvt';
projection?: string;
attributions?: string | string[];
format?: any;
ol?: olSourceVectorTile;
url?: string;
pathOffline?: string;
excludeAttribute?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export class MVTDataSource extends DataSource {
public declare options: MVTDataSourceOptions;
public declare ol: olSourceVectorTile;

get saveableOptions(): Partial<MVTDataSourceOptions> {
return super.saveableOptions;
}

protected createOlSource(): olSourceVectorTile {
let mvtFormat;
if (this.options.featureClass === 'feature') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import olSourceOSM from 'ol/source/OSM';

import { DataSourceOptions } from './datasource.interface';

export interface OSMDataSourceOptions extends DataSourceOptions {
// type?: 'osm';
maxZoom?: number;
url?: string;
ol?: olSourceOSM;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import olSourceTileArcGISRest from 'ol/source/TileArcGISRest';

import { DataSourceOptions } from './datasource.interface';

export interface TileArcGISRestDataSourceOptions extends DataSourceOptions {
Expand All @@ -14,6 +12,5 @@ export interface TileArcGISRestDataSourceOptions extends DataSourceOptions {
url?: string;
urls?: string[];

ol?: olSourceTileArcGISRest;
idColumn?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ export class TileArcGISRestDataSource extends DataSource {
: QueryHtmlTarget.BLANK;
}

get saveableOptions(): Partial<TileArcGISRestDataSourceOptions> {
const baseOptions = super.saveableOptions;
return {
...baseOptions,
params: this.options.params
};
}

protected createOlSource(): olSourceTileArcGISRest {
return new olSourceTileArcGISRest(this.options as Options);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import TileDebug from 'ol/source/TileDebug';

import { DataSourceOptions, TileGridOptions } from './datasource.interface';

export interface TileDebugDataSourceOptions extends DataSourceOptions {
projection?: string;
wrapX?: boolean;
ol?: TileDebug;
zDirection?: number;
tileGrid?: TileGridOptions;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import olSource from 'ol/source/Source';
import olSourceVector from 'ol/source/Vector';

import { OgcFiltersOptions } from '../../../filter';
import { FeatureDataSourceOptions } from './feature-datasource.interface';

export interface WFSDataSourceOptions extends FeatureDataSourceOptions {
// type?: 'wfs';
params: WFSDataSourceOptionsParams; // Used by user
paramsWFS?: WFSDataSourceOptionsParams; // Used by code
urlWfs?: string; // Used by code
ol?: olSourceVector | olSource;
ogcFilters?: OgcFiltersOptions;
}

// TODO: Are those WFS protocol params or something else? This is not clear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ export class WFSDataSource extends DataSource {
return (this.options as OgcFilterableDataSourceOptions).ogcFilters;
}

get saveableOptions(): Partial<WFSDataSourceOptions> {
const baseOptions = super.saveableOptions;
return {
...baseOptions,
params: this.options.params
};
}

constructor(
public options: WFSDataSourceOptions,
protected wfsService: WFSService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import olSource from 'ol/source/Source';
import olSourceVector from 'ol/source/Vector';
import type { ServerType } from 'ol/source/wms';

import { OgcFiltersOptions } from '../../../filter';
import { TimeFilterOptions } from '../../../filter/shared/time-filter.interface';
import { DataSourceOptions } from './datasource.interface';
import { WFSDataSourceOptionsParams } from './wfs-datasource.interface';
Expand All @@ -17,10 +16,11 @@ export interface WMSDataSourceOptions extends DataSourceOptions {
resolutions?: number[];
serverType?: ServerType;
ratio?: number;
ol?: olSourceVector | olSource;
refreshIntervalSec?: number;
contentDependentLegend?: boolean;
excludeAttribute?: string[];
excludeAttribute?: Array<string>;
ogcFilters?: OgcFiltersOptions;
timeFilter?: TimeFilterOptions;
}

export interface WMSDataSourceOptionsParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ export class WMSDataSource extends DataSource {
}
readonly timeFilter$ = new BehaviorSubject<TimeFilterOptions>(undefined);

get saveableOptions(): Partial<WMSDataSourceOptions> {
const baseOptions = super.saveableOptions;
return {
...baseOptions,
params: this.params
};
}

constructor(
public options: WMSDataSourceOptions,
protected wfsService: WFSService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import olSourceWMTS from 'ol/source/WMTS';

import { DataSourceOptions } from './datasource.interface';

export interface WMTSDataSourceOptions extends DataSourceOptions {
Expand All @@ -12,5 +10,4 @@ export interface WMTSDataSourceOptions extends DataSourceOptions {
matrixSet?: string;
url?: string;
urls?: string[];
ol?: olSourceWMTS;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import olSourceXYZ from 'ol/source/XYZ';

import { DataSourceOptions } from './datasource.interface';

export interface XYZDataSourceOptions extends DataSourceOptions {
// type?: 'xyz';
projection?: string;
ol?: olSourceXYZ;
url?: string;
urls?: string[];
pathOffline?: string;
Expand Down
Loading
Loading