@deck.gl/geo-layers 8.10.0-alpha.4 → 8.10.0-alpha.6

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 (84) hide show
  1. package/dist/dist.dev.js +23 -666
  2. package/dist/es5/geo-cell-layer/GeoCellLayer.js +66 -69
  3. package/dist/es5/geo-cell-layer/GeoCellLayer.js.map +1 -1
  4. package/dist/es5/geohash-layer/geohash-layer.js +18 -22
  5. package/dist/es5/geohash-layer/geohash-layer.js.map +1 -1
  6. package/dist/es5/great-circle-layer/great-circle-layer.js +2 -4
  7. package/dist/es5/great-circle-layer/great-circle-layer.js.map +1 -1
  8. package/dist/es5/h3-layers/h3-cluster-layer.js +85 -91
  9. package/dist/es5/h3-layers/h3-cluster-layer.js.map +1 -1
  10. package/dist/es5/h3-layers/h3-hexagon-layer.js +222 -234
  11. package/dist/es5/h3-layers/h3-hexagon-layer.js.map +1 -1
  12. package/dist/es5/index.js.map +1 -1
  13. package/dist/es5/mesh-layer/mesh-layer.js +126 -136
  14. package/dist/es5/mesh-layer/mesh-layer.js.map +1 -1
  15. package/dist/es5/mvt-layer/mvt-layer.js +338 -350
  16. package/dist/es5/mvt-layer/mvt-layer.js.map +1 -1
  17. package/dist/es5/quadkey-layer/quadkey-layer.js +23 -27
  18. package/dist/es5/quadkey-layer/quadkey-layer.js.map +1 -1
  19. package/dist/es5/s2-layer/s2-layer.js +18 -22
  20. package/dist/es5/s2-layer/s2-layer.js.map +1 -1
  21. package/dist/es5/terrain-layer/terrain-layer.js +225 -234
  22. package/dist/es5/terrain-layer/terrain-layer.js.map +1 -1
  23. package/dist/es5/tile-3d-layer/tile-3d-layer.js +338 -354
  24. package/dist/es5/tile-3d-layer/tile-3d-layer.js.map +1 -1
  25. package/dist/es5/tile-layer/tile-layer.js +219 -234
  26. package/dist/es5/tile-layer/tile-layer.js.map +1 -1
  27. package/dist/es5/tileset-2d/tile-2d-header.js +160 -164
  28. package/dist/es5/tileset-2d/tile-2d-header.js.map +1 -1
  29. package/dist/es5/tileset-2d/tile-2d-traversal.js +118 -122
  30. package/dist/es5/tileset-2d/tile-2d-traversal.js.map +1 -1
  31. package/dist/es5/tileset-2d/tileset-2d.js +397 -411
  32. package/dist/es5/tileset-2d/tileset-2d.js.map +1 -1
  33. package/dist/es5/trips-layer/trips-layer.js +48 -52
  34. package/dist/es5/trips-layer/trips-layer.js.map +1 -1
  35. package/dist/es5/wms-layer/wms-layer.js +263 -274
  36. package/dist/es5/wms-layer/wms-layer.js.map +1 -1
  37. package/dist/esm/geo-cell-layer/GeoCellLayer.js +2 -5
  38. package/dist/esm/geo-cell-layer/GeoCellLayer.js.map +1 -1
  39. package/dist/esm/geohash-layer/geohash-layer.js +2 -5
  40. package/dist/esm/geohash-layer/geohash-layer.js.map +1 -1
  41. package/dist/esm/great-circle-layer/great-circle-layer.js +2 -5
  42. package/dist/esm/great-circle-layer/great-circle-layer.js.map +1 -1
  43. package/dist/esm/h3-layers/h3-cluster-layer.js +2 -5
  44. package/dist/esm/h3-layers/h3-cluster-layer.js.map +1 -1
  45. package/dist/esm/h3-layers/h3-hexagon-layer.js +4 -8
  46. package/dist/esm/h3-layers/h3-hexagon-layer.js.map +1 -1
  47. package/dist/esm/index.js.map +1 -1
  48. package/dist/esm/mesh-layer/mesh-layer-fragment.glsl.js +55 -1
  49. package/dist/esm/mesh-layer/mesh-layer-fragment.glsl.js.map +1 -1
  50. package/dist/esm/mesh-layer/mesh-layer-vertex.glsl.js +80 -1
  51. package/dist/esm/mesh-layer/mesh-layer-vertex.glsl.js.map +1 -1
  52. package/dist/esm/mesh-layer/mesh-layer.js +2 -5
  53. package/dist/esm/mesh-layer/mesh-layer.js.map +1 -1
  54. package/dist/esm/mvt-layer/mvt-layer.js +2 -5
  55. package/dist/esm/mvt-layer/mvt-layer.js.map +1 -1
  56. package/dist/esm/quadkey-layer/quadkey-layer.js +2 -5
  57. package/dist/esm/quadkey-layer/quadkey-layer.js.map +1 -1
  58. package/dist/esm/s2-layer/s2-geometry.js +1 -1
  59. package/dist/esm/s2-layer/s2-geometry.js.map +1 -1
  60. package/dist/esm/s2-layer/s2-layer.js +2 -5
  61. package/dist/esm/s2-layer/s2-layer.js.map +1 -1
  62. package/dist/esm/terrain-layer/terrain-layer.js +3 -7
  63. package/dist/esm/terrain-layer/terrain-layer.js.map +1 -1
  64. package/dist/esm/tile-3d-layer/tile-3d-layer.js +7 -11
  65. package/dist/esm/tile-3d-layer/tile-3d-layer.js.map +1 -1
  66. package/dist/esm/tile-layer/tile-layer.js +2 -5
  67. package/dist/esm/tile-layer/tile-layer.js.map +1 -1
  68. package/dist/esm/tileset-2d/tile-2d-header.js +19 -39
  69. package/dist/esm/tileset-2d/tile-2d-header.js.map +1 -1
  70. package/dist/esm/tileset-2d/tile-2d-traversal.js +6 -13
  71. package/dist/esm/tileset-2d/tile-2d-traversal.js.map +1 -1
  72. package/dist/esm/tileset-2d/tileset-2d.js +17 -34
  73. package/dist/esm/tileset-2d/tileset-2d.js.map +1 -1
  74. package/dist/esm/tileset-2d/utils.js +1 -1
  75. package/dist/esm/tileset-2d/utils.js.map +1 -1
  76. package/dist/esm/trips-layer/trips-layer.js +27 -10
  77. package/dist/esm/trips-layer/trips-layer.js.map +1 -1
  78. package/dist/esm/wms-layer/wms-layer.js +3 -7
  79. package/dist/esm/wms-layer/wms-layer.js.map +1 -1
  80. package/dist.min.js +111 -56
  81. package/package.json +2 -2
  82. package/src/index.ts +1 -0
  83. package/typed/index.d.ts +1 -0
  84. package/typed/index.d.ts.map +1 -1
@@ -13,12 +13,12 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
13
13
 
14
14
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
15
 
16
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
+
16
18
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
17
19
 
18
20
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
19
21
 
20
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
21
-
22
22
  var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
23
23
 
24
24
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
@@ -27,8 +27,6 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
27
27
 
28
28
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
29
29
 
30
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
31
-
32
30
  var _core = require("@deck.gl/core");
33
31
 
34
32
  var _layers = require("@deck.gl/layers");
@@ -95,295 +93,286 @@ var WMSLayer = function (_CompositeLayer) {
95
93
  }
96
94
 
97
95
  _this = _super.call.apply(_super, [this].concat(args));
98
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "state", void 0);
96
+ _this.state = void 0;
99
97
  return _this;
100
98
  }
101
99
 
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
- }, {
108
- key: "shouldUpdateState",
109
- value: function shouldUpdateState() {
110
- return true;
100
+ var _proto = WMSLayer.prototype;
101
+
102
+ _proto.shouldUpdateState = function shouldUpdateState() {
103
+ return true;
104
+ };
105
+
106
+ _proto.initializeState = function initializeState() {
107
+ this.state._nextRequestId = 0;
108
+ this.state.lastRequestId = -1;
109
+ this.state.loadCounter = 0;
110
+ };
111
+
112
+ _proto.updateState = function updateState(_ref) {
113
+ var _this2 = this;
114
+
115
+ var changeFlags = _ref.changeFlags,
116
+ props = _ref.props,
117
+ oldProps = _ref.oldProps;
118
+ var viewport = this.context.viewport;
119
+
120
+ if (changeFlags.dataChanged || props.serviceType !== oldProps.serviceType) {
121
+ this.state.imageSource = this._createImageSource(props);
122
+
123
+ this._loadMetadata();
124
+
125
+ this.debounce(function () {
126
+ return _this2.loadImage(viewport, 'image source changed');
127
+ }, 0);
128
+ } else if (!(0, _core._deepEqual)(props.layers, oldProps.layers, 1)) {
129
+ this.debounce(function () {
130
+ return _this2.loadImage(viewport, 'layers changed');
131
+ }, 0);
132
+ } else if (changeFlags.viewportChanged) {
133
+ this.debounce(function () {
134
+ return _this2.loadImage(viewport, 'viewport changed');
135
+ });
111
136
  }
112
- }, {
113
- key: "initializeState",
114
- value: function initializeState() {
115
- this.state._nextRequestId = 0;
116
- this.state.lastRequestId = -1;
117
- this.state.loadCounter = 0;
137
+ };
138
+
139
+ _proto.finalizeState = function finalizeState() {};
140
+
141
+ _proto.renderLayers = function renderLayers() {
142
+ var _this$state = this.state,
143
+ bounds = _this$state.bounds,
144
+ image = _this$state.image,
145
+ lastRequestParameters = _this$state.lastRequestParameters;
146
+ return image && new _layers.BitmapLayer(_objectSpread(_objectSpread({}, this.getSubLayerProps({
147
+ id: 'bitmap'
148
+ })), {}, {
149
+ _imageCoordinateSystem: lastRequestParameters.srs === 'EPSG:4326' ? _core.COORDINATE_SYSTEM.LNGLAT : _core.COORDINATE_SYSTEM.CARTESIAN,
150
+ bounds: bounds,
151
+ image: image
152
+ }));
153
+ };
154
+
155
+ _proto.getFeatureInfoText = function () {
156
+ var _getFeatureInfoText = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(x, y) {
157
+ var lastRequestParameters, _this$state$imageSour, _this$state$imageSour2, featureInfo;
158
+
159
+ return _regenerator.default.wrap(function _callee$(_context) {
160
+ while (1) {
161
+ switch (_context.prev = _context.next) {
162
+ case 0:
163
+ lastRequestParameters = this.state.lastRequestParameters;
164
+
165
+ if (!lastRequestParameters) {
166
+ _context.next = 6;
167
+ break;
168
+ }
169
+
170
+ _context.next = 4;
171
+ return (_this$state$imageSour = (_this$state$imageSour2 = this.state.imageSource).getFeatureInfoText) === null || _this$state$imageSour === void 0 ? void 0 : _this$state$imageSour.call(_this$state$imageSour2, _objectSpread(_objectSpread({}, lastRequestParameters), {}, {
172
+ query_layers: lastRequestParameters.layers,
173
+ x: x,
174
+ y: y,
175
+ info_format: 'application/vnd.ogc.gml'
176
+ }));
177
+
178
+ case 4:
179
+ featureInfo = _context.sent;
180
+ return _context.abrupt("return", featureInfo);
181
+
182
+ case 6:
183
+ return _context.abrupt("return", '');
184
+
185
+ case 7:
186
+ case "end":
187
+ return _context.stop();
188
+ }
189
+ }
190
+ }, _callee, this);
191
+ }));
192
+
193
+ function getFeatureInfoText(_x, _x2) {
194
+ return _getFeatureInfoText.apply(this, arguments);
118
195
  }
119
- }, {
120
- key: "updateState",
121
- value: function updateState(_ref) {
122
- var _this2 = this;
123
-
124
- var changeFlags = _ref.changeFlags,
125
- props = _ref.props,
126
- oldProps = _ref.oldProps;
127
- var viewport = this.context.viewport;
128
-
129
- if (changeFlags.dataChanged || props.serviceType !== oldProps.serviceType) {
130
- this.state.imageSource = this._createImageSource(props);
131
-
132
- this._loadMetadata();
133
-
134
- this.debounce(function () {
135
- return _this2.loadImage(viewport, 'image source changed');
136
- }, 0);
137
- } else if (!(0, _core._deepEqual)(props.layers, oldProps.layers, 1)) {
138
- this.debounce(function () {
139
- return _this2.loadImage(viewport, 'layers changed');
140
- }, 0);
141
- } else if (changeFlags.viewportChanged) {
142
- this.debounce(function () {
143
- return _this2.loadImage(viewport, 'viewport changed');
144
- });
145
- }
196
+
197
+ return getFeatureInfoText;
198
+ }();
199
+
200
+ _proto._createImageSource = function _createImageSource(props) {
201
+ if (props.data instanceof _wms.ImageSource) {
202
+ return props.data;
146
203
  }
147
- }, {
148
- key: "finalizeState",
149
- value: function finalizeState() {}
150
- }, {
151
- key: "renderLayers",
152
- value: function renderLayers() {
153
- var _this$state = this.state,
154
- bounds = _this$state.bounds,
155
- image = _this$state.image,
156
- lastRequestParameters = _this$state.lastRequestParameters;
157
- return image && new _layers.BitmapLayer(_objectSpread(_objectSpread({}, this.getSubLayerProps({
158
- id: 'bitmap'
159
- })), {}, {
160
- _imageCoordinateSystem: lastRequestParameters.srs === 'EPSG:4326' ? _core.COORDINATE_SYSTEM.LNGLAT : _core.COORDINATE_SYSTEM.CARTESIAN,
161
- bounds: bounds,
162
- image: image
163
- }));
204
+
205
+ if (typeof props.data === 'string') {
206
+ return (0, _wms.createImageSource)({
207
+ url: props.data,
208
+ loadOptions: props.loadOptions,
209
+ type: props.serviceType
210
+ });
164
211
  }
165
- }, {
166
- key: "getFeatureInfoText",
167
- value: function () {
168
- var _getFeatureInfoText = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(x, y) {
169
- var lastRequestParameters, _this$state$imageSour, _this$state$imageSour2, featureInfo;
170
-
171
- return _regenerator.default.wrap(function _callee$(_context) {
172
- while (1) {
173
- switch (_context.prev = _context.next) {
174
- case 0:
175
- lastRequestParameters = this.state.lastRequestParameters;
176
-
177
- if (!lastRequestParameters) {
178
- _context.next = 6;
179
- break;
180
- }
181
-
182
- _context.next = 4;
183
- return (_this$state$imageSour = (_this$state$imageSour2 = this.state.imageSource).getFeatureInfoText) === null || _this$state$imageSour === void 0 ? void 0 : _this$state$imageSour.call(_this$state$imageSour2, _objectSpread(_objectSpread({}, lastRequestParameters), {}, {
184
- query_layers: lastRequestParameters.layers,
185
- x: x,
186
- y: y,
187
- info_format: 'application/vnd.ogc.gml'
188
- }));
189
-
190
- case 4:
191
- featureInfo = _context.sent;
192
- return _context.abrupt("return", featureInfo);
193
-
194
- case 6:
195
- return _context.abrupt("return", '');
196
-
197
- case 7:
198
- case "end":
199
- return _context.stop();
200
- }
212
+
213
+ throw new Error('invalid image source in props.data');
214
+ };
215
+
216
+ _proto._loadMetadata = function () {
217
+ var _loadMetadata2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2() {
218
+ var imageSource, _metadata, _this$getCurrentLayer, _this$getCurrentLayer2;
219
+
220
+ return _regenerator.default.wrap(function _callee2$(_context2) {
221
+ while (1) {
222
+ switch (_context2.prev = _context2.next) {
223
+ case 0:
224
+ imageSource = this.state.imageSource;
225
+ _context2.prev = 1;
226
+ this.state.loadCounter++;
227
+ _context2.next = 5;
228
+ return imageSource.getMetadata();
229
+
230
+ case 5:
231
+ _metadata = _context2.sent;
232
+
233
+ if (this.state.imageSource === imageSource) {
234
+ (_this$getCurrentLayer = this.getCurrentLayer()) === null || _this$getCurrentLayer === void 0 ? void 0 : _this$getCurrentLayer.props.onMetadataLoad(_metadata);
235
+ }
236
+
237
+ _context2.next = 12;
238
+ break;
239
+
240
+ case 9:
241
+ _context2.prev = 9;
242
+ _context2.t0 = _context2["catch"](1);
243
+ (_this$getCurrentLayer2 = this.getCurrentLayer()) === null || _this$getCurrentLayer2 === void 0 ? void 0 : _this$getCurrentLayer2.props.onMetadataLoadError(_context2.t0);
244
+
245
+ case 12:
246
+ _context2.prev = 12;
247
+ this.state.loadCounter--;
248
+ return _context2.finish(12);
249
+
250
+ case 15:
251
+ case "end":
252
+ return _context2.stop();
201
253
  }
202
- }, _callee, this);
203
- }));
204
-
205
- function getFeatureInfoText(_x, _x2) {
206
- return _getFeatureInfoText.apply(this, arguments);
207
- }
208
-
209
- return getFeatureInfoText;
210
- }()
211
- }, {
212
- key: "_createImageSource",
213
- value: function _createImageSource(props) {
214
- if (props.data instanceof _wms.ImageSource) {
215
- return props.data;
216
- }
217
-
218
- if (typeof props.data === 'string') {
219
- return (0, _wms.createImageSource)({
220
- url: props.data,
221
- loadOptions: props.loadOptions,
222
- type: props.serviceType
223
- });
224
- }
225
-
226
- throw new Error('invalid image source in props.data');
254
+ }
255
+ }, _callee2, this, [[1, 9, 12, 15]]);
256
+ }));
257
+
258
+ function _loadMetadata() {
259
+ return _loadMetadata2.apply(this, arguments);
227
260
  }
228
- }, {
229
- key: "_loadMetadata",
230
- value: function () {
231
- var _loadMetadata2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2() {
232
- var imageSource, _metadata, _this$getCurrentLayer, _this$getCurrentLayer2;
233
-
234
- return _regenerator.default.wrap(function _callee2$(_context2) {
235
- while (1) {
236
- switch (_context2.prev = _context2.next) {
237
- case 0:
238
- imageSource = this.state.imageSource;
239
- _context2.prev = 1;
240
- this.state.loadCounter++;
241
- _context2.next = 5;
242
- return imageSource.getMetadata();
243
-
244
- case 5:
245
- _metadata = _context2.sent;
246
-
247
- if (this.state.imageSource === imageSource) {
248
- (_this$getCurrentLayer = this.getCurrentLayer()) === null || _this$getCurrentLayer === void 0 ? void 0 : _this$getCurrentLayer.props.onMetadataLoad(_metadata);
249
- }
250
-
251
- _context2.next = 12;
252
- break;
253
261
 
254
- case 9:
255
- _context2.prev = 9;
256
- _context2.t0 = _context2["catch"](1);
257
- (_this$getCurrentLayer2 = this.getCurrentLayer()) === null || _this$getCurrentLayer2 === void 0 ? void 0 : _this$getCurrentLayer2.props.onMetadataLoadError(_context2.t0);
262
+ return _loadMetadata;
263
+ }();
258
264
 
259
- case 12:
260
- _context2.prev = 12;
261
- this.state.loadCounter--;
262
- return _context2.finish(12);
265
+ _proto.loadImage = function () {
266
+ var _loadImage = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(viewport, reason) {
267
+ var _this$props, layers, serviceType, bounds, width, height, requestId, srs, requestParams, _WGS84ToPseudoMercato, _WGS84ToPseudoMercato2, minX, minY, _WGS84ToPseudoMercato3, _WGS84ToPseudoMercato4, maxX, maxY, image, _this$getCurrentLayer3, _this$getCurrentLayer4;
263
268
 
264
- case 15:
265
- case "end":
266
- return _context2.stop();
267
- }
268
- }
269
- }, _callee2, this, [[1, 9, 12, 15]]);
270
- }));
271
-
272
- function _loadMetadata() {
273
- return _loadMetadata2.apply(this, arguments);
274
- }
275
-
276
- return _loadMetadata;
277
- }()
278
- }, {
279
- key: "loadImage",
280
- value: function () {
281
- var _loadImage = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3(viewport, reason) {
282
- var _this$props, layers, serviceType, bounds, width, height, requestId, srs, requestParams, _WGS84ToPseudoMercato, _WGS84ToPseudoMercato2, minX, minY, _WGS84ToPseudoMercato3, _WGS84ToPseudoMercato4, maxX, maxY, image, _this$getCurrentLayer3, _this$getCurrentLayer4;
283
-
284
- return _regenerator.default.wrap(function _callee3$(_context3) {
285
- while (1) {
286
- switch (_context3.prev = _context3.next) {
287
- case 0:
288
- _this$props = this.props, layers = _this$props.layers, serviceType = _this$props.serviceType;
289
-
290
- if (!(serviceType === 'wms' && layers.length === 0)) {
291
- _context3.next = 3;
292
- break;
293
- }
294
-
295
- return _context3.abrupt("return");
296
-
297
- case 3:
298
- bounds = viewport.getBounds();
299
- width = viewport.width, height = viewport.height;
300
- requestId = this.getRequestId();
301
- srs = this.props.srs;
302
-
303
- if (srs === 'auto') {
304
- srs = viewport.resolution ? 'EPSG:4326' : 'EPSG:3857';
305
- }
306
-
307
- requestParams = {
308
- width: width,
309
- height: height,
310
- bbox: bounds,
311
- layers: layers,
312
- srs: srs
313
- };
314
-
315
- if (srs === 'EPSG:3857') {
316
- _WGS84ToPseudoMercato = (0, _utils.WGS84ToPseudoMercator)([bounds[0], bounds[1]]), _WGS84ToPseudoMercato2 = (0, _slicedToArray2.default)(_WGS84ToPseudoMercato, 2), minX = _WGS84ToPseudoMercato2[0], minY = _WGS84ToPseudoMercato2[1];
317
- _WGS84ToPseudoMercato3 = (0, _utils.WGS84ToPseudoMercator)([bounds[2], bounds[3]]), _WGS84ToPseudoMercato4 = (0, _slicedToArray2.default)(_WGS84ToPseudoMercato3, 2), maxX = _WGS84ToPseudoMercato4[0], maxY = _WGS84ToPseudoMercato4[1];
318
- requestParams.bbox = [minX, minY, maxX, maxY];
319
- }
320
-
321
- _context3.prev = 10;
322
- this.state.loadCounter++;
323
- this.props.onImageLoadStart(requestId);
324
- _context3.next = 15;
325
- return this.state.imageSource.getImage(requestParams);
326
-
327
- case 15:
328
- image = _context3.sent;
329
-
330
- if (this.state.lastRequestId < requestId) {
331
- (_this$getCurrentLayer3 = this.getCurrentLayer()) === null || _this$getCurrentLayer3 === void 0 ? void 0 : _this$getCurrentLayer3.props.onImageLoad(requestId);
332
- this.setState({
333
- image: image,
334
- bounds: bounds,
335
- lastRequestParameters: requestParams,
336
- lastRequestId: requestId
337
- });
338
- }
339
-
340
- _context3.next = 23;
341
- break;
269
+ return _regenerator.default.wrap(function _callee3$(_context3) {
270
+ while (1) {
271
+ switch (_context3.prev = _context3.next) {
272
+ case 0:
273
+ _this$props = this.props, layers = _this$props.layers, serviceType = _this$props.serviceType;
342
274
 
343
- case 19:
344
- _context3.prev = 19;
345
- _context3.t0 = _context3["catch"](10);
346
- this.raiseError(_context3.t0, 'Load image');
347
- (_this$getCurrentLayer4 = this.getCurrentLayer()) === null || _this$getCurrentLayer4 === void 0 ? void 0 : _this$getCurrentLayer4.props.onImageLoadError(requestId, _context3.t0);
348
-
349
- case 23:
350
- _context3.prev = 23;
351
- this.state.loadCounter--;
352
- return _context3.finish(23);
353
-
354
- case 26:
355
- case "end":
356
- return _context3.stop();
357
- }
275
+ if (!(serviceType === 'wms' && layers.length === 0)) {
276
+ _context3.next = 3;
277
+ break;
278
+ }
279
+
280
+ return _context3.abrupt("return");
281
+
282
+ case 3:
283
+ bounds = viewport.getBounds();
284
+ width = viewport.width, height = viewport.height;
285
+ requestId = this.getRequestId();
286
+ srs = this.props.srs;
287
+
288
+ if (srs === 'auto') {
289
+ srs = viewport.resolution ? 'EPSG:4326' : 'EPSG:3857';
290
+ }
291
+
292
+ requestParams = {
293
+ width: width,
294
+ height: height,
295
+ bbox: bounds,
296
+ layers: layers,
297
+ srs: srs
298
+ };
299
+
300
+ if (srs === 'EPSG:3857') {
301
+ _WGS84ToPseudoMercato = (0, _utils.WGS84ToPseudoMercator)([bounds[0], bounds[1]]), _WGS84ToPseudoMercato2 = (0, _slicedToArray2.default)(_WGS84ToPseudoMercato, 2), minX = _WGS84ToPseudoMercato2[0], minY = _WGS84ToPseudoMercato2[1];
302
+ _WGS84ToPseudoMercato3 = (0, _utils.WGS84ToPseudoMercator)([bounds[2], bounds[3]]), _WGS84ToPseudoMercato4 = (0, _slicedToArray2.default)(_WGS84ToPseudoMercato3, 2), maxX = _WGS84ToPseudoMercato4[0], maxY = _WGS84ToPseudoMercato4[1];
303
+ requestParams.bbox = [minX, minY, maxX, maxY];
304
+ }
305
+
306
+ _context3.prev = 10;
307
+ this.state.loadCounter++;
308
+ this.props.onImageLoadStart(requestId);
309
+ _context3.next = 15;
310
+ return this.state.imageSource.getImage(requestParams);
311
+
312
+ case 15:
313
+ image = _context3.sent;
314
+
315
+ if (this.state.lastRequestId < requestId) {
316
+ (_this$getCurrentLayer3 = this.getCurrentLayer()) === null || _this$getCurrentLayer3 === void 0 ? void 0 : _this$getCurrentLayer3.props.onImageLoad(requestId);
317
+ this.setState({
318
+ image: image,
319
+ bounds: bounds,
320
+ lastRequestParameters: requestParams,
321
+ lastRequestId: requestId
322
+ });
323
+ }
324
+
325
+ _context3.next = 23;
326
+ break;
327
+
328
+ case 19:
329
+ _context3.prev = 19;
330
+ _context3.t0 = _context3["catch"](10);
331
+ this.raiseError(_context3.t0, 'Load image');
332
+ (_this$getCurrentLayer4 = this.getCurrentLayer()) === null || _this$getCurrentLayer4 === void 0 ? void 0 : _this$getCurrentLayer4.props.onImageLoadError(requestId, _context3.t0);
333
+
334
+ case 23:
335
+ _context3.prev = 23;
336
+ this.state.loadCounter--;
337
+ return _context3.finish(23);
338
+
339
+ case 26:
340
+ case "end":
341
+ return _context3.stop();
358
342
  }
359
- }, _callee3, this, [[10, 19, 23, 26]]);
360
- }));
361
-
362
- function loadImage(_x3, _x4) {
363
- return _loadImage.apply(this, arguments);
364
- }
365
-
366
- return loadImage;
367
- }()
368
- }, {
369
- key: "getRequestId",
370
- value: function getRequestId() {
371
- return this.state._nextRequestId++;
343
+ }
344
+ }, _callee3, this, [[10, 19, 23, 26]]);
345
+ }));
346
+
347
+ function loadImage(_x3, _x4) {
348
+ return _loadImage.apply(this, arguments);
372
349
  }
373
- }, {
374
- key: "debounce",
375
- value: function debounce(fn) {
376
- var ms = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
377
- clearTimeout(this.state._timeoutId);
378
- this.state._timeoutId = setTimeout(function () {
379
- return fn();
380
- }, ms);
350
+
351
+ return loadImage;
352
+ }();
353
+
354
+ _proto.getRequestId = function getRequestId() {
355
+ return this.state._nextRequestId++;
356
+ };
357
+
358
+ _proto.debounce = function debounce(fn) {
359
+ var ms = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
360
+ clearTimeout(this.state._timeoutId);
361
+ this.state._timeoutId = setTimeout(function () {
362
+ return fn();
363
+ }, ms);
364
+ };
365
+
366
+ (0, _createClass2.default)(WMSLayer, [{
367
+ key: "isLoaded",
368
+ get: function get() {
369
+ return Boolean(this.state) && this.state.loadCounter === 0 && (0, _get2.default)((0, _getPrototypeOf2.default)(WMSLayer.prototype), "isLoaded", this);
381
370
  }
382
371
  }]);
383
372
  return WMSLayer;
384
373
  }(_core.CompositeLayer);
385
374
 
386
375
  exports.WMSLayer = WMSLayer;
387
- (0, _defineProperty2.default)(WMSLayer, "layerName", 'WMSLayer');
388
- (0, _defineProperty2.default)(WMSLayer, "defaultProps", defaultProps);
376
+ WMSLayer.layerName = 'WMSLayer';
377
+ WMSLayer.defaultProps = defaultProps;
389
378
  //# sourceMappingURL=wms-layer.js.map
@@ -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","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,EAAAA,gBAAgB,EAAE;AAACP,IAAAA,IAAI,EAAE,UAAP;AAAmBE,IAAAA,KAAK,EAAE,iBAAM,CAAE;AAAlC,GAT8B;AAUhDM,EAAAA,WAAW,EAAE;AAACR,IAAAA,IAAI,EAAE,UAAP;AAAmBE,IAAAA,KAAK,EAAE,iBAAM,CAAE;AAAlC,GAVmC;AAWhDO,EAAAA,gBAAgB,EAAE;AAChBT,IAAAA,IAAI,EAAE,UADU;AAEhBC,IAAAA,OAAO,EAAE,KAFO;AAIhBC,IAAAA,KAAK,EAAE,eAACQ,SAAD,EAAqBJ,KAArB;AAAA,aAAsCD,OAAO,CAACC,KAAR,C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AAL,oFAAwBhC,KAAxB,CAA8BV,WAA9B,CAA0CE,SAA1C;AAEA,uBAAKuD,QAAL,CAAc;AACZnC,oBAAAA,KAAK,EAALA,KADY;AAEZD,oBAAAA,MAAM,EAANA,MAFY;AAGZE,oBAAAA,qBAAqB,EAAE2B,aAHX;AAIZ1C,oBAAAA,aAAa,EAAEN;AAJH,mBAAd;AAMD;;AA7CL;AAAA;;AAAA;AAAA;AAAA;AA+CI,qBAAKwD,UAAL,eAAgC,YAAhC;AACA,+CAAKhB,eAAL,oFAAwBhC,KAAxB,CAA8BT,gBAA9B,CAA+CC,SAA/C;;AAhDJ;AAAA;AAkDI,qBAAKG,KAAL,CAAWC,WAAX;AAlDJ;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;WAyDA,wBAA+B;AAC7B,aAAO,KAAKD,KAAL,CAAWE,cAAX,EAAP;AACD;;;WAGD,kBAAiBoD,EAAjB,EAA+C;AAAA,UAAhBC,EAAgB,uEAAX,GAAW;AAC7CC,MAAAA,YAAY,CAAC,KAAKxD,KAAL,CAAWyD,UAAZ,CAAZ;AACA,WAAKzD,KAAL,CAAWyD,UAAX,GAAwBC,UAAU,CAAC;AAAA,eAAMJ,EAAE,EAAR;AAAA,OAAD,EAAaC,EAAb,CAAlC;AACD;;;EArMwDI,oB;;;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"}
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","shouldUpdateState","initializeState","_nextRequestId","lastRequestId","loadCounter","updateState","changeFlags","props","oldProps","viewport","context","dataChanged","imageSource","_createImageSource","_loadMetadata","debounce","loadImage","viewportChanged","finalizeState","renderLayers","bounds","image","lastRequestParameters","BitmapLayer","getSubLayerProps","_imageCoordinateSystem","COORDINATE_SYSTEM","LNGLAT","CARTESIAN","getFeatureInfoText","x","y","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","Boolean","CompositeLayer","layerName"],"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,EA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,CAAW8D,UAAX,GAAwBC,UAAU,CAAC;AAAA,aAAMJ,EAAE,EAAR;AAAA,KAAD,EAAaC,EAAb,CAAlC;AACD,G;;;;SA5KD,eAAwB;AAEtB,aAAOI,OAAO,CAAC,KAAKhE,KAAN,CAAP,IAAuB,KAAKA,KAAL,CAAWK,WAAX,KAA2B,CAAlD,2FAAP;AACD;;;EA5BwD4D,oB;;;AAA9ClE,Q,CAGJmE,S,GAAY,U;AAHRnE,Q,CAIJjB,Y,GAA6BA,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"}