Skip to content

Commit

Permalink
feat(add-data-url-wms): Run capabilities/legend requests in queue
Browse files Browse the repository at this point in the history
  • Loading branch information
DailisLangovskis authored and raitisbe committed Aug 10, 2021
1 parent 5694244 commit a39ccde
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -56,6 +56,7 @@
"ol-popup": "^4.0.0",
"passport-oauth2-middleware": "^1.0.3",
"proj4": "^2.7.5",
"queue": "^6.0.2",
"rxjs": "^6.6.7",
"share-api-polyfill": "^1.0.21",
"tslib": "^2.3.0",
Expand Down
Expand Up @@ -56,6 +56,7 @@ export class HsAddDataUrlWmsService {
registerMetadata: true,
tileSize: 512,
addUnder: null,
visible: true,
};

this.hsEventBusService.olMapLoads.subscribe(() => {
Expand Down Expand Up @@ -341,7 +342,7 @@ export class HsAddDataUrlWmsService {
if (this.data.services === undefined) {
return;
}

this.setAddedLayerVisibility();
if (this.data.base) {
this.addLayer(
{
Expand All @@ -364,7 +365,6 @@ export class HsAddDataUrlWmsService {
this.data.base = false;
this.hsLayoutService.setMainPanel('layermanager');
}

createBasemapName(services): string {
const names = [];
for (const layer of services.filter((layer) => layer.checked)) {
Expand All @@ -373,6 +373,16 @@ export class HsAddDataUrlWmsService {
return names.join(',');
}

setAddedLayerVisibility(): void {
const selectedLayersLength = this.data.services.filter(
(layer) => layer.checked === true
).length;
if (selectedLayersLength > 10) {
this.data.visible = false;
} else {
this.data.visible = true;
}
}
/**
* @param service
* @returns {Array}
Expand Down Expand Up @@ -510,6 +520,7 @@ export class HsAddDataUrlWmsService {
legends: legends,
subLayers: subLayers,
base: this.data.base,
visible: this.data.visible,
});
this.hsMapService.proxifyLayerLoader(new_layer, this.data.useTiles);
this.hsAddDataService.addLayer(new_layer, this.data.addUnder);
Expand Down
Expand Up @@ -252,6 +252,7 @@ export class HsLayerManagerMetadataService {
*/
async queryMetadata(layerDescriptor: HsLayerDescriptor): Promise<boolean> {
const layer = layerDescriptor.layer;
let capabilities = '';
const url = this.HsLayerUtilsService.getURL(layer);
if (!url) {
return;
Expand Down
11 changes: 9 additions & 2 deletions projects/hslayers/src/components/legend/legend.component.ts
Expand Up @@ -7,6 +7,8 @@ import {HsLayerUtilsService} from '../utils/layer-utils.service';
import {HsLegendDescriptor} from './legend-descriptor.interface';
import {HsLegendService} from './legend.service';
import {HsMapService} from '../map/map.service';
import {HsUtilsService} from '../utils/utils.service';

@Component({
selector: 'hs-legend',
templateUrl: './partials/legend.html',
Expand All @@ -18,7 +20,8 @@ export class HsLegendComponent {
constructor(
public HsLegendService: HsLegendService,
public HsMapService: HsMapService,
public HsLayerUtilsService: HsLayerUtilsService
public HsLayerUtilsService: HsLayerUtilsService,
public hsUtilsService: HsUtilsService
) {
this.HsMapService.loaded().then((map) => this.init(map));
}
Expand Down Expand Up @@ -106,7 +109,11 @@ export class HsLegendComponent {
* @private
*/
layerAdded(e): void {
this.addLayerToLegends(e.element);
this.hsUtilsService.createQueue('addLayerToLegends', 3);
this.hsUtilsService.queues['addLayerToLegends'].q.push(async (cb) => {
this.addLayerToLegends(e.element);
cb(null);
});
}

/**
Expand Down
18 changes: 18 additions & 0 deletions projects/hslayers/src/components/utils/utils.service.ts
@@ -1,3 +1,4 @@
import queue from 'queue';
import {HsConfig} from './../../config.service';
import {HsLogService} from './../../common/log/log.service';
import {HttpClient} from '@angular/common/http';
Expand All @@ -7,6 +8,11 @@ import {isPlatformBrowser} from '@angular/common';

@Injectable()
export class HsUtilsService {
queues: {
[usecase: string]: {
q: any; // queueObject
};
} = {};
constructor(
public HsConfig: HsConfig,
private http: HttpClient,
Expand Down Expand Up @@ -368,6 +374,18 @@ export class HsUtilsService {
objectToCheck && {}.toString.call(objectToCheck) === '[object Object]'
);
}
createQueue(useCase: string, customConcurrency?: number): void {
if (this.queues[useCase]) {
return;
}
this.queues[useCase] = {
q: queue({results: [], concurrency: customConcurrency || 5}),
};
this.queues[useCase].q.autostart = true;
this.queues[useCase].q.on('end', () => {
delete this.queues[useCase];
});
}

/**
* Check if object is an instance of a class
Expand Down

0 comments on commit a39ccde

Please sign in to comment.