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

LogoControl cleanup #4842

Merged
merged 4 commits into from
Jul 7, 2017
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
3 changes: 2 additions & 1 deletion src/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Style extends Evented {

this.on('data', (event) => {
if (event.dataType === 'source' && event.sourceDataType === 'metadata') {
const source = this.sourceCaches[event.sourceId].getSource();
const source = !!this.sourceCaches[event.sourceId] && this.sourceCaches[event.sourceId].getSource();
if (source && source.vectorLayerIds) {
for (const layerId in this._layers) {
const layer = this._layers[layerId];
Expand Down Expand Up @@ -408,6 +408,7 @@ class Style extends Evented {
const sourceCache = this.sourceCaches[id];
delete this.sourceCaches[id];
delete this._updatedSources[id];
sourceCache.fire('data', {sourceDataType: 'metadata', dataType:'source', sourceId: id});
sourceCache.setEventedParent(null);
sourceCache.clearTiles();

Expand Down
19 changes: 8 additions & 11 deletions src/ui/control/logo_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class LogoControl {
onAdd(map) {
this._map = map;
this._container = DOM.create('div', 'mapboxgl-ctrl');
const anchor = DOM.create('a', 'mapboxgl-ctrl-logo');
anchor.target = "_blank";
anchor.href = "https://www.mapbox.com/";
anchor.setAttribute("aria-label", "Mapbox logo");
this._container.appendChild(anchor);
this._container.style.display = 'none';

this._map.on('sourcedata', this._updateLogo);
this._updateLogo();
Expand All @@ -36,17 +42,8 @@ class LogoControl {
}

_updateLogo(e) {
if (e && e.sourceDataType === 'metadata') {
if (!this._container.childNodes.length && this._logoRequired()) {
const anchor = DOM.create('a', 'mapboxgl-ctrl-logo');
anchor.target = "_blank";
anchor.href = "https://www.mapbox.com/";
anchor.setAttribute("aria-label", "Mapbox logo");
this._container.appendChild(anchor);
this._map.off('data', this._updateLogo);
} else if (this._container.childNodes.length && !this._logoRequired()) {
this.onRemove();
}
if (!e || e.sourceDataType === 'metadata') {
this._container.style.display = this._logoRequired() ? 'block' : 'none';
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit/ui/control/logo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ test('LogoControl appears in the position specified by the position option', (t)
});
});

test('LogoControl is not added when the mapbox_logo property is false', (t) => {
test('LogoControl is not displayed when the mapbox_logo property is false', (t) => {
const map = createMap('top-left', false);
map.on('load', () => {
t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-top-left .mapboxgl-ctrl-logo').length, 0);
t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-top-left > .mapboxgl-ctrl')[0].style.display, 'none');
t.end();
});
});
Expand Down