ol 7.2.3-dev.1674137185986 → 7.2.3-dev.1674202692707

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/Image.d.ts CHANGED
@@ -46,8 +46,11 @@ declare class ImageWrapper extends ImageBase {
46
46
  * @param {string} src Image source URI.
47
47
  * @param {?string} crossOrigin Cross origin.
48
48
  * @param {LoadFunction} imageLoadFunction Image load function.
49
+ * @param {CanvasRenderingContext2D} [context] Canvas context. When provided, the image will be
50
+ * drawn into the context's canvas, and `getImage()` will return the canvas once the image
51
+ * has finished loading.
49
52
  */
50
- constructor(extent: import("./extent.js").Extent, resolution: number | undefined, pixelRatio: number, src: string, crossOrigin: string | null, imageLoadFunction: LoadFunction);
53
+ constructor(extent: import("./extent.js").Extent, resolution: number | undefined, pixelRatio: number, src: string, crossOrigin: string | null, imageLoadFunction: LoadFunction, context?: CanvasRenderingContext2D | undefined);
51
54
  /**
52
55
  * @private
53
56
  * @type {string}
@@ -58,6 +61,11 @@ declare class ImageWrapper extends ImageBase {
58
61
  * @type {HTMLCanvasElement|HTMLImageElement|HTMLVideoElement}
59
62
  */
60
63
  private image_;
64
+ /**
65
+ * @private
66
+ * @type {CanvasRenderingContext2D}
67
+ */
68
+ private context_;
61
69
  /**
62
70
  * @private
63
71
  * @type {?function():void}
package/Image.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["Image.js"],"names":[],"mappings":"AA0JA;;;;;GAKG;AACH,mCALW,iBAAiB,GAAC,gBAAgB,GAAC,gBAAgB,qBACxC,GAAG,sBACH,GAAG,SACF,IAAI,CA2C1B;;;;;;;;;;;;;;;;kCAjLqB,YAAY,QAAE,MAAM,KAAG,IAAI;AAdjD;;;;;;;;;;;;;;;;GAgBG;AAEH;IACE;;;;;;;OAOG;IACH,oBAPW,OAAO,aAAa,EAAE,MAAM,cAC5B,MAAM,GAAC,SAAS,cAChB,MAAM,OACN,MAAM,eACL,MAAM,4BACP,YAAY,EA4CtB;IAhCC;;;OAGG;IACH,aAAe;IAEf;;;OAGG;IACH,eAAyB;IAKzB;;;OAGG;IACH,kBAAqB;IAQrB;;;OAGG;IACH,2BAA2C;IAW7C;;;;OAIG;IACH,0BAIC;IAED;;;;OAIG;IACH,yBAOC;IAqBD;;OAEG;IACH,gBAFW,iBAAiB,GAAC,gBAAgB,GAAC,gBAAgB,QAK7D;IAED;;;;OAIG;IACH,uBAKC;CACF"}
1
+ {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["Image.js"],"names":[],"mappings":"AA+KA;;;;;GAKG;AACH,mCALW,iBAAiB,GAAC,gBAAgB,GAAC,gBAAgB,qBACxC,GAAG,sBACH,GAAG,SACF,IAAI,CA2C1B;;;;;;;;;;;;;;;;kCAtMqB,YAAY,QAAE,MAAM,KAAG,IAAI;AAdjD;;;;;;;;;;;;;;;;GAgBG;AAEH;IACE;;;;;;;;;;OAUG;IACH,oBAVW,OAAO,aAAa,EAAE,MAAM,cAC5B,MAAM,GAAC,SAAS,cAChB,MAAM,OACN,MAAM,eACL,MAAM,4BACP,YAAY,kDAsDtB;IAtCC;;;OAGG;IACH,aAAe;IAEf;;;OAGG;IACH,eAAyB;IAKzB;;;OAGG;IACH,iBAAuB;IAEvB;;;OAGG;IACH,kBAAqB;IAQrB;;;OAGG;IACH,2BAA2C;IAsB7C;;;;OAIG;IACH,0BAIC;IAED;;;;OAIG;IACH,yBAOC;IAqBD;;OAEG;IACH,gBAFW,iBAAiB,GAAC,gBAAgB,GAAC,gBAAgB,QAK7D;IAED;;;;OAIG;IACH,uBAKC;CACF"}
package/Image.js CHANGED
@@ -34,6 +34,9 @@ class ImageWrapper extends ImageBase {
34
34
  * @param {string} src Image source URI.
35
35
  * @param {?string} crossOrigin Cross origin.
36
36
  * @param {LoadFunction} imageLoadFunction Image load function.
37
+ * @param {CanvasRenderingContext2D} [context] Canvas context. When provided, the image will be
38
+ * drawn into the context's canvas, and `getImage()` will return the canvas once the image
39
+ * has finished loading.
37
40
  */
38
41
  constructor(
39
42
  extent,
@@ -41,7 +44,8 @@ class ImageWrapper extends ImageBase {
41
44
  pixelRatio,
42
45
  src,
43
46
  crossOrigin,
44
- imageLoadFunction
47
+ imageLoadFunction,
48
+ context
45
49
  ) {
46
50
  super(extent, resolution, pixelRatio, ImageState.IDLE);
47
51
 
@@ -60,6 +64,12 @@ class ImageWrapper extends ImageBase {
60
64
  this.image_.crossOrigin = crossOrigin;
61
65
  }
62
66
 
67
+ /**
68
+ * @private
69
+ * @type {CanvasRenderingContext2D}
70
+ */
71
+ this.context_ = context;
72
+
63
73
  /**
64
74
  * @private
65
75
  * @type {?function():void}
@@ -84,6 +94,17 @@ class ImageWrapper extends ImageBase {
84
94
  * @api
85
95
  */
86
96
  getImage() {
97
+ if (
98
+ this.state == ImageState.LOADED &&
99
+ this.context_ &&
100
+ !(this.image_ instanceof HTMLCanvasElement)
101
+ ) {
102
+ const canvas = this.context_.canvas;
103
+ canvas.width = this.image_.width;
104
+ canvas.height = this.image_.height;
105
+ this.context_.drawImage(this.image_, 0, 0);
106
+ this.image_ = this.context_.canvas;
107
+ }
87
108
  return this.image_;
88
109
  }
89
110