@deck.gl/geo-layers 8.9.9 → 8.9.11
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.
- package/dist/dist.dev.js +10 -0
- package/dist/es5/wms-layer/wms-layer.js +34 -14
- package/dist/es5/wms-layer/wms-layer.js.map +1 -1
- package/dist/esm/wms-layer/wms-layer.js +11 -0
- package/dist/esm/wms-layer/wms-layer.js.map +1 -1
- package/dist.min.js +56 -56
- package/package.json +2 -2
- package/src/wms-layer/wms-layer.ts +15 -1
- package/typed/wms-layer/wms-layer.d.ts +4 -0
- package/typed/wms-layer/wms-layer.d.ts.map +1 -1
package/dist/dist.dev.js
CHANGED
|
@@ -5445,12 +5445,16 @@ var __exports__ = (() => {
|
|
|
5445
5445
|
}
|
|
5446
5446
|
};
|
|
5447
5447
|
var WMSLayer = class extends import_core.CompositeLayer {
|
|
5448
|
+
get isLoaded() {
|
|
5449
|
+
return Boolean(this.state) && this.state.loadCounter === 0 && super.isLoaded;
|
|
5450
|
+
}
|
|
5448
5451
|
shouldUpdateState() {
|
|
5449
5452
|
return true;
|
|
5450
5453
|
}
|
|
5451
5454
|
initializeState() {
|
|
5452
5455
|
this.state._nextRequestId = 0;
|
|
5453
5456
|
this.state.lastRequestId = -1;
|
|
5457
|
+
this.state.loadCounter = 0;
|
|
5454
5458
|
}
|
|
5455
5459
|
updateState({
|
|
5456
5460
|
changeFlags,
|
|
@@ -5521,12 +5525,15 @@ var __exports__ = (() => {
|
|
|
5521
5525
|
imageSource
|
|
5522
5526
|
} = this.state;
|
|
5523
5527
|
try {
|
|
5528
|
+
this.state.loadCounter++;
|
|
5524
5529
|
const metadata = await imageSource.getMetadata();
|
|
5525
5530
|
if (this.state.imageSource === imageSource) {
|
|
5526
5531
|
this.getCurrentLayer()?.props.onMetadataLoad(metadata);
|
|
5527
5532
|
}
|
|
5528
5533
|
} catch (error2) {
|
|
5529
5534
|
this.getCurrentLayer()?.props.onMetadataLoadError(error2);
|
|
5535
|
+
} finally {
|
|
5536
|
+
this.state.loadCounter--;
|
|
5530
5537
|
}
|
|
5531
5538
|
}
|
|
5532
5539
|
async loadImage(viewport, reason) {
|
|
@@ -5562,6 +5569,7 @@ var __exports__ = (() => {
|
|
|
5562
5569
|
requestParams.bbox = [minX, minY, maxX, maxY];
|
|
5563
5570
|
}
|
|
5564
5571
|
try {
|
|
5572
|
+
this.state.loadCounter++;
|
|
5565
5573
|
this.props.onImageLoadStart(requestId);
|
|
5566
5574
|
const image = await this.state.imageSource.getImage(requestParams);
|
|
5567
5575
|
if (this.state.lastRequestId < requestId) {
|
|
@@ -5576,6 +5584,8 @@ var __exports__ = (() => {
|
|
|
5576
5584
|
} catch (error2) {
|
|
5577
5585
|
this.raiseError(error2, "Load image");
|
|
5578
5586
|
this.getCurrentLayer()?.props.onImageLoadError(requestId, error2);
|
|
5587
|
+
} finally {
|
|
5588
|
+
this.state.loadCounter--;
|
|
5579
5589
|
}
|
|
5580
5590
|
}
|
|
5581
5591
|
getRequestId() {
|
|
@@ -19,6 +19,8 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
|
|
|
19
19
|
|
|
20
20
|
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
21
21
|
|
|
22
|
+
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
23
|
+
|
|
22
24
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
23
25
|
|
|
24
26
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
@@ -98,6 +100,11 @@ var WMSLayer = function (_CompositeLayer) {
|
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
(0, _createClass2.default)(WMSLayer, [{
|
|
103
|
+
key: "isLoaded",
|
|
104
|
+
get: function get() {
|
|
105
|
+
return Boolean(this.state) && this.state.loadCounter === 0 && (0, _get2.default)((0, _getPrototypeOf2.default)(WMSLayer.prototype), "isLoaded", this);
|
|
106
|
+
}
|
|
107
|
+
}, {
|
|
101
108
|
key: "shouldUpdateState",
|
|
102
109
|
value: function shouldUpdateState() {
|
|
103
110
|
return true;
|
|
@@ -107,6 +114,7 @@ var WMSLayer = function (_CompositeLayer) {
|
|
|
107
114
|
value: function initializeState() {
|
|
108
115
|
this.state._nextRequestId = 0;
|
|
109
116
|
this.state.lastRequestId = -1;
|
|
117
|
+
this.state.loadCounter = 0;
|
|
110
118
|
}
|
|
111
119
|
}, {
|
|
112
120
|
key: "updateState",
|
|
@@ -229,30 +237,36 @@ var WMSLayer = function (_CompositeLayer) {
|
|
|
229
237
|
case 0:
|
|
230
238
|
imageSource = this.state.imageSource;
|
|
231
239
|
_context2.prev = 1;
|
|
232
|
-
|
|
240
|
+
this.state.loadCounter++;
|
|
241
|
+
_context2.next = 5;
|
|
233
242
|
return imageSource.getMetadata();
|
|
234
243
|
|
|
235
|
-
case
|
|
244
|
+
case 5:
|
|
236
245
|
_metadata = _context2.sent;
|
|
237
246
|
|
|
238
247
|
if (this.state.imageSource === imageSource) {
|
|
239
248
|
(_this$getCurrentLayer = this.getCurrentLayer()) === null || _this$getCurrentLayer === void 0 ? void 0 : _this$getCurrentLayer.props.onMetadataLoad(_metadata);
|
|
240
249
|
}
|
|
241
250
|
|
|
242
|
-
_context2.next =
|
|
251
|
+
_context2.next = 12;
|
|
243
252
|
break;
|
|
244
253
|
|
|
245
|
-
case
|
|
246
|
-
_context2.prev =
|
|
254
|
+
case 9:
|
|
255
|
+
_context2.prev = 9;
|
|
247
256
|
_context2.t0 = _context2["catch"](1);
|
|
248
257
|
(_this$getCurrentLayer2 = this.getCurrentLayer()) === null || _this$getCurrentLayer2 === void 0 ? void 0 : _this$getCurrentLayer2.props.onMetadataLoadError(_context2.t0);
|
|
249
258
|
|
|
250
|
-
case
|
|
259
|
+
case 12:
|
|
260
|
+
_context2.prev = 12;
|
|
261
|
+
this.state.loadCounter--;
|
|
262
|
+
return _context2.finish(12);
|
|
263
|
+
|
|
264
|
+
case 15:
|
|
251
265
|
case "end":
|
|
252
266
|
return _context2.stop();
|
|
253
267
|
}
|
|
254
268
|
}
|
|
255
|
-
}, _callee2, this, [[1,
|
|
269
|
+
}, _callee2, this, [[1, 9, 12, 15]]);
|
|
256
270
|
}));
|
|
257
271
|
|
|
258
272
|
function _loadMetadata() {
|
|
@@ -305,11 +319,12 @@ var WMSLayer = function (_CompositeLayer) {
|
|
|
305
319
|
}
|
|
306
320
|
|
|
307
321
|
_context3.prev = 10;
|
|
322
|
+
this.state.loadCounter++;
|
|
308
323
|
this.props.onImageLoadStart(requestId);
|
|
309
|
-
_context3.next =
|
|
324
|
+
_context3.next = 15;
|
|
310
325
|
return this.state.imageSource.getImage(requestParams);
|
|
311
326
|
|
|
312
|
-
case
|
|
327
|
+
case 15:
|
|
313
328
|
image = _context3.sent;
|
|
314
329
|
|
|
315
330
|
if (this.state.lastRequestId < requestId) {
|
|
@@ -322,21 +337,26 @@ var WMSLayer = function (_CompositeLayer) {
|
|
|
322
337
|
});
|
|
323
338
|
}
|
|
324
339
|
|
|
325
|
-
_context3.next =
|
|
340
|
+
_context3.next = 23;
|
|
326
341
|
break;
|
|
327
342
|
|
|
328
|
-
case
|
|
329
|
-
_context3.prev =
|
|
343
|
+
case 19:
|
|
344
|
+
_context3.prev = 19;
|
|
330
345
|
_context3.t0 = _context3["catch"](10);
|
|
331
346
|
this.raiseError(_context3.t0, 'Load image');
|
|
332
347
|
(_this$getCurrentLayer4 = this.getCurrentLayer()) === null || _this$getCurrentLayer4 === void 0 ? void 0 : _this$getCurrentLayer4.props.onImageLoadError(requestId, _context3.t0);
|
|
333
348
|
|
|
334
|
-
case
|
|
349
|
+
case 23:
|
|
350
|
+
_context3.prev = 23;
|
|
351
|
+
this.state.loadCounter--;
|
|
352
|
+
return _context3.finish(23);
|
|
353
|
+
|
|
354
|
+
case 26:
|
|
335
355
|
case "end":
|
|
336
356
|
return _context3.stop();
|
|
337
357
|
}
|
|
338
358
|
}
|
|
339
|
-
}, _callee3, this, [[10,
|
|
359
|
+
}, _callee3, this, [[10, 19, 23, 26]]);
|
|
340
360
|
}));
|
|
341
361
|
|
|
342
362
|
function loadImage(_x3, _x4) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/wms-layer/wms-layer.ts"],"names":["defaultProps","id","data","serviceType","srs","layers","type","compare","value","onMetadataLoad","onMetadataLoadError","console","error","onImageLoadStart","onImageLoad","onImageLoadError","requestId","WMSLayer","state","_nextRequestId","lastRequestId","changeFlags","props","oldProps","viewport","context","dataChanged","imageSource","_createImageSource","_loadMetadata","debounce","loadImage","viewportChanged","bounds","image","lastRequestParameters","BitmapLayer","getSubLayerProps","_imageCoordinateSystem","COORDINATE_SYSTEM","LNGLAT","CARTESIAN","x","y","getFeatureInfoText","query_layers","info_format","featureInfo","ImageSource","url","loadOptions","Error","getMetadata","metadata","getCurrentLayer","reason","length","getBounds","width","height","getRequestId","resolution","requestParams","bbox","minX","minY","maxX","maxY","getImage","setState","raiseError","fn","ms","clearTimeout","_timeoutId","setTimeout","CompositeLayer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA;;AAUA;;AAEA;;AACA;;;;;;;;;;AAkBA,IAAMA,YAAyC,GAAG;AAChDC,EAAAA,EAAE,EAAE,eAD4C;AAEhDC,EAAAA,IAAI,EAAE,EAF0C;AAGhDC,EAAAA,WAAW,EAAE,MAHmC;AAIhDC,EAAAA,GAAG,EAAE,MAJ2C;AAKhDC,EAAAA,MAAM,EAAE;AAACC,IAAAA,IAAI,EAAE,OAAP;AAAgBC,IAAAA,OAAO,EAAE,IAAzB;AAA+BC,IAAAA,KAAK,EAAE;AAAtC,GALwC;AAMhDC,EAAAA,cAAc,EAAE;AAACH,IAAAA,IAAI,EAAE,UAAP;AAAmBE,IAAAA,KAAK,EAAE,iBAAM,CAAE;AAAlC,GANgC;AAQhDE,EAAAA,mBAAmB,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BG,SAA5B;AA9BJ;AAAA,uBAgCwB,KAAKE,KAAL,CAAWS,WAAX,CAAuByC,QAAvB,CAAgCN,aAAhC,CAhCxB;;AAAA;AAgCU5B,gBAAAA,KAhCV;;AAmCI,oBAAI,KAAKhB,KAAL,CAAWE,aAAX,GAA2BJ,SAA/B,EAA0C;AACxC,iDAAKsC,eAAL,oFAAwBhC,KAAxB,CAA8BR,WAA9B,CAA0CE,SAA1C;AAEA,uBAAKqD,QAAL,CAAc;AACZnC,oBAAAA,KAAK,EAALA,KADY;AAEZD,oBAAAA,MAAM,EAANA,MAFY;AAGZE,oBAAAA,qBAAqB,EAAE2B,aAHX;AAIZ1C,oBAAAA,aAAa,EAAEJ;AAJH,mBAAd;AAMD;;AA5CL;AAAA;;AAAA;AAAA;AAAA;AA8CI,qBAAKsD,UAAL,eAAgC,YAAhC;AACA,+CAAKhB,eAAL,oFAAwBhC,KAAxB,CAA8BP,gBAA9B,CAA+CC,SAA/C;;AA/CJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;WAsDA,wBAA+B;AAC7B,aAAO,KAAKE,KAAL,CAAWC,cAAX,EAAP;AACD;;;WAGD,kBAAiBoD,EAAjB,EAA+C;AAAA,UAAhBC,EAAgB,uEAAX,GAAW;AAC7CC,MAAAA,YAAY,CAAC,KAAKvD,KAAL,CAAWwD,UAAZ,CAAZ;AACA,WAAKxD,KAAL,CAAWwD,UAAX,GAAwBC,UAAU,CAAC;AAAA,eAAMJ,EAAE,EAAR;AAAA,OAAD,EAAaC,EAAb,CAAlC;AACD;;;EAvLwDI,oB;;;8BAA9C3D,Q,eAGQ,U;8BAHRA,Q,kBAIyBjB,Y","sourcesContent":["// deck.gl, MIT license\n// Attributions:\n// Copyright 2022 Foursquare Labs, Inc.\n\n/* eslint-disable camelcase */ // Some WMS parameters are not in camel case\n/* global setTimeout, clearTimeout */\n\nimport {\n Layer,\n CompositeLayer,\n CompositeLayerProps,\n UpdateParameters,\n DefaultProps,\n Viewport,\n COORDINATE_SYSTEM,\n _deepEqual as deepEqual\n} from '@deck.gl/core';\nimport {BitmapLayer} from '@deck.gl/layers';\nimport type {ImageSourceMetadata, ImageType, ImageServiceType} from '@loaders.gl/wms';\nimport {ImageSource, createImageSource} from '@loaders.gl/wms';\nimport {WGS84ToPseudoMercator} from './utils';\n\n/** All props supported by the TileLayer */\nexport type WMSLayerProps = CompositeLayerProps & _WMSLayerProps;\n\n/** Props added by the TileLayer */\ntype _WMSLayerProps = {\n data: string | ImageSource;\n serviceType?: ImageServiceType | 'auto';\n layers?: string[];\n srs?: 'EPSG:4326' | 'EPSG:3857' | 'auto';\n onMetadataLoad?: (metadata: ImageSourceMetadata) => void;\n onMetadataLoadError?: (error: Error) => void;\n onImageLoadStart?: (requestId: unknown) => void;\n onImageLoad?: (requestId: unknown) => void;\n onImageLoadError?: (requestId: unknown, error: Error) => void;\n};\n\nconst defaultProps: DefaultProps<WMSLayerProps> = {\n id: 'imagery-layer',\n data: '',\n serviceType: 'auto',\n srs: 'auto',\n layers: {type: 'array', compare: true, value: []},\n onMetadataLoad: {type: 'function', value: () => {}},\n // eslint-disable-next-line\n onMetadataLoadError: {type: 'function', value: console.error},\n onImageLoadStart: {type: 'function', value: () => {}},\n onImageLoad: {type: 'function', value: () => {}},\n onImageLoadError: {\n type: 'function',\n compare: false,\n // eslint-disable-next-line\n value: (requestId: unknown, error: Error) => console.error(error, requestId)\n }\n};\n\n/**\n * The layer is used in Hex Tile layer in order to properly discard invisible elements during animation\n */\nexport class WMSLayer<ExtraPropsT extends {} = {}> extends CompositeLayer<\n ExtraPropsT & Required<_WMSLayerProps>\n> {\n static layerName = 'WMSLayer';\n static defaultProps: DefaultProps = defaultProps;\n\n state!: {\n imageSource: ImageSource;\n image: ImageType;\n bounds: [number, number, number, number];\n lastRequestParameters: {\n bbox: [number, number, number, number];\n layers: string[];\n srs: 'EPSG:4326' | 'EPSG:3857';\n width: number;\n height: number;\n };\n lastRequestId: number;\n\n _nextRequestId: number;\n _timeoutId: any;\n };\n\n /** Lets deck.gl know that we want viewport change events */\n override shouldUpdateState(): boolean {\n return true;\n }\n\n override initializeState(): void {\n // intentionally empty, initialization is done in updateState\n this.state._nextRequestId = 0;\n this.state.lastRequestId = -1;\n }\n\n override updateState({changeFlags, props, oldProps}: UpdateParameters<this>): void {\n const {viewport} = this.context;\n\n // Check if data source has changed\n if (changeFlags.dataChanged || props.serviceType !== oldProps.serviceType) {\n this.state.imageSource = this._createImageSource(props);\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this._loadMetadata();\n this.debounce(() => this.loadImage(viewport, 'image source changed'), 0);\n } else if (!deepEqual(props.layers, oldProps.layers, 1)) {\n this.debounce(() => this.loadImage(viewport, 'layers changed'), 0);\n } else if (changeFlags.viewportChanged) {\n this.debounce(() => this.loadImage(viewport, 'viewport changed'));\n }\n }\n\n override finalizeState(): void {\n // TODO - we could cancel outstanding requests\n }\n\n override renderLayers(): Layer {\n // TODO - which bitmap layer is rendered should depend on the current viewport\n // Currently Studio only uses one viewport\n const {bounds, image, lastRequestParameters} = this.state;\n\n return (\n image &&\n new BitmapLayer({\n ...this.getSubLayerProps({id: 'bitmap'}),\n _imageCoordinateSystem:\n lastRequestParameters.srs === 'EPSG:4326'\n ? COORDINATE_SYSTEM.LNGLAT\n : COORDINATE_SYSTEM.CARTESIAN,\n bounds,\n image\n })\n );\n }\n\n async getFeatureInfoText(x: number, y: number): Promise<string | null> {\n const {lastRequestParameters} = this.state;\n if (lastRequestParameters) {\n // @ts-expect-error Undocumented method\n const featureInfo = await this.state.imageSource.getFeatureInfoText?.({\n ...lastRequestParameters,\n query_layers: lastRequestParameters.layers,\n x,\n y,\n info_format: 'application/vnd.ogc.gml'\n });\n return featureInfo;\n }\n return '';\n }\n\n _createImageSource(props: WMSLayerProps): ImageSource {\n if (props.data instanceof ImageSource) {\n return props.data;\n }\n\n if (typeof props.data === 'string') {\n return createImageSource({\n url: props.data,\n loadOptions: props.loadOptions,\n type: props.serviceType\n });\n }\n\n throw new Error('invalid image source in props.data');\n }\n\n /** Run a getMetadata on the image service */\n async _loadMetadata(): Promise<void> {\n const {imageSource} = this.state;\n try {\n const metadata = await imageSource.getMetadata();\n\n // If a request takes a long time, it may no longer be expected\n if (this.state.imageSource === imageSource) {\n this.getCurrentLayer()?.props.onMetadataLoad(metadata);\n }\n } catch (error) {\n this.getCurrentLayer()?.props.onMetadataLoadError(error as Error);\n }\n }\n\n /** Load an image */\n async loadImage(viewport: Viewport, reason: string): Promise<void> {\n const {layers, serviceType} = this.props;\n\n // TODO - move to ImageSource?\n if (serviceType === 'wms' && layers.length === 0) {\n return;\n }\n\n const bounds = viewport.getBounds();\n const {width, height} = viewport;\n const requestId = this.getRequestId();\n let {srs} = this.props;\n if (srs === 'auto') {\n // BitmapLayer only supports LNGLAT or CARTESIAN (Web-Mercator)\n srs = viewport.resolution ? 'EPSG:4326' : 'EPSG:3857';\n }\n const requestParams = {\n width,\n height,\n bbox: bounds,\n layers,\n srs\n };\n if (srs === 'EPSG:3857') {\n const [minX, minY] = WGS84ToPseudoMercator([bounds[0], bounds[1]]);\n const [maxX, maxY] = WGS84ToPseudoMercator([bounds[2], bounds[3]]);\n requestParams.bbox = [minX, minY, maxX, maxY];\n }\n\n try {\n this.props.onImageLoadStart(requestId);\n\n const image = await this.state.imageSource.getImage(requestParams);\n\n // If a request takes a long time, later requests may have already loaded.\n if (this.state.lastRequestId < requestId) {\n this.getCurrentLayer()?.props.onImageLoad(requestId);\n // Not type safe...\n this.setState({\n image,\n bounds,\n lastRequestParameters: requestParams,\n lastRequestId: requestId\n });\n }\n } catch (error) {\n this.raiseError(error as Error, 'Load image');\n this.getCurrentLayer()?.props.onImageLoadError(requestId, error as Error);\n }\n }\n\n // HELPERS\n\n /** Global counter for issuing unique request ids */\n private getRequestId(): number {\n return this.state._nextRequestId++;\n }\n\n /** Runs an action in the future, cancels it if the new action is issued before it executes */\n private debounce(fn: Function, ms = 500): void {\n clearTimeout(this.state._timeoutId);\n this.state._timeoutId = setTimeout(() => fn(), ms);\n }\n}\n"],"file":"wms-layer.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/wms-layer/wms-layer.ts"],"names":["defaultProps","id","data","serviceType","srs","layers","type","compare","value","onMetadataLoad","onMetadataLoadError","console","error","onImageLoadStart","onImageLoad","onImageLoadError","requestId","WMSLayer","Boolean","state","loadCounter","_nextRequestId","lastRequestId","changeFlags","props","oldProps","viewport","context","dataChanged","imageSource","_createImageSource","_loadMetadata","debounce","loadImage","viewportChanged","bounds","image","lastRequestParameters","BitmapLayer","getSubLayerProps","_imageCoordinateSystem","COORDINATE_SYSTEM","LNGLAT","CARTESIAN","x","y","getFeatureInfoText","query_layers","info_format","featureInfo","ImageSource","url","loadOptions","Error","getMetadata","metadata","getCurrentLayer","reason","length","getBounds","width","height","getRequestId","resolution","requestParams","bbox","minX","minY","maxX","maxY","getImage","setState","raiseError","fn","ms","clearTimeout","_timeoutId","setTimeout","CompositeLayer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA;;AAUA;;AAEA;;AACA;;;;;;;;;;AAkBA,IAAMA,YAAyC,GAAG;AAChDC,EAAAA,EAAE,EAAE,eAD4C;AAEhDC,EAAAA,IAAI,EAAE,EAF0C;AAGhDC,EAAAA,WAAW,EAAE,MAHmC;AAIhDC,EAAAA,GAAG,EAAE,MAJ2C;AAKhDC,EAAAA,MAAM,EAAE;AAACC,IAAAA,IAAI,EAAE,OAAP;AAAgBC,IAAAA,OAAO,EAAE,IAAzB;AAA+BC,IAAAA,KAAK,EAAE;AAAtC,GALwC;AAMhDC,EAAAA,cAAc,EAAE;AAACH,IAAAA,IAAI,EAAE,UAAP;AAAmBE,IAAAA,KAAK,EAAE,iBAAM,CAAE;AAAlC,GANgC;AAQhDE,EAAAA,mBAAmB,EAAE;AAACJ,IAAAA,IAAI,EAAE,UAAP;AAAmBE,IAAAA,KAAK,EAAEG,OAAO,CAACC;AAAlC,GAR2B;AAShDC,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B;;;8BAA9C7D,Q,eAGQ,U;8BAHRA,Q,kBAIyBjB,Y","sourcesContent":["// deck.gl, MIT license\n// Attributions:\n// Copyright 2022 Foursquare Labs, Inc.\n\n/* eslint-disable camelcase */ // Some WMS parameters are not in camel case\n/* global setTimeout, clearTimeout */\n\nimport {\n Layer,\n CompositeLayer,\n CompositeLayerProps,\n UpdateParameters,\n DefaultProps,\n Viewport,\n COORDINATE_SYSTEM,\n _deepEqual as deepEqual\n} from '@deck.gl/core';\nimport {BitmapLayer} from '@deck.gl/layers';\nimport type {ImageSourceMetadata, ImageType, ImageServiceType} from '@loaders.gl/wms';\nimport {ImageSource, createImageSource} from '@loaders.gl/wms';\nimport {WGS84ToPseudoMercator} from './utils';\n\n/** All props supported by the TileLayer */\nexport type WMSLayerProps = CompositeLayerProps & _WMSLayerProps;\n\n/** Props added by the TileLayer */\ntype _WMSLayerProps = {\n data: string | ImageSource;\n serviceType?: ImageServiceType | 'auto';\n layers?: string[];\n srs?: 'EPSG:4326' | 'EPSG:3857' | 'auto';\n onMetadataLoad?: (metadata: ImageSourceMetadata) => void;\n onMetadataLoadError?: (error: Error) => void;\n onImageLoadStart?: (requestId: unknown) => void;\n onImageLoad?: (requestId: unknown) => void;\n onImageLoadError?: (requestId: unknown, error: Error) => void;\n};\n\nconst defaultProps: DefaultProps<WMSLayerProps> = {\n id: 'imagery-layer',\n data: '',\n serviceType: 'auto',\n srs: 'auto',\n layers: {type: 'array', compare: true, value: []},\n onMetadataLoad: {type: 'function', value: () => {}},\n // eslint-disable-next-line\n onMetadataLoadError: {type: 'function', value: console.error},\n onImageLoadStart: {type: 'function', value: () => {}},\n onImageLoad: {type: 'function', value: () => {}},\n onImageLoadError: {\n type: 'function',\n compare: false,\n // eslint-disable-next-line\n value: (requestId: unknown, error: Error) => console.error(error, requestId)\n }\n};\n\n/**\n * The layer is used in Hex Tile layer in order to properly discard invisible elements during animation\n */\nexport class WMSLayer<ExtraPropsT extends {} = {}> extends CompositeLayer<\n ExtraPropsT & Required<_WMSLayerProps>\n> {\n static layerName = 'WMSLayer';\n static defaultProps: DefaultProps = defaultProps;\n\n state!: {\n imageSource: ImageSource;\n image: ImageType;\n bounds: [number, number, number, number];\n lastRequestParameters: {\n bbox: [number, number, number, number];\n layers: string[];\n srs: 'EPSG:4326' | 'EPSG:3857';\n width: number;\n height: number;\n };\n lastRequestId: number;\n _nextRequestId: number;\n /** TODO: Change any => setTimeout return type. Different between Node and browser... */\n _timeoutId: any;\n loadCounter: number;\n };\n\n /** Returns true if all async resources are loaded */\n get isLoaded(): boolean {\n // Track the explicit loading done by this layer\n return Boolean(this.state) && this.state.loadCounter === 0 && super.isLoaded;\n }\n\n /** Lets deck.gl know that we want viewport change events */\n override shouldUpdateState(): boolean {\n return true;\n }\n\n override initializeState(): void {\n // intentionally empty, initialization is done in updateState\n this.state._nextRequestId = 0;\n this.state.lastRequestId = -1;\n this.state.loadCounter = 0;\n }\n\n override updateState({changeFlags, props, oldProps}: UpdateParameters<this>): void {\n const {viewport} = this.context;\n\n // Check if data source has changed\n if (changeFlags.dataChanged || props.serviceType !== oldProps.serviceType) {\n this.state.imageSource = this._createImageSource(props);\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this._loadMetadata();\n this.debounce(() => this.loadImage(viewport, 'image source changed'), 0);\n } else if (!deepEqual(props.layers, oldProps.layers, 1)) {\n this.debounce(() => this.loadImage(viewport, 'layers changed'), 0);\n } else if (changeFlags.viewportChanged) {\n this.debounce(() => this.loadImage(viewport, 'viewport changed'));\n }\n }\n\n override finalizeState(): void {\n // TODO - we could cancel outstanding requests\n }\n\n override renderLayers(): Layer {\n // TODO - which bitmap layer is rendered should depend on the current viewport\n // Currently Studio only uses one viewport\n const {bounds, image, lastRequestParameters} = this.state;\n\n return (\n image &&\n new BitmapLayer({\n ...this.getSubLayerProps({id: 'bitmap'}),\n _imageCoordinateSystem:\n lastRequestParameters.srs === 'EPSG:4326'\n ? COORDINATE_SYSTEM.LNGLAT\n : COORDINATE_SYSTEM.CARTESIAN,\n bounds,\n image\n })\n );\n }\n\n async getFeatureInfoText(x: number, y: number): Promise<string | null> {\n const {lastRequestParameters} = this.state;\n if (lastRequestParameters) {\n // @ts-expect-error Undocumented method\n const featureInfo = await this.state.imageSource.getFeatureInfoText?.({\n ...lastRequestParameters,\n query_layers: lastRequestParameters.layers,\n x,\n y,\n info_format: 'application/vnd.ogc.gml'\n });\n return featureInfo;\n }\n return '';\n }\n\n _createImageSource(props: WMSLayerProps): ImageSource {\n if (props.data instanceof ImageSource) {\n return props.data;\n }\n\n if (typeof props.data === 'string') {\n return createImageSource({\n url: props.data,\n loadOptions: props.loadOptions,\n type: props.serviceType\n });\n }\n\n throw new Error('invalid image source in props.data');\n }\n\n /** Run a getMetadata on the image service */\n async _loadMetadata(): Promise<void> {\n const {imageSource} = this.state;\n try {\n this.state.loadCounter++;\n const metadata = await imageSource.getMetadata();\n\n // If a request takes a long time, it may no longer be expected\n if (this.state.imageSource === imageSource) {\n this.getCurrentLayer()?.props.onMetadataLoad(metadata);\n }\n } catch (error) {\n this.getCurrentLayer()?.props.onMetadataLoadError(error as Error);\n } finally {\n this.state.loadCounter--;\n }\n }\n\n /** Load an image */\n async loadImage(viewport: Viewport, reason: string): Promise<void> {\n const {layers, serviceType} = this.props;\n\n // TODO - move to ImageSource?\n if (serviceType === 'wms' && layers.length === 0) {\n return;\n }\n\n const bounds = viewport.getBounds();\n const {width, height} = viewport;\n const requestId = this.getRequestId();\n let {srs} = this.props;\n if (srs === 'auto') {\n // BitmapLayer only supports LNGLAT or CARTESIAN (Web-Mercator)\n srs = viewport.resolution ? 'EPSG:4326' : 'EPSG:3857';\n }\n const requestParams = {\n width,\n height,\n bbox: bounds,\n layers,\n srs\n };\n if (srs === 'EPSG:3857') {\n const [minX, minY] = WGS84ToPseudoMercator([bounds[0], bounds[1]]);\n const [maxX, maxY] = WGS84ToPseudoMercator([bounds[2], bounds[3]]);\n requestParams.bbox = [minX, minY, maxX, maxY];\n }\n\n try {\n this.state.loadCounter++;\n this.props.onImageLoadStart(requestId);\n\n const image = await this.state.imageSource.getImage(requestParams);\n\n // If a request takes a long time, later requests may have already loaded.\n if (this.state.lastRequestId < requestId) {\n this.getCurrentLayer()?.props.onImageLoad(requestId);\n // Not type safe...\n this.setState({\n image,\n bounds,\n lastRequestParameters: requestParams,\n lastRequestId: requestId\n });\n }\n } catch (error) {\n this.raiseError(error as Error, 'Load image');\n this.getCurrentLayer()?.props.onImageLoadError(requestId, error as Error);\n } finally {\n this.state.loadCounter--;\n }\n }\n\n // HELPERS\n\n /** Global counter for issuing unique request ids */\n private getRequestId(): number {\n return this.state._nextRequestId++;\n }\n\n /** Runs an action in the future, cancels it if the new action is issued before it executes */\n private debounce(fn: Function, ms = 500): void {\n clearTimeout(this.state._timeoutId);\n this.state._timeoutId = setTimeout(() => fn(), ms);\n }\n}\n"],"file":"wms-layer.js"}
|
|
@@ -42,6 +42,10 @@ export class WMSLayer extends CompositeLayer {
|
|
|
42
42
|
_defineProperty(this, "state", void 0);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
get isLoaded() {
|
|
46
|
+
return Boolean(this.state) && this.state.loadCounter === 0 && super.isLoaded;
|
|
47
|
+
}
|
|
48
|
+
|
|
45
49
|
shouldUpdateState() {
|
|
46
50
|
return true;
|
|
47
51
|
}
|
|
@@ -49,6 +53,7 @@ export class WMSLayer extends CompositeLayer {
|
|
|
49
53
|
initializeState() {
|
|
50
54
|
this.state._nextRequestId = 0;
|
|
51
55
|
this.state.lastRequestId = -1;
|
|
56
|
+
this.state.loadCounter = 0;
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
updateState({
|
|
@@ -132,6 +137,7 @@ export class WMSLayer extends CompositeLayer {
|
|
|
132
137
|
} = this.state;
|
|
133
138
|
|
|
134
139
|
try {
|
|
140
|
+
this.state.loadCounter++;
|
|
135
141
|
const metadata = await imageSource.getMetadata();
|
|
136
142
|
|
|
137
143
|
if (this.state.imageSource === imageSource) {
|
|
@@ -143,6 +149,8 @@ export class WMSLayer extends CompositeLayer {
|
|
|
143
149
|
var _this$getCurrentLayer2;
|
|
144
150
|
|
|
145
151
|
(_this$getCurrentLayer2 = this.getCurrentLayer()) === null || _this$getCurrentLayer2 === void 0 ? void 0 : _this$getCurrentLayer2.props.onMetadataLoadError(error);
|
|
152
|
+
} finally {
|
|
153
|
+
this.state.loadCounter--;
|
|
146
154
|
}
|
|
147
155
|
}
|
|
148
156
|
|
|
@@ -185,6 +193,7 @@ export class WMSLayer extends CompositeLayer {
|
|
|
185
193
|
}
|
|
186
194
|
|
|
187
195
|
try {
|
|
196
|
+
this.state.loadCounter++;
|
|
188
197
|
this.props.onImageLoadStart(requestId);
|
|
189
198
|
const image = await this.state.imageSource.getImage(requestParams);
|
|
190
199
|
|
|
@@ -204,6 +213,8 @@ export class WMSLayer extends CompositeLayer {
|
|
|
204
213
|
|
|
205
214
|
this.raiseError(error, 'Load image');
|
|
206
215
|
(_this$getCurrentLayer4 = this.getCurrentLayer()) === null || _this$getCurrentLayer4 === void 0 ? void 0 : _this$getCurrentLayer4.props.onImageLoadError(requestId, error);
|
|
216
|
+
} finally {
|
|
217
|
+
this.state.loadCounter--;
|
|
207
218
|
}
|
|
208
219
|
}
|
|
209
220
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/wms-layer/wms-layer.ts"],"names":["CompositeLayer","COORDINATE_SYSTEM","_deepEqual","deepEqual","BitmapLayer","ImageSource","createImageSource","WGS84ToPseudoMercator","defaultProps","id","data","serviceType","srs","layers","type","compare","value","onMetadataLoad","onMetadataLoadError","console","error","onImageLoadStart","onImageLoad","onImageLoadError","requestId","WMSLayer","shouldUpdateState","initializeState","state","_nextRequestId","lastRequestId","updateState","changeFlags","props","oldProps","viewport","context","dataChanged","imageSource","_createImageSource","_loadMetadata","debounce","loadImage","viewportChanged","finalizeState","renderLayers","bounds","image","lastRequestParameters","getSubLayerProps","_imageCoordinateSystem","LNGLAT","CARTESIAN","getFeatureInfoText","x","y","featureInfo","query_layers","info_format","url","loadOptions","Error","metadata","getMetadata","getCurrentLayer","reason","length","getBounds","width","height","getRequestId","resolution","requestParams","bbox","minX","minY","maxX","maxY","getImage","setState","raiseError","fn","ms","clearTimeout","_timeoutId","setTimeout"],"mappings":";AAOA,SAEEA,cAFF,EAOEC,iBAPF,EAQEC,UAAU,IAAIC,SARhB,QASO,eATP;AAUA,SAAQC,WAAR,QAA0B,iBAA1B;AAEA,SAAQC,WAAR,EAAqBC,iBAArB,QAA6C,iBAA7C;AACA,SAAQC,qBAAR,QAAoC,SAApC;AAkBA,MAAMC,YAAyC,GAAG;AAChDC,EAAAA,EAAE,EAAE,eAD4C;AAEhDC,EAAAA,IAAI,EAAE,EAF0C;AAGhDC,EAAAA,WAAW,EAAE,MAHmC;AAIhDC,EAAAA,GAAG,EAAE,MAJ2C;AAKhDC,EAAAA,MAAM,EAAE;AAACC,IAAAA,IAAI,EAAE,OAAP;AAAgBC,IAAAA,OAAO,EAAE,IAAzB;AAA+BC,IAAAA,KAAK,EAAE;AAAtC,GALwC;AAMhDC,EAAAA,cAAc,EAAE;AAACH,IAAAA,IAAI,EAAE,UAAP;AAAmBE,IAAAA,KAAK,EAAE,MAAM,CAAE;AAAlC,GANgC;AAQhDE,EAAAA,mBAAmB,EAAE;AAACJ,IAAAA,IAAI,EAAE,UAAP;AAAmBE,IAAAA,KAAK,EAAEG,OAAO,CAACC;AAAlC,GAR2B;AAShDC,EAAAA,gBAAgB,EAAE;AAACP,IAAAA,IAAI,EAAE,UAAP;AAAmBE,IAAAA,KAAK,EAAE,MAAM,CAAE;AAAlC,GAT8B;AAUhDM,EAAAA,WAAW,EAAE;AAACR,IAAAA,IAAI,EAAE,UAAP;AAAmBE,IAAAA,KAAK,EAAE,MAAM,CAAE;AAAlC,GAVmC;AAWhDO,EAAAA,gBAAgB,EAAE;AAChBT,IAAAA,IAAI,EAAE,UADU;AAEhBC,IAAAA,OAAO,EAAE,KAFO;AA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AAeC,EAAE,GAAG,GAApB,EAA+B;AAC7CC,IAAAA,YAAY,CAAC,KAAKvD,KAAL,CAAWwD,UAAZ,CAAZ;AACA,SAAKxD,KAAL,CAAWwD,UAAX,GAAwBC,UAAU,CAAC,MAAMJ,EAAE,EAAT,EAAaC,EAAb,CAAlC;AACD;;AArLD;;gBAFWzD,Q,eAGQ,U;;gBAHRA,Q,kBAIyBjB,Y","sourcesContent":["// deck.gl, MIT license\n// Attributions:\n// Copyright 2022 Foursquare Labs, Inc.\n\n/* eslint-disable camelcase */ // Some WMS parameters are not in camel case\n/* global setTimeout, clearTimeout */\n\nimport {\n Layer,\n CompositeLayer,\n CompositeLayerProps,\n UpdateParameters,\n DefaultProps,\n Viewport,\n COORDINATE_SYSTEM,\n _deepEqual as deepEqual\n} from '@deck.gl/core';\nimport {BitmapLayer} from '@deck.gl/layers';\nimport type {ImageSourceMetadata, ImageType, ImageServiceType} from '@loaders.gl/wms';\nimport {ImageSource, createImageSource} from '@loaders.gl/wms';\nimport {WGS84ToPseudoMercator} from './utils';\n\n/** All props supported by the TileLayer */\nexport type WMSLayerProps = CompositeLayerProps & _WMSLayerProps;\n\n/** Props added by the TileLayer */\ntype _WMSLayerProps = {\n data: string | ImageSource;\n serviceType?: ImageServiceType | 'auto';\n layers?: string[];\n srs?: 'EPSG:4326' | 'EPSG:3857' | 'auto';\n onMetadataLoad?: (metadata: ImageSourceMetadata) => void;\n onMetadataLoadError?: (error: Error) => void;\n onImageLoadStart?: (requestId: unknown) => void;\n onImageLoad?: (requestId: unknown) => void;\n onImageLoadError?: (requestId: unknown, error: Error) => void;\n};\n\nconst defaultProps: DefaultProps<WMSLayerProps> = {\n id: 'imagery-layer',\n data: '',\n serviceType: 'auto',\n srs: 'auto',\n layers: {type: 'array', compare: true, value: []},\n onMetadataLoad: {type: 'function', value: () => {}},\n // eslint-disable-next-line\n onMetadataLoadError: {type: 'function', value: console.error},\n onImageLoadStart: {type: 'function', value: () => {}},\n onImageLoad: {type: 'function', value: () => {}},\n onImageLoadError: {\n type: 'function',\n compare: false,\n // eslint-disable-next-line\n value: (requestId: unknown, error: Error) => console.error(error, requestId)\n }\n};\n\n/**\n * The layer is used in Hex Tile layer in order to properly discard invisible elements during animation\n */\nexport class WMSLayer<ExtraPropsT extends {} = {}> extends CompositeLayer<\n ExtraPropsT & Required<_WMSLayerProps>\n> {\n static layerName = 'WMSLayer';\n static defaultProps: DefaultProps = defaultProps;\n\n state!: {\n imageSource: ImageSource;\n image: ImageType;\n bounds: [number, number, number, number];\n lastRequestParameters: {\n bbox: [number, number, number, number];\n layers: string[];\n srs: 'EPSG:4326' | 'EPSG:3857';\n width: number;\n height: number;\n };\n lastRequestId: number;\n\n _nextRequestId: number;\n _timeoutId: any;\n };\n\n /** Lets deck.gl know that we want viewport change events */\n override shouldUpdateState(): boolean {\n return true;\n }\n\n override initializeState(): void {\n // intentionally empty, initialization is done in updateState\n this.state._nextRequestId = 0;\n this.state.lastRequestId = -1;\n }\n\n override updateState({changeFlags, props, oldProps}: UpdateParameters<this>): void {\n const {viewport} = this.context;\n\n // Check if data source has changed\n if (changeFlags.dataChanged || props.serviceType !== oldProps.serviceType) {\n this.state.imageSource = this._createImageSource(props);\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this._loadMetadata();\n this.debounce(() => this.loadImage(viewport, 'image source changed'), 0);\n } else if (!deepEqual(props.layers, oldProps.layers, 1)) {\n this.debounce(() => this.loadImage(viewport, 'layers changed'), 0);\n } else if (changeFlags.viewportChanged) {\n this.debounce(() => this.loadImage(viewport, 'viewport changed'));\n }\n }\n\n override finalizeState(): void {\n // TODO - we could cancel outstanding requests\n }\n\n override renderLayers(): Layer {\n // TODO - which bitmap layer is rendered should depend on the current viewport\n // Currently Studio only uses one viewport\n const {bounds, image, lastRequestParameters} = this.state;\n\n return (\n image &&\n new BitmapLayer({\n ...this.getSubLayerProps({id: 'bitmap'}),\n _imageCoordinateSystem:\n lastRequestParameters.srs === 'EPSG:4326'\n ? COORDINATE_SYSTEM.LNGLAT\n : COORDINATE_SYSTEM.CARTESIAN,\n bounds,\n image\n })\n );\n }\n\n async getFeatureInfoText(x: number, y: number): Promise<string | null> {\n const {lastRequestParameters} = this.state;\n if (lastRequestParameters) {\n // @ts-expect-error Undocumented method\n const featureInfo = await this.state.imageSource.getFeatureInfoText?.({\n ...lastRequestParameters,\n query_layers: lastRequestParameters.layers,\n x,\n y,\n info_format: 'application/vnd.ogc.gml'\n });\n return featureInfo;\n }\n return '';\n }\n\n _createImageSource(props: WMSLayerProps): ImageSource {\n if (props.data instanceof ImageSource) {\n return props.data;\n }\n\n if (typeof props.data === 'string') {\n return createImageSource({\n url: props.data,\n loadOptions: props.loadOptions,\n type: props.serviceType\n });\n }\n\n throw new Error('invalid image source in props.data');\n }\n\n /** Run a getMetadata on the image service */\n async _loadMetadata(): Promise<void> {\n const {imageSource} = this.state;\n try {\n const metadata = await imageSource.getMetadata();\n\n // If a request takes a long time, it may no longer be expected\n if (this.state.imageSource === imageSource) {\n this.getCurrentLayer()?.props.onMetadataLoad(metadata);\n }\n } catch (error) {\n this.getCurrentLayer()?.props.onMetadataLoadError(error as Error);\n }\n }\n\n /** Load an image */\n async loadImage(viewport: Viewport, reason: string): Promise<void> {\n const {layers, serviceType} = this.props;\n\n // TODO - move to ImageSource?\n if (serviceType === 'wms' && layers.length === 0) {\n return;\n }\n\n const bounds = viewport.getBounds();\n const {width, height} = viewport;\n const requestId = this.getRequestId();\n let {srs} = this.props;\n if (srs === 'auto') {\n // BitmapLayer only supports LNGLAT or CARTESIAN (Web-Mercator)\n srs = viewport.resolution ? 'EPSG:4326' : 'EPSG:3857';\n }\n const requestParams = {\n width,\n height,\n bbox: bounds,\n layers,\n srs\n };\n if (srs === 'EPSG:3857') {\n const [minX, minY] = WGS84ToPseudoMercator([bounds[0], bounds[1]]);\n const [maxX, maxY] = WGS84ToPseudoMercator([bounds[2], bounds[3]]);\n requestParams.bbox = [minX, minY, maxX, maxY];\n }\n\n try {\n this.props.onImageLoadStart(requestId);\n\n const image = await this.state.imageSource.getImage(requestParams);\n\n // If a request takes a long time, later requests may have already loaded.\n if (this.state.lastRequestId < requestId) {\n this.getCurrentLayer()?.props.onImageLoad(requestId);\n // Not type safe...\n this.setState({\n image,\n bounds,\n lastRequestParameters: requestParams,\n lastRequestId: requestId\n });\n }\n } catch (error) {\n this.raiseError(error as Error, 'Load image');\n this.getCurrentLayer()?.props.onImageLoadError(requestId, error as Error);\n }\n }\n\n // HELPERS\n\n /** Global counter for issuing unique request ids */\n private getRequestId(): number {\n return this.state._nextRequestId++;\n }\n\n /** Runs an action in the future, cancels it if the new action is issued before it executes */\n private debounce(fn: Function, ms = 500): void {\n clearTimeout(this.state._timeoutId);\n this.state._timeoutId = setTimeout(() => fn(), ms);\n }\n}\n"],"file":"wms-layer.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/wms-layer/wms-layer.ts"],"names":["CompositeLayer","COORDINATE_SYSTEM","_deepEqual","deepEqual","BitmapLayer","ImageSource","createImageSource","WGS84ToPseudoMercator","defaultProps","id","data","serviceType","srs","layers","type","compare","value","onMetadataLoad","onMetadataLoadError","console","error","onImageLoadStart","onImageLoad","onImageLoadError","requestId","WMSLayer","isLoaded","Boolean","state","loadCounter","shouldUpdateState","initializeState","_nextRequestId","lastRequestId","updateState","changeFlags","props","oldProps","viewport","context","dataChanged","imageSource","_createImageSource","_loadMetadata","debounce","loadImage","viewportChanged","finalizeState","renderLayers","bounds","image","lastRequestParameters","getSubLayerProps","_imageCoordinateSystem","LNGLAT","CARTESIAN","getFeatureInfoText","x","y","featureInfo","query_layers","info_format","url","loadOptions","Error","metadata","getMetadata","getCurrentLayer","reason","length","getBounds","width","height","getRequestId","resolution","requestParams","bbox","minX","minY","maxX","maxY","getImage","setState","raiseError","fn","ms","clearTimeout","_timeoutId","setTimeout"],"mappings":";AAOA,SAEEA,cAFF,EAOEC,iBAPF,EAQEC,UAAU,IAAIC,SARhB,QASO,eATP;AAUA,SAAQC,WAA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AC7B,WAAO,KAAK7C,KAAL,CAAWI,cAAX,EAAP;AACD;;AAGOY,EAAAA,QAAQ,CAACwC,EAAD,EAAeC,EAAE,GAAG,GAApB,EAA+B;AAC7CC,IAAAA,YAAY,CAAC,KAAK1D,KAAL,CAAW2D,UAAZ,CAAZ;AACA,SAAK3D,KAAL,CAAW2D,UAAX,GAAwBC,UAAU,CAAC,MAAMJ,EAAE,EAAT,EAAaC,EAAb,CAAlC;AACD;;AAnMD;;gBAFW5D,Q,eAGQ,U;;gBAHRA,Q,kBAIyBjB,Y","sourcesContent":["// deck.gl, MIT license\n// Attributions:\n// Copyright 2022 Foursquare Labs, Inc.\n\n/* eslint-disable camelcase */ // Some WMS parameters are not in camel case\n/* global setTimeout, clearTimeout */\n\nimport {\n Layer,\n CompositeLayer,\n CompositeLayerProps,\n UpdateParameters,\n DefaultProps,\n Viewport,\n COORDINATE_SYSTEM,\n _deepEqual as deepEqual\n} from '@deck.gl/core';\nimport {BitmapLayer} from '@deck.gl/layers';\nimport type {ImageSourceMetadata, ImageType, ImageServiceType} from '@loaders.gl/wms';\nimport {ImageSource, createImageSource} from '@loaders.gl/wms';\nimport {WGS84ToPseudoMercator} from './utils';\n\n/** All props supported by the TileLayer */\nexport type WMSLayerProps = CompositeLayerProps & _WMSLayerProps;\n\n/** Props added by the TileLayer */\ntype _WMSLayerProps = {\n data: string | ImageSource;\n serviceType?: ImageServiceType | 'auto';\n layers?: string[];\n srs?: 'EPSG:4326' | 'EPSG:3857' | 'auto';\n onMetadataLoad?: (metadata: ImageSourceMetadata) => void;\n onMetadataLoadError?: (error: Error) => void;\n onImageLoadStart?: (requestId: unknown) => void;\n onImageLoad?: (requestId: unknown) => void;\n onImageLoadError?: (requestId: unknown, error: Error) => void;\n};\n\nconst defaultProps: DefaultProps<WMSLayerProps> = {\n id: 'imagery-layer',\n data: '',\n serviceType: 'auto',\n srs: 'auto',\n layers: {type: 'array', compare: true, value: []},\n onMetadataLoad: {type: 'function', value: () => {}},\n // eslint-disable-next-line\n onMetadataLoadError: {type: 'function', value: console.error},\n onImageLoadStart: {type: 'function', value: () => {}},\n onImageLoad: {type: 'function', value: () => {}},\n onImageLoadError: {\n type: 'function',\n compare: false,\n // eslint-disable-next-line\n value: (requestId: unknown, error: Error) => console.error(error, requestId)\n }\n};\n\n/**\n * The layer is used in Hex Tile layer in order to properly discard invisible elements during animation\n */\nexport class WMSLayer<ExtraPropsT extends {} = {}> extends CompositeLayer<\n ExtraPropsT & Required<_WMSLayerProps>\n> {\n static layerName = 'WMSLayer';\n static defaultProps: DefaultProps = defaultProps;\n\n state!: {\n imageSource: ImageSource;\n image: ImageType;\n bounds: [number, number, number, number];\n lastRequestParameters: {\n bbox: [number, number, number, number];\n layers: string[];\n srs: 'EPSG:4326' | 'EPSG:3857';\n width: number;\n height: number;\n };\n lastRequestId: number;\n _nextRequestId: number;\n /** TODO: Change any => setTimeout return type. Different between Node and browser... */\n _timeoutId: any;\n loadCounter: number;\n };\n\n /** Returns true if all async resources are loaded */\n get isLoaded(): boolean {\n // Track the explicit loading done by this layer\n return Boolean(this.state) && this.state.loadCounter === 0 && super.isLoaded;\n }\n\n /** Lets deck.gl know that we want viewport change events */\n override shouldUpdateState(): boolean {\n return true;\n }\n\n override initializeState(): void {\n // intentionally empty, initialization is done in updateState\n this.state._nextRequestId = 0;\n this.state.lastRequestId = -1;\n this.state.loadCounter = 0;\n }\n\n override updateState({changeFlags, props, oldProps}: UpdateParameters<this>): void {\n const {viewport} = this.context;\n\n // Check if data source has changed\n if (changeFlags.dataChanged || props.serviceType !== oldProps.serviceType) {\n this.state.imageSource = this._createImageSource(props);\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this._loadMetadata();\n this.debounce(() => this.loadImage(viewport, 'image source changed'), 0);\n } else if (!deepEqual(props.layers, oldProps.layers, 1)) {\n this.debounce(() => this.loadImage(viewport, 'layers changed'), 0);\n } else if (changeFlags.viewportChanged) {\n this.debounce(() => this.loadImage(viewport, 'viewport changed'));\n }\n }\n\n override finalizeState(): void {\n // TODO - we could cancel outstanding requests\n }\n\n override renderLayers(): Layer {\n // TODO - which bitmap layer is rendered should depend on the current viewport\n // Currently Studio only uses one viewport\n const {bounds, image, lastRequestParameters} = this.state;\n\n return (\n image &&\n new BitmapLayer({\n ...this.getSubLayerProps({id: 'bitmap'}),\n _imageCoordinateSystem:\n lastRequestParameters.srs === 'EPSG:4326'\n ? COORDINATE_SYSTEM.LNGLAT\n : COORDINATE_SYSTEM.CARTESIAN,\n bounds,\n image\n })\n );\n }\n\n async getFeatureInfoText(x: number, y: number): Promise<string | null> {\n const {lastRequestParameters} = this.state;\n if (lastRequestParameters) {\n // @ts-expect-error Undocumented method\n const featureInfo = await this.state.imageSource.getFeatureInfoText?.({\n ...lastRequestParameters,\n query_layers: lastRequestParameters.layers,\n x,\n y,\n info_format: 'application/vnd.ogc.gml'\n });\n return featureInfo;\n }\n return '';\n }\n\n _createImageSource(props: WMSLayerProps): ImageSource {\n if (props.data instanceof ImageSource) {\n return props.data;\n }\n\n if (typeof props.data === 'string') {\n return createImageSource({\n url: props.data,\n loadOptions: props.loadOptions,\n type: props.serviceType\n });\n }\n\n throw new Error('invalid image source in props.data');\n }\n\n /** Run a getMetadata on the image service */\n async _loadMetadata(): Promise<void> {\n const {imageSource} = this.state;\n try {\n this.state.loadCounter++;\n const metadata = await imageSource.getMetadata();\n\n // If a request takes a long time, it may no longer be expected\n if (this.state.imageSource === imageSource) {\n this.getCurrentLayer()?.props.onMetadataLoad(metadata);\n }\n } catch (error) {\n this.getCurrentLayer()?.props.onMetadataLoadError(error as Error);\n } finally {\n this.state.loadCounter--;\n }\n }\n\n /** Load an image */\n async loadImage(viewport: Viewport, reason: string): Promise<void> {\n const {layers, serviceType} = this.props;\n\n // TODO - move to ImageSource?\n if (serviceType === 'wms' && layers.length === 0) {\n return;\n }\n\n const bounds = viewport.getBounds();\n const {width, height} = viewport;\n const requestId = this.getRequestId();\n let {srs} = this.props;\n if (srs === 'auto') {\n // BitmapLayer only supports LNGLAT or CARTESIAN (Web-Mercator)\n srs = viewport.resolution ? 'EPSG:4326' : 'EPSG:3857';\n }\n const requestParams = {\n width,\n height,\n bbox: bounds,\n layers,\n srs\n };\n if (srs === 'EPSG:3857') {\n const [minX, minY] = WGS84ToPseudoMercator([bounds[0], bounds[1]]);\n const [maxX, maxY] = WGS84ToPseudoMercator([bounds[2], bounds[3]]);\n requestParams.bbox = [minX, minY, maxX, maxY];\n }\n\n try {\n this.state.loadCounter++;\n this.props.onImageLoadStart(requestId);\n\n const image = await this.state.imageSource.getImage(requestParams);\n\n // If a request takes a long time, later requests may have already loaded.\n if (this.state.lastRequestId < requestId) {\n this.getCurrentLayer()?.props.onImageLoad(requestId);\n // Not type safe...\n this.setState({\n image,\n bounds,\n lastRequestParameters: requestParams,\n lastRequestId: requestId\n });\n }\n } catch (error) {\n this.raiseError(error as Error, 'Load image');\n this.getCurrentLayer()?.props.onImageLoadError(requestId, error as Error);\n } finally {\n this.state.loadCounter--;\n }\n }\n\n // HELPERS\n\n /** Global counter for issuing unique request ids */\n private getRequestId(): number {\n return this.state._nextRequestId++;\n }\n\n /** Runs an action in the future, cancels it if the new action is issued before it executes */\n private debounce(fn: Function, ms = 500): void {\n clearTimeout(this.state._timeoutId);\n this.state._timeoutId = setTimeout(() => fn(), ms);\n }\n}\n"],"file":"wms-layer.js"}
|