Skip to content

Commit

Permalink
feat(imported vector): allow to store vector data and layer in indexe…
Browse files Browse the repository at this point in the history
…ddb (#1204)

* fix(demo): unable to add layers from the catalog

* refactor(*):unifying styles in a single directory

* refactor(*):unifying styles in a single directory

* refactor(style-modal): move to style directory

* wip

* fix(context): crash on context export with vector data (infra-geo-ouverte/igo2#711)

* refactor(import-style): random style based on attributes

* BREAKING CHANGE(style): Various style interface moved into igoStyle property

* wip

* wip

* wip

* wip

* refactor(style-modal): renaming style-modal to style-modal-drawing

* feat(style): methods to change imported vector layer style (base style only)

* wip merge conflict resolution

* feat(confirm-dialog): now support translations

* feat(*): allow to store imported data to indexed db

* wip

* feat(indexeddb): adding a store to save layers

* wip

* feat(imported vector): allow to store vector data and layer in indexeddb

* wip

* lint

* feat(import): add a config allowToStoreLayer to control layer storage

* wip

* wip

* fix(longpress): prevent multitouch event emissioon

* feat(geolocation): code refactor + better handling view zom/move when followposition is true

* wip

* feat(geolocation): added feature to show movement direction

* wip

* lint

* wip

* feat(geolocation): changed orientation symbol style and now checks speed as well to determine mobility

* feat(workspace):add option to index or not content

* wip

* wip

* lint

* fix(map): set resolution to 0 was impossible

* BREAKING CHANGE(OFFLINE): major refactor and some properties moved

* wip

* wip

* wip

* wip

* wip

* feat(geolocation): fixed condition to change arrow orientation

* feat(geolocation): fixed possibly undefined speed in orientation check

---------

Co-authored-by: Simon Castonguay <[email protected]>
  • Loading branch information
pelord and CASSI01 authored Apr 20, 2023
1 parent 566d0f4 commit 7862664
Show file tree
Hide file tree
Showing 16 changed files with 2,009 additions and 1,847 deletions.
3,482 changes: 1,690 additions & 1,792 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,7 @@ export class LayerContextDirective implements OnInit, OnDestroy {
layersAndIndex$
.pipe(buffer(layersAndIndex$.pipe(debounceTime(500))))
.subscribe((layers: Layer[]) => {
layers = layers
.filter((layer: Layer) => layer !== undefined)
.map((layer) => {
layer.visible = this.computeLayerVisibilityFromUrl(layer);
layer.zIndex = layer.zIndex;

return layer;
});

this.contextLayers.concat(layers);
this.map.addLayers(layers);
this.handleAddLayers(layers);

if (context.extraFeatures) {
context.extraFeatures.forEach((featureCollection) => {
Expand Down Expand Up @@ -137,6 +127,23 @@ export class LayerContextDirective implements OnInit, OnDestroy {
});
}
});

this.layerService.createAsyncIdbLayers(context.uri).pipe(debounceTime(500))
.subscribe((layers: Layer[]) => this.handleAddLayers(layers));

}

private handleAddLayers(layers: Layer[]) {
layers = layers
.filter((layer: Layer) => layer !== undefined)
.map((layer) => {
layer.visible = this.computeLayerVisibilityFromUrl(layer);
layer.zIndex = layer.zIndex;

return layer;
});
this.contextLayers.concat(layers);
this.map.addLayers(layers);
}

private computeLayerVisibilityFromUrl(layer: Layer): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
import { StyleService } from '../../style/style-service/style.service';
import { StyleListService } from '../../style/style-list/style-list.service';
import { skipWhile } from 'rxjs/operators';
import { EntityRecord, Workspace } from '@igo2/common';
import { ConfirmDialogService, EntityRecord, Workspace } from '@igo2/common';
import type { WorkspaceStore } from '@igo2/common';
import { WfsWorkspace } from '../../workspace/shared/wfs-workspace';
import { EditionWorkspace } from '../../workspace/shared/edition-workspace';
Expand All @@ -56,6 +56,7 @@ import { computeProjectionsConstraints } from '../../map';
import olVectorSource from 'ol/source/Vector';
import olClusterSource from 'ol/source/Cluster';
import type { default as OlGeometry } from 'ol/geom/Geometry';
import { LayerService } from '../../layer/shared/layer.service';
import { ImportExportServiceOptions } from '../shared/import.interface';

@Component({
Expand Down Expand Up @@ -107,6 +108,8 @@ export class ImportExportComponent implements OnDestroy, OnInit {

@Input() map: IgoMap;

@Input() contextUri: string;

private _projectionsLimitations: ProjectionsLimitationsOptions = {};
@Input()
set projectionsLimitations(value: ProjectionsLimitationsOptions) {
Expand Down Expand Up @@ -165,7 +168,9 @@ export class ImportExportComponent implements OnDestroy, OnInit {
private config: ConfigService,
private cdRef: ChangeDetectorRef,
private storageService: StorageService,
private downloadService: DownloadService
private downloadService: DownloadService,
private layerService: LayerService,
private confirmDialogService: ConfirmDialogService
) {
this.loadConfig();
this.buildForm();
Expand Down Expand Up @@ -743,6 +748,7 @@ export class ImportExportComponent implements OnDestroy, OnInit {

private onFileImportSuccess(file: File, features: Feature[]) {
const importExportOptions = this.config.getConfig('importExport') as ImportExportServiceOptions;
const confirmDialogService = importExportOptions?.allowToStoreLayer ? this.confirmDialogService : undefined;
const importWithStyle =importExportOptions?.importWithStyle || this.config.getConfig('importWithStyle');
if (this.config.getConfig('importWithStyle')) {
console.warn(`
Expand All @@ -758,14 +764,20 @@ export class ImportExportComponent implements OnDestroy, OnInit {
file,
features,
this.map,
this.messageService
this.contextUri,
this.messageService,
this.layerService,
confirmDialogService
);
} else {
handleFileImportSuccess(
file,
features,
this.map,
this.contextUri,
this.messageService,
this.layerService,
confirmDialogService,
this.styleListService,
this.styleService
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Directive, HostListener, EventEmitter, OnInit, OnDestroy } from '@angular/core';
import { Directive, HostListener, EventEmitter, OnInit, OnDestroy, Input } from '@angular/core';

import { BehaviorSubject, Subscription } from 'rxjs';

import { MessageService, ConfigService } from '@igo2/core';
import { DragAndDropDirective } from '@igo2/common';
import { ConfirmDialogService, DragAndDropDirective } from '@igo2/common';

import { Feature } from '../../feature/shared/feature.interfaces';
import { IgoMap } from '../../map/shared/map';
Expand All @@ -13,6 +13,7 @@ import { handleFileImportSuccess, handleFileImportError } from '../shared/import
import { StyleService } from '../../style/style-service/style.service';
import { StyleListService } from '../../style/style-list/style-list.service';
import { concatMap, first, skipWhile } from 'rxjs/operators';
import { LayerService } from '../../layer/shared/layer.service';
import { ImportExportServiceOptions } from './import.interface';

@Directive({
Expand All @@ -30,13 +31,17 @@ export class DropGeoFileDirective extends DragAndDropDirective implements OnInit
return this.component.map;
}

@Input() contextUri: string;

constructor(
private component: MapBrowserComponent,
private importService: ImportService,
private styleListService: StyleListService,
private styleService: StyleService,
private config: ConfigService,
private messageService: MessageService
private messageService: MessageService,
private layerService: LayerService,
private confirmDialogService: ConfirmDialogService
) {
super();
}
Expand Down Expand Up @@ -140,11 +145,19 @@ export class DropGeoFileDirective extends DragAndDropDirective implements OnInit
This legacy conversion will be deleted in 2024.
`);
}
const confirmDialogService = importExportOptions?.allowToStoreLayer ? this.confirmDialogService : undefined;
if (!importWithStyle) {
handleFileImportSuccess(file, features, this.map, this.messageService);
handleFileImportSuccess(
file,
features,
this.map,
this.contextUri,
this.messageService,
this.layerService,
confirmDialogService);
} else {
handleFileImportSuccess(file, features, this.map, this.messageService,
this.styleListService, this.styleService);
handleFileImportSuccess(file, features, this.map, this.contextUri, this.messageService,
this.layerService, confirmDialogService, this.styleListService, this.styleService);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export interface ImportExportServiceOptions {
forceNaming?: boolean;
formats?: ExportFormat[];
configFileToGeoDBService?: string;
allowToStoreLayer?: boolean;
importWithStyle?: boolean;
}
72 changes: 52 additions & 20 deletions packages/geo/src/lib/import-export/shared/import.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,25 @@ import { ClusterDataSource } from '../../datasource/shared/datasources/cluster-d
import { ClusterDataSourceOptions } from '../../datasource/shared/datasources/cluster-datasource.interface';
import { uuid } from '@igo2/utils';
import { featureRandomStyle, featureRandomStyleFunction } from '../../style/shared/feature/feature-style';
import { LayerService } from '../../layer/shared/layer.service';
import { ConfirmDialogService } from '@igo2/common';
import { first, of } from 'rxjs';

export function addLayerAndFeaturesToMap(
features: Feature[],
map: IgoMap,
layerTitle: string
contextUri: string,
layerTitle: string,
layerService: LayerService,
storeToIdb: boolean = false
): VectorLayer {
const olFeatures = features.map((feature: Feature) =>
featureToOl(feature, map.projection)
);

const id = uuid();
const sourceOptions: FeatureDataSourceOptions & QueryableDataSourceOptions = {
id,
type: 'vector',
queryable: true
};
Expand All @@ -45,14 +53,16 @@ export function addLayerAndFeaturesToMap(
randomStyle = featureRandomStyle();
editable = true;
}
const layer = new VectorLayer({
const layer = layerService.createLayer({
id,
title: layerTitle,
workspace: { enabled: true, searchIndexEnabled: true },
isIgoInternalLayer: true,
source,
igoStyle: { editable },
idbInfo: { firstLoad: true, storeToIdb, contextUri: contextUri || '*' },
style: randomStyle
});
}) as VectorLayer;
layer.setExtent(computeOlFeaturesExtent(map, olFeatures));
map.addLayer(layer);
moveToOlFeatures(map, olFeatures);
Expand Down Expand Up @@ -182,11 +192,18 @@ export function addLayerAndFeaturesStyledToMap(
return layer;
}

function padTo2Digits(num) {
return num.toString().padStart(2, '0');
}

export function handleFileImportSuccess(
file: File,
features: Feature[],
map: IgoMap,
contextUri: string,
messageService: MessageService,
layerService: LayerService,
confirmDialogService?: ConfirmDialogService,
styleListService?: StyleListService,
styleService?: StyleService
) {
Expand All @@ -195,24 +212,39 @@ export function handleFileImportSuccess(
return;
}

const layerTitle = computeLayerTitleFromFile(file);
let layerTitle = computeLayerTitleFromFile(file);

if (!styleListService) {
addLayerAndFeaturesToMap(features, map, layerTitle);
} else {
addLayerAndFeaturesStyledToMap(
features,
map,
layerTitle,
styleListService,
styleService
);
}
messageService.success(
'igo.geo.dropGeoFile.success.text',
'igo.geo.dropGeoFile.success.title',
undefined,
{ value: layerTitle });
const obs$ = confirmDialogService ? confirmDialogService.open('igo.geo.import.promptStoreToIdb') : of(false);

obs$.pipe(first()).subscribe((confirm) => {
const d = new Date();
const dformat =
[d.getFullYear(),
padTo2Digits(d.getMonth() + 1),
padTo2Digits(d.getDate()), ].join('/') +
' ' +
[padTo2Digits(d.getHours()),padTo2Digits(d.getMinutes())].join(':');


layerTitle = confirm ? `${layerTitle} (${dformat})` : layerTitle;
if (!styleListService) {
addLayerAndFeaturesToMap(features, map, contextUri, layerTitle, layerService, confirm);
} else {
addLayerAndFeaturesStyledToMap(
features,
map,
layerTitle,
styleListService,
styleService
);
}

messageService.success(
'igo.geo.dropGeoFile.success.text',
'igo.geo.dropGeoFile.success.title',
undefined,
{ value: layerTitle });
});
}

export function handleFileImportError(
Expand Down
Loading

0 comments on commit 7862664

Please sign in to comment.