ol 7.0.1-dev.1661609353651 → 7.0.1-dev.1661713055938

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/README.md CHANGED
@@ -23,7 +23,7 @@ new Map({
23
23
  layers: [
24
24
  new TileLayer({
25
25
  source: new XYZ({
26
- url: 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'
26
+ url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'
27
27
  })
28
28
  })
29
29
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ol",
3
- "version": "7.0.1-dev.1661609353651",
3
+ "version": "7.0.1-dev.1661713055938",
4
4
  "description": "OpenLayers mapping library",
5
5
  "keywords": [
6
6
  "map",
@@ -233,6 +233,11 @@ declare class GeoTIFFSource extends DataTile {
233
233
  * @private
234
234
  */
235
235
  private sourceImagery_;
236
+ /**
237
+ * @type {Array<Array<GeoTIFFImage>>}
238
+ * @private
239
+ */
240
+ private sourceMasks_;
236
241
  /**
237
242
  * @type {Array<number>}
238
243
  * @private
@@ -293,7 +298,21 @@ declare class GeoTIFFSource extends DataTile {
293
298
  * @private
294
299
  */
295
300
  private configure_;
296
- loadTile_(z: any, x: any, y: any): Promise<Uint8Array | Float32Array>;
301
+ /**
302
+ * @param {number} z The z tile index.
303
+ * @param {number} x The x tile index.
304
+ * @param {number} y The y tile index.
305
+ * @return {Promise} The composed tile data.
306
+ * @private
307
+ */
308
+ private loadTile_;
309
+ /**
310
+ * @param {import("../size.js").Size} sourceTileSize The source tile size.
311
+ * @param {Array} sourceSamples The source samples.
312
+ * @return {import("../DataTile.js").Data} The composed tile data.
313
+ * @private
314
+ */
315
+ private composeTile_;
297
316
  }
298
317
  import DataTile from "./DataTile.js";
299
318
  //# sourceMappingURL=GeoTIFF.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GeoTIFF.d.ts","sourceRoot":"","sources":["GeoTIFF.js"],"names":[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ACN,MAAM;;;;2BACN,MAAM;;sBAIP,OAAO,SAAS,EAAE,OAAO;2BAIzB,OAAO,SAAS,EAAE,YAAY;;;;;wBAK7B,MAAM;;;;wBACN,MAAM;;2BAOP,OAAO,SAAS,EAAE,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAoO7B,MAAM,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAhB/B;;;;;;;;;;;;GAYG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH;;;;GAIG;AACH;IACE;;OAEG;IACH,qBAFW,OAAO,EAyGjB;IA5FC;;;OAGG;IACH,oBAAkC;IAIlC;;;OAGG;IACH,uBAA2C;IAE3C;;;OAGG;IACH,uBAA2C;IAE3C;;;OAGG;IACH,qBAAyC;IAEzC;;;OAGG;IACH,2BAA+C;IAE/C;;;OAGG;IACH,yBAAqB;IAErB;;;OAGG;IACH,sBAAkB;IAElB;;;OAGG;IACH,kBAAc;IAEd;;;OAGG;IACH,mBAA6C;IAE7C;;;OAGG;IACH,kBAAsB;IAEtB;;;OAGG;IACH,eAAkB;IAElB;;OAEG;IACH,aAFU,aAAa,GAAG,SAAS,CAEgC;IAuBrE;;;;;;;;;;;OAWG;IACH,YAXY,KAAK,CAahB;IAED;;;;;;OAMG;IACH,mBAoOC;IAED;;;;;;OAMG;IACH,kBAwEC;IAED;;;;;OAKG;IACH,qBA4GC;CACF"}
package/source/GeoTIFF.js CHANGED
@@ -19,6 +19,18 @@ import {clamp} from '../math.js';
19
19
  import {getCenter, getIntersection} from '../extent.js';
20
20
  import {fromCode as unitsFromCode} from '../proj/Units.js';
21
21
 
22
+ /**
23
+ * Determine if an image type is a mask.
24
+ * See https://www.awaresystems.be/imaging/tiff/tifftags/newsubfiletype.html
25
+ * @param {GeoTIFFImage} image The image.
26
+ * @return {boolean} The image is a mask.
27
+ */
28
+ function isMask(image) {
29
+ const fileDirectory = image.fileDirectory;
30
+ const type = fileDirectory.NewSubfileType || 0;
31
+ return (type & 4) === 4;
32
+ }
33
+
22
34
  /**
23
35
  * @typedef {Object} SourceInfo
24
36
  * @property {string} [url] URL for the source GeoTIFF.
@@ -363,6 +375,12 @@ class GeoTIFFSource extends DataTile {
363
375
  */
364
376
  this.sourceImagery_ = new Array(numSources);
365
377
 
378
+ /**
379
+ * @type {Array<Array<GeoTIFFImage>>}
380
+ * @private
381
+ */
382
+ this.sourceMasks_ = new Array(numSources);
383
+
366
384
  /**
367
385
  * @type {Array<number>}
368
386
  * @private
@@ -467,8 +485,22 @@ class GeoTIFFSource extends DataTile {
467
485
 
468
486
  const sourceCount = sources.length;
469
487
  for (let sourceIndex = 0; sourceIndex < sourceCount; ++sourceIndex) {
470
- const images = sources[sourceIndex];
488
+ const images = [];
489
+ const masks = [];
490
+ sources[sourceIndex].forEach((item) => {
491
+ if (isMask(item)) {
492
+ masks.push(item);
493
+ } else {
494
+ images.push(item);
495
+ }
496
+ });
497
+
471
498
  const imageCount = images.length;
499
+ if (masks.length > 0 && masks.length !== imageCount) {
500
+ throw new Error(
501
+ `Expected one mask per image found ${masks.length} masks and ${imageCount} images`
502
+ );
503
+ }
472
504
 
473
505
  let sourceExtent;
474
506
  let sourceOrigin;
@@ -574,6 +606,7 @@ class GeoTIFFSource extends DataTile {
574
606
  }
575
607
 
576
608
  this.sourceImagery_[sourceIndex] = images.reverse();
609
+ this.sourceMasks_[sourceIndex] = masks.reverse();
577
610
  }
578
611
 
579
612
  for (let i = 0, ii = this.sourceImagery_.length; i < ii; ++i) {
@@ -606,6 +639,10 @@ class GeoTIFFSource extends DataTile {
606
639
  this.addAlpha_ = true;
607
640
  break;
608
641
  }
642
+ if (this.sourceMasks_[sourceIndex].length) {
643
+ this.addAlpha_ = true;
644
+ break;
645
+ }
609
646
 
610
647
  const values = nodataValues[sourceIndex];
611
648
 
@@ -630,12 +667,11 @@ class GeoTIFFSource extends DataTile {
630
667
  }
631
668
  }
632
669
 
633
- const additionalBands = this.addAlpha_ ? 1 : 0;
634
- this.bandCount =
635
- samplesPerPixel.reduce((accumulator, value) => {
636
- accumulator += value;
637
- return accumulator;
638
- }, 0) + additionalBands;
670
+ let bandCount = this.addAlpha_ ? 1 : 0;
671
+ for (let sourceIndex = 0; sourceIndex < sourceCount; ++sourceIndex) {
672
+ bandCount += samplesPerPixel[sourceIndex];
673
+ }
674
+ this.bandCount = bandCount;
639
675
 
640
676
  const tileGrid = new TileGrid({
641
677
  extent: extent,
@@ -650,24 +686,36 @@ class GeoTIFFSource extends DataTile {
650
686
 
651
687
  this.setLoader(this.loadTile_.bind(this));
652
688
  this.setState('ready');
689
+
690
+ let zoom = 0;
691
+ if (resolutions.length === 1) {
692
+ resolutions = [resolutions[0] * 2, resolutions[0]];
693
+ zoom = 1;
694
+ }
653
695
  this.viewResolver({
696
+ showFullExtent: true,
654
697
  projection: this.projection,
655
698
  resolutions: resolutions,
656
699
  center: toUserCoordinate(getCenter(extent), this.projection),
657
700
  extent: toUserExtent(extent, this.projection),
658
- zoom: 0,
701
+ zoom: zoom,
659
702
  });
660
703
  }
661
704
 
705
+ /**
706
+ * @param {number} z The z tile index.
707
+ * @param {number} x The x tile index.
708
+ * @param {number} y The y tile index.
709
+ * @return {Promise} The composed tile data.
710
+ * @private
711
+ */
662
712
  loadTile_(z, x, y) {
663
713
  const sourceTileSize = this.getTileSize(z);
664
714
  const sourceCount = this.sourceImagery_.length;
665
- const requests = new Array(sourceCount);
666
- const addAlpha = this.addAlpha_;
667
- const bandCount = this.bandCount;
668
- const samplesPerPixel = this.samplesPerPixel_;
715
+ const requests = new Array(sourceCount * 2);
669
716
  const nodataValues = this.nodataValues_;
670
717
  const sourceInfo = this.sourceInfo_;
718
+ const pool = getWorkerPool();
671
719
  for (let sourceIndex = 0; sourceIndex < sourceCount; ++sourceIndex) {
672
720
  const source = sourceInfo[sourceIndex];
673
721
  const resolutionFactor = this.resolutionFactors_[sourceIndex];
@@ -705,112 +753,150 @@ class GeoTIFFSource extends DataTile {
705
753
  height: sourceTileSize[1],
706
754
  samples: samples,
707
755
  fillValue: fillValue,
708
- pool: getWorkerPool(),
756
+ pool: pool,
757
+ interleave: false,
758
+ });
759
+
760
+ // requests after `sourceCount` are for mask data (if any)
761
+ const maskIndex = sourceCount + sourceIndex;
762
+ const mask = this.sourceMasks_[sourceIndex][z];
763
+ if (!mask) {
764
+ requests[maskIndex] = Promise.resolve(null);
765
+ continue;
766
+ }
767
+
768
+ requests[maskIndex] = mask.readRasters({
769
+ window: pixelBounds,
770
+ width: sourceTileSize[0],
771
+ height: sourceTileSize[1],
772
+ samples: [0],
773
+ pool: pool,
709
774
  interleave: false,
710
775
  });
711
776
  }
712
777
 
778
+ return Promise.all(requests)
779
+ .then(this.composeTile_.bind(this, sourceTileSize))
780
+ .catch(function (error) {
781
+ console.error(error); // eslint-disable-line no-console
782
+ throw error;
783
+ });
784
+ }
785
+
786
+ /**
787
+ * @param {import("../size.js").Size} sourceTileSize The source tile size.
788
+ * @param {Array} sourceSamples The source samples.
789
+ * @return {import("../DataTile.js").Data} The composed tile data.
790
+ * @private
791
+ */
792
+ composeTile_(sourceTileSize, sourceSamples) {
793
+ const metadata = this.metadata_;
794
+ const sourceInfo = this.sourceInfo_;
795
+ const sourceCount = this.sourceImagery_.length;
796
+ const bandCount = this.bandCount;
797
+ const samplesPerPixel = this.samplesPerPixel_;
798
+ const nodataValues = this.nodataValues_;
799
+ const normalize = this.normalize_;
800
+ const addAlpha = this.addAlpha_;
801
+
713
802
  const pixelCount = sourceTileSize[0] * sourceTileSize[1];
714
803
  const dataLength = pixelCount * bandCount;
715
- const normalize = this.normalize_;
716
- const metadata = this.metadata_;
717
804
 
718
- return Promise.all(requests)
719
- .then(function (sourceSamples) {
720
- /** @type {Uint8Array|Float32Array} */
721
- let data;
722
- if (normalize) {
723
- data = new Uint8Array(dataLength);
724
- } else {
725
- data = new Float32Array(dataLength);
726
- }
805
+ /** @type {Uint8Array|Float32Array} */
806
+ let data;
807
+ if (normalize) {
808
+ data = new Uint8Array(dataLength);
809
+ } else {
810
+ data = new Float32Array(dataLength);
811
+ }
727
812
 
728
- let dataIndex = 0;
729
- for (let pixelIndex = 0; pixelIndex < pixelCount; ++pixelIndex) {
730
- let transparent = addAlpha;
731
- for (let sourceIndex = 0; sourceIndex < sourceCount; ++sourceIndex) {
732
- const source = sourceInfo[sourceIndex];
733
-
734
- let min = source.min;
735
- let max = source.max;
736
- let gain, bias;
737
- if (normalize) {
738
- const stats = metadata[sourceIndex][0];
739
- if (min === undefined) {
740
- if (stats && STATISTICS_MINIMUM in stats) {
741
- min = parseFloat(stats[STATISTICS_MINIMUM]);
742
- } else {
743
- min = getMinForDataType(sourceSamples[sourceIndex][0]);
744
- }
745
- }
746
- if (max === undefined) {
747
- if (stats && STATISTICS_MAXIMUM in stats) {
748
- max = parseFloat(stats[STATISTICS_MAXIMUM]);
749
- } else {
750
- max = getMaxForDataType(sourceSamples[sourceIndex][0]);
751
- }
752
- }
813
+ let dataIndex = 0;
814
+ for (let pixelIndex = 0; pixelIndex < pixelCount; ++pixelIndex) {
815
+ let transparent = addAlpha;
816
+ for (let sourceIndex = 0; sourceIndex < sourceCount; ++sourceIndex) {
817
+ const source = sourceInfo[sourceIndex];
753
818
 
754
- gain = 255 / (max - min);
755
- bias = -min * gain;
819
+ let min = source.min;
820
+ let max = source.max;
821
+ let gain, bias;
822
+ if (normalize) {
823
+ const stats = metadata[sourceIndex][0];
824
+ if (min === undefined) {
825
+ if (stats && STATISTICS_MINIMUM in stats) {
826
+ min = parseFloat(stats[STATISTICS_MINIMUM]);
827
+ } else {
828
+ min = getMinForDataType(sourceSamples[sourceIndex][0]);
756
829
  }
830
+ }
831
+ if (max === undefined) {
832
+ if (stats && STATISTICS_MAXIMUM in stats) {
833
+ max = parseFloat(stats[STATISTICS_MAXIMUM]);
834
+ } else {
835
+ max = getMaxForDataType(sourceSamples[sourceIndex][0]);
836
+ }
837
+ }
757
838
 
758
- for (
759
- let sampleIndex = 0;
760
- sampleIndex < samplesPerPixel[sourceIndex];
761
- ++sampleIndex
762
- ) {
763
- const sourceValue =
764
- sourceSamples[sourceIndex][sampleIndex][pixelIndex];
839
+ gain = 255 / (max - min);
840
+ bias = -min * gain;
841
+ }
765
842
 
766
- let value;
767
- if (normalize) {
768
- value = clamp(gain * sourceValue + bias, 0, 255);
769
- } else {
770
- value = sourceValue;
771
- }
843
+ for (
844
+ let sampleIndex = 0;
845
+ sampleIndex < samplesPerPixel[sourceIndex];
846
+ ++sampleIndex
847
+ ) {
848
+ const sourceValue =
849
+ sourceSamples[sourceIndex][sampleIndex][pixelIndex];
850
+
851
+ let value;
852
+ if (normalize) {
853
+ value = clamp(gain * sourceValue + bias, 0, 255);
854
+ } else {
855
+ value = sourceValue;
856
+ }
772
857
 
773
- if (!addAlpha) {
774
- data[dataIndex] = value;
858
+ if (!addAlpha) {
859
+ data[dataIndex] = value;
860
+ } else {
861
+ let nodata = source.nodata;
862
+ if (nodata === undefined) {
863
+ let bandIndex;
864
+ if (source.bands) {
865
+ bandIndex = source.bands[sampleIndex] - 1;
775
866
  } else {
776
- let nodata = source.nodata;
777
- if (nodata === undefined) {
778
- let bandIndex;
779
- if (source.bands) {
780
- bandIndex = source.bands[sampleIndex] - 1;
781
- } else {
782
- bandIndex = sampleIndex;
783
- }
784
- nodata = nodataValues[sourceIndex][bandIndex];
785
- }
786
-
787
- const nodataIsNaN = isNaN(nodata);
788
- if (
789
- (!nodataIsNaN && sourceValue !== nodata) ||
790
- (nodataIsNaN && !isNaN(sourceValue))
791
- ) {
792
- transparent = false;
793
- data[dataIndex] = value;
794
- }
867
+ bandIndex = sampleIndex;
795
868
  }
796
- dataIndex++;
869
+ nodata = nodataValues[sourceIndex][bandIndex];
797
870
  }
798
- }
799
- if (addAlpha) {
800
- if (!transparent) {
801
- data[dataIndex] = 255;
871
+
872
+ const nodataIsNaN = isNaN(nodata);
873
+ if (
874
+ (!nodataIsNaN && sourceValue !== nodata) ||
875
+ (nodataIsNaN && !isNaN(sourceValue))
876
+ ) {
877
+ transparent = false;
878
+ data[dataIndex] = value;
802
879
  }
803
- dataIndex++;
804
880
  }
881
+ dataIndex++;
805
882
  }
883
+ if (!transparent) {
884
+ const maskIndex = sourceCount + sourceIndex;
885
+ const mask = sourceSamples[maskIndex];
886
+ if (mask && !mask[0][pixelIndex]) {
887
+ transparent = true;
888
+ }
889
+ }
890
+ }
891
+ if (addAlpha) {
892
+ if (!transparent) {
893
+ data[dataIndex] = 255;
894
+ }
895
+ dataIndex++;
896
+ }
897
+ }
806
898
 
807
- return data;
808
- })
809
- .catch(function (error) {
810
- // output then rethrow
811
- console.error(error); // eslint-disable-line no-console
812
- throw error;
813
- });
899
+ return data;
814
900
  }
815
901
  }
816
902
 
package/source/OSM.d.ts CHANGED
@@ -90,7 +90,7 @@ export type Options = {
90
90
  * ```
91
91
  * @property {number} [transition=250] Duration of the opacity transition for rendering.
92
92
  * To disable the opacity transition, pass `transition: 0`.
93
- * @property {string} [url='https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'] URL template.
93
+ * @property {string} [url='https://tile.openstreetmap.org/{z}/{x}/{y}.png'] URL template.
94
94
  * Must include `{x}`, `{y}` or `{-y}`, and `{z}` placeholders.
95
95
  * @property {boolean} [wrapX=true] Whether to wrap the world horizontally.
96
96
  * @property {number|import("../array.js").NearestDirectionFunction} [zDirection=0]
package/source/OSM.js CHANGED
@@ -37,7 +37,7 @@ export const ATTRIBUTION =
37
37
  * ```
38
38
  * @property {number} [transition=250] Duration of the opacity transition for rendering.
39
39
  * To disable the opacity transition, pass `transition: 0`.
40
- * @property {string} [url='https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'] URL template.
40
+ * @property {string} [url='https://tile.openstreetmap.org/{z}/{x}/{y}.png'] URL template.
41
41
  * Must include `{x}`, `{y}` or `{-y}`, and `{z}` placeholders.
42
42
  * @property {boolean} [wrapX=true] Whether to wrap the world horizontally.
43
43
  * @property {number|import("../array.js").NearestDirectionFunction} [zDirection=0]
@@ -70,7 +70,7 @@ class OSM extends XYZ {
70
70
  const url =
71
71
  options.url !== undefined
72
72
  ? options.url
73
- : 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png';
73
+ : 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
74
74
 
75
75
  super({
76
76
  attributions: attributions,
package/util.js CHANGED
@@ -33,4 +33,4 @@ export function getUid(obj) {
33
33
  * OpenLayers version.
34
34
  * @type {string}
35
35
  */
36
- export const VERSION = '7.0.1-dev.1661609353651';
36
+ export const VERSION = '7.0.1-dev.1661713055938';