From df55cdf7097bd514449b33e12a9d66f9d40f909f Mon Sep 17 00:00:00 2001 From: xiongjj Date: Fri, 6 Dec 2024 09:33:18 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90fix=E3=80=91setWebMapOptions=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96;=20review=20by=20songym?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/mapping/WebMapBase.js | 2 +- test/mapboxgl/mapping/WebMapSpec.js | 14 ++++++++++---- test/maplibregl/mapping/WebMapSpec.js | 14 ++++++++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/common/mapping/WebMapBase.js b/src/common/mapping/WebMapBase.js index 4fc2501e6..2a202c90e 100644 --- a/src/common/mapping/WebMapBase.js +++ b/src/common/mapping/WebMapBase.js @@ -350,7 +350,7 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) { */ setWebMapOptions(webMapOptions) { this.setServerUrl(webMapOptions.server); - this._createWebMap(); + this._initWebMap(); } /** diff --git a/test/mapboxgl/mapping/WebMapSpec.js b/test/mapboxgl/mapping/WebMapSpec.js index e0f89cf6a..1b7ef9387 100644 --- a/test/mapboxgl/mapping/WebMapSpec.js +++ b/test/mapboxgl/mapping/WebMapSpec.js @@ -135,6 +135,7 @@ describe('mapboxgl_WebMap', () => { done(); }); }); + it('setWebMapOptions', (done) => { let options = { server: server @@ -151,13 +152,18 @@ describe('mapboxgl_WebMap', () => { }); datavizWebmap = new WebMap(id, options); datavizWebmap.once('mapcreatesucceeded', () => { - const nextUrl = 'http://www.test.com'; - datavizWebmap.setServerUrl('http://www.test.com'); - expect(datavizWebmap.options.server).toBe(`${nextUrl}/`); + expect(datavizWebmap.options.server).toBe(server); expect(datavizWebmap.options.serverUrl).toBe(datavizWebmap.options.server); - done(); + const nextUrl = 'http://www.test.com'; + datavizWebmap.setWebMapOptions({ server: nextUrl }); + datavizWebmap.on('mapcreatesucceeded', () => { + expect(datavizWebmap.options.server).toBe(`${nextUrl}/`); + expect(datavizWebmap.options.serverUrl).toBe(datavizWebmap.options.server); + done(); + }); }); }); + it('setMapOptions', (done) => { spyOn(FetchRequest, 'get').and.callFake((url) => { if (url.indexOf('web/config/portal.json') > -1) { diff --git a/test/maplibregl/mapping/WebMapSpec.js b/test/maplibregl/mapping/WebMapSpec.js index 3a5161c67..b42513fed 100644 --- a/test/maplibregl/mapping/WebMapSpec.js +++ b/test/maplibregl/mapping/WebMapSpec.js @@ -135,6 +135,7 @@ describe('maplibregl_WebMap', () => { done(); }); }); + it('setWebMapOptions', (done) => { let options = { server: server @@ -151,13 +152,18 @@ describe('maplibregl_WebMap', () => { }); datavizWebmap = new WebMap(id, options); datavizWebmap.once('mapcreatesucceeded', () => { - const nextUrl = 'http://www.test.com'; - datavizWebmap.setServerUrl('http://www.test.com'); - expect(datavizWebmap.options.server).toBe(`${nextUrl}/`); + expect(datavizWebmap.options.server).toBe(server); expect(datavizWebmap.options.serverUrl).toBe(datavizWebmap.options.server); - done(); + const nextUrl = 'http://www.test.com'; + datavizWebmap.setWebMapOptions({ server: nextUrl }); + datavizWebmap.on('mapcreatesucceeded', () => { + expect(datavizWebmap.options.server).toBe(`${nextUrl}/`); + expect(datavizWebmap.options.serverUrl).toBe(datavizWebmap.options.server); + done(); + }); }); }); + it('setMapOptions', (done) => { spyOn(FetchRequest, 'get').and.callFake((url) => { if (url.indexOf('web/config/portal.json') > -1) {