Skip to content

Commit

Permalink
feat: Assign extent to WMTS layers
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipLeitner authored and raitisbe committed Jun 20, 2022
1 parent 5f2c83e commit 5d498f4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions projects/hslayers/src/components/add-data/url/wmts/wmts.service.ts
Expand Up @@ -6,12 +6,14 @@ import {Layer, Tile} from 'ol/layer';
import {Source} from 'ol/source';

import {CapabilitiesResponseWrapper} from '../../../../common/get-capabilities/capabilities-response-wrapper';
import {Extent} from 'ol/extent';
import {HsAddDataCommonService} from '../../common/common.service';
import {HsAddDataUrlService} from '../add-data-url.service';
import {HsLayoutService} from '../../../layout/layout.service';
import {HsMapService} from '../../../map/map.service';
import {HsUrlTypeServiceModel} from '../models/url-type-service.model';
import {addAnchors} from '../../../../common/attribution-utils';
import {transformExtent} from 'ol/proj';
import {urlDataObject} from '../types/data-object.type';

class HsUrlWmtsParams {
Expand Down Expand Up @@ -211,6 +213,21 @@ export class HsUrlWmtsService implements HsUrlTypeServiceModel {
}
}

/***
* Get WMTS layer bounding box
*/
getWMTSExtent(identifier: string, app: string): Extent {
const caps = this.get(app).data.caps;
const layer = caps.Contents.Layer.find((l) => l.Identifier == identifier);
return layer?.WGS84BoundingBox
? transformExtent(
layer.WGS84BoundingBox,
'EPSG:4326',
this.hsMapService.getCurrentProj(app)
)
: undefined;
}

/**
* Get WMTS layer
* Uses previously received capabilities response as a reference for the source
Expand All @@ -219,6 +236,7 @@ export class HsUrlWmtsService implements HsUrlTypeServiceModel {
getLayer(layer, options, app: string): Layer<Source> {
try {
const wmts = new Tile({
extent: this.getWMTSExtent(layer.Identifier, app),
properties: {
title: layer.Title,
name: layer.Title,
Expand Down

0 comments on commit 5d498f4

Please sign in to comment.