ol 7.5.1 → 8.0.0-dev.1692053484481

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 (135) hide show
  1. package/DataTile.d.ts +2 -2
  2. package/DataTile.d.ts.map +1 -1
  3. package/DataTile.js +3 -2
  4. package/Image.d.ts +139 -40
  5. package/Image.d.ts.map +1 -1
  6. package/Image.js +194 -96
  7. package/ImageCanvas.d.ts +2 -2
  8. package/ImageCanvas.d.ts.map +1 -1
  9. package/ImageCanvas.js +2 -2
  10. package/Object.d.ts +7 -0
  11. package/Object.d.ts.map +1 -1
  12. package/Object.js +8 -0
  13. package/dist/ol.js +2 -2
  14. package/dist/ol.js.map +1 -1
  15. package/expr/cpu.d.ts +71 -0
  16. package/expr/cpu.d.ts.map +1 -0
  17. package/expr/cpu.js +312 -0
  18. package/expr/expression.d.ts +97 -0
  19. package/expr/expression.d.ts.map +1 -0
  20. package/expr/expression.js +373 -0
  21. package/has.d.ts +5 -0
  22. package/has.d.ts.map +1 -1
  23. package/has.js +6 -0
  24. package/index.d.ts +1 -2
  25. package/index.js +1 -1
  26. package/layer/Base.d.ts +12 -8
  27. package/layer/Base.d.ts.map +1 -1
  28. package/layer/Base.js +12 -8
  29. package/layer/BaseVector.d.ts.map +1 -1
  30. package/layer/BaseVector.js +67 -33
  31. package/layer/Heatmap.d.ts.map +1 -1
  32. package/layer/Heatmap.js +16 -55
  33. package/layer/Layer.d.ts +2 -2
  34. package/layer/Layer.d.ts.map +1 -1
  35. package/layer/Layer.js +1 -1
  36. package/layer/WebGLPoints.d.ts +7 -12
  37. package/layer/WebGLPoints.d.ts.map +1 -1
  38. package/layer/WebGLPoints.js +7 -12
  39. package/package.json +1 -1
  40. package/render/Feature.d.ts +8 -0
  41. package/render/Feature.d.ts.map +1 -1
  42. package/render/Feature.js +9 -0
  43. package/render/canvas/Immediate.d.ts.map +1 -1
  44. package/render/canvas/Immediate.js +5 -3
  45. package/render/canvas/TextBuilder.js +2 -2
  46. package/render/canvas/style.d.ts +69 -0
  47. package/render/canvas/style.d.ts.map +1 -0
  48. package/render/canvas/style.js +1192 -0
  49. package/render/canvas.js +1 -1
  50. package/render/webgl/VectorStyleRenderer.d.ts.map +1 -1
  51. package/render/webgl/VectorStyleRenderer.js +4 -0
  52. package/renderer/Layer.d.ts +2 -2
  53. package/renderer/Layer.d.ts.map +1 -1
  54. package/renderer/Layer.js +1 -1
  55. package/renderer/canvas/ImageLayer.d.ts +4 -4
  56. package/renderer/canvas/ImageLayer.d.ts.map +1 -1
  57. package/renderer/canvas/ImageLayer.js +17 -12
  58. package/renderer/canvas/Layer.d.ts +2 -2
  59. package/renderer/canvas/Layer.d.ts.map +1 -1
  60. package/renderer/canvas/Layer.js +1 -1
  61. package/renderer/canvas/VectorImageLayer.d.ts.map +1 -1
  62. package/renderer/canvas/VectorImageLayer.js +3 -2
  63. package/renderer/webgl/VectorLayer.d.ts +1 -2
  64. package/renderer/webgl/VectorLayer.d.ts.map +1 -1
  65. package/reproj/Image.d.ts +5 -5
  66. package/reproj/Image.d.ts.map +1 -1
  67. package/reproj/Image.js +6 -6
  68. package/reproj.d.ts +2 -2
  69. package/reproj.d.ts.map +1 -1
  70. package/reproj.js +1 -1
  71. package/resolution.d.ts +13 -0
  72. package/resolution.d.ts.map +1 -0
  73. package/resolution.js +18 -0
  74. package/source/Image.d.ts +44 -7
  75. package/source/Image.d.ts.map +1 -1
  76. package/source/Image.js +97 -8
  77. package/source/ImageArcGISRest.d.ts +0 -23
  78. package/source/ImageArcGISRest.d.ts.map +1 -1
  79. package/source/ImageArcGISRest.js +18 -120
  80. package/source/ImageMapGuide.d.ts +0 -24
  81. package/source/ImageMapGuide.d.ts.map +1 -1
  82. package/source/ImageMapGuide.js +21 -113
  83. package/source/ImageStatic.d.ts +2 -27
  84. package/source/ImageStatic.d.ts.map +1 -1
  85. package/source/ImageStatic.js +20 -70
  86. package/source/ImageWMS.d.ts +2 -46
  87. package/source/ImageWMS.d.ts.map +1 -1
  88. package/source/ImageWMS.js +43 -201
  89. package/source/{Stamen.d.ts → StadiaMaps.d.ts} +17 -7
  90. package/source/StadiaMaps.d.ts.map +1 -0
  91. package/source/{Stamen.js → StadiaMaps.js} +85 -38
  92. package/source/TileArcGISRest.d.ts.map +1 -1
  93. package/source/TileArcGISRest.js +11 -22
  94. package/source/TileWMS.d.ts +0 -1
  95. package/source/TileWMS.d.ts.map +1 -1
  96. package/source/TileWMS.js +43 -106
  97. package/source/arcgisRest.d.ts +88 -0
  98. package/source/arcgisRest.d.ts.map +1 -0
  99. package/source/arcgisRest.js +131 -0
  100. package/source/common.d.ts +5 -0
  101. package/source/common.d.ts.map +1 -1
  102. package/source/common.js +6 -0
  103. package/source/mapguide.d.ts +52 -0
  104. package/source/mapguide.d.ts.map +1 -0
  105. package/source/mapguide.js +116 -0
  106. package/source/static.d.ts +45 -0
  107. package/source/static.d.ts.map +1 -0
  108. package/source/static.js +44 -0
  109. package/source/wms.d.ts +109 -1
  110. package/source/wms.d.ts.map +1 -1
  111. package/source/wms.js +170 -0
  112. package/source.d.ts +5 -1
  113. package/source.d.ts.map +1 -1
  114. package/source.js +5 -1
  115. package/style/flat.d.ts +332 -173
  116. package/style/flat.d.ts.map +1 -1
  117. package/style/flat.js +176 -248
  118. package/style/literal.d.ts +27 -72
  119. package/style/literal.d.ts.map +1 -1
  120. package/style/literal.js +14 -35
  121. package/util.d.ts.map +1 -1
  122. package/util.js +1 -1
  123. package/webgl/Helper.d.ts +7 -2
  124. package/webgl/Helper.d.ts.map +1 -1
  125. package/webgl/Helper.js +16 -27
  126. package/webgl/ShaderBuilder.d.ts +4 -14
  127. package/webgl/ShaderBuilder.d.ts.map +1 -1
  128. package/webgl/ShaderBuilder.js +72 -72
  129. package/webgl/styleparser.d.ts +3 -9
  130. package/webgl/styleparser.d.ts.map +1 -1
  131. package/webgl/styleparser.js +503 -88
  132. package/ImageBase.d.ts +0 -65
  133. package/ImageBase.d.ts.map +0 -1
  134. package/ImageBase.js +0 -98
  135. package/source/Stamen.d.ts.map +0 -1
package/source/Image.js CHANGED
@@ -2,12 +2,23 @@
2
2
  * @module ol/source/Image
3
3
  */
4
4
  import Event from '../events/Event.js';
5
+ import EventType from '../events/EventType.js';
5
6
  import ImageState from '../ImageState.js';
7
+ import ImageWrapper from '../Image.js';
6
8
  import ReprojImage from '../reproj/Image.js';
7
9
  import Source from './Source.js';
8
- import {abstract} from '../util.js';
9
- import {equals} from '../extent.js';
10
+ import {DECIMALS} from './common.js';
11
+ import {ceil} from '../math.js';
12
+ import {
13
+ containsExtent,
14
+ equals,
15
+ getCenter,
16
+ getForViewAndSize,
17
+ getHeight,
18
+ getWidth,
19
+ } from '../extent.js';
10
20
  import {equivalent} from '../proj.js';
21
+ import {fromResolutionLike} from '../resolution.js';
11
22
  import {linearFindNearest} from '../array.js';
12
23
 
13
24
  /**
@@ -76,6 +87,10 @@ export class ImageSourceEvent extends Event {
76
87
  * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
77
88
  * @property {boolean} [interpolate=true] Use interpolated values when resampling. By default,
78
89
  * linear interpolation is used when resampling. Set to false to use the nearest neighbor instead.
90
+ * @property {import("../Image.js").Loader} [loader] Loader. Can either be a custom loader, or one of the
91
+ * loaders created with a `createLoader()` function ({@link module:ol/source/wms.createLoader wms},
92
+ * {@link module:ol/source/arcgisRest.createLoader arcgisRest}, {@link module:ol/source/mapguide.createLoader mapguide},
93
+ * {@link module:ol/source/static.createLoader static}).
79
94
  * @property {import("../proj.js").ProjectionLike} [projection] Projection.
80
95
  * @property {Array<number>} [resolutions] Resolutions.
81
96
  * @property {import("./Source.js").State} [state] State.
@@ -83,10 +98,7 @@ export class ImageSourceEvent extends Event {
83
98
 
84
99
  /**
85
100
  * @classdesc
86
- * Abstract base class; normally only used for creating subclasses and not
87
- * instantiated in apps.
88
101
  * Base class for sources providing a single image.
89
- * @abstract
90
102
  * @fires module:ol/source/Image.ImageSourceEvent
91
103
  * @api
92
104
  */
@@ -118,6 +130,12 @@ class ImageSource extends Source {
118
130
  */
119
131
  this.un;
120
132
 
133
+ /**
134
+ * @protected
135
+ * @type {import("../Image.js").Loader}
136
+ */
137
+ this.loader = options.loader || null;
138
+
121
139
  /**
122
140
  * @private
123
141
  * @type {Array<number>|null}
@@ -136,6 +154,24 @@ class ImageSource extends Source {
136
154
  * @type {number}
137
155
  */
138
156
  this.reprojectedRevision_ = 0;
157
+
158
+ /**
159
+ * @protected
160
+ * @type {import("../Image.js").default}
161
+ */
162
+ this.image = null;
163
+
164
+ /**
165
+ * @private
166
+ * @type {import("../extent.js").Extent}
167
+ */
168
+ this.wantedExtent_;
169
+
170
+ /**
171
+ * @private
172
+ * @type {number}
173
+ */
174
+ this.wantedResolution_;
139
175
  }
140
176
 
141
177
  /**
@@ -171,7 +207,7 @@ class ImageSource extends Source {
171
207
  * @param {number} resolution Resolution.
172
208
  * @param {number} pixelRatio Pixel ratio.
173
209
  * @param {import("../proj/Projection.js").default} projection Projection.
174
- * @return {import("../ImageBase.js").default} Single image.
210
+ * @return {import("../Image.js").default} Single image.
175
211
  */
176
212
  getImage(extent, resolution, pixelRatio, projection) {
177
213
  const sourceProjection = this.getProjection();
@@ -183,6 +219,7 @@ class ImageSource extends Source {
183
219
  if (sourceProjection) {
184
220
  projection = sourceProjection;
185
221
  }
222
+
186
223
  return this.getImageInternal(extent, resolution, pixelRatio, projection);
187
224
  }
188
225
  if (this.reprojectedImage_) {
@@ -219,11 +256,40 @@ class ImageSource extends Source {
219
256
  * @param {number} resolution Resolution.
220
257
  * @param {number} pixelRatio Pixel ratio.
221
258
  * @param {import("../proj/Projection.js").default} projection Projection.
222
- * @return {import("../ImageBase.js").default} Single image.
259
+ * @return {import("../Image.js").default} Single image.
223
260
  * @protected
224
261
  */
225
262
  getImageInternal(extent, resolution, pixelRatio, projection) {
226
- return abstract();
263
+ if (this.loader) {
264
+ const requestExtent = getRequestExtent(extent, resolution, pixelRatio, 1);
265
+ const requestResolution = this.findNearestResolution(resolution);
266
+ if (this.image) {
267
+ if (
268
+ ((this.wantedExtent_ &&
269
+ containsExtent(this.wantedExtent_, requestExtent)) ||
270
+ containsExtent(this.image.getExtent(), requestExtent)) &&
271
+ ((this.wantedResolution_ &&
272
+ fromResolutionLike(this.wantedResolution_) === requestResolution) ||
273
+ fromResolutionLike(this.image.getResolution()) ===
274
+ requestResolution)
275
+ ) {
276
+ return this.image;
277
+ }
278
+ }
279
+ this.wantedExtent_ = requestExtent;
280
+ this.wantedResolution_ = requestResolution;
281
+ this.image = new ImageWrapper(
282
+ requestExtent,
283
+ requestResolution,
284
+ pixelRatio,
285
+ this.loader
286
+ );
287
+ this.image.addEventListener(
288
+ EventType.CHANGE,
289
+ this.handleImageChange.bind(this)
290
+ );
291
+ }
292
+ return this.image;
227
293
  }
228
294
 
229
295
  /**
@@ -266,4 +332,27 @@ export function defaultImageLoadFunction(image, src) {
266
332
  /** @type {HTMLImageElement|HTMLVideoElement} */ (image.getImage()).src = src;
267
333
  }
268
334
 
335
+ /**
336
+ * Adjusts the extent so it aligns with pixel boundaries.
337
+ * @param {import("../extent.js").Extent} extent Extent.
338
+ * @param {number} resolution Reolution.
339
+ * @param {number} pixelRatio Pixel ratio.
340
+ * @param {number} ratio Ratio between request size and view size.
341
+ * @return {import("../extent.js").Extent} Request extent.
342
+ */
343
+ export function getRequestExtent(extent, resolution, pixelRatio, ratio) {
344
+ const imageResolution = resolution / pixelRatio;
345
+ const center = getCenter(extent);
346
+ const viewWidth = ceil(getWidth(extent) / imageResolution, DECIMALS);
347
+ const viewHeight = ceil(getHeight(extent) / imageResolution, DECIMALS);
348
+ const marginWidth = ceil(((ratio - 1) * viewWidth) / 2, DECIMALS);
349
+ const requestWidth = viewWidth + 2 * marginWidth;
350
+ const marginHeight = ceil(((ratio - 1) * viewHeight) / 2, DECIMALS);
351
+ const requestHeight = viewHeight + 2 * marginHeight;
352
+ return getForViewAndSize(center, imageResolution, 0, [
353
+ requestWidth,
354
+ requestHeight,
355
+ ]);
356
+ }
357
+
269
358
  export default ImageSource;
@@ -103,11 +103,6 @@ declare class ImageArcGISRest extends ImageSource {
103
103
  * @param {Options} [options] Image ArcGIS Rest Options.
104
104
  */
105
105
  constructor(options?: Options | undefined);
106
- /**
107
- * @private
108
- * @type {CanvasRenderingContext2D}
109
- */
110
- private context_;
111
106
  /**
112
107
  * @private
113
108
  * @type {?string}
@@ -160,30 +155,12 @@ declare class ImageArcGISRest extends ImageSource {
160
155
  * @api
161
156
  */
162
157
  getParams(): any;
163
- /**
164
- * @param {import("../extent.js").Extent} extent Extent.
165
- * @param {number} resolution Resolution.
166
- * @param {number} pixelRatio Pixel ratio.
167
- * @param {import("../proj/Projection.js").default} projection Projection.
168
- * @return {import("../Image.js").default} Single image.
169
- */
170
- getImageInternal(extent: import("../extent.js").Extent, resolution: number, pixelRatio: number, projection: import("../proj/Projection.js").default): import("../Image.js").default;
171
158
  /**
172
159
  * Return the image load function of the source.
173
160
  * @return {import("../Image.js").LoadFunction} The image load function.
174
161
  * @api
175
162
  */
176
163
  getImageLoadFunction(): import("../Image.js").LoadFunction;
177
- /**
178
- * @param {import("../extent.js").Extent} extent Extent.
179
- * @param {import("../size.js").Size} size Size.
180
- * @param {number} pixelRatio Pixel ratio.
181
- * @param {import("../proj/Projection.js").default} projection Projection.
182
- * @param {Object} params Params.
183
- * @return {string} Request URL.
184
- * @private
185
- */
186
- private getRequestUrl_;
187
164
  /**
188
165
  * Return the URL used for this ArcGIS source.
189
166
  * @return {string|undefined} URL.
@@ -1 +1 @@
1
- {"version":3,"file":"ImageArcGISRest.d.ts","sourceRoot":"","sources":["ImageArcGISRest.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8Bc,OAAO,YAAY,EAAE,cAAc;;;;;;;;;;;;;;;;;AAlBjD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;;;;;;GAWG;AACH;IACE;;OAEG;IACH,2CAyEC;I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;IAExB;;;OAGG;IACH,0BAA0B;IAE1B;;;OAGG;IACH,eAA+D;IAGjE;;;;;OAKG;IACH,iBAEC;IAiCD;;;;OAIG;IACH,wBAHY,OAAO,aAAa,EAAE,YAAY,CAK7C;IAED;;;;OAIG;IACH,UAHY,MAAM,GAAC,SAAS,CAK3B;IAED;;;;OAIG;IACH,wCAHW,OAAO,aAAa,EAAE,YAAY,QAO5C;IAED;;;;OAIG;IACH,YAHW,MAAM,GAAC,SAAS,QAS1B;IAED;;;;OAIG;IACH,gCAIC;CACF;wBAnNmD,YAAY"}
@@ -2,13 +2,9 @@
2
2
  * @module ol/source/ImageArcGISRest
3
3
  */
4
4
 
5
- import EventType from '../events/EventType.js';
6
5
  import ImageSource, {defaultImageLoadFunction} from './Image.js';
7
- import ImageWrapper from '../Image.js';
8
- import {appendParams} from '../uri.js';
9
- import {assert} from '../asserts.js';
10
- import {containsExtent, getHeight, getWidth} from '../extent.js';
11
- import {createCanvasContext2D} from '../dom.js';
6
+ import {createLoader} from './arcgisRest.js';
7
+ import {decode} from '../Image.js';
12
8
 
13
9
  /**
14
10
  * @typedef {Object} Options
@@ -65,12 +61,6 @@ class ImageArcGISRest extends ImageSource {
65
61
  resolutions: options.resolutions,
66
62
  });
67
63
 
68
- /**
69
- * @private
70
- * @type {CanvasRenderingContext2D}
71
- */
72
- this.context_ = createCanvasContext2D(1, 1);
73
-
74
64
  /**
75
65
  * @private
76
66
  * @type {?string}
@@ -151,81 +141,24 @@ class ImageArcGISRest extends ImageSource {
151
141
  if (this.url_ === undefined) {
152
142
  return null;
153
143
  }
154
-
155
- resolution = this.findNearestResolution(resolution);
156
- pixelRatio = this.hidpi_ ? pixelRatio : 1;
157
-
158
- const image = this.image_;
159
- if (
160
- image &&
161
- this.renderedRevision_ == this.getRevision() &&
162
- image.getResolution() == resolution &&
163
- image.getPixelRatio() == pixelRatio &&
164
- containsExtent(image.getExtent(), extent)
165
- ) {
166
- return image;
144
+ if (!this.loader) {
145
+ // Lazily create loader to pick up the view projection and to allow `params` updates
146
+ this.loader = createLoader({
147
+ crossOrigin: this.crossOrigin_,
148
+ params: this.params_,
149
+ projection: projection,
150
+ hidpi: this.hidpi_,
151
+ url: this.url_,
152
+ ratio: this.ratio_,
153
+ load: (image, src) => {
154
+ this.image.setImage(image);
155
+ this.imageLoadFunction_(this.image, src);
156
+ return decode(image);
157
+ },
158
+ });
167
159
  }
168
160
 
169
- const params = {
170
- 'F': 'image',
171
- 'FORMAT': 'PNG32',
172
- 'TRANSPARENT': true,
173
- };
174
- Object.assign(params, this.params_);
175
-
176
- extent = extent.slice();
177
- const centerX = (extent[0] + extent[2]) / 2;
178
- const centerY = (extent[1] + extent[3]) / 2;
179
- if (this.ratio_ != 1) {
180
- const halfWidth = (this.ratio_ * getWidth(extent)) / 2;
181
- const halfHeight = (this.ratio_ * getHeight(extent)) / 2;
182
- extent[0] = centerX - halfWidth;
183
- extent[1] = centerY - halfHeight;
184
- extent[2] = centerX + halfWidth;
185
- extent[3] = centerY + halfHeight;
186
- }
187
-
188
- const imageResolution = resolution / pixelRatio;
189
-
190
- // Compute an integer width and height.
191
- const width = Math.ceil(getWidth(extent) / imageResolution);
192
- const height = Math.ceil(getHeight(extent) / imageResolution);
193
-
194
- // Modify the extent to match the integer width and height.
195
- extent[0] = centerX - (imageResolution * width) / 2;
196
- extent[2] = centerX + (imageResolution * width) / 2;
197
- extent[1] = centerY - (imageResolution * height) / 2;
198
- extent[3] = centerY + (imageResolution * height) / 2;
199
-
200
- this.imageSize_[0] = width;
201
- this.imageSize_[1] = height;
202
-
203
- const url = this.getRequestUrl_(
204
- extent,
205
- this.imageSize_,
206
- pixelRatio,
207
- projection,
208
- params
209
- );
210
-
211
- this.image_ = new ImageWrapper(
212
- extent,
213
- resolution,
214
- pixelRatio,
215
- url,
216
- this.crossOrigin_,
217
- this.imageLoadFunction_,
218
- this.context_
219
- );
220
-
221
- this.renderedRevision_ = this.getRevision();
222
-
223
- this.image_.addEventListener(
224
- EventType.CHANGE,
225
- this.handleImageChange.bind(this)
226
- );
227
-
228
- return this.image_;
161
+ return super.getImageInternal(extent, resolution, pixelRatio, projection);
229
162
  }
230
163
 
231
164
  /**
@@ -237,41 +170,6 @@ class ImageArcGISRest extends ImageSource {
237
170
  return this.imageLoadFunction_;
238
171
  }
239
172
 
240
- /**
241
- * @param {import("../extent.js").Extent} extent Extent.
242
- * @param {import("../size.js").Size} size Size.
243
- * @param {number} pixelRatio Pixel ratio.
244
- * @param {import("../proj/Projection.js").default} projection Projection.
245
- * @param {Object} params Params.
246
- * @return {string} Request URL.
247
- * @private
248
- */
249
- getRequestUrl_(extent, size, pixelRatio, projection, params) {
250
- // ArcGIS Server only wants the numeric portion of the projection ID.
251
- // (if there is no numeric portion the entire projection code must
252
- // form a valid ArcGIS SpatialReference definition).
253
- const srid = projection
254
- .getCode()
255
- .split(/:(?=\d+$)/)
256
- .pop();
257
-
258
- params['SIZE'] = size[0] + ',' + size[1];
259
- params['BBOX'] = extent.join(',');
260
- params['BBOXSR'] = srid;
261
- params['IMAGESR'] = srid;
262
- params['DPI'] = Math.round(90 * pixelRatio);
263
-
264
- const url = this.url_;
265
-
266
- const modifiedUrl = url
267
- .replace(/MapServer\/?$/, 'MapServer/export')
268
- .replace(/ImageServer\/?$/, 'ImageServer/exportImage');
269
- if (modifiedUrl == url) {
270
- assert(false, 50); // `options.featureTypes` should be an Array
271
- }
272
- return appendParams(modifiedUrl, params);
273
- }
274
-
275
173
  /**
276
174
  * Return the URL used for this ArcGIS source.
277
175
  * @return {string|undefined} URL.
@@ -88,11 +88,6 @@ declare class ImageMapGuide extends ImageSource {
88
88
  * @param {Options} options ImageMapGuide options.
89
89
  */
90
90
  constructor(options: Options);
91
- /**
92
- * @private
93
- * @type {CanvasRenderingContext2D}
94
- */
95
- private context_;
96
91
  /**
97
92
  * @private
98
93
  * @type {?string}
@@ -155,14 +150,6 @@ declare class ImageMapGuide extends ImageSource {
155
150
  * @api
156
151
  */
157
152
  getParams(): any;
158
- /**
159
- * @param {import("../extent.js").Extent} extent Extent.
160
- * @param {number} resolution Resolution.
161
- * @param {number} pixelRatio Pixel ratio.
162
- * @param {import("../proj/Projection.js").default} projection Projection.
163
- * @return {import("../Image.js").default} Single image.
164
- */
165
- getImageInternal(extent: import("../extent.js").Extent, resolution: number, pixelRatio: number, projection: import("../proj/Projection.js").default): import("../Image.js").default;
166
153
  /**
167
154
  * Return the image load function of the source.
168
155
  * @return {import("../Image.js").LoadFunction} The image load function.
@@ -175,17 +162,6 @@ declare class ImageMapGuide extends ImageSource {
175
162
  * @api
176
163
  */
177
164
  updateParams(params: any): void;
178
- /**
179
- * @param {string} baseUrl The mapagent url.
180
- * @param {Object<string, string|number>} params Request parameters.
181
- * @param {import("../extent.js").Extent} extent Extent.
182
- * @param {import("../size.js").Size} size Size.
183
- * @param {import("../proj/Projection.js").default} projection Projection.
184
- * @return {string} The mapagent map image request URL.
185
- */
186
- getUrl(baseUrl: string, params: {
187
- [x: string]: string | number;
188
- }, extent: import("../extent.js").Extent, size: import("../size.js").Size, projection: import("../proj/Projection.js").default): string;
189
165
  /**
190
166
  * Set the image load function of the MapGuide source.
191
167
  * @param {import("../Image.js").LoadFunction} imageLoadFunction Image load function.
@@ -1 +1 @@
1
- {"version":3,"file":"ImageMapGuide.d.ts","sourceRoot":"","sources":["ImageMapGuide.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4Bc,OAAO,YAAY,EAAE,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;AAXjD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH;;;;;;GAMG;AACH;IACE;;OAEG;IACH,qBAFW,OAAO,EAuFjB;IA9EC;;;OAGG;IACH,iBAA2C;IAE3C;;;OAGG;IACH,qBACgE;IAEhE;;;OAGG;IACH,oBAC4D;IAE5D;;;OAGG;IACH,gBAAmC;IAEnC;;;OAGG;IACH,aAAuB;IAEvB;;;OAGG;IACH,2BAG8B;IAE9B;;;OAGG;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;IAElB;;;OAGG;IACH,0BAA0B;IAG5B;;;;;OAKG;IACH,iBAEC;IAkCD;;;;OAIG;IACH,wBAHY,OAAO,aAAa,EAAE,YAAY,CAK7C;IAED;;;;OAIG;IACH,gCAGC;IAED;;;;OAIG;IACH,wCAHW,OAAO,aAAa,EAAE,YAAY,QAO5C;CACF;wBA7LmD,YAAY"}
@@ -2,18 +2,9 @@
2
2
  * @module ol/source/ImageMapGuide
3
3
  */
4
4
 
5
- import EventType from '../events/EventType.js';
6
5
  import ImageSource, {defaultImageLoadFunction} from './Image.js';
7
- import ImageWrapper from '../Image.js';
8
- import {appendParams} from '../uri.js';
9
- import {
10
- containsExtent,
11
- getCenter,
12
- getHeight,
13
- getWidth,
14
- scaleFromCenter,
15
- } from '../extent.js';
16
- import {createCanvasContext2D} from '../dom.js';
6
+ import {createLoader} from './mapguide.js';
7
+ import {decode} from '../Image.js';
17
8
 
18
9
  /**
19
10
  * @typedef {Object} Options
@@ -55,12 +46,6 @@ class ImageMapGuide extends ImageSource {
55
46
  resolutions: options.resolutions,
56
47
  });
57
48
 
58
- /**
59
- * @private
60
- * @type {CanvasRenderingContext2D}
61
- */
62
- this.context_ = createCanvasContext2D(1, 1);
63
-
64
49
  /**
65
50
  * @private
66
51
  * @type {?string}
@@ -153,56 +138,28 @@ class ImageMapGuide extends ImageSource {
153
138
  * @return {import("../Image.js").default} Single image.
154
139
  */
155
140
  getImageInternal(extent, resolution, pixelRatio, projection) {
156
- resolution = this.findNearestResolution(resolution);
157
- pixelRatio = this.hidpi_ ? pixelRatio : 1;
158
-
159
- let image = this.image_;
160
- if (
161
- image &&
162
- this.renderedRevision_ == this.getRevision() &&
163
- image.getResolution() == resolution &&
164
- image.getPixelRatio() == pixelRatio &&
165
- containsExtent(image.getExtent(), extent)
166
- ) {
167
- return image;
141
+ if (this.url_ === undefined) {
142
+ return null;
168
143
  }
169
-
170
- if (this.ratio_ != 1) {
171
- extent = extent.slice();
172
- scaleFromCenter(extent, this.ratio_);
173
- }
174
- const width = getWidth(extent) / resolution;
175
- const height = getHeight(extent) / resolution;
176
- const size = [width * pixelRatio, height * pixelRatio];
177
-
178
- if (this.url_ !== undefined) {
179
- const imageUrl = this.getUrl(
180
- this.url_,
181
- this.params_,
182
- extent,
183
- size,
184
- projection
185
- );
186
- image = new ImageWrapper(
187
- extent,
188
- resolution,
189
- pixelRatio,
190
- imageUrl,
191
- this.crossOrigin_,
192
- this.imageLoadFunction_,
193
- this.context_
194
- );
195
- image.addEventListener(
196
- EventType.CHANGE,
197
- this.handleImageChange.bind(this)
198
- );
199
- } else {
200
- image = null;
144
+ if (!this.loader) {
145
+ // Lazily create loader to pick up the view projection and to allow `params` updates
146
+ this.loader = createLoader({
147
+ crossOrigin: this.crossOrigin_,
148
+ params: this.params_,
149
+ hidpi: this.hidpi_,
150
+ metersPerUnit: this.metersPerUnit_,
151
+ url: this.url_,
152
+ useOverlay: this.useOverlay_,
153
+ ratio: this.ratio_,
154
+ load: (image, src) => {
155
+ this.image.setImage(image);
156
+ this.imageLoadFunction_(this.image, src);
157
+ return decode(image);
158
+ },
159
+ });
201
160
  }
202
- this.image_ = image;
203
- this.renderedRevision_ = this.getRevision();
204
161
 
205
- return image;
162
+ return super.getImageInternal(extent, resolution, pixelRatio, projection);
206
163
  }
207
164
 
208
165
  /**
@@ -224,36 +181,6 @@ class ImageMapGuide extends ImageSource {
224
181
  this.changed();
225
182
  }
226
183
 
227
- /**
228
- * @param {string} baseUrl The mapagent url.
229
- * @param {Object<string, string|number>} params Request parameters.
230
- * @param {import("../extent.js").Extent} extent Extent.
231
- * @param {import("../size.js").Size} size Size.
232
- * @param {import("../proj/Projection.js").default} projection Projection.
233
- * @return {string} The mapagent map image request URL.
234
- */
235
- getUrl(baseUrl, params, extent, size, projection) {
236
- const scale = getScale(extent, size, this.metersPerUnit_, this.displayDpi_);
237
- const center = getCenter(extent);
238
- const baseParams = {
239
- 'OPERATION': this.useOverlay_
240
- ? 'GETDYNAMICMAPOVERLAYIMAGE'
241
- : 'GETMAPIMAGE',
242
- 'VERSION': '2.0.0',
243
- 'LOCALE': 'en',
244
- 'CLIENTAGENT': 'ol/source/ImageMapGuide source',
245
- 'CLIP': '1',
246
- 'SETDISPLAYDPI': this.displayDpi_,
247
- 'SETDISPLAYWIDTH': Math.round(size[0]),
248
- 'SETDISPLAYHEIGHT': Math.round(size[1]),
249
- 'SETVIEWSCALE': scale,
250
- 'SETVIEWCENTERX': center[0],
251
- 'SETVIEWCENTERY': center[1],
252
- };
253
- Object.assign(baseParams, params);
254
- return appendParams(baseUrl, baseParams);
255
- }
256
-
257
184
  /**
258
185
  * Set the image load function of the MapGuide source.
259
186
  * @param {import("../Image.js").LoadFunction} imageLoadFunction Image load function.
@@ -266,23 +193,4 @@ class ImageMapGuide extends ImageSource {
266
193
  }
267
194
  }
268
195
 
269
- /**
270
- * @param {import("../extent.js").Extent} extent The map extents.
271
- * @param {import("../size.js").Size} size The viewport size.
272
- * @param {number} metersPerUnit The meters-per-unit value.
273
- * @param {number} dpi The display resolution.
274
- * @return {number} The computed map scale.
275
- */
276
- function getScale(extent, size, metersPerUnit, dpi) {
277
- const mcsW = getWidth(extent);
278
- const mcsH = getHeight(extent);
279
- const devW = size[0];
280
- const devH = size[1];
281
- const mpp = 0.0254 / dpi;
282
- if (devH * mcsW > devW * mcsH) {
283
- return (mcsW * metersPerUnit) / (devW * mpp); // width limited
284
- }
285
- return (mcsH * metersPerUnit) / (devH * mpp); // height limited
286
- }
287
-
288
196
  export default ImageMapGuide;
@@ -14,7 +14,7 @@ export type Options = {
14
14
  * Extent of the image in map coordinates.
15
15
  * This is the [left, bottom, right, top] map coordinates of your image.
16
16
  */
17
- imageExtent?: import("../extent.js").Extent | undefined;
17
+ imageExtent: import("../extent.js").Extent;
18
18
  /**
19
19
  * Optional function to load an image given a URL.
20
20
  */
@@ -28,11 +28,6 @@ export type Options = {
28
28
  * Projection. Default is the view projection.
29
29
  */
30
30
  projection?: import("../proj.js").ProjectionLike;
31
- /**
32
- * Size of the image in pixels. Usually the image size is auto-detected, so this
33
- * only needs to be set if auto-detection fails for some reason.
34
- */
35
- imageSize?: import("../size.js").Size | undefined;
36
31
  /**
37
32
  * Image URL.
38
33
  */
@@ -44,14 +39,12 @@ export type Options = {
44
39
  * @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that
45
40
  * you must provide a `crossOrigin` value if you want to access pixel data with the Canvas renderer.
46
41
  * See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.
47
- * @property {import("../extent.js").Extent} [imageExtent] Extent of the image in map coordinates.
42
+ * @property {import("../extent.js").Extent} imageExtent Extent of the image in map coordinates.
48
43
  * This is the [left, bottom, right, top] map coordinates of your image.
49
44
  * @property {import("../Image.js").LoadFunction} [imageLoadFunction] Optional function to load an image given a URL.
50
45
  * @property {boolean} [interpolate=true] Use interpolated values when resampling. By default,
51
46
  * linear interpolation is used when resampling. Set to false to use the nearest neighbor instead.
52
47
  * @property {import("../proj.js").ProjectionLike} [projection] Projection. Default is the view projection.
53
- * @property {import("../size.js").Size} [imageSize] Size of the image in pixels. Usually the image size is auto-detected, so this
54
- * only needs to be set if auto-detection fails for some reason.
55
48
  * @property {string} url Image URL.
56
49
  */
57
50
  /**
@@ -74,30 +67,12 @@ declare class Static extends ImageSource {
74
67
  * @type {import("../extent.js").Extent}
75
68
  */
76
69
  private imageExtent_;
77
- /**
78
- * @private
79
- * @type {import("../Image.js").default}
80
- */
81
- private image_;
82
- /**
83
- * @private
84
- * @type {import("../size.js").Size|null}
85
- */
86
- private imageSize_;
87
70
  /**
88
71
  * Returns the image extent
89
72
  * @return {import("../extent.js").Extent} image extent.
90
73
  * @api
91
74
  */
92
75
  getImageExtent(): import("../extent.js").Extent;
93
- /**
94
- * @param {import("../extent.js").Extent} extent Extent.
95
- * @param {number} resolution Resolution.
96
- * @param {number} pixelRatio Pixel ratio.
97
- * @param {import("../proj/Projection.js").default} projection Projection.
98
- * @return {import("../Image.js").default} Single image.
99
- */
100
- getImageInternal(extent: import("../extent.js").Extent, resolution: number, pixelRatio: number, projection: import("../proj/Projection.js").default): import("../Image.js").default;
101
76
  /**
102
77
  * Return the URL used for this image source.
103
78
  * @return {string} URL.