Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the Mapbox logo when no style is provided #10361

Merged
merged 2 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ui/control/logo_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 16 additions & 4 deletions test/unit/ui/control/logo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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) {
Expand All @@ -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', () => {
Expand All @@ -59,13 +64,20 @@ 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', () => {
t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-top-left > .mapboxgl-ctrl')[0].style.display, 'none');
t.end();
});
});

test('LogoControl is not added more than once', (t) => {
const map = createMap(t);
const source = createSource({
Expand Down