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

feat(context): save opacity and all datasource options #1686

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from
Draft
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
211 changes: 111 additions & 100 deletions packages/context/src/lib/context-manager/shared/context.interface.ts
Original file line number Diff line number Diff line change
@@ -1,100 +1,111 @@
import { Tool } from '@igo2/common/tool';
import { Message } from '@igo2/core/message';
import {
LayerOptions,
MapAttributionOptions,
MapExtent,
MapScaleLineOptions,
MapViewOptions
} from '@igo2/geo';

import { FeatureCollection } from 'geojson';

import { TypePermission } from './context.enum';

export interface Context {
id?: string;
title?: string;
uri?: string;
scope?: string; // Scope: 'public' | 'protected' | 'private';
permission?: string; // TypePermission: 'read' | 'write'
description?: string;
icon?: string;
iconImage?: string;
hidden?: boolean;
imported?: boolean;
}

export interface ContextsList {
ours: Context[];
shared?: Context[];
public?: Context[];
}

export type ExtraFeatures = FeatureCollection & {
name: string;
opacity: number;
visible: boolean;
};
export interface DetailedContext extends Context {
base?: string;
map?: ContextMap;
layers?: LayerOptions[];
tools?: Tool[];
toolbar?: string[];
message?: Message;
messages?: Message[];
removeLayersOnContextChange?: boolean;
extraFeatures?: ExtraFeatures[];
}

export interface ContextMapView extends MapViewOptions {
keepCurrentView?: boolean;
homeExtent?: ContextHomeExtent;
}

export interface ContextHomeExtent {
extent?: MapExtent;
center?: [number, number];
zoom?: number;
}

export interface ContextMap {
view: ContextMapView;
controls?: {
scaleLine?: boolean | MapScaleLineOptions;
attribution?: boolean | MapAttributionOptions;
};
}

export interface ContextServiceOptions {
url?: string;
basePath?: string;
contextListFile?: string;
defaultContextUri?: string;
}

export interface ContextPermission {
id?: string;
contextId?: string;
profil: string;
profilTitle?: string;
typePermission: TypePermission;
}

export interface ContextPermissionsList {
read: ContextPermission[];
write: ContextPermission[];
}

export interface ContextUserPermission {
name: string;
checked: boolean;
indeterminate?: boolean;
}

export interface ContextProfils {
name: string;
title: string;
childs?: ContextProfils[];
}
import { Tool } from '@igo2/common/tool';
import { Message } from '@igo2/core/message';
import {
AnyDataSourceOptions,
LayerOptions,
MapAttributionOptions,
MapExtent,
MapScaleLineOptions,
MapViewOptions
} from '@igo2/geo';

import { FeatureCollection } from 'geojson';

import { TypePermission } from './context.enum';

export interface Context {
id?: string;
title?: string;
uri?: string;
scope?: string; // Scope: 'public' | 'protected' | 'private';
permission?: string; // TypePermission: 'read' | 'write'
description?: string;
icon?: string;
iconImage?: string;
hidden?: boolean;
imported?: boolean;
}

export interface ContextsList {
ours: Context[];
shared?: Context[];
public?: Context[];
}

export type ExtraFeatures = FeatureCollection & {
name: string;
opacity: number;
visible: boolean;
};
export interface DetailedContext extends Context {
base?: string;
map?: ContextMap;
layers?: IContextLayer[];
tools?: Tool[];
toolbar?: string[];
message?: Message;
messages?: Message[];
removeLayersOnContextChange?: boolean;
extraFeatures?: ExtraFeatures[];
}

export interface ContextMapView extends MapViewOptions {
keepCurrentView?: boolean;
homeExtent?: ContextHomeExtent;
}

export interface ContextHomeExtent {
extent?: MapExtent;
center?: [number, number];
zoom?: number;
}

export interface ContextMap {
view: ContextMapView;
controls?: {
scaleLine?: boolean | MapScaleLineOptions;
attribution?: boolean | MapAttributionOptions;
};
}

export interface ContextServiceOptions {
url?: string;
basePath?: string;
contextListFile?: string;
defaultContextUri?: string;
}

export interface ContextPermission {
id?: string;
contextId?: string;
profil: string;
profilTitle?: string;
typePermission: TypePermission;
}

export interface ContextPermissionsList {
read: ContextPermission[];
write: ContextPermission[];
}

export interface ContextUserPermission {
name: string;
checked: boolean;
indeterminate?: boolean;
}

export interface ContextProfils {
name: string;
title: string;
childs?: ContextProfils[];
}

export interface IContextLayer {
id?: string;
layerId?: number;
contextId?: number;
layerOptions?:
| LayerOptions
| Pick<LayerOptions, 'title' | 'zIndex' | 'visible' | 'security'>;
sourceOptions?: AnyDataSourceOptions;
}
104 changes: 31 additions & 73 deletions packages/context/src/lib/context-manager/shared/context.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ import { LanguageService } from '@igo2/core/language';
import { Message, MessageService } from '@igo2/core/message';
import { RouteService } from '@igo2/core/route';
import { StorageService } from '@igo2/core/storage';
import type {
AnyLayerOptions,
IgoMap,
Layer,
VectorLayerOptions,
VectorTileLayerOptions
} from '@igo2/geo';
import type { IgoMap, Layer, LayerOptions } from '@igo2/geo';
import { ExportService } from '@igo2/geo';
import { ObjectUtils, uuid } from '@igo2/utils';

Expand Down Expand Up @@ -45,7 +39,8 @@ import {
ContextServiceOptions,
ContextsList,
DetailedContext,
ExtraFeatures
ExtraFeatures,
IContextLayer
} from './context.interface';

@Injectable({
Expand Down Expand Up @@ -464,41 +459,29 @@ export class ContextService {
tools: []
};

let layers = [];
if (empty === true) {
layers = igoMap.layers$
.getValue()
.filter(
(lay) =>
lay.baseLayer === true ||
const layers: Layer[] = igoMap.layers$
.getValue()
.filter((lay) =>
empty === true
? lay.baseLayer === true ||
lay.options.id === 'searchPointerSummaryId'
)
.sort((a, b) => a.zIndex - b.zIndex);
} else {
layers = igoMap.layers$
.getValue()
.filter((lay) => !lay.id.includes('WfsWorkspaceTableDest'))
.sort((a, b) => a.zIndex - b.zIndex);
}
: !lay.id.includes('WfsWorkspaceTableDest')
)
.sort((a, b) => a.zIndex - b.zIndex);

let i = 0;
for (const layer of layers) {
const layerOptions: AnyLayerOptions = {
const layerOptions: LayerOptions = {
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
}
sourceOptions: layer.dataSource.options
};
if (opts.sourceOptions.type) {
context.layers.push(opts);
Expand All @@ -509,7 +492,7 @@ export class ContextService {
return {
id: String(tool.id),
global: tool.global
} as Tool;
} as any; // the type doesn't match. @TODO Analyze the problematic with the api
});

return context;
Expand Down Expand Up @@ -559,48 +542,23 @@ export class ContextService {
});

layers.forEach((layer) => {
// Do not seem to work properly. layerFound is always undefined.
const layerFound = currentContext.layers.find((contextLayer) => {
const source = contextLayer.source;
return source && layer.id === source.id && !contextLayer.baseLayer;
});
if (layerFound) {
let layerFoundAs = layerFound as
| VectorLayerOptions
| VectorTileLayerOptions;
let layerStyle = layerFoundAs.style;
if (layerFoundAs.igoStyle?.styleByAttribute) {
layerStyle = undefined;
} else if (layerFoundAs.igoStyle?.clusterBaseStyle) {
layerStyle = undefined;
delete layerFound.sourceOptions[`source`];
delete layerFound.sourceOptions[`format`];
}
delete layerFound.source;
const opts: AnyLayerOptions = {
...layerFound,
title: layer.options.title,
zIndex: layer.zIndex,
style: layerStyle,
visible: layer.visible,
opacity: layer.opacity
};
context.layers.push(opts);
if (!(layer.ol.getSource() instanceof olVectorSource)) {
const catalogLayer = layer.options;
catalogLayer.zIndex = layer.zIndex;
catalogLayer.visible = layer.visible;
catalogLayer.opacity = layer.opacity;
delete catalogLayer.source;
context.layers.push({
id: catalogLayer.id,
layerOptions: catalogLayer,
sourceOptions: catalogLayer.sourceOptions
});
} else {
if (!(layer.ol.getSource() instanceof olVectorSource)) {
const catalogLayer = layer.options;
catalogLayer.zIndex = layer.zIndex;
(catalogLayer.visible = layer.visible),
(catalogLayer.opacity = layer.opacity);
delete catalogLayer.source;
context.layers.push(catalogLayer);
} else {
const extraFeatures = this.getExtraFeatures(layer);
extraFeatures.name = layer.options.title;
extraFeatures.opacity = layer.opacity;
extraFeatures.visible = layer.visible;
context.extraFeatures.push(extraFeatures);
}
const extraFeatures = this.getExtraFeatures(layer);
extraFeatures.name = layer.options.title;
extraFeatures.opacity = layer.opacity;
extraFeatures.visible = layer.visible;
context.extraFeatures.push(extraFeatures);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ export class ShareMapService {
for (const contextLayer of contextLayers) {
if (
typeof contextLayer.id !== 'undefined' ||
typeof contextLayer.source !== 'undefined'
typeof (contextLayer as any).source !== 'undefined'
) {
contextLayersID.push(contextLayer.id || contextLayer.source.id);
contextLayersID.push(
contextLayer.id || (contextLayer as any).source.id
);
}
}

Expand Down
Loading