src/utility/eposLeaflet/components/layers/wmtsTileLayer.ts
constructor(id: string, name?: string)
|
Protected getCapabilitiesPromise |
Type : null | Promise<JQuery<XMLDocument>>
|
Protected getCapabilitiesXML |
Type : JQuery<XMLDocument>
|
Public attr |
Type : string
|
Inherited from
TileLayer
|
Defined in
TileLayer:23
|
Public sd |
Type : Array<string>
|
Inherited from
TileLayer
|
Defined in
TileLayer:24
|
Public url |
Type : string
|
Inherited from
TileLayer
|
Defined in
TileLayer:22
|
Public addedToMap |
Default value : new SimpleConfigObservableWithValue<this, null | boolean>(this)
|
Inherited from
MapLayer
|
Defined in
MapLayer:123
|
The above code is declaring a public property called "addedToMap" which is an instance of the "SimpleConfigObservableWithValue" class. This class is a generic class that takes two type parameters: "this" and "null | boolean". The "this" type parameter refers to the current class, while the "null | boolean" type parameter represents a value that can be either null or boolean. |
Static Readonly BBOX_EDITABLE_LAYER_ID |
Type : string
|
Default value : 'editablebbox'
|
Inherited from
MapLayer
|
Defined in
MapLayer:77
|
The above code is declaring a public static readonly variable named BBOX_EDITABLE_LAYER_ID with the value 'editablebbox'. |
Static Readonly BBOX_LAYER_ID |
Type : string
|
Default value : 'spatialbbox'
|
Inherited from
MapLayer
|
Defined in
MapLayer:73
|
The above code is declaring a public static readonly variable named BBOX_LAYER_ID with the value 'spatialbbox'. |
Protected clickSource |
Default value : new Subject<L.LeafletMouseEvent>()
|
Inherited from
MapLayer
|
Defined in
MapLayer:147
|
The above code is defining a protected property called "clickSource" which is an instance of the Subject class from the RxJS library. This Subject is specifically configured to emit LeafletMouseEvent objects. |
Static Readonly DEFAULT_LAYER_LEGEND_LABEL |
Type : []
|
Default value : [
{
type: this.MARKERTYPE_POINT,
value: 'Default Marker'
},
{
type: this.MARKERTYPE_POLYGON,
value: 'Default Polygon'
},
{
type: this.MARKERTYPE_LINE,
value: 'Default Line'
},
]
|
Inherited from
MapLayer
|
Defined in
MapLayer:86
|
The above code is defining a static readonly array called DEFAULT_LAYER_LEGEND_LABEL. This array contains objects with two properties: type and value. Each object represents a different type of marker (point, polygon, or line) and its corresponding label. |
Protected eposLeaflet |
Type : EposLeafletComponent
|
Inherited from
MapLayer
|
Defined in
MapLayer:163
|
The above code is declaring a protected variable called "eposLeaflet" of type "EposLeafletComponent". |
Public hidden |
Default value : new SimpleConfigObservableWithValue<this, boolean>(this, false)
|
Inherited from
MapLayer
|
Defined in
MapLayer:136
|
The above code is declaring a public property called "hidden" of type "SimpleConfigObservableWithValue". It is initializing this property with a new instance of "SimpleConfigObservableWithValue" and passing in the current object (this) and a boolean value of false. |
Public id |
Type : string
|
Inherited from
MapLayer
|
Defined in
MapLayer:102
|
The above code is declaring a public property called "id" of type string in a TypeScript class. |
Static Readonly IMAGE_OVERLAY_LAYER_TYPE |
Type : string
|
Default value : 'imageOverlay'
|
Inherited from
MapLayer
|
Defined in
MapLayer:81
|
The above code is defining a public static readonly variable named IMAGE_OVERLAY_LAYER_TYPE with the value 'imageOverlay'. |
Protected layerBboxRetrieverFunction |
Type : function
|
Inherited from
MapLayer
|
Defined in
MapLayer:159
|
Protected layerClickFeatureItemGenerator |
Type : null | FeatureDisplayItemGenerator
|
Inherited from
MapLayer
|
Defined in
MapLayer:151
|
The above code is declaring a protected property called |
Protected leafletMapLayer |
Type : L.Layer
|
Inherited from
MapLayer
|
Defined in
MapLayer:170
|
The above code is declaring a protected variable called "leafletMapLayer" of type L.Layer. |
Protected leafletWrapperLayer |
Type : L.LayerGroup
|
Inherited from
MapLayer
|
Defined in
MapLayer:167
|
The above code is declaring a protected variable called "leafletWrapperLayer" of type "L.LayerGroup" in TypeScript. |
Protected legendCreatorFunction |
Type : function
|
Inherited from
MapLayer
|
Defined in
MapLayer:157
|
The above code is defining a protected property called |
Static Readonly MARKERTYPE_CHARACTER |
Type : string
|
Default value : 'character'
|
Inherited from
MapLayer
|
Defined in
MapLayer:61
|
The above code is defining a public static readonly variable named MARKERTYPE_CHARACTER with the value 'character'. |
Static Readonly MARKERTYPE_FA |
Type : string
|
Default value : 'font_awesome'
|
Inherited from
MapLayer
|
Defined in
MapLayer:57
|
The above code is declaring a public static readonly variable named MARKERTYPE_FA and assigning it the value 'font_awesome'. |
Static Readonly MARKERTYPE_IMAGE |
Type : string
|
Default value : 'image'
|
Inherited from
MapLayer
|
Defined in
MapLayer:53
|
The above code is defining a public static readonly variable named MARKERTYPE_IMAGE with the value 'image'. |
Static Readonly MARKERTYPE_LINE |
Type : string
|
Default value : 'line'
|
Inherited from
MapLayer
|
Defined in
MapLayer:45
|
The above code is defining a public static readonly variable named MARKERTYPE_LINE with the value 'line'. |
Static Readonly MARKERTYPE_PIN_FA |
Type : string
|
Default value : 'pin_font_awesome'
|
Inherited from
MapLayer
|
Defined in
MapLayer:65
|
The above code is declaring a public static readonly variable named MARKERTYPE_PIN_FA and assigning it the value 'pin_font_awesome'. |
Static Readonly MARKERTYPE_POINT |
Type : string
|
Default value : 'point'
|
Inherited from
MapLayer
|
Defined in
MapLayer:41
|
The above code is defining a public static readonly variable called MARKERTYPE_POINT with the value 'point'. |
Static Readonly MARKERTYPE_POLYGON |
Type : string
|
Default value : 'poly'
|
Inherited from
MapLayer
|
Defined in
MapLayer:49
|
The above code is defining a public static readonly variable named MARKERTYPE_POLYGON with the value 'poly'. |
Static Readonly MARKERTYPE_RAW |
Type : string
|
Default value : 'raw'
|
Inherited from
MapLayer
|
Defined in
MapLayer:69
|
The above code is declaring a public static readonly variable named MARKERTYPE_RAW and assigning it the value 'raw'. |
Public name |
Type : string
|
Inherited from
MapLayer
|
Defined in
MapLayer:105
|
The above code is declaring a public property called "name" of type string in a TypeScript class. |
Public options |
Default value : new LayerOptions<this>(this)
|
Inherited from
MapLayer
|
Defined in
MapLayer:142
|
The above code is declaring a public property called "options" and initializing it with a new instance of the "LayerOptions" class. The "LayerOptions" class is a generic class that takes the current class as a type parameter. This allows the "options" property to have access to the properties and methods of the current class. |
Public toggleable |
Default value : new SimpleConfigObservableWithValue<this, boolean>(this, true)
|
Inherited from
MapLayer
|
Defined in
MapLayer:130
|
The above code is declaring a public property called "toggleable" of type "SimpleConfigObservableWithValue" with a generic parameter of "this" (referring to the current class) and "boolean". It is initializing this property with a new instance of "SimpleConfigObservableWithValue" and passing in the current class (this) and a boolean value of true as arguments. |
Public tryToRender |
Default value : new SimpleConfigValue<this, boolean>(this, true)
|
Inherited from
MapLayer
|
Defined in
MapLayer:117
|
The above code is declaring a public variable named "tryToRender" of type "SimpleConfigValue" with a generic parameter of "this" (referring to the current class) and "boolean". It is initializing this variable with a new instance of "SimpleConfigValue" and passing in the current class instance (this) and a boolean value of true as arguments. |
Protected userPostLayerAddFunction |
Type : function
|
Default value : () => {...}
|
Inherited from
MapLayer
|
Defined in
MapLayer:494
|
The above code is defining a protected property called |
Protected userPostLayerRemoveFunction |
Type : function
|
Default value : () => {...}
|
Inherited from
MapLayer
|
Defined in
MapLayer:506
|
The above code is defining a protected property called |
Protected userPreLayerAddFunction |
Type : function
|
Default value : () => {...}
|
Inherited from
MapLayer
|
Defined in
MapLayer:488
|
The above code is defining a protected property called |
Protected userPreLayerRemoveFunction |
Type : function
|
Default value : () => {...}
|
Inherited from
MapLayer
|
Defined in
MapLayer:500
|
The above code is defining a protected property called |
Public visibleOnLayerControl |
Default value : new SimpleConfigValue<this, boolean>(this, true)
|
Inherited from
MapLayer
|
Defined in
MapLayer:111
|
The above code is declaring a public property called |
Public createLegendsDefault | |||||||||
createLegendsDefault(layer: WmtsTileLayer, http: HttpClient)
|
|||||||||
Parameters :
Returns :
Promise<null | Array>
|
Public getCapabilitiesXml | ||||||
getCapabilitiesXml(http: HttpClient)
|
||||||
Parameters :
Returns :
Promise<JQuery<XMLDocument>>
|
Public getElementWithName | ||||||||||||
getElementWithName($srcXml: JQuery
|
||||||||||||
Parameters :
Returns :
null | JQuery
|
Public getLeafletLayer |
getLeafletLayer()
|
Inherited from
MapLayer
|
Defined in
MapLayer:70
|
Returns :
Promise<null | L.Layer>
|
Public setFeatureIdentifiable | ||||||
setFeatureIdentifiable(itemGenerator?: FeatureDisplayItemGenerator)
|
||||||
Parameters :
|
Public setAttr | ||||||||
setAttr(attr: string)
|
||||||||
Inherited from
TileLayer
|
||||||||
Defined in
TileLayer:53
|
||||||||
The function
Parameters :
|
Public setSubdomain | ||||||||
setSubdomain(sd: Array
|
||||||||
Inherited from
TileLayer
|
||||||||
Defined in
TileLayer:70
|
||||||||
The function
Parameters :
|
Public setUrl | ||||||||
setUrl(url: string)
|
||||||||
Inherited from
TileLayer
|
||||||||
Defined in
TileLayer:41
|
||||||||
The function
Parameters :
|
Public addClickListener | ||||||||
addClickListener(func: (clickEvent: L.LeafletMouseEvent) => void)
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:426
|
||||||||
The addClickListener function subscribes to a click event source and executes a callback function
when a click event occurs.
Parameters :
|
Public addSelfToMap | ||||||||
addSelfToMap(eposLeaflet: EposLeafletComponent)
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:229
|
||||||||
The function
Parameters :
Returns :
Promise<void>
The function |
Protected bringLayerToBack | ||||||||
bringLayerToBack(refIndex: number)
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:642
|
||||||||
The function brings a layer to the back of the map. layer you want to bring to the back.
Parameters :
Returns :
void
|
Protected bringLayerToFront | ||||||||
bringLayerToFront(refIndex: number)
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:632
|
||||||||
The function brings a specific layer to the front in a Leaflet map. layer that you want to bring to the front.
Parameters :
Returns :
void
|
Protected checkOpacityOnAdd |
checkOpacityOnAdd()
|
Inherited from
MapLayer
|
Defined in
MapLayer:583
|
The function checks the opacity value for a custom layer option and sets it to a default value if it is not provided, and triggers an update if necessary.
Returns :
void
|
Public click | ||||||||
click(clickEvent: L.LeafletMouseEvent)
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:415
|
||||||||
The click function in TypeScript triggers a click event and emits it to the clickSource. event object that is triggered when a click event occurs on a Leaflet map.
Parameters :
Returns :
void
|
Protected ensureAddedToMap |
ensureAddedToMap()
|
Inherited from
MapLayer
|
Defined in
MapLayer:545
|
The function
Returns :
Promise<void>
A Promise that resolves to void. |
Public getEposLeaflet |
getEposLeaflet()
|
Inherited from
MapLayer
|
Defined in
MapLayer:475
|
The function returns an instance of the EposLeafletComponent.
Returns :
EposLeafletComponent
The method is returning an instance of the EposLeafletComponent. |
Public getLayerBbox | ||||||
getLayerBbox(http: HttpClient)
|
||||||
Inherited from
MapLayer
|
||||||
Defined in
MapLayer:399
|
||||||
Parameters :
Returns :
Promise<null | Array>
|
Public getLayerClickFeatureItem | ||||||||||||
getLayerClickFeatureItem(clickEvent: L.LeafletMouseEvent, http: HttpClient)
|
||||||||||||
Inherited from
MapLayer
|
||||||||||||
Defined in
MapLayer:462
|
||||||||||||
The function returns an array of feature display items based on a click event and an HTTP client.
It contains information about the click event, such as the coordinates of the click and the target
element that was clicked on.
used to make HTTP requests. It is likely being used in the
Parameters :
Returns :
Promise<Array<FeatureDisplayItem>>
a Promise that resolves to an array of FeatureDisplayItem objects. |
Public getLayerClickFeatureItemGenerator |
getLayerClickFeatureItemGenerator()
|
Inherited from
MapLayer
|
Defined in
MapLayer:448
|
The function returns the layerClickFeatureItemGenerator or null. class.
Returns :
null | FeatureDisplayItemGenerator
The method is returning either null or an instance of the FeatureDisplayItemGenerator class. |
Protected getLeafletLayerFromMap |
getLeafletLayerFromMap()
|
Inherited from
MapLayer
|
Defined in
MapLayer:567
|
The function returns a Leaflet layer object from a map based on a specified ID.
Returns :
null | L.Layer
either |
Public getLegendData | ||||||||
getLegendData(http: HttpClient)
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:386
|
||||||||
The function
Parameters :
Returns :
Promise<null | Array>
a Promise that resolves to either null or an array of Legend objects. |
Public getStylable |
getStylable()
|
Inherited from
MapLayer
|
Defined in
MapLayer:482
|
The function returns an instance of the Stylable class or void.
Returns :
Stylable | void
|
Protected hasImageOverlay | ||||||||
hasImageOverlay(data: GeoJsonObject)
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:689
|
||||||||
The function checks if a given GeoJsonObject has an image overlay. type representing a GeoJSON object. GeoJSON is a format for encoding a variety of geographic data structures. It can represent different types of geometries (e.g., points, lines, polygons) and collections of features (
Parameters :
Returns :
boolean
a boolean value. |
Protected postLayerAdd |
postLayerAdd()
|
Inherited from
MapLayer
|
Defined in
MapLayer:520
|
The function "postLayerAdd" returns a promise that resolves to void.
Returns :
Promise<void>
A Promise that resolves to void. |
Protected postLayerRemove |
postLayerRemove()
|
Inherited from
MapLayer
|
Defined in
MapLayer:536
|
The function "postLayerRemove" returns a promise that resolves to void.
Returns :
Promise<void>
A Promise that resolves to void. |
Protected preLayerAdd |
preLayerAdd()
|
Inherited from
MapLayer
|
Defined in
MapLayer:513
|
The function ensures that a specific pane exists in a Leaflet map.
Returns :
Promise<void>
A Promise that resolves to void. |
Protected preLayerRemove |
preLayerRemove()
|
Inherited from
MapLayer
|
Defined in
MapLayer:528
|
The function "preLayerRemove" returns a promise that resolves to void.
Returns :
Promise<void>
A Promise that resolves to void. |
Protected processForFeatureIdentification | ||||||||
processForFeatureIdentification(data: GeoJsonObject)
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:655
|
||||||||
The function processes a GeoJsonObject by adding a geometry property to features that don't have one, using the bbox property from an imageOverlayObj. geographic object in GeoJSON format. It can be either a single feature or a collection of features.
Parameters :
Returns :
GeoJsonObject
the modified |
Public removeSelfFromMap |
removeSelfFromMap()
|
Inherited from
MapLayer
|
Defined in
MapLayer:280
|
The
Returns :
Promise<void>
a Promise that resolves to void (i.e., no value). |
Public setLayerBboxRetrieverFunction | ||||||
setLayerBboxRetrieverFunction(layerBboxRetrieverFunction: (layer: MapLayer,http: HttpClient) => void)
|
||||||
Inherited from
MapLayer
|
||||||
Defined in
MapLayer:372
|
||||||
Parameters :
|
Public setLayerClickFeatureItemGenerator | ||||||||
setLayerClickFeatureItemGenerator(featureItemGenerator: null | FeatureDisplayItemGenerator)
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:438
|
||||||||
The function sets the layer click feature item generator and returns the current object. parameter is of type null or FeatureDisplayItemGenerator. It is used to set the generator for creating feature display items when a layer is clicked.
Parameters :
|
Public setLegendCreatorFunction | ||||||||
setLegendCreatorFunction(legendCreatorFunction: (layer: MapLayer,http: HttpClient) => void)
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:365
|
||||||||
The function sets a legend creator function for a map layer in TypeScript. HttpClient object, and returns a Promise that resolves to either null or an array of Legend objects.
Parameters :
|
Public setPostLayerAddFunction | ||||||||
setPostLayerAddFunction(func: null | )
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:330
|
||||||||
The function sets a callback function to be executed after a Leaflet layer is added to the map.
function that takes a
Parameters :
|
Public setPostLayerRemoveFunction | ||||||||
setPostLayerRemoveFunction(func: null | )
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:353
|
||||||||
The function sets a callback function to be executed when a leaflet layer is removed.
function that takes a
Parameters :
|
Public setPreLayerAddFunction | ||||||||
setPreLayerAddFunction(func: null | )
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:319
|
||||||||
The function sets a pre-layer add function for a TypeScript class.
arguments and returns a promise that resolves to
Parameters :
|
Public setPreLayerRemoveFunction | ||||||||
setPreLayerRemoveFunction(func: null | )
|
||||||||
Inherited from
MapLayer
|
||||||||
Defined in
MapLayer:342
|
||||||||
The function sets a callback function that will be executed before removing a layer in a Leaflet map. layer as a parameter and returns a Promise that resolves when the layer is removed. This function can be null if no pre-layer remove function is needed.
Parameters :
|
Protected updateHidden |
updateHidden()
|
Inherited from
MapLayer
|
Defined in
MapLayer:604
|
The function updates the visibility of a Leaflet map layer based on a hidden property.
Returns :
void
|
Protected updateLeafletLayerMarker |
updateLeafletLayerMarker()
|
Inherited from
MapLayer
|
Defined in
MapLayer:623
|
Protected updateLeafletLayerOpacity |
updateLeafletLayerOpacity()
|
Inherited from
MapLayer
|
Defined in
MapLayer:617
|
The function updates the opacity of a Leaflet map layer based on a custom option.
Returns :
void
|
import * as L from 'leaflet';
import { HttpClient } from '@angular/common/http';
import { Legend } from '../controls/legendControl/legend';
import { TileLayer } from './tileLayer';
import { FeatureDisplayItemGenerator } from '../featureDisplay/featureDisplayItemGenerator';
import 'jquery';
import { MapLayer } from './mapLayer.abstract';
import { WmtsFeatureDisplayItemGenerator } from './wmtsFeatureDisplayItemGenerator';
export enum WMTSParameter {
FORMAT = 'FORMAT',
LAYER = 'LAYER',
REQUEST = 'REQUEST',
SERVICE = 'SERVICE',
TILEMATRIX = 'TILEMATRIX',
TILEMATRIXSET = 'TILEMATRIXSET',
SRS = 'SRS',
TILECOL = 'TILECOL',
TILEROW = 'TILEROW',
INFOFORMAT = 'INFOFORMAT',
WIDTH = 'WIDTH',
HEIGHT = 'HEIGHT',
}
export class WmtsTileLayer extends TileLayer {
public static readonly WMTSParameters: Array<string> = [
WMTSParameter.FORMAT,
WMTSParameter.LAYER,
WMTSParameter.REQUEST,
WMTSParameter.SERVICE,
WMTSParameter.TILEMATRIX,
WMTSParameter.TILEMATRIXSET,
WMTSParameter.SRS,
WMTSParameter.TILECOL,
WMTSParameter.TILEROW
];
protected getCapabilitiesXML: JQuery<XMLDocument>;
protected getCapabilitiesPromise: null | Promise<JQuery<XMLDocument>>;
constructor(id: string, name?: string) {
super(id, name);
// Default options
this.options.setOptions({
format: 'image/png',
transparent: true,
pane: id,
});
this.setLegendCreatorFunction(this.createLegendsDefault.bind(this) as (layer: MapLayer, http: HttpClient) => Promise<null | Array<Legend>>);
}
public getLeafletLayer(): Promise<null | L.Layer> {
return new Promise((resolve) => {
try {
// use copy
const options = {
...this.options.getAll(),
};
const parameters = new Map<string, null | string>();
// make any option alterations that are required
const optionsCopy = {};
Object.keys(options).forEach((key: string) => {
switch (true) {
// we don't want bbx being set by anything other than client
case key.toLowerCase() === 'bbox':
break;
// remove extra custom options
case key.startsWith('customLayerOption'):
break;
case WmtsTileLayer.WMTSParameters.includes(key.toUpperCase()):
parameters.set(key.toUpperCase(), options[key] as string);
break;
default:
optionsCopy[key] = options[key];
break;
}
});
const url =
this.url +
'?' +
Array.from(parameters.keys())
.filter((key) => null != parameters.get(key))
.map((key) => `${key}=${parameters.get(key)}`)
.join('&');
return resolve(L.tileLayer(url, optionsCopy));
} catch (e) {
console.error('Layer not found');
return resolve(null);
}
});
}
public setFeatureIdentifiable(itemGenerator?: FeatureDisplayItemGenerator): this {
this.setLayerClickFeatureItemGenerator(itemGenerator ? itemGenerator : new WmtsFeatureDisplayItemGenerator(this));
return this;
}
// TODO: these static funcs could do with being re-written in a class of their own
// Used for getting layer/style elements from xml and tries without workspace in name too
public getElementWithName(
$srcXml: JQuery<JQuery.Node>,
name: string,
parentElementType: string,
): null | JQuery<Element> {
name = name.trim();
let $returnElement: null | JQuery<Element> = null;
if (name.length > 0) {
let $nameElement: JQuery<Element> = $srcXml.find(`${parentElementType}>Name:contains("${name}")`).first();
// if not found try without workspace (part before ":" in "europe:SHEEC_1000_1899")
if ($nameElement.length === 0) {
// get part after colon
const newName = name.split(':').pop();
if (name !== newName) {
$nameElement = $srcXml.find(`${parentElementType}>Name:contains("${newName}")`).first();
}
}
$returnElement = $nameElement.length > 0 ? $nameElement.parent() : null;
}
return $returnElement;
}
/**
* @returns promise of jQuery object of xml response
*/
public refreshGetCapabilitiesXml(
http: HttpClient,
additionalParams = new Map<string, string>(),
): Promise<JQuery<XMLDocument>> {
// set defaults
const params = new Map<string, string>([
['SERVICE', 'WMTS'],
['REQUEST', 'GetCapabilities'],
]);
// set any additional values (allows overriding)
additionalParams.forEach((value: string, key: string) => {
params.set(key, value);
});
const url =
this.url +
'?' +
Array.from(params.keys())
.filter((key) => null != params.get(key))
.map((key) => `${key}=${params.get(key)}`)
.join('&');
this.getCapabilitiesPromise = http
.get(url, { responseType: 'text' })
.toPromise()
.catch((error) => {
throw error;
// this.userNotificationService.sendErrorNotification('STOP', 2000);
})
.then((res: string) => {
const xml = $.parseXML(res);
this.getCapabilitiesXML = jQuery(xml);
return this.getCapabilitiesXML;
})
.finally(() => {
this.getCapabilitiesPromise = null;
});
return this.getCapabilitiesPromise;
}
public getCapabilitiesXml(http: HttpClient): Promise<JQuery<XMLDocument>> {
switch (true) {
case null != this.getCapabilitiesXML:
return Promise.resolve(this.getCapabilitiesXML);
case null != this.getCapabilitiesPromise:
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
return this.getCapabilitiesPromise!;
default:
return this.refreshGetCapabilitiesXml(http);
}
}
public createLegendsDefault(layer: WmtsTileLayer, http: HttpClient): Promise<null | Array<Legend>> {
const layerNames = layer.options.get('layers') != null ? layer.options.get<string>('layers')!.split(',') : [];
const styleNames = layer.options.get('styles') != null ? layer.options.get<string>('styles')!.split(',') : [];
return Promise.resolve<null | Array<Legend>>(
this.getCapabilitiesXml(http)
.then(($xml: JQuery<XMLDocument>) => {
const legends = new Array<Legend>();
layerNames.forEach((layerName: string) => {
const $layerElement = this.getElementWithName($xml, layerName, 'Layer');
if (null != $layerElement) {
const $styleElements = new Array<JQuery<Element>>();
styleNames.forEach((styleName: string) => {
const $styleElement = this.getElementWithName($layerElement, styleName, 'Style');
if (null != $styleElement) {
$styleElements.push($styleElement);
}
});
// if no matching style elements just get the first one
if ($styleElements.length === 0) {
$styleElements.push($layerElement.find('Style').first());
}
$styleElements.forEach(($styleElement) => {
const $titleElement = $styleElement.find('Title').first();
const $onlineResourceElement = $styleElement.find('OnlineResource').first();
if ($onlineResourceElement.length > 0) {
let href = $onlineResourceElement.attr('xlink:href') || '';
if (href != null && href.trim().length > 0) {
// high quality image
href = href.concat('&scale=1&legend_options=fontAntiAliasing:true');
const name =
$titleElement.length === 0
? layer.name
: `<span>${layer.name}</span><span class="multilayer-specific-name">${String(
$titleElement.html(),
)}</span>`;
legends.push(
new Legend(layer.id, name).setDisplayFunction(() => {
const img = document.createElement('img');
img.setAttribute('src', href);
return img;
}),
);
}
}
});
}
});
return legends;
})
.catch((message) => {
console.log('No WMTS legend found', message);
return null;
}),
);
}
}