@@ -29,12 +29,18 @@ export const LEGEND_STYLE_KEYS = {
29
29
} ;
30
30
31
31
export class WebMap extends mapboxgl . Evented {
32
- constructor ( mapId , options ) {
32
+ constructor ( mapId , options , mapOptions ) {
33
33
super ( ) ;
34
34
this . mapId = mapId ;
35
35
this . server = options . server ;
36
36
this . withCredentials = options . withCredentials ;
37
37
this . target = options . target ;
38
+ this . mapOptions = {
39
+ center : mapOptions . center ,
40
+ zoom : mapOptions . zoom ,
41
+ bearing : mapOptions . bearing ,
42
+ pitch : mapOptions . pitch
43
+ }
38
44
this . mapResourceUrl = Util . transformUrl ( Object . assign ( { url : `${ this . server } web/maps/${ mapId } ` } , this . options ) ) ;
39
45
this . _layersOfV3 = [ ] ;
40
46
this . _layerIdMapList = { } ;
@@ -67,9 +73,13 @@ export class WebMap extends mapboxgl.Evented {
67
73
*/
68
74
_createMap ( ) {
69
75
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 ;
70
77
if ( this . _mapInfo . center && crs === 'EPSG:3857' ) {
71
78
center = Util . unproject ( center ) ;
72
79
}
80
+ zoom = this . mapOptions . zoom || zoom ;
81
+ bearing = this . mapOptions . bearing || bearing ;
82
+ pitch = this . mapOptions . pitch || pitch ;
73
83
const fontFamilys = this . _getLabelFontFamily ( ) ;
74
84
// 初始化 map
75
85
const mapOptions = {
@@ -259,6 +269,15 @@ export class WebMap extends mapboxgl.Evented {
259
269
return this . _legendList ;
260
270
}
261
271
272
+ cleanWebMap ( ) {
273
+ if ( this . map ) {
274
+ this . map = null ;
275
+ this . _legendList = [ ] ;
276
+ this . mapOptions = { } ;
277
+ this . _appreciableLayers = [ ] ;
278
+ }
279
+ }
280
+
262
281
/**
263
282
* @private
264
283
* @function WebMap.prototype._generateV2LayersStructure
@@ -333,6 +352,7 @@ export class WebMap extends mapboxgl.Evented {
333
352
* @description 获取雪碧图信息。
334
353
*/
335
354
_getSpriteDatas ( spriteUrl ) {
355
+ spriteUrl = this . server + spriteUrl . split ( '/iportal' ) [ 1 ] ;
336
356
return FetchRequest . get ( spriteUrl , null , { withCredentials : this . withCredentials } )
337
357
. then ( ( response ) => {
338
358
return response . json ( ) ;
@@ -355,7 +375,7 @@ export class WebMap extends mapboxgl.Evented {
355
375
layerId : layer . id
356
376
} ;
357
377
if ( keyName === 'color' ) {
358
- let symbolId = simpleStyle [ 'symbolsContent' ] . value . symbol ;
378
+ let symbolId = simpleStyle [ 'symbolsContent' ] && simpleStyle [ 'symbolsContent' ] . value . symbol ;
359
379
if ( symbolId ) {
360
380
let symbolInfo = this . _spriteDatas [ symbolId ] ;
361
381
styleList [ keyName ] . values . forEach ( ( info ) => {
0 commit comments