@supermapgis/iclient-ol 11.2.0 → 11.2.1

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.
@@ -34,6 +34,7 @@ import decryptTileUtil from '@supermapgis/tile-decryptor';
34
34
  * @param {(string|Object)} [options.attributions='Tile Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a></span>'] - 版权描述信息。
35
35
  * @param {Object} [options.format] - 瓦片的要素格式化。
36
36
  * @param {boolean} [options.withCredentials] - 请求是否携带 cookie。
37
+ * @param {Object} [options.headers] - 请求头。
37
38
  * @param {boolean|Function} [options.decrypt] - 瓦片解密。如果是 true 表示用内置的解密方法, 如 decrypt: true;如果是function 则是自定义解密如 decrypt: function ({ key, bytes })。
38
39
  * @param {Function} [options.decryptCompletedFunction] - 解密完成后触发。如 decryptCompletedFunction(completeData)。
39
40
  * @extends {ol.source.VectorTile}
@@ -77,6 +78,7 @@ export class VectorTileSuperMapRest extends VectorTile {
77
78
  });
78
79
  var me = this;
79
80
  me.withCredentials = options.withCredentials;
81
+ me.headers = options.headers || {};
80
82
  me._tileType = options.tileType || 'ScaleXY';
81
83
  this.vectorTileStyles = new VectorTileStyles();
82
84
  this._initialized(options);
@@ -165,9 +167,9 @@ export class VectorTileSuperMapRest extends VectorTile {
165
167
  var regHeight = new RegExp('(^|\\?|&)' + 'height' + '=([^&]*)(\\s|&|$)');
166
168
  var width = Number(tileUrl.match(regWidth)[2]);
167
169
  var height = Number(tileUrl.match(regHeight)[2]);
168
-
170
+ var me = this;
169
171
  tile.setLoader(function (extent, resolution, projection) {
170
- FetchRequest.get(tileUrl)
172
+ FetchRequest.get(tileUrl, null, {headers:me.headers})
171
173
  .then(function (response) {
172
174
  if (tile.getFormat() instanceof GeoJSON) {
173
175
  return response.json();
@@ -251,45 +253,50 @@ export class VectorTileSuperMapRest extends VectorTile {
251
253
  xhr.responseType = 'arraybuffer';
252
254
  }
253
255
  xhr.withCredentials = me.withCredentials;
256
+ for (const key in me.headers) {
257
+ if (me.headers.hasOwnProperty(key)) {
258
+ xhr.setRequestHeader(key, me.headers[key]);
259
+ }
260
+ }
254
261
  xhr.onload = function () {
255
- if (!xhr.status || (xhr.status >= 200 && xhr.status < 300)) {
256
- const type = format.getType();
257
- let source = void 0;
258
- if (type === 'json' || type === 'text') {
259
- source = xhr.responseText;
260
- } else if (type === 'xml') {
261
- source = xhr.responseXML;
262
- if (!source) {
263
- source = new DOMParser().parseFromString(xhr.responseText, 'application/xml');
264
- }
265
- } else if (type === 'arraybuffer') {
266
- source = xhr.response;
267
- }
268
- if (source) {
269
- source = me._decryptMvt(source);
270
- if (['4', '5'].indexOf(Util.getOlVersion()) > -1) {
271
- success.call(
272
- this,
273
- format.readFeatures(source, { featureProjection: projection }),
274
- format.readProjection(source),
275
- format.getLastExtent()
276
- );
277
- } else {
278
- success.call(
279
- this,
280
- format.readFeatures(source, {
281
- extent: extent,
282
- featureProjection: projection
283
- }),
284
- format.readProjection(source)
285
- );
286
- }
287
- } else {
288
- failure.call(this);
289
- }
262
+ if (!xhr.status || (xhr.status >= 200 && xhr.status < 300)) {
263
+ const type = format.getType();
264
+ let source = void 0;
265
+ if (type === 'json' || type === 'text') {
266
+ source = xhr.responseText;
267
+ } else if (type === 'xml') {
268
+ source = xhr.responseXML;
269
+ if (!source) {
270
+ source = new DOMParser().parseFromString(xhr.responseText, 'application/xml');
271
+ }
272
+ } else if (type === 'arraybuffer') {
273
+ source = xhr.response;
274
+ }
275
+ if (source) {
276
+ source = me._decryptMvt(source);
277
+ if (['4', '5'].indexOf(Util.getOlVersion()) > -1) {
278
+ success.call(
279
+ this,
280
+ format.readFeatures(source, { featureProjection: projection }),
281
+ format.readProjection(source),
282
+ format.getLastExtent()
283
+ );
284
+ } else {
285
+ success.call(
286
+ this,
287
+ format.readFeatures(source, {
288
+ extent: extent,
289
+ featureProjection: projection
290
+ }),
291
+ format.readProjection(source)
292
+ );
293
+ }
290
294
  } else {
291
- failure.call(this);
295
+ failure.call(this);
292
296
  }
297
+ } else {
298
+ failure.call(this);
299
+ }
293
300
  }.bind(this);
294
301
  xhr.onerror = function () {
295
302
  failure.call(this);
@@ -304,7 +311,10 @@ export class VectorTileSuperMapRest extends VectorTile {
304
311
  let style = options.style;
305
312
  if (Object.prototype.toString.call(options.style) == '[object String]') {
306
313
  var url = SecurityManager.appendCredential(options.style);
307
- const response = await FetchRequest.get(url, null, { withCredentials: options.withCredentials })
314
+ const response = await FetchRequest.get(url, null, {
315
+ withCredentials: options.withCredentials,
316
+ headers: options.headers
317
+ });
308
318
  style = await response.json();
309
319
  }
310
320
  this._fillByStyleJSON(style, options.source);
@@ -34,6 +34,7 @@ import Text from 'ol/style/Text';
34
34
  * @param {ol.Map} [options.map] - Openlayers 地图对象,仅用于面填充样式,若没有面填充样式可不填。
35
35
  * @param {ol.StyleFunction} [options.selectedStyle] -选中样式 Function。
36
36
  * @param {boolean} [options.withCredentials] - 请求是否携带 cookie。
37
+ * @param {Object} [options.headers] - 请求头。
37
38
  * @example
38
39
  * var mbStyle = new MapboxStyles({
39
40
  url: url,
@@ -73,6 +74,7 @@ export class MapboxStyles extends Observable {
73
74
  );
74
75
  this.resolutions = options.resolutions;
75
76
  this.withCredentials = options.withCredentials;
77
+ this.headers = options.headers;
76
78
  this.selectedObjects = [];
77
79
  this.selectedStyle =
78
80
  options.selectedStyle ||
@@ -252,7 +254,7 @@ export class MapboxStyles extends Observable {
252
254
  }, 0);
253
255
  } else {
254
256
  var url = SecurityManager.appendCredential(style);
255
- FetchRequest.get(url, null, { withCredentials: this.withCredentials })
257
+ FetchRequest.get(url, null, { withCredentials: this.withCredentials, headers: this.headers })
256
258
  .then(response => response.json())
257
259
  .then(mbStyle => {
258
260
  this._mbStyle = mbStyle;
@@ -271,32 +273,48 @@ export class MapboxStyles extends Observable {
271
273
  this._mbStyle.sprite = this._mbStyle.sprite.replace('@2x', '');
272
274
  const spriteUrl = this._toSpriteUrl(this._mbStyle.sprite, this.path, sizeFactor + '.json');
273
275
  FetchRequest.get(SecurityManager.appendCredential(spriteUrl), null, {
274
- withCredentials: this.withCredentials
276
+ withCredentials: this.withCredentials,
277
+ headers: this.headers
275
278
  })
276
- .then(response => response.json())
277
- .then(spritesJson => {
278
- this._spriteData = spritesJson;
279
- this._spriteImageUrl = SecurityManager.appendCredential(
280
- this._toSpriteUrl(this._mbStyle.sprite, this.path, sizeFactor + '.png')
281
- );
282
- this._spriteImage = null;
279
+ .then((response) => response.json())
280
+ .then((spritesJson) => {
281
+ this._spriteData = spritesJson;
282
+ this._spriteImageUrl = SecurityManager.appendCredential(
283
+ this._toSpriteUrl(this._mbStyle.sprite, this.path, sizeFactor + '.png')
284
+ );
285
+ this._spriteImage = null;
286
+
287
+ var xhr = new XMLHttpRequest();
288
+ xhr.responseType = 'blob';
289
+ xhr.addEventListener('loadend',(e) => {
290
+ var data = e.target.response;
291
+ if (data !== undefined) {
283
292
  const img = new Image();
284
- img.crossOrigin = this.withCredentials ? 'use-credentials' : 'anonymous';
285
- img.onload = () => {
286
- this._spriteImage = img;
287
- this._initStyleFunction();
288
- };
289
- img.onerror = () => {
290
- this._spriteImage = null;
291
- this._initStyleFunction();
292
- };
293
- img.src = this._spriteImageUrl;
294
- })
295
- .catch( err => {
296
- console.log(err);
293
+ img.src = URL.createObjectURL(data);
294
+ this._spriteImage = img;
295
+ } else {
297
296
  this._spriteImage = null;
298
- this._initStyleFunction();
297
+ }
298
+ this._initStyleFunction();
299
+ });
300
+ xhr.addEventListener('error', () => {
301
+ this._spriteImage = null;
302
+ this._initStyleFunction();
299
303
  });
304
+ xhr.open('GET', this._spriteImageUrl);
305
+ for (const key in this.headers) {
306
+ if (this.headers.hasOwnProperty(key)) {
307
+ xhr.setRequestHeader(key, this.headers[key]);
308
+ }
309
+ }
310
+ xhr.withCredentials = this.withCredentials;
311
+ xhr.send();
312
+ })
313
+ .catch((err) => {
314
+ console.log(err);
315
+ this._spriteImage = null;
316
+ this._initStyleFunction();
317
+ });
300
318
  } else {
301
319
  this._initStyleFunction();
302
320
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@supermapgis/iclient-ol",
3
3
  "description": "",
4
- "version": "11.2.0",
4
+ "version": "11.2.1",
5
5
  "keywords": [
6
6
  "SuperMap",
7
7
  "OpenLayers"
@@ -15,7 +15,7 @@
15
15
  "author": "SuperMap",
16
16
  "license": "Apache-2.0",
17
17
  "dependencies": {
18
- "@supermapgis/iclient-common": "11.2.0",
18
+ "@supermapgis/iclient-common": "11.2.1",
19
19
  "@supermapgis/tile-decryptor": "^1.0.0",
20
20
  "@turf/turf": "6.5.0",
21
21
  "mapv": "2.0.62",