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(catalog)Keep catalog's sort for added layers #448

Merged
merged 3 commits into from
Oct 4, 2019
Merged
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
Expand Up @@ -175,20 +175,50 @@ export class CatalogBrowserComponent implements OnInit, OnDestroy {
});
}

/**
* Sort the layers by title. asc or desc.
* @internal
*/
private sortCatalogItemsByTitle(items: CatalogItem[], direction) {
const returnItem = items.sort((a, b) => {
const titleA = a.title.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
const titleB = b.title.normalize('NFD').replace(/[\u0300-\u036f]/g, '');

if (titleA < titleB) {
return -1;
}
if (titleA > titleB) {
return 1;
}
return 0;
});
switch (direction) {
case 'asc':
return returnItem;
case 'desc':
return returnItem.reverse();
default:
return items;
}
}

/**
* Add all the layers of a group to map
* @param group Catalog group
*/
private addGroupToMap(group: CatalogItemGroup) {
const layers = group.items.filter((item: CatalogItem) => {
let layers = group.items.filter((item: CatalogItem) => {
const added = this.store.state.get(item).added || false;
return this.isLayer(item) && added === false;
});
if (this.catalog && this.catalog.sortDirection !== undefined) {
layers = this.sortCatalogItemsByTitle(layers, this.catalog.sortDirection);
}
this.addLayersToMap(layers.reverse() as CatalogItemLayer[]);
}

/**
* Remove all the layers of a groufrom map
* Remove all the layers of a group from map
* @param group Catalog group
*/
private removeGroupFromMap(group: CatalogItemGroup) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface IChercheData {
geometry: FeatureGeometry;
bbox: [number, number, number, number];
properties: { [key: string]: any };
icon?: string
icon?: string;
highlight: {
title: string;
title2?: string;
Expand All @@ -20,7 +20,7 @@ export interface IChercheResponse {
export interface IChercheReverseData {
geometry: FeatureGeometry;
bbox: [number, number, number, number];
icon?: string
icon?: string;
properties: { [key: string]: any };
}

Expand Down