Skip to content

Commit 47d149a

Browse files
committed
【fix】修复雪碧图地址错误; review by qiw
1 parent 3d4d0a3 commit 47d149a

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/mapboxgl/mapping/webmap/v2/WebMap.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ export class WebMap extends mapboxgl.Evented {
9595
this._addLayers(layers);
9696
}
9797
});
98+
this.map.on('remove', () => {
99+
this._stopCanvg();
100+
});
98101
}
99102

100103
/**
@@ -149,9 +152,6 @@ export class WebMap extends mapboxgl.Evented {
149152
localIdeographFontFamily: fontFamilys || ''
150153
});
151154
this.fire('mapinitialized');
152-
this.map.on('remove', () => {
153-
this._stopCanvg();
154-
});
155155
}
156156

157157
/**

src/mapboxgl/mapping/webmap/v3/WebMap.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ export const LEGEND_STYLE_KEYS = {
2929
};
3030

3131
export class WebMap extends mapboxgl.Evented {
32-
constructor(mapId, options) {
32+
constructor(mapId, options, mapOptions) {
3333
super();
3434
this.mapId = mapId;
3535
this.server = options.server;
3636
this.withCredentials = options.withCredentials;
3737
this.target = options.target;
38+
this.mapOptions = {
39+
center: mapOptions.center,
40+
zoom: mapOptions.zoom,
41+
bearing: mapOptions.bearing,
42+
pitch: mapOptions.pitch
43+
}
3844
this.mapResourceUrl = Util.transformUrl(Object.assign({ url: `${this.server}web/maps/${mapId}` }, this.options));
3945
this._layersOfV3 = [];
4046
this._layerIdMapList = {};
@@ -67,9 +73,13 @@ export class WebMap extends mapboxgl.Evented {
6773
*/
6874
_createMap() {
6975
let { name, crs, center = new mapboxgl.LngLat(0, 0), zoom = 0, bearing = 0, pitch = 0, minzoom, maxzoom, sprite } = this._mapInfo;
76+
center = this.mapOptions.center || center;
7077
if (this._mapInfo.center && crs === 'EPSG:3857') {
7178
center = Util.unproject(center);
7279
}
80+
zoom = this.mapOptions.zoom || zoom;
81+
bearing = this.mapOptions.bearing || bearing;
82+
pitch = this.mapOptions.pitch || pitch;
7383
const fontFamilys = this._getLabelFontFamily();
7484
// 初始化 map
7585
const mapOptions = {
@@ -259,6 +269,15 @@ export class WebMap extends mapboxgl.Evented {
259269
return this._legendList;
260270
}
261271

272+
cleanWebMap() {
273+
if (this.map) {
274+
this.map = null;
275+
this._legendList = [];
276+
this.mapOptions = {};
277+
this._appreciableLayers = [];
278+
}
279+
}
280+
262281
/**
263282
* @private
264283
* @function WebMap.prototype._generateV2LayersStructure
@@ -333,6 +352,7 @@ export class WebMap extends mapboxgl.Evented {
333352
* @description 获取雪碧图信息。
334353
*/
335354
_getSpriteDatas(spriteUrl) {
355+
spriteUrl = this.server + spriteUrl.split('/iportal')[1];
336356
return FetchRequest.get(spriteUrl, null, { withCredentials: this.withCredentials })
337357
.then((response) => {
338358
return response.json();
@@ -355,7 +375,7 @@ export class WebMap extends mapboxgl.Evented {
355375
layerId: layer.id
356376
};
357377
if (keyName === 'color') {
358-
let symbolId = simpleStyle['symbolsContent'].value.symbol;
378+
let symbolId = simpleStyle['symbolsContent'] && simpleStyle['symbolsContent'].value.symbol;
359379
if (symbolId) {
360380
let symbolInfo = this._spriteDatas[symbolId];
361381
styleList[keyName].values.forEach((info) => {

0 commit comments

Comments
 (0)