ol 7.1.1-dev.1667574553768 → 7.1.1-dev.1667678878080

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/DataTile.d.ts CHANGED
@@ -1,16 +1,43 @@
1
+ /**
2
+ * @typedef {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} ImageLike
3
+ */
4
+ /**
5
+ * @typedef {Uint8Array|Uint8ClampedArray|Float32Array|DataView} ArrayLike
6
+ */
7
+ /**
8
+ * Data that can be used with a DataTile.
9
+ * @typedef {ArrayLike|ImageLike} Data
10
+ */
11
+ /**
12
+ * @param {Data} data Tile data.
13
+ * @return {ImageLike|null} The image-like data.
14
+ */
15
+ export function asImageLike(data: Data): ImageLike | null;
16
+ /**
17
+ * @param {Data} data Tile data.
18
+ * @return {ArrayLike|null} The array-like data.
19
+ */
20
+ export function asArrayLike(data: Data): ArrayLike | null;
21
+ /**
22
+ * @param {ImageLike} image The image.
23
+ * @return {Uint8ClampedArray} The data.
24
+ */
25
+ export function toArray(image: ImageLike): Uint8ClampedArray;
1
26
  export default DataTile;
27
+ export type ImageLike = HTMLImageElement | HTMLCanvasElement | HTMLVideoElement;
28
+ export type ArrayLike = Uint8Array | Uint8ClampedArray | Float32Array | DataView;
2
29
  /**
3
- * Data that can be used with a DataTile. For increased browser compatibility, use
4
- * Uint8Array instead of Uint8ClampedArray where possible.
30
+ * Data that can be used with a DataTile.
5
31
  */
6
- export type Data = Uint8Array | Uint8ClampedArray | Float32Array | DataView;
32
+ export type Data = ArrayLike | ImageLike;
7
33
  export type Options = {
8
34
  /**
9
35
  * Tile coordinate.
10
36
  */
11
37
  tileCoord: import("./tilecoord.js").TileCoord;
12
38
  /**
13
- * Data loader.
39
+ * Data loader. For loaders that generate images,
40
+ * the promise should not resolve until the image is loaded.
14
41
  */
15
42
  loader: () => Promise<Data>;
16
43
  /**
@@ -28,15 +55,11 @@ export type Options = {
28
55
  */
29
56
  size?: import("./size.js").Size | undefined;
30
57
  };
31
- /**
32
- * Data that can be used with a DataTile. For increased browser compatibility, use
33
- * Uint8Array instead of Uint8ClampedArray where possible.
34
- * @typedef {Uint8Array|Uint8ClampedArray|Float32Array|DataView} Data
35
- */
36
58
  /**
37
59
  * @typedef {Object} Options
38
60
  * @property {import("./tilecoord.js").TileCoord} tileCoord Tile coordinate.
39
- * @property {function(): Promise<Data>} loader Data loader.
61
+ * @property {function(): Promise<Data>} loader Data loader. For loaders that generate images,
62
+ * the promise should not resolve until the image is loaded.
40
63
  * @property {number} [transition=250] A duration for tile opacity
41
64
  * transitions in milliseconds. A duration of 0 disables the opacity transition.
42
65
  * @property {boolean} [interpolate=false] Use interpolated values when resampling. By default,
@@ -65,7 +88,7 @@ declare class DataTile extends Tile {
65
88
  */
66
89
  private error_;
67
90
  /**
68
- * @type {import('./size.js').Size}
91
+ * @type {import('./size.js').Size|null}
69
92
  * @private
70
93
  */
71
94
  private size_;
package/DataTile.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"DataTile.d.ts","sourceRoot":"","sources":["DataTile.js"],"names":[],"mappings":";;;;;mBASa,UAAU,GAAC,iBAAiB,GAAC,YAAY,GAAC,QAAQ;;;;;eAKjD,OAAO,gBAAgB,EAAE,SAAS;;;;kBACtB,QAAQ,IAAI,CAAC;;;;;;;;;;;;;;;;AATvC;;;;GAIG;AAEH;;;;;;;;;;GAUG;AAEH;IACE;;OAEG;IACH,qBAFW,OAAO,EAiCjB;IAvBC;;;OAGG;IACH,gBAA6B;IAE7B;;;OAGG;IACH,cAAiB;IAEjB;;;OAGG;IACH,eAAkB;IAElB;;;OAGG;IACH,cAAuC;IAGzC;;;OAGG;IACH,WAFY,OAAO,WAAW,EAAE,IAAI,CAInC;IAED;;;;OAIG;IACH,WAHY,IAAI,CAKf;IAED;;;;OAIG;IACH,YAHY,KAAK,CAKhB;CA0BF"}
1
+ {"version":3,"file":"DataTile.d.ts","sourceRoot":"","sources":["DataTile.js"],"names":[],"mappings":"AAOA;;GAEG;AAEH;;GAEG;AAEH;;;GAGG;AAEH;;;GAGG;AACH,kCAHW,IAAI,GACH,SAAS,GAAC,IAAI,CAQzB;AAED;;;GAGG;AACH,kCAHW,IAAI,GACH,SAAS,GAAC,IAAI,CASzB;AAOD;;;GAGG;AACH,+BAHW,SAAS,GACR,iBAAiB,CAsB5B;;wBAlEY,gBAAgB,GAAC,iBAAiB,GAAC,gBAAgB;wBAInD,UAAU,GAAC,iBAAiB,GAAC,YAAY,GAAC,QAAQ;;;;mBAKlD,SAAS,GAAC,SAAS;;;;;eAkElB,OAAO,gBAAgB,EAAE,SAAS;;;;;kBACtB,QAAQ,IAAI,CAAC;;;;;;;;;;;;;;;;AAHvC;;;;;;;;;;;GAWG;AAEH;IACE;;OAEG;IACH,qBAFW,OAAO,EAiCjB;IAvBC;;;OAGG;IACH,gBAA6B;IAE7B;;;OAGG;IACH,cAAiB;IAEjB;;;OAGG;IACH,eAAkB;IAElB;;;OAGG;IACH,cAAiC;IAGnC;;;OAGG;IACH,WAFY,OAAO,WAAW,EAAE,IAAI,CAWnC;IAED;;;;OAIG;IACH,WAHY,IAAI,CAKf;IAED;;;;OAIG;IACH,YAHY,KAAK,CAKhB;CA0BF"}
package/DataTile.js CHANGED
@@ -3,17 +3,87 @@
3
3
  */
4
4
  import Tile from './Tile.js';
5
5
  import TileState from './TileState.js';
6
+ import {createCanvasContext2D} from './dom.js';
6
7
 
7
8
  /**
8
- * Data that can be used with a DataTile. For increased browser compatibility, use
9
- * Uint8Array instead of Uint8ClampedArray where possible.
10
- * @typedef {Uint8Array|Uint8ClampedArray|Float32Array|DataView} Data
9
+ * @typedef {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} ImageLike
11
10
  */
12
11
 
12
+ /**
13
+ * @typedef {Uint8Array|Uint8ClampedArray|Float32Array|DataView} ArrayLike
14
+ */
15
+
16
+ /**
17
+ * Data that can be used with a DataTile.
18
+ * @typedef {ArrayLike|ImageLike} Data
19
+ */
20
+
21
+ /**
22
+ * @param {Data} data Tile data.
23
+ * @return {ImageLike|null} The image-like data.
24
+ */
25
+ export function asImageLike(data) {
26
+ return data instanceof Image ||
27
+ data instanceof HTMLCanvasElement ||
28
+ data instanceof HTMLVideoElement
29
+ ? data
30
+ : null;
31
+ }
32
+
33
+ /**
34
+ * @param {Data} data Tile data.
35
+ * @return {ArrayLike|null} The array-like data.
36
+ */
37
+ export function asArrayLike(data) {
38
+ return data instanceof Uint8Array ||
39
+ data instanceof Uint8ClampedArray ||
40
+ data instanceof Float32Array ||
41
+ data instanceof DataView
42
+ ? data
43
+ : null;
44
+ }
45
+
46
+ /**
47
+ * @type {CanvasRenderingContext2D|null}
48
+ */
49
+ let sharedContext = null;
50
+
51
+ /**
52
+ * @param {ImageLike} image The image.
53
+ * @return {Uint8ClampedArray} The data.
54
+ */
55
+ export function toArray(image) {
56
+ if (!sharedContext) {
57
+ sharedContext = createCanvasContext2D(
58
+ image.width,
59
+ image.height,
60
+ undefined,
61
+ {willReadFrequently: true}
62
+ );
63
+ }
64
+ const canvas = sharedContext.canvas;
65
+ const width = image.width;
66
+ if (canvas.width !== width) {
67
+ canvas.width = width;
68
+ }
69
+ const height = image.height;
70
+ if (canvas.height !== height) {
71
+ canvas.height = height;
72
+ }
73
+ sharedContext.drawImage(image, width, height);
74
+ return sharedContext.getImageData(0, 0, width, height).data;
75
+ }
76
+
77
+ /**
78
+ * @type {import('./size.js').Size}
79
+ */
80
+ const defaultSize = [256, 256];
81
+
13
82
  /**
14
83
  * @typedef {Object} Options
15
84
  * @property {import("./tilecoord.js").TileCoord} tileCoord Tile coordinate.
16
- * @property {function(): Promise<Data>} loader Data loader.
85
+ * @property {function(): Promise<Data>} loader Data loader. For loaders that generate images,
86
+ * the promise should not resolve until the image is loaded.
17
87
  * @property {number} [transition=250] A duration for tile opacity
18
88
  * transitions in milliseconds. A duration of 0 disables the opacity transition.
19
89
  * @property {boolean} [interpolate=false] Use interpolated values when resampling. By default,
@@ -53,10 +123,10 @@ class DataTile extends Tile {
53
123
  this.error_ = null;
54
124
 
55
125
  /**
56
- * @type {import('./size.js').Size}
126
+ * @type {import('./size.js').Size|null}
57
127
  * @private
58
128
  */
59
- this.size_ = options.size || [256, 256];
129
+ this.size_ = options.size || null;
60
130
  }
61
131
 
62
132
  /**
@@ -64,7 +134,14 @@ class DataTile extends Tile {
64
134
  * @return {import('./size.js').Size} Tile size.
65
135
  */
66
136
  getSize() {
67
- return this.size_;
137
+ if (this.size_) {
138
+ return this.size_;
139
+ }
140
+ const imageData = asImageLike(this.data_);
141
+ if (imageData) {
142
+ return [imageData.width, imageData.height];
143
+ }
144
+ return defaultSize;
68
145
  }
69
146
 
70
147
  /**