@@ -257,11 +257,19 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) {
257257 * @function WebMapBase.prototype.setStyle
258258 * @description 更新地图样式。
259259 * @param {Object } style - 地图 style 样式
260+ * @param {boolean } preserveMap - 保留地图实例,覆盖图层样式。
260261 */
261- setStyle ( style ) {
262+ setStyle ( style , preserveMap = false ) {
262263 if ( this . map ) {
263264 this . mapOptions . style = style ;
264- this . _initWebMap ( ) ;
265+ if ( preserveMap ) {
266+ this . cleanLayers ( ) ;
267+ }
268+ if ( this . _isWebMapV3 ( style ) ) {
269+ this . setMapId ( style , preserveMap )
270+ return ;
271+ }
272+ this . _initWebMap ( ! preserveMap ) ;
265273 }
266274 }
267275
@@ -454,7 +462,7 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) {
454462 this . _handler . clean ( removeMap ) ;
455463 this . _handler = null ;
456464 }
457- this . map = null ;
465+ removeMap && ( this . map = null ) ;
458466 if ( this . mapOptions && ( this . mapId || this . webMapInfo ) ) {
459467 this . mapOptions . center = null ;
460468 this . mapOptions . zoom = null ;
@@ -472,7 +480,7 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) {
472480 if ( ! this . map ) {
473481 return ;
474482 }
475- const layersToClean = this . _cacheCleanLayers . filter ( item => ! item . reused ) ;
483+ const layersToClean = this . _cacheCleanLayers . filter ( ( item ) => ! item . reused ) ;
476484 this . _handler && this . _handler . cleanLayers ( layersToClean ) ;
477485 this . _cacheCleanLayers = [ ] ;
478486 this . clean ( false ) ;
@@ -538,7 +546,7 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) {
538546 this . webMapService . setProxy ( proxy ) ;
539547 }
540548
541- setMapId ( mapId ) {
549+ setMapId ( mapId , preserveMap = false ) {
542550 if ( typeof mapId === 'string' || typeof mapId === 'number' ) {
543551 this . mapId = mapId ;
544552 this . webMapInfo = null ;
@@ -551,7 +559,7 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) {
551559 return ;
552560 }
553561 setTimeout ( ( ) => {
554- this . _initWebMap ( ) ;
562+ this . _initWebMap ( ! preserveMap ) ;
555563 } , 0 ) ;
556564 }
557565
@@ -601,8 +609,19 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) {
601609 this . fire ( 'layeraddchanged' , params ) ;
602610 }
603611
612+ _isWebMapV3 ( styleInfo ) {
613+ if ( ! styleInfo . version ) {
614+ return false ;
615+ }
616+ const subVersions = `${ styleInfo . version } ` . split ( '.' )
617+ if ( subVersions . length <= 1 ) {
618+ return false ;
619+ }
620+ return + subVersions [ 0 ] >= 3 ;
621+ }
622+
604623 _getMapInfo ( mapInfo ) {
605- const type = + mapInfo . version . split ( '.' ) [ 0 ] >= 3 ? 'WebMap3' : 'WebMap2' ;
624+ const type = this . _isWebMapV3 ( mapInfo ) ? 'WebMap3' : 'WebMap2' ;
606625 this . _createMap ( type , mapInfo ) ;
607626 }
608627
0 commit comments