@artstesh/maps 1.1.10 → 1.1.11

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
@@ -1,13 +1,11 @@
1
- # @artstesh/maps
2
-
3
- Let's map a feature ;)
4
-
5
- ### Description of the project
6
-
7
- The main purpose of the project is to make easier the process of using of [openlayers library](https://openlayers.org/) in Angular projects.
8
-
9
- It's just the first, initial version of the library, that gonna become much more functional in a few weeks.
10
-
11
- ### License
12
-
13
- This project is licensed under the MIT License
1
+ # @artstesh/maps
2
+
3
+ Let's map a feature ;)
4
+
5
+ ### Description of the project
6
+
7
+ The main purpose of the project is to make easier the process of using of [openlayers library](https://openlayers.org/) in Angular projects.
8
+
9
+ ### License
10
+
11
+ This project is licensed under the MIT License
@@ -1855,6 +1855,13 @@
1855
1855
  * @default 'EPSG:3857'
1856
1856
  */
1857
1857
  this.projection = 'EPSG:3857';
1858
+ /**
1859
+ * Additional headers that should be added to each tile request
1860
+ *
1861
+ * @type {Record<string, string>}
1862
+ * @default An empty array
1863
+ */
1864
+ this.requestHeaders = null;
1858
1865
  }
1859
1866
  /**
1860
1867
  * Creates a copy of the given tile layer settings.
@@ -1869,6 +1876,7 @@
1869
1876
  result.projection = model.projection;
1870
1877
  result.opacity = model.opacity;
1871
1878
  result.url = model.url;
1879
+ result.requestHeaders = model.requestHeaders;
1872
1880
  return result;
1873
1881
  };
1874
1882
  /**
@@ -1880,6 +1888,15 @@
1880
1888
  TileLayerSettings.prototype.setUrl = function (url) {
1881
1889
  return TileLayerSettings.copy(Object.assign(Object.assign({}, this), { url: url }));
1882
1890
  };
1891
+ /**
1892
+ * Sets the requestHeaders of the TileLayerSettings object.
1893
+ *
1894
+ * @param {Record<string, string>} requestHeaders - The headers which should be provided.
1895
+ * @return {TileLayerSettings} - The updated TileLayerSettings object.
1896
+ */
1897
+ TileLayerSettings.prototype.setRequestHeaders = function (requestHeaders) {
1898
+ return TileLayerSettings.copy(Object.assign(Object.assign({}, this), { requestHeaders: requestHeaders }));
1899
+ };
1883
1900
  /**
1884
1901
  * Sets the maximum zoom level for the tile layer.
1885
1902
  *
@@ -1933,6 +1950,8 @@
1933
1950
  return false;
1934
1951
  if (this.opacity !== model.opacity)
1935
1952
  return false;
1953
+ if (this.requestHeaders !== model.requestHeaders)
1954
+ return false;
1936
1955
  return true;
1937
1956
  };
1938
1957
  return TileLayerSettings;
@@ -1942,6 +1961,7 @@
1942
1961
  function TileLayerFactory() {
1943
1962
  }
1944
1963
  TileLayerFactory.prototype.build = function (settings) {
1964
+ var _this = this;
1945
1965
  var source$1 = new source.XYZ({
1946
1966
  tileSize: 256,
1947
1967
  maxZoom: settings.maxZoom || 14,
@@ -1949,6 +1969,9 @@
1949
1969
  projection: proj.get(settings.projection),
1950
1970
  tileUrlFunction: this.getTileFunc(settings),
1951
1971
  crossOrigin: 'Anonymous',
1972
+ tileLoadFunction: !!settings.requestHeaders
1973
+ ? function (tile, src) { return _this.tileLoader(tile, src, settings.requestHeaders); }
1974
+ : undefined,
1952
1975
  });
1953
1976
  return new TileLayer__default["default"]({ source: source$1, opacity: settings.opacity });
1954
1977
  };
@@ -1966,6 +1989,21 @@
1966
1989
  .replace('{y}', String(bound - ((normalizedCoord === null || normalizedCoord === void 0 ? void 0 : normalizedCoord.y) || y) - 1));
1967
1990
  };
1968
1991
  };
1992
+ TileLayerFactory.prototype.tileLoader = function (tile, src, headers) {
1993
+ var client = new XMLHttpRequest();
1994
+ client.open('GET', src);
1995
+ client.responseType = 'arraybuffer';
1996
+ Object.keys(headers).forEach(function (k) { return client.setRequestHeader(k, headers[k]); });
1997
+ client.onload = function () {
1998
+ if (this.response !== undefined) {
1999
+ var arrayBufferView = new Uint8Array(this.response);
2000
+ var blob = new Blob([arrayBufferView], { type: 'image/png' });
2001
+ var urlCreator = window.URL || window.webkitURL;
2002
+ tile.getImage().src = urlCreator.createObjectURL(blob);
2003
+ }
2004
+ };
2005
+ client.send();
2006
+ };
1969
2007
  TileLayerFactory.prototype.getNormalizedCoord = function (coord, zoom) {
1970
2008
  var y = coord.y;
1971
2009
  var x = coord.x;