@@ -136,7 +136,7 @@ export class WebMap extends mapboxgl.Evented {
136136 */
137137 _createMap ( ) {
138138 let {
139- name,
139+ name = '' ,
140140 crs,
141141 center = new mapboxgl . LngLat ( 0 , 0 ) ,
142142 zoom = 0 ,
@@ -188,6 +188,15 @@ export class WebMap extends mapboxgl.Evented {
188188 this . fire ( 'projectionisnotmatch' ) ;
189189 return ;
190190 }
191+ if ( Object . prototype . toString . call ( this . mapId ) === '[object Object]' ) {
192+ this . mapParams = {
193+ title : this . _mapInfo . name ,
194+ description : ''
195+ } ;
196+ this . _createMapRelatedInfo ( ) ;
197+ this . _addLayersToMap ( ) ;
198+ return ;
199+ }
191200 Promise . all ( [ this . _getMapRelatedInfo ( ) , this . _getSpriteDatas ( ) ] )
192201 . then ( ( [ relatedInfo ] ) => {
193202 this . mapParams = {
@@ -240,56 +249,21 @@ export class WebMap extends mapboxgl.Evented {
240249 * @description emit 图层加载成功事件。
241250 */
242251 _addLayersToMap ( ) {
243- const { sources, layers, layerIdMapList } = this . _setUniqueId ( this . _mapInfo ) ;
252+ const { sources, layers } = this . _mapInfo ;
244253 layers . forEach ( ( layer ) => {
245254 layer . source && ! this . map . getSource ( layer . source ) && this . map . addSource ( layer . source , sources [ layer . source ] ) ;
246255 this . map . addLayer ( layer ) ;
247256 } ) ;
248- this . _sendMapToUser ( layerIdMapList ) ;
249- }
250-
251- /**
252- * @private
253- * @function WebMap.prototype._setUniqueId
254- * @description 返回唯一 id 的 sources 和 layers。
255- * @param {Object } mapInfo - map 信息。
256- */
257- _setUniqueId ( mapInfo ) {
258- let layersToMap = JSON . parse ( JSON . stringify ( mapInfo . layers ) ) ;
259- const nextSources = { } ;
260- const layerIdToChange = { } ;
261- for ( let sourceId in mapInfo . sources ) {
262- let timestamp = this . map . getSource ( sourceId ) ? `_${ + new Date ( ) } ` : '' ;
263- const nextSourceId = sourceId + timestamp ;
264- nextSources [ nextSourceId ] = mapInfo . sources [ sourceId ] ;
265- layersToMap = layersToMap . map ( ( layer ) => {
266- let nextLayer = layer ;
267- if ( layer . source === sourceId ) {
268- let layerId = layer . id ;
269- if ( this . map . getLayer ( layerId ) ) {
270- layerId = timestamp ? layer . id + timestamp : `${ layer . id } _${ + new Date ( ) } ` ;
271- }
272- nextLayer = Object . assign ( { } , layer , { id : layerId , source : nextSourceId } ) ;
273- }
274- layerIdToChange [ layer . id ] = nextLayer . id ;
275- return nextLayer ;
276- } ) ;
277- }
278- return {
279- sources : nextSources ,
280- layers : layersToMap ,
281- layerIdMapList : layerIdToChange
282- } ;
257+ this . _sendMapToUser ( ) ;
283258 }
284259
285260 /**
286261 * @private
287262 * @function WebMap.prototype._sendMapToUser
288263 * @description emit 图层加载成功事件。
289- * @param {Object } layerIdMapList - 图层 id 信息
290264 */
291- _sendMapToUser ( layerIdMapList ) {
292- this . _appreciableLayers = this . _generateLayers ( layerIdMapList ) ;
265+ _sendMapToUser ( ) {
266+ this . _appreciableLayers = this . _generateLayers ( ) ;
293267 this . fire ( 'addlayerssucceeded' , { map : this . map , mapparams : this . mapParams , layers : this . _appreciableLayers } ) ;
294268 }
295269
@@ -314,9 +288,11 @@ export class WebMap extends mapboxgl.Evented {
314288
315289 clean ( ) {
316290 if ( this . map ) {
291+ this . map . remove ( ) ;
317292 this . map = null ;
318293 this . _legendList = [ ] ;
319294 this . mapOptions = { } ;
295+ this . options = { } ;
320296 this . _appreciableLayers = [ ] ;
321297 }
322298 }
@@ -325,18 +301,16 @@ export class WebMap extends mapboxgl.Evented {
325301 * @private
326302 * @function WebMap.prototype._generateV2LayersStructure
327303 * @description emit 图层加载成功事件。
328- * @param {Array<Object> } layers - 图层信息。
329304 */
330- _generateLayers ( layerIdMapList ) {
305+ _generateLayers ( ) {
331306 const { catalogs = [ ] } = this . _mapResourceInfo ;
332307 const originLayers = this . _getLayerInfosFromCatalogs ( catalogs ) ;
333308 const layers = originLayers . map ( ( layer ) => {
334309 const { title, visualization } = layer ;
335- const realLayerId = layerIdMapList [ layer . id ] ;
336310 const layerFromMapInfo = this . _mapInfo . layers . find ( ( item ) => {
337311 return item . id === layer . id ;
338312 } ) ;
339- this . _createLegendInfo ( Object . assign ( { } , layerFromMapInfo , { id : realLayerId } ) , visualization ) ;
313+ this . _createLegendInfo ( Object . assign ( { } , layerFromMapInfo ) , visualization ) ;
340314 let dataType = '' ;
341315 let dataId = '' ;
342316 for ( const data of this . _mapResourceInfo . datas ) {
@@ -352,7 +326,7 @@ export class WebMap extends mapboxgl.Evented {
352326 serverId : dataId ,
353327 type : dataType
354328 } ,
355- layerID : realLayerId ,
329+ layerID : layer . id ,
356330 layerType : layerFromMapInfo . type === 'raster' ? 'raster' : 'vector' ,
357331 type : layerFromMapInfo . type ,
358332 name : title
0 commit comments