-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Don't fire sourcedata event with sourceDataType: 'metadata' when a source is removed #5771
Closed
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
31812da
Don't fire sourcedata event with sourceDataType: 'metadata' when a so…
jfirebaugh 36fdac9
make relevant changes to attribution control, remove sourcedata updat…
a3a47b1
fix logo test
d8a166f
put sourcedata listener back in
e22c807
fix flow
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,109 @@ | ||
'use strict'; | ||
|
||
const test = require('mapbox-gl-js-test').test; | ||
const VectorTileSource = require('../../../../src/source/vector_tile_source'); | ||
const window = require('../../../../src/util/window'); | ||
const Map = require('../../../../src/ui/map'); | ||
|
||
function createMap(logoPosition, logoRequired) { | ||
test('LogoControl appears in bottom-left by default', (t) => { | ||
const container = window.document.createElement('div'); | ||
const map = new Map({container}); | ||
t.equal(map.getContainer().querySelectorAll( | ||
'.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl-logo' | ||
).length, 1); | ||
t.end(); | ||
}); | ||
|
||
test('LogoControl appears in the position specified by the position option', (t) => { | ||
const container = window.document.createElement('div'); | ||
return new Map({ | ||
container: container, | ||
const map = new Map({container, logoPosition: 'top-left'}); | ||
t.equal(map.getContainer().querySelectorAll( | ||
'.mapboxgl-ctrl-top-left .mapboxgl-ctrl-logo' | ||
).length, 1); | ||
t.end(); | ||
}); | ||
|
||
test('LogoControl is hidden when no sources with the mapbox_logo property exist', (t) => { | ||
const container = window.document.createElement('div'); | ||
const map = new Map({ | ||
container, | ||
style: { | ||
version: 8, | ||
sources: { | ||
'composite': createSource({ | ||
minzoom: 1, | ||
maxzoom: 10, | ||
attribution: "Mapbox", | ||
tiles: [ | ||
"http://example.com/{z}/{x}/{y}.png" | ||
] | ||
}, logoRequired) | ||
}, | ||
sources: {}, | ||
layers: [] | ||
}, | ||
logoPosition: logoPosition || undefined | ||
}); | ||
} | ||
|
||
function createSource(options, logoRequired) { | ||
const source = new VectorTileSource('id', options, { send: function () {} }); | ||
source.onAdd({ | ||
transform: { angle: 0, pitch: 0, showCollisionBoxes: false } | ||
}); | ||
source.on('error', (e) => { | ||
throw e.error; | ||
}); | ||
const logoFlag = "mapbox_logo"; | ||
source[logoFlag] = logoRequired === undefined ? true : logoRequired; | ||
return source; | ||
} | ||
test('LogoControl appears in bottom-left by default', (t) => { | ||
const map = createMap(); | ||
map.on('load', () => { | ||
t.equal(map.getContainer().querySelectorAll( | ||
'.mapboxgl-ctrl-bottom-left .mapboxgl-ctrl-logo' | ||
).length, 1); | ||
t.equal(map.getContainer().querySelector('.mapboxgl-ctrl-logo').parentNode.style.display, 'none'); | ||
t.end(); | ||
}); | ||
}); | ||
|
||
test('LogoControl appears in the position specified by the position option', (t) => { | ||
const map = createMap('top-left'); | ||
test('LogoControl is shown when a source with the mapbox_logo property is added', (t) => { | ||
const container = window.document.createElement('div'); | ||
const map = new Map({ | ||
container, | ||
style: { | ||
version: 8, | ||
sources: {}, | ||
layers: [] | ||
}, | ||
}); | ||
map.on('load', () => { | ||
t.equal(map.getContainer().querySelectorAll( | ||
'.mapboxgl-ctrl-top-left .mapboxgl-ctrl-logo' | ||
).length, 1); | ||
t.end(); | ||
map.addSource('source', { | ||
type: 'raster', | ||
tiles: ["http://example.com/{z}/{x}/{y}.png"], | ||
mapbox_logo: true // eslint-disable-line | ||
}); | ||
map.once('styledata', () => { | ||
t.equal(map.getContainer().querySelector('.mapboxgl-ctrl-logo').parentNode.style.display, 'block'); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
|
||
test('LogoControl is not displayed when the mapbox_logo property is false', (t) => { | ||
const map = createMap('top-left', false); | ||
test('LogoControl is visible when a source with the mapbox_logo property exists', (t) => { | ||
const container = window.document.createElement('div'); | ||
const map = new Map({ | ||
container, | ||
style: { | ||
version: 8, | ||
sources: { | ||
source: { | ||
type: 'raster', | ||
tiles: ["http://example.com/{z}/{x}/{y}.png"], | ||
mapbox_logo: true // eslint-disable-line | ||
} | ||
}, | ||
layers: [] | ||
}, | ||
}); | ||
map.on('load', () => { | ||
t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-top-left > .mapboxgl-ctrl')[0].style.display, 'none'); | ||
t.equal(map.getContainer().querySelector('.mapboxgl-ctrl-logo').parentNode.style.display, 'block'); | ||
t.end(); | ||
}); | ||
}); | ||
test('LogoControl is not added more than once', (t)=>{ | ||
const map = createMap(); | ||
const source = createSource({ | ||
minzoom: 1, | ||
maxzoom: 10, | ||
attribution: "Mapbox", | ||
tiles: [ | ||
"http://example.com/{z}/{x}/{y}.png" | ||
] | ||
|
||
test('LogoControl is hidden when the last source with the mapbox_logo property is removed', (t) => { | ||
const container = window.document.createElement('div'); | ||
const map = new Map({ | ||
container, | ||
style: { | ||
version: 8, | ||
sources: { | ||
source: { | ||
type: 'raster', | ||
tiles: ["http://example.com/{z}/{x}/{y}.png"], | ||
mapbox_logo: true // eslint-disable-line | ||
} | ||
}, | ||
layers: [] | ||
}, | ||
}); | ||
map.on('load', ()=>{ | ||
t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-logo').length, 1, 'first LogoControl'); | ||
map.addSource('source2', source); | ||
map.on('sourcedata', (e)=>{ | ||
if (e.isSourceLoaded && e.sourceId === 'source2' && e.sourceDataType === 'metadata') { | ||
t.equal(map.getContainer().querySelectorAll('.mapboxgl-ctrl-logo').length, 1, 'only one LogoControl is added with multiple sources'); | ||
t.end(); | ||
} | ||
map.on('load', () => { | ||
map.removeSource('source'); | ||
map.once('styledata', () => { | ||
t.equal(map.getContainer().querySelector('.mapboxgl-ctrl-logo').parentNode.style.display, 'none'); | ||
t.end(); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll also need to remove this event listener in the
onRemove
function