Skip to content

Commit

Permalink
fix(geo-layer-id): id is the same with or whitout origin
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Aug 19, 2019
1 parent 1978446 commit 09e2218
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
54 changes: 30 additions & 24 deletions packages/geo/src/lib/catalog/shared/catalog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { EMPTY, Observable, of, concat } from 'rxjs';
import { map, catchError } from 'rxjs/operators';

import { uuid } from '@igo2/utils';
import { LanguageService, ConfigService } from '@igo2/core';
import {
CapabilitiesService,
Expand Down Expand Up @@ -40,36 +41,41 @@ export class CatalogService {
const apiUrl = catalogConfig.url || contextConfig.url;
const catalogsFromConfig = catalogConfig.sources || [];

if (apiUrl === undefined) {
return of(catalogsFromConfig);
}

const observables$ = [];

// Base layers catalog
if (catalogConfig.baseLayers) {
const translate = this.languageService.translate;
const title = translate.instant('igo.geo.catalog.baseLayers');
const baseLayersCatalog = {
id: 'catalog.baselayers',
title,
url: `${apiUrl}/baselayers`,
type: 'baselayers'
};
observables$.push(of(baseLayersCatalog));
}
if (apiUrl) {
// Base layers catalog
if (catalogConfig.baseLayers) {
const translate = this.languageService.translate;
const title = translate.instant('igo.geo.catalog.baseLayers');
const baseLayersCatalog = {
id: 'catalog.baselayers',
title,
url: `${apiUrl}/baselayers`,
type: 'baselayers'
};
observables$.push(of(baseLayersCatalog));
}

// Catalogs from API
const catalogsFromApi$ = this.http
.get<Catalog[]>(`${apiUrl}/catalogs`)
.pipe(
catchError((response: HttpErrorResponse) => EMPTY)
);
observables$.push(catalogsFromApi$);
// Catalogs from API
const catalogsFromApi$ = this.http
.get<Catalog[]>(`${apiUrl}/catalogs`)
.pipe(
catchError((response: HttpErrorResponse) => EMPTY)
);
observables$.push(catalogsFromApi$);
}

// Catalogs from config
if (catalogsFromConfig.length > 0) {
observables$.push(of(catalogsFromConfig));
observables$.push(of(catalogsFromConfig).pipe(
map((catalogs: Catalog[]) => catalogs.map((c) => {
if (!c.id) {
c.id = uuid();
}
return c;
}))
));
}

return concat(...observables$) as Observable<Catalog[]>;
Expand Down
3 changes: 2 additions & 1 deletion packages/geo/src/lib/datasource/utils/id-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export function generateIdFromSourceOptions(options: DataSourceOptions): string
*/
export function generateWMSIdFromSourceOptions(options: WMSDataSourceOptions) {
const layers = options.params.layers;
const chain = 'wms' + options.url + layers;
const url = options.url.charAt(0) === '/'? window.location.origin + options.url : options.url
const chain = 'wms' + url + layers;
return Md5.hashStr(chain) as string;
}

Expand Down

0 comments on commit 09e2218

Please sign in to comment.