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

compact mapbox wordmark on narrow maps #6472

Merged
merged 6 commits into from
May 15, 2018
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
6 changes: 6 additions & 0 deletions src/css/mapbox-gl.css
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ a.mapboxgl-ctrl-logo {
background-image: svg-load('svg/mapboxgl-ctrl-logo.svg');
}

a.mapboxgl-ctrl-logo.mapboxgl-compact {
width: 21px;
height: 21px;
background-image: svg-load('svg/mapboxgl-ctrl-logo-compact.svg');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than adding another SVG, could we hide the wordmark portion of the existing logo SVG by toggling a CSS class?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea but since the logo is loaded as a background-image I don't think it's possible to control that through standard CSS, I think it would need to be an embedded SVG for that to work 🤔. Given it doesn't add much weight to the file size, I'd be tempted to leave it as is

}

.mapboxgl-ctrl.mapboxgl-ctrl-attrib {
padding: 0 5px;
background-color: rgba(255, 255, 255, 0.5);
Expand Down
2 changes: 2 additions & 0 deletions src/css/svg/mapboxgl-ctrl-logo-compact.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/ui/control/logo_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class LogoControl {

constructor() {
bindAll(['_updateLogo'], this);
bindAll(['_updateCompact'], this);
}

onAdd(map: Map) {
Expand All @@ -35,12 +36,17 @@ class LogoControl {

this._map.on('sourcedata', this._updateLogo);
this._updateLogo();

this._map.on('resize', this._updateCompact);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this binding in onRemove.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, fixed.

this._updateCompact();

return this._container;
}

onRemove() {
DOM.remove(this._container);
this._map.off('sourcedata', this._updateLogo);
this._map.off('resize', this._updateCompact);
}

getDefaultPosition() {
Expand All @@ -67,6 +73,18 @@ class LogoControl {
return false;
}

_updateCompact() {
const containerChildren = this._container.children;
if (containerChildren.length) {
const anchor = containerChildren[0];
if (this._map.getCanvasContainer().offsetWidth < 250) {
anchor.classList.add('mapboxgl-compact');
} else {
anchor.classList.remove('mapboxgl-compact');
}
}
}

}


Expand Down
15 changes: 15 additions & 0 deletions test/unit/ui/control/logo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,18 @@ test('LogoControl is not added more than once', (t)=>{
});
});
});

test('LogoControl appears in compact mode if container is less then 250 pixel wide', (t) => {
const map = createMap();
const container = map.getContainer();

Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 255, configurable: true});
map.resize();
t.equal(container.querySelectorAll('.mapboxgl-ctrl-logo:not(.mapboxgl-compact)').length, 1);

Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 245, configurable: true});
map.resize();
t.equal(container.querySelectorAll('.mapboxgl-ctrl-logo.mapboxgl-compact').length, 1);

t.end();
});