From f532d0d9beb40b390ea524b41f5c319a1c7c5243 Mon Sep 17 00:00:00 2001 From: Ryan Hamley Date: Fri, 5 Feb 2021 16:14:26 -0800 Subject: [PATCH 1/2] Show the Mapbox logo when no style is provided --- src/ui/control/logo_control.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/control/logo_control.js b/src/ui/control/logo_control.js index e733805536d..e62ffc0c33d 100644 --- a/src/ui/control/logo_control.js +++ b/src/ui/control/logo_control.js @@ -62,7 +62,7 @@ class LogoControl { } _logoRequired() { - if (!this._map.style) return; + if (!this._map.style) return true; const sourceCaches = this._map.style._sourceCaches; if (Object.entries(sourceCaches).length === 0) return true; for (const id in sourceCaches) { From 06f5265035fc3b390429860e597050e3ccff9ea7 Mon Sep 17 00:00:00 2001 From: Ryan Hamley Date: Thu, 11 Feb 2021 15:17:40 -0800 Subject: [PATCH 2/2] Add unit test --- test/unit/ui/control/logo.test.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/test/unit/ui/control/logo.test.js b/test/unit/ui/control/logo.test.js index e21bef616f3..ea0c77f7825 100644 --- a/test/unit/ui/control/logo.test.js +++ b/test/unit/ui/control/logo.test.js @@ -2,8 +2,8 @@ import {test} from '../../../util/test.js'; import {createMap as globalCreateMap} from '../../../util/index.js'; import VectorTileSource from '../../../../src/source/vector_tile_source.js'; -function createMap(t, logoPosition, logoRequired) { - return globalCreateMap(t, { +function createMap(t, logoPosition, logoRequired, deleteStyle) { + const options = { style: { version: 8, sources: { @@ -18,8 +18,12 @@ function createMap(t, logoPosition, logoRequired) { }, layers: [] }, - logoPosition: logoPosition || undefined - }); + logoPosition: logoPosition || undefined, + deleteStyle: deleteStyle || undefined + }; + + if (deleteStyle) delete options.style; + return globalCreateMap(t, options); } function createSource(options, logoRequired) { @@ -39,6 +43,7 @@ function createSource(options, logoRequired) { source[logoFlag] = logoRequired === undefined ? true : logoRequired; return source; } + test('LogoControl appears in bottom-left by default', (t) => { const map = createMap(t); map.on('load', () => { @@ -59,6 +64,12 @@ test('LogoControl appears in the position specified by the position option', (t) }); }); +test('LogoControl is displayed when no style is supplied', (t) => { + const map = createMap(t, 'bottom-left', false, true, true); + t.equal(map.getContainer().querySelector('.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl').style.display, 'block'); + t.end(); +}); + test('LogoControl is not displayed when the mapbox_logo property is false', (t) => { const map = createMap(t, 'top-left', false); map.on('load', () => { @@ -66,6 +77,7 @@ test('LogoControl is not displayed when the mapbox_logo property is false', (t) t.end(); }); }); + test('LogoControl is not added more than once', (t) => { const map = createMap(t); const source = createSource({