@loaders.gl/wms 4.0.0-alpha.22 → 4.0.0-alpha.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/dist/csw-capabilities-loader.d.ts +1 -17
  2. package/dist/csw-capabilities-loader.d.ts.map +1 -1
  3. package/dist/csw-domain-loader.d.ts +1 -17
  4. package/dist/csw-domain-loader.d.ts.map +1 -1
  5. package/dist/csw-records-loader.d.ts +1 -1
  6. package/dist/csw-records-loader.d.ts.map +1 -1
  7. package/dist/dist.min.js +6 -13
  8. package/dist/es5/csw-capabilities-loader.js +2 -4
  9. package/dist/es5/csw-capabilities-loader.js.map +1 -1
  10. package/dist/es5/csw-domain-loader.js +2 -4
  11. package/dist/es5/csw-domain-loader.js.map +1 -1
  12. package/dist/es5/csw-records-loader.js +2 -2
  13. package/dist/es5/csw-records-loader.js.map +1 -1
  14. package/dist/es5/gml-loader.js +2 -4
  15. package/dist/es5/gml-loader.js.map +1 -1
  16. package/dist/es5/lerc-loader.js +2 -4
  17. package/dist/es5/lerc-loader.js.map +1 -1
  18. package/dist/es5/lib/parsers/gml/parse-gml.js.map +1 -1
  19. package/dist/es5/lib/services/ogc/csw-service.js +4 -2
  20. package/dist/es5/lib/services/ogc/csw-service.js.map +1 -1
  21. package/dist/es5/lib/services/ogc/wms-service.js +4 -3
  22. package/dist/es5/lib/services/ogc/wms-service.js.map +1 -1
  23. package/dist/es5/wip/wcs-capabilities-loader.js +1 -1
  24. package/dist/es5/wip/wfs-capabilities-loader.js +2 -2
  25. package/dist/es5/wip/wfs-capabilities-loader.js.map +1 -1
  26. package/dist/es5/wip/wms-feature-info-loader.js.map +1 -1
  27. package/dist/es5/wip/wmts-capabilities-loader.js +1 -1
  28. package/dist/es5/wms-capabilities-loader.js +2 -4
  29. package/dist/es5/wms-capabilities-loader.js.map +1 -1
  30. package/dist/es5/wms-error-loader.js +2 -4
  31. package/dist/es5/wms-error-loader.js.map +1 -1
  32. package/dist/esm/csw-capabilities-loader.js +1 -2
  33. package/dist/esm/csw-capabilities-loader.js.map +1 -1
  34. package/dist/esm/csw-domain-loader.js +1 -2
  35. package/dist/esm/csw-domain-loader.js.map +1 -1
  36. package/dist/esm/csw-records-loader.js +2 -2
  37. package/dist/esm/csw-records-loader.js.map +1 -1
  38. package/dist/esm/gml-loader.js +1 -2
  39. package/dist/esm/gml-loader.js.map +1 -1
  40. package/dist/esm/lerc-loader.js +1 -2
  41. package/dist/esm/lerc-loader.js.map +1 -1
  42. package/dist/esm/lib/parsers/gml/parse-gml.js.map +1 -1
  43. package/dist/esm/lib/services/ogc/csw-service.js +4 -2
  44. package/dist/esm/lib/services/ogc/csw-service.js.map +1 -1
  45. package/dist/esm/lib/services/ogc/wms-service.js +4 -3
  46. package/dist/esm/lib/services/ogc/wms-service.js.map +1 -1
  47. package/dist/esm/wip/wcs-capabilities-loader.js +1 -1
  48. package/dist/esm/wip/wfs-capabilities-loader.js +2 -2
  49. package/dist/esm/wip/wfs-capabilities-loader.js.map +1 -1
  50. package/dist/esm/wip/wms-feature-info-loader.js.map +1 -1
  51. package/dist/esm/wip/wmts-capabilities-loader.js +1 -1
  52. package/dist/esm/wms-capabilities-loader.js +1 -2
  53. package/dist/esm/wms-capabilities-loader.js.map +1 -1
  54. package/dist/esm/wms-error-loader.js +1 -2
  55. package/dist/esm/wms-error-loader.js.map +1 -1
  56. package/dist/gml-loader.d.ts +2 -18
  57. package/dist/gml-loader.d.ts.map +1 -1
  58. package/dist/lerc-loader.d.ts +1 -14
  59. package/dist/lerc-loader.d.ts.map +1 -1
  60. package/dist/lib/parsers/gml/parse-gml.d.ts +1 -0
  61. package/dist/lib/parsers/gml/parse-gml.d.ts.map +1 -1
  62. package/dist/lib/services/ogc/csw-service.d.ts +1 -33
  63. package/dist/lib/services/ogc/csw-service.d.ts.map +1 -1
  64. package/dist/lib/services/ogc/wms-service.d.ts +0 -65
  65. package/dist/lib/services/ogc/wms-service.d.ts.map +1 -1
  66. package/dist/wip/wfs-capabilities-loader.d.ts +1 -16
  67. package/dist/wip/wfs-capabilities-loader.d.ts.map +1 -1
  68. package/dist/wip/wms-feature-info-loader.d.ts +1 -15
  69. package/dist/wip/wms-feature-info-loader.d.ts.map +1 -1
  70. package/dist/wip/wms-layer-description-loader.d.ts +19 -6
  71. package/dist/wip/wms-layer-description-loader.d.ts.map +1 -1
  72. package/dist/wms-capabilities-loader.d.ts +2 -17
  73. package/dist/wms-capabilities-loader.d.ts.map +1 -1
  74. package/dist/wms-error-loader.d.ts +1 -21
  75. package/dist/wms-error-loader.d.ts.map +1 -1
  76. package/package.json +6 -6
  77. package/src/csw-capabilities-loader.ts +1 -4
  78. package/src/csw-domain-loader.ts +1 -3
  79. package/src/csw-records-loader.ts +2 -3
  80. package/src/gml-loader.ts +2 -3
  81. package/src/lerc-loader.ts +1 -3
  82. package/src/lib/parsers/gml/parse-gml.ts +2 -0
  83. package/src/lib/services/ogc/csw-service.ts +2 -2
  84. package/src/lib/services/ogc/wms-service.ts +2 -11
  85. package/src/wip/wfs-capabilities-loader.ts +2 -2
  86. package/src/wip/wms-feature-info-loader.ts +2 -1
  87. package/src/wms-capabilities-loader.ts +6 -4
  88. package/src/wms-error-loader.ts +1 -3
  89. package/dist/bundle.js +0 -6
  90. package/dist/csw-capabilities-loader.js +0 -31
  91. package/dist/csw-domain-loader.js +0 -31
  92. package/dist/csw-records-loader.js +0 -30
  93. package/dist/gml-loader.js +0 -31
  94. package/dist/index.js +0 -39
  95. package/dist/lerc-loader.js +0 -56
  96. package/dist/lib/create-image-source.js +0 -39
  97. package/dist/lib/parsers/csw/parse-csw-capabilities.js +0 -24
  98. package/dist/lib/parsers/csw/parse-csw-domain.js +0 -33
  99. package/dist/lib/parsers/csw/parse-csw-records.js +0 -58
  100. package/dist/lib/parsers/csw/parse-exception-report.js +0 -30
  101. package/dist/lib/parsers/gml/deep-strict-equal.js +0 -119
  102. package/dist/lib/parsers/gml/parse-gml.js +0 -371
  103. package/dist/lib/parsers/lerc/lerc-types.js +0 -3
  104. package/dist/lib/parsers/wms/parse-wms-capabilities.js +0 -233
  105. package/dist/lib/parsers/wms/parse-wms-error.js +0 -22
  106. package/dist/lib/parsers/wms/parse-wms-features.js +0 -27
  107. package/dist/lib/parsers/wms/parse-wms-layer-description.js +0 -15
  108. package/dist/lib/parsers/xml/parse-xml-helpers.js +0 -68
  109. package/dist/lib/services/arcgis/arcgis-image-service.js +0 -94
  110. package/dist/lib/services/arcgis/arcgis-server.js +0 -42
  111. package/dist/lib/services/generic/image-service.js +0 -47
  112. package/dist/lib/services/ogc/csw-service.js +0 -168
  113. package/dist/lib/services/ogc/wms-service.js +0 -317
  114. package/dist/lib/sources/data-source.js +0 -56
  115. package/dist/lib/sources/image-source.js +0 -13
  116. package/dist/lib/sources/tile-source.js +0 -13
  117. package/dist/lib/sources/utils/utils.js +0 -38
  118. package/dist/lib/wfs/parse-wfs.js +0 -32
  119. package/dist/lib/wmts/parse-wmts.js +0 -35
  120. package/dist/wip/arcgis-feature-service.js +0 -28
  121. package/dist/wip/data-source.js +0 -59
  122. package/dist/wip/lib/wcs/parse-wcs-capabilities.js +0 -15
  123. package/dist/wip/lib/wfs/parse-wfs-capabilities.js +0 -19
  124. package/dist/wip/lib/wmts/parse-wmts-capabilities.js +0 -77
  125. package/dist/wip/wcs-capabilities-loader.js +0 -31
  126. package/dist/wip/wfs-capabilities-loader.js +0 -31
  127. package/dist/wip/wms-feature-info-loader.js +0 -17
  128. package/dist/wip/wms-layer-description-loader.js +0 -17
  129. package/dist/wip/wmts-capabilities-loader.js +0 -32
  130. package/dist/wms-capabilities-loader.js +0 -35
  131. package/dist/wms-error-loader.js +0 -43
@@ -1,168 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.CSWService = void 0;
5
- const data_source_1 = require("../../sources/data-source");
6
- const csw_capabilities_loader_1 = require("../../../csw-capabilities-loader");
7
- const csw_records_loader_1 = require("../../../csw-records-loader");
8
- const csw_domain_loader_1 = require("../../../csw-domain-loader");
9
- const wms_error_loader_1 = require("../../../wms-error-loader");
10
- /**
11
- * The CSWService class
12
- * - provides type safe methods to form URLs to a CSW service
13
- * - provides type safe methods to query and parse results (and errors) from a CSW service
14
- * @note Only the URL parameter conversion is supported. XML posts are not supported.
15
- */
16
- class CSWService extends data_source_1.DataSource {
17
- /** Create a CSWService */
18
- constructor(props) {
19
- super(props);
20
- this.capabilities = null;
21
- /** A list of loaders used by the CSWService methods */
22
- this.loaders = [wms_error_loader_1.WMSErrorLoader, csw_capabilities_loader_1.CSWCapabilitiesLoader];
23
- }
24
- async getMetadata() {
25
- const capabilities = await this.getCapabilities();
26
- return this.normalizeMetadata(capabilities);
27
- }
28
- normalizeMetadata(capabilities) {
29
- return capabilities;
30
- }
31
- async getServiceDirectory(options) {
32
- const services = [];
33
- const unknownServices = [];
34
- const records = await this.getRecords();
35
- for (const record of records.records) {
36
- for (const reference of record.references) {
37
- const url = reference.value;
38
- switch (reference.scheme) {
39
- case 'OGC:WMS':
40
- services.push({ name: record.title, type: 'ogc-wms-service', ...this._parseOGCUrl(url) });
41
- break;
42
- case 'OGC:WMTS':
43
- services.push({
44
- name: record.title,
45
- type: 'ogc-wmts-service',
46
- ...this._parseOGCUrl(url)
47
- });
48
- break;
49
- case 'OGC:WFS':
50
- services.push({ name: record.title, type: 'ogc-wfs-service', ...this._parseOGCUrl(url) });
51
- break;
52
- default:
53
- unknownServices.push({
54
- name: record.title,
55
- type: 'unknown',
56
- url: reference.value,
57
- scheme: reference.scheme
58
- });
59
- }
60
- }
61
- }
62
- return options?.includeUnknown ? services.concat(unknownServices) : services;
63
- }
64
- _parseOGCUrl(url) {
65
- const parts = url.split('?');
66
- return {
67
- url: parts[0],
68
- params: parts[1] || ''
69
- };
70
- }
71
- // CSW Service API Stubs
72
- /** Get Capabilities */
73
- async getCapabilities(wmsParameters, vendorParameters) {
74
- const url = this.getCapabilitiesURL(wmsParameters, vendorParameters);
75
- const response = await this.fetch(url);
76
- const arrayBuffer = await response.arrayBuffer();
77
- this._checkResponse(response, arrayBuffer);
78
- const capabilities = await csw_capabilities_loader_1.CSWCapabilitiesLoader.parse(arrayBuffer, this.props.loadOptions);
79
- return capabilities;
80
- }
81
- /** Get Records */
82
- async getRecords(wmsParameters, vendorParameters) {
83
- const url = this.getRecordsURL(wmsParameters, vendorParameters);
84
- const response = await this.fetch(url);
85
- const arrayBuffer = await response.arrayBuffer();
86
- this._checkResponse(response, arrayBuffer);
87
- return await csw_records_loader_1.CSWRecordsLoader.parse(arrayBuffer, this.props.loadOptions);
88
- }
89
- /** Get Domain */
90
- async getDomain(wmsParameters, vendorParameters) {
91
- const url = this.getDomainURL(wmsParameters, vendorParameters);
92
- const response = await this.fetch(url);
93
- const arrayBuffer = await response.arrayBuffer();
94
- this._checkResponse(response, arrayBuffer);
95
- return await csw_domain_loader_1.CSWDomainLoader.parse(arrayBuffer, this.props.loadOptions);
96
- }
97
- // Typed URL creators
98
- // For applications that want full control of fetching and parsing
99
- /** Generate a URL for the GetCapabilities request */
100
- getCapabilitiesURL(wmsParameters, vendorParameters) {
101
- const options = {
102
- version: '3.0.0',
103
- ...wmsParameters,
104
- ...vendorParameters,
105
- service: 'CSW',
106
- request: 'GetCapabilities'
107
- };
108
- return this._getCSWUrl(options, vendorParameters);
109
- }
110
- /** Generate a URL for the GetCapabilities request */
111
- getRecordsURL(wmsParameters, vendorParameters) {
112
- const options = {
113
- version: '3.0.0',
114
- typenames: 'csw:Record',
115
- ...wmsParameters,
116
- ...vendorParameters,
117
- service: 'CSW',
118
- request: 'GetRecords'
119
- };
120
- return this._getCSWUrl(options, vendorParameters);
121
- }
122
- /** Generate a URL for the GetCapabilities request */
123
- getDomainURL(wmsParameters, vendorParameters) {
124
- const options = {
125
- version: '3.0.0',
126
- ...wmsParameters,
127
- ...vendorParameters,
128
- service: 'CSW',
129
- request: 'GetDomain'
130
- };
131
- return this._getCSWUrl(options, vendorParameters);
132
- }
133
- // INTERNAL METHODS
134
- /**
135
- * @note case _getCSWUrl may need to be overridden to handle certain backends?
136
- * */
137
- _getCSWUrl(options, vendorParameters) {
138
- let url = this.props.url;
139
- let first = true;
140
- for (const [key, value] of Object.entries(options)) {
141
- url += first ? '?' : '&';
142
- first = false;
143
- if (Array.isArray(value)) {
144
- url += `${key.toUpperCase()}=${value.join(',')}`;
145
- }
146
- else {
147
- url += `${key.toUpperCase()}=${value ? String(value) : ''}`;
148
- }
149
- }
150
- return encodeURI(url);
151
- }
152
- /** Checks for and parses a CSW XML formatted ServiceError and throws an exception */
153
- _checkResponse(response, arrayBuffer) {
154
- const contentType = response.headers['content-type'];
155
- if (!response.ok || wms_error_loader_1.WMSErrorLoader.mimeTypes.includes(contentType)) {
156
- const error = wms_error_loader_1.WMSErrorLoader.parseSync(arrayBuffer, this.props.loadOptions);
157
- throw new Error(error);
158
- }
159
- }
160
- /** Error situation detected */
161
- _parseError(arrayBuffer) {
162
- const error = wms_error_loader_1.WMSErrorLoader.parseSync(arrayBuffer, this.props.loadOptions);
163
- return new Error(error);
164
- }
165
- }
166
- exports.CSWService = CSWService;
167
- CSWService.type = 'csw';
168
- CSWService.testURL = (url) => url.toLowerCase().includes('csw');
@@ -1,317 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.WMSService = void 0;
5
- const images_1 = require("@loaders.gl/images");
6
- const loader_utils_1 = require("@loaders.gl/loader-utils");
7
- const image_source_1 = require("../../sources/image-source");
8
- const wms_capabilities_loader_1 = require("../../../wms-capabilities-loader");
9
- const wms_feature_info_loader_1 = require("../../../wip/wms-feature-info-loader");
10
- const wms_layer_description_loader_1 = require("../../../wip/wms-layer-description-loader");
11
- const wms_error_loader_1 = require("../../../wms-error-loader");
12
- /**
13
- * The WMSService class provides
14
- * - provides type safe methods to form URLs to a WMS service
15
- * - provides type safe methods to query and parse results (and errors) from a WMS service
16
- * - implements the ImageService interface
17
- * @note Only the URL parameter conversion is supported. XML posts are not supported.
18
- */
19
- class WMSService extends image_source_1.ImageSource {
20
- /** Create a WMSService */
21
- constructor(props) {
22
- super(props);
23
- this.capabilities = null;
24
- /** A list of loaders used by the WMSService methods */
25
- this.loaders = [
26
- images_1.ImageLoader,
27
- wms_error_loader_1.WMSErrorLoader,
28
- wms_capabilities_loader_1.WMSCapabilitiesLoader,
29
- wms_feature_info_loader_1.WMSFeatureInfoLoader,
30
- wms_layer_description_loader_1.WMSLayerDescriptionLoader
31
- ];
32
- // TODO - defaults such as version, layers etc could be extracted from a base URL with parameters
33
- // This would make pasting in any WMS URL more likely to make this class just work.
34
- // const {baseUrl, parameters} = this._parseWMSUrl(props.url);
35
- this.url = props.url;
36
- this.substituteCRS84 = props.substituteCRS84 ?? false;
37
- this.flipCRS = ['EPSG:4326'];
38
- this.wmsParameters = {
39
- layers: undefined,
40
- query_layers: undefined,
41
- styles: undefined,
42
- version: '1.3.0',
43
- crs: 'EPSG:4326',
44
- format: 'image/png',
45
- info_format: 'text/plain',
46
- transparent: undefined,
47
- time: undefined,
48
- elevation: undefined,
49
- ...props.wmsParameters
50
- };
51
- this.vendorParameters = props.vendorParameters || {};
52
- }
53
- // ImageSource implementation
54
- async getMetadata() {
55
- const capabilities = await this.getCapabilities();
56
- return this.normalizeMetadata(capabilities);
57
- }
58
- async getImage(parameters) {
59
- return await this.getMap(parameters);
60
- }
61
- normalizeMetadata(capabilities) {
62
- return capabilities;
63
- }
64
- // WMS Service API Stubs
65
- /** Get Capabilities */
66
- async getCapabilities(wmsParameters, vendorParameters) {
67
- const url = this.getCapabilitiesURL(wmsParameters, vendorParameters);
68
- const response = await this.fetch(url);
69
- const arrayBuffer = await response.arrayBuffer();
70
- this._checkResponse(response, arrayBuffer);
71
- const capabilities = await wms_capabilities_loader_1.WMSCapabilitiesLoader.parse(arrayBuffer, this.loadOptions);
72
- this.capabilities = capabilities;
73
- return capabilities;
74
- }
75
- /** Get a map image */
76
- async getMap(wmsParameters, vendorParameters) {
77
- const url = this.getMapURL(wmsParameters, vendorParameters);
78
- const response = await this.fetch(url);
79
- const arrayBuffer = await response.arrayBuffer();
80
- this._checkResponse(response, arrayBuffer);
81
- try {
82
- return await images_1.ImageLoader.parse(arrayBuffer, this.loadOptions);
83
- }
84
- catch {
85
- throw this._parseError(arrayBuffer);
86
- }
87
- }
88
- /** Get Feature Info for a coordinate */
89
- async getFeatureInfo(wmsParameters, vendorParameters) {
90
- const url = this.getFeatureInfoURL(wmsParameters, vendorParameters);
91
- const response = await this.fetch(url);
92
- const arrayBuffer = await response.arrayBuffer();
93
- this._checkResponse(response, arrayBuffer);
94
- return await wms_feature_info_loader_1.WMSFeatureInfoLoader.parse(arrayBuffer, this.loadOptions);
95
- }
96
- /** Get Feature Info for a coordinate */
97
- async getFeatureInfoText(wmsParameters, vendorParameters) {
98
- const url = this.getFeatureInfoURL(wmsParameters, vendorParameters);
99
- const response = await this.fetch(url);
100
- const arrayBuffer = await response.arrayBuffer();
101
- this._checkResponse(response, arrayBuffer);
102
- return new TextDecoder().decode(arrayBuffer);
103
- }
104
- /** Get more information about a layer */
105
- async describeLayer(wmsParameters, vendorParameters) {
106
- const url = this.describeLayerURL(wmsParameters, vendorParameters);
107
- const response = await this.fetch(url);
108
- const arrayBuffer = await response.arrayBuffer();
109
- this._checkResponse(response, arrayBuffer);
110
- return await wms_layer_description_loader_1.WMSLayerDescriptionLoader.parse(arrayBuffer, this.loadOptions);
111
- }
112
- /** Get an image with a semantic legend */
113
- async getLegendGraphic(wmsParameters, vendorParameters) {
114
- const url = this.getLegendGraphicURL(wmsParameters, vendorParameters);
115
- const response = await this.fetch(url);
116
- const arrayBuffer = await response.arrayBuffer();
117
- this._checkResponse(response, arrayBuffer);
118
- try {
119
- return await images_1.ImageLoader.parse(arrayBuffer, this.loadOptions);
120
- }
121
- catch {
122
- throw this._parseError(arrayBuffer);
123
- }
124
- }
125
- // Typed URL creators
126
- // For applications that want full control of fetching and parsing
127
- /** Generate a URL for the GetCapabilities request */
128
- getCapabilitiesURL(wmsParameters, vendorParameters) {
129
- const options = {
130
- version: this.wmsParameters.version,
131
- ...wmsParameters
132
- };
133
- return this._getWMSUrl('GetCapabilities', options, vendorParameters);
134
- }
135
- /** Generate a URL for the GetMap request */
136
- getMapURL(wmsParameters, vendorParameters) {
137
- wmsParameters = this._getWMS130Parameters(wmsParameters);
138
- const options = {
139
- version: this.wmsParameters.version,
140
- format: this.wmsParameters.format,
141
- transparent: this.wmsParameters.transparent,
142
- time: this.wmsParameters.time,
143
- elevation: this.wmsParameters.elevation,
144
- layers: this.wmsParameters.layers,
145
- styles: this.wmsParameters.styles,
146
- crs: this.wmsParameters.crs,
147
- // bbox: [-77.87304, 40.78975, -77.85828, 40.80228],
148
- // width: 1200,
149
- // height: 900,
150
- ...wmsParameters
151
- };
152
- return this._getWMSUrl('GetMap', options, vendorParameters);
153
- }
154
- /** Generate a URL for the GetFeatureInfo request */
155
- getFeatureInfoURL(wmsParameters, vendorParameters) {
156
- const options = {
157
- version: this.wmsParameters.version,
158
- // query_layers: [],
159
- // format: this.wmsParameters.format,
160
- info_format: this.wmsParameters.info_format,
161
- layers: this.wmsParameters.layers,
162
- query_layers: this.wmsParameters.query_layers,
163
- styles: this.wmsParameters.styles,
164
- crs: this.wmsParameters.crs,
165
- // bbox: [-77.87304, 40.78975, -77.85828, 40.80228],
166
- // width: 1200,
167
- // height: 900,
168
- // x: undefined!,
169
- // y: undefined!,
170
- ...wmsParameters
171
- };
172
- return this._getWMSUrl('GetFeatureInfo', options, vendorParameters);
173
- }
174
- /** Generate a URL for the GetFeatureInfo request */
175
- describeLayerURL(wmsParameters, vendorParameters) {
176
- const options = {
177
- version: this.wmsParameters.version,
178
- ...wmsParameters
179
- };
180
- return this._getWMSUrl('DescribeLayer', options, vendorParameters);
181
- }
182
- getLegendGraphicURL(wmsParameters, vendorParameters) {
183
- const options = {
184
- version: this.wmsParameters.version,
185
- // format?
186
- ...wmsParameters
187
- };
188
- return this._getWMSUrl('GetLegendGraphic', options, vendorParameters);
189
- }
190
- // INTERNAL METHODS
191
- _parseWMSUrl(url) {
192
- const [baseUrl, search] = url.split('?');
193
- const searchParams = search.split('&');
194
- const parameters = {};
195
- for (const parameter of searchParams) {
196
- const [key, value] = parameter.split('=');
197
- parameters[key] = value;
198
- }
199
- return { url: baseUrl, parameters };
200
- }
201
- /**
202
- * Generate a URL with parameters
203
- * @note case _getWMSUrl may need to be overridden to handle certain backends?
204
- * @note at the moment, only URLs with parameters are supported (no XML payloads)
205
- * */
206
- _getWMSUrl(request, wmsParameters, vendorParameters) {
207
- let url = this.url;
208
- let first = true;
209
- // Add any vendor searchParams
210
- const allParameters = {
211
- service: 'WMS',
212
- version: wmsParameters.version,
213
- request,
214
- ...wmsParameters,
215
- ...this.vendorParameters,
216
- ...vendorParameters
217
- };
218
- // Encode the keys
219
- const IGNORE_EMPTY_KEYS = ['transparent', 'time', 'elevation'];
220
- for (const [key, value] of Object.entries(allParameters)) {
221
- // hack to preserve test cases. Not super clear if keys should be included when values are undefined
222
- if (!IGNORE_EMPTY_KEYS.includes(key) || value) {
223
- url += first ? '?' : '&';
224
- first = false;
225
- url += this._getURLParameter(key, value, wmsParameters);
226
- }
227
- }
228
- return encodeURI(url);
229
- }
230
- _getWMS130Parameters(wmsParameters) {
231
- const newParameters = { ...wmsParameters };
232
- if (newParameters.srs) {
233
- newParameters.crs = newParameters.crs || newParameters.srs;
234
- delete newParameters.srs;
235
- }
236
- return newParameters;
237
- }
238
- // eslint-disable-complexity
239
- _getURLParameter(key, value, wmsParameters) {
240
- // Substitute by key
241
- switch (key) {
242
- case 'crs':
243
- // CRS was called SRS before WMS 1.3.0
244
- if (wmsParameters.version !== '1.3.0') {
245
- key = 'srs';
246
- }
247
- else if (this.substituteCRS84 && value === 'EPSG:4326') {
248
- /** In 1.3.0, replaces references to 'EPSG:4326' with the new backwards compatible CRS:84 */
249
- // Substitute by value
250
- value = 'CRS:84';
251
- }
252
- break;
253
- case 'srs':
254
- // CRS was called SRS before WMS 1.3.0
255
- if (wmsParameters.version === '1.3.0') {
256
- key = 'crs';
257
- }
258
- break;
259
- case 'bbox':
260
- // Coordinate order is flipped for certain CRS in WMS 1.3.0
261
- const bbox = this._flipBoundingBox(value, wmsParameters);
262
- if (bbox) {
263
- value = bbox;
264
- }
265
- break;
266
- default:
267
- // do nothing
268
- }
269
- key = key.toUpperCase();
270
- return Array.isArray(value)
271
- ? `${key}=${value.join(',')}`
272
- : `${key}=${value ? String(value) : ''}`;
273
- }
274
- /** Coordinate order is flipped for certain CRS in WMS 1.3.0 */
275
- _flipBoundingBox(bboxValue, wmsParameters) {
276
- // Sanity checks
277
- if (!Array.isArray(bboxValue) || bboxValue.length !== 4) {
278
- return null;
279
- }
280
- const flipCoordinates =
281
- // Only affects WMS 1.3.0
282
- wmsParameters.version === '1.3.0' &&
283
- // Flip if we are dealing with a CRS that was flipped in 1.3.0
284
- this.flipCRS.includes(wmsParameters.crs || '') &&
285
- // Don't flip if we are subsituting EPSG:4326 with CRS:84
286
- !(this.substituteCRS84 && wmsParameters.crs === 'EPSG:4326');
287
- const bbox = bboxValue;
288
- return flipCoordinates ? [bbox[1], bbox[0], bbox[3], bbox[2]] : bbox;
289
- }
290
- /** Fetches an array buffer and checks the response (boilerplate reduction) */
291
- async _fetchArrayBuffer(url) {
292
- const response = await this.fetch(url);
293
- const arrayBuffer = await response.arrayBuffer();
294
- this._checkResponse(response, arrayBuffer);
295
- return arrayBuffer;
296
- }
297
- /** Checks for and parses a WMS XML formatted ServiceError and throws an exception */
298
- _checkResponse(response, arrayBuffer) {
299
- const contentType = response.headers['content-type'];
300
- if (!response.ok || wms_error_loader_1.WMSErrorLoader.mimeTypes.includes(contentType)) {
301
- // We want error responses to throw exceptions, the WMSErrorLoader can do this
302
- const loadOptions = (0, loader_utils_1.mergeLoaderOptions)(this.loadOptions, {
303
- wms: { throwOnError: true }
304
- });
305
- const error = wms_error_loader_1.WMSErrorLoader.parseSync(arrayBuffer, loadOptions);
306
- throw new Error(error);
307
- }
308
- }
309
- /** Error situation detected */
310
- _parseError(arrayBuffer) {
311
- const error = wms_error_loader_1.WMSErrorLoader.parseSync(arrayBuffer, this.loadOptions);
312
- return new Error(error);
313
- }
314
- }
315
- exports.WMSService = WMSService;
316
- WMSService.type = 'wms';
317
- WMSService.testURL = (url) => url.toLowerCase().includes('wms');
@@ -1,56 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.getFetchFunction = exports.DataSource = void 0;
5
- /** base class of all data sources */
6
- class DataSource {
7
- constructor(props) {
8
- this._needsRefresh = true;
9
- this.props = { ...props };
10
- this.loadOptions = { ...props.loadOptions };
11
- this.fetch = getFetchFunction(this.loadOptions);
12
- }
13
- setProps(props) {
14
- this.props = Object.assign(this.props, props);
15
- // TODO - add a shallow compare to avoid setting refresh if no change?
16
- this.setNeedsRefresh();
17
- }
18
- /** Mark this data source as needing a refresh (redraw) */
19
- setNeedsRefresh() {
20
- this._needsRefresh = true;
21
- }
22
- /**
23
- * Does this data source need refreshing?
24
- * @note The specifics of the refresh mechanism depends on type of data source
25
- */
26
- getNeedsRefresh(clear = true) {
27
- const needsRefresh = this._needsRefresh;
28
- if (clear) {
29
- this._needsRefresh = false;
30
- }
31
- return needsRefresh;
32
- }
33
- }
34
- exports.DataSource = DataSource;
35
- /**
36
- * Gets the current fetch function from options
37
- * @todo - move to loader-utils module
38
- * @todo - use in core module counterpart
39
- * @param options
40
- * @param context
41
- */
42
- function getFetchFunction(options) {
43
- const fetchFunction = options?.fetch;
44
- // options.fetch can be a function
45
- if (fetchFunction && typeof fetchFunction === 'function') {
46
- return (url, fetchOptions) => fetchFunction(url, fetchOptions);
47
- }
48
- // options.fetch can be an options object, use global fetch with those options
49
- const fetchOptions = options?.fetch;
50
- if (fetchOptions && typeof fetchOptions !== 'function') {
51
- return (url) => fetch(url, fetchOptions);
52
- }
53
- // else return the global fetch function
54
- return (url) => fetch(url);
55
- }
56
- exports.getFetchFunction = getFetchFunction;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ImageSource = void 0;
5
- const data_source_1 = require("./data-source");
6
- /**
7
- * MapImageSource - data sources that allow data to be queried by (geospatial) extents
8
- * @note
9
- * - If geospatial, bounding box is expected to be in web mercator coordinates
10
- */
11
- class ImageSource extends data_source_1.DataSource {
12
- }
13
- exports.ImageSource = ImageSource;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.TileSource = void 0;
5
- const data_source_1 = require("./data-source");
6
- /**
7
- * MapTileSource - data sources that allow data to be queried by (geospatial) extents
8
- * @note
9
- * - If geospatial, bounding box is expected to be in web mercator coordinates
10
- */
11
- class TileSource extends data_source_1.DataSource {
12
- }
13
- exports.TileSource = TileSource;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.mergeImageServiceProps = exports.getFetchFunction = void 0;
5
- /**
6
- * Gets the current fetch function from options
7
- * @todo - move to loader-utils module
8
- * @todo - use in core module counterpart
9
- * @param options
10
- * @param context
11
- */
12
- function getFetchFunction(options) {
13
- const fetchFunction = options?.fetch;
14
- // options.fetch can be a function
15
- if (fetchFunction && typeof fetchFunction === 'function') {
16
- return (url, fetchOptions) => fetchFunction(url, fetchOptions);
17
- }
18
- // options.fetch can be an options object, use global fetch with those options
19
- const fetchOptions = options?.fetch;
20
- if (fetchOptions && typeof fetchOptions !== 'function') {
21
- return (url) => fetch(url, fetchOptions);
22
- }
23
- // else return the global fetch function
24
- return (url) => fetch(url);
25
- }
26
- exports.getFetchFunction = getFetchFunction;
27
- function mergeImageServiceProps(props) {
28
- // @ts-expect-error
29
- return {
30
- // Default fetch
31
- ...props,
32
- loadOptions: {
33
- ...props.loadOptions,
34
- fetch: getFetchFunction(props.loadOptions)
35
- }
36
- };
37
- }
38
- exports.mergeImageServiceProps = mergeImageServiceProps;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.parseWFSCapabilities = void 0;
5
- const xml_1 = require("@loaders.gl/xml");
6
- /**
7
- * Parses a typed data structure from raw XML for `GetCapabilities` response
8
- * @note Error handlings is fairly weak
9
- */
10
- function parseWFSCapabilities(text, options) {
11
- // Remove namespaces in XML
12
- options = { ...options, xml: { ...options?.xml, removeNSPrefix: true } };
13
- const parsedXML = xml_1.XMLLoader.parseTextSync?.(text, options);
14
- const xmlCapabilities = parsedXML.Capabilities || parsedXML;
15
- return uncapitalizeKeys(xmlCapabilities);
16
- }
17
- exports.parseWFSCapabilities = parseWFSCapabilities;
18
- /** Uncapitalize all keys of an object */
19
- function uncapitalizeKeys(object) {
20
- if (object && typeof object === 'object') {
21
- const newObject = {};
22
- for (const [key, value] of Object.entries(object)) {
23
- newObject[uncapitalize(key)] = uncapitalizeKeys(value);
24
- }
25
- return newObject;
26
- }
27
- return object;
28
- }
29
- /** Uncapitalize first letter of a string */
30
- function uncapitalize(str) {
31
- return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str;
32
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.parseWMTSCapabilities = void 0;
5
- const xml_1 = require("@loaders.gl/xml");
6
- /**
7
- * Parses a typed data structure from raw XML for `GetCapabilities` response
8
- * @note Error handlings is fairly weak
9
- */
10
- function parseWMTSCapabilities(text, options) {
11
- // Remove namespaces in XML
12
- options = { ...options, xml: { ...options?.xml, removeNSPrefix: true } };
13
- const parsedXML = xml_1.XMLLoader.parseTextSync?.(text, options);
14
- const xmlCapabilities = parsedXML.Capabilities || parsedXML;
15
- return uncapitalizeKeys(xmlCapabilities);
16
- }
17
- exports.parseWMTSCapabilities = parseWMTSCapabilities;
18
- function uncapitalizeKeys(object) {
19
- if (object && typeof object === 'object') {
20
- const newObject = {};
21
- for (const [key, value] of Object.entries(object)) {
22
- newObject[uncapitalize(key)] = uncapitalizeKeys(value);
23
- }
24
- return newObject;
25
- }
26
- return object;
27
- }
28
- /**
29
- * Uncapitalize first letter of a string
30
- * @param {string} str
31
- * @returns {string}
32
- */
33
- function uncapitalize(str) {
34
- return typeof str === 'string' ? str.charAt(0).toLowerCase() + str.slice(1) : str;
35
- }