-
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
Add "data" event #3255
Merged
Add "data" event #3255
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2106db6
source.change -> data
24efa54
source.load -> sourceload & data
3e4e80e
style.change -> data
fd04e20
style.load -> data, styleload
702df69
tile.add -> dataloading
73bf845
tile.load -> data
d44480d
tile.remove -> data
0650f8d
Unrename "source.load" and "style.load"
58e0a6b
source.add & source.remove -> data
4abeca4
layer.add & layer.remove -> data
04ddd41
Remove isDataRemoved flag
7e60cc6
Add documentation for "data" event
56a1efc
Fix setDataPerf benchmark utility
506014d
Minor doc fix
ef4f8b7
Add docs for dataloading event
8e9c10f
merge 'sprite' and 'style' into 'style'
6d71d52
merge all several types into 'source'
1ab2e44
Refactor "set data perf" benchmark utility
b7bd4fe
Ensure "Map#_update(true)" is only called after style mutations
87a5f7b
Ensure Attribution#_update is only called for "data[dataType=source]"…
5f5085e
Attach Source, not SourceCache, to data events
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
'use strict'; | ||
|
||
var NUM_TILES = 6; | ||
|
||
module.exports = function(source, numCalls, geojson, cb) { | ||
var tileCount = 0; | ||
module.exports = function(sourceCache, data, callback) { | ||
var sampleCount = 50; | ||
var startTime = null; | ||
var times = []; | ||
|
||
source.on('tile.load', function tileCounter() { | ||
tileCount++; | ||
if (tileCount === NUM_TILES) { | ||
tileCount = 0; | ||
times.push(performance.now() - startTime); | ||
var samples = []; | ||
|
||
if (times.length < numCalls) { | ||
sourceCache.on('data', function onData() { | ||
if (sourceCache.loaded()) { | ||
samples.push(performance.now() - startTime); | ||
sourceCache.off('data', onData); | ||
if (samples.length < sampleCount) { | ||
startTime = performance.now(); | ||
source.setData(geojson); | ||
sourceCache.clearTiles(); | ||
sourceCache.on('data', onData); | ||
sourceCache.getSource().setData(data); | ||
} else { | ||
var avgTileTime = times.reduce(function (v, t) { | ||
return v + t; | ||
}, 0) / times.length; | ||
source.off('tile.load', tileCounter); | ||
cb(null, avgTileTime); | ||
callback(null, average(samples)); | ||
} | ||
} | ||
}); | ||
|
||
startTime = performance.now(); | ||
source.setData(geojson); | ||
sourceCache.getSource().setData(data); | ||
}; | ||
|
||
function average(array) { | ||
return array.reduce(function (sum, value) { return sum + value; }, 0) / array.length; | ||
} |
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
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
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 |
---|---|---|
|
@@ -54,9 +54,7 @@ Attribution.prototype = util.inherit(Control, { | |
container = this._container = DOM.create('div', className, map.getContainer()); | ||
|
||
this._update(); | ||
map.on('source.load', this._update.bind(this)); | ||
map.on('source.change', this._update.bind(this)); | ||
map.on('source.remove', this._update.bind(this)); | ||
map.on('data', this._update.bind(this)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
map.on('moveend', this._updateEditLink.bind(this)); | ||
|
||
return container; | ||
|
Oops, something went wrong.
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.
I've been trying to reduce or eliminate the dependency of other class on
Map
. The dependency here is required bySource#on{Add,Remove}(map)
-- we should work towards eliminating those two methods.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.
Removing the dependency was my first instinct as well. Unfortunately it wasn't straightforward to do so and will require a standalone PR.
Even though the dependency is undesirable, it is a real dependency and should be passed explicitly and simply. As our code is architected,
Source
s need to know about the state ofCamera
(which is a mixin onMap
). I see #2741 as the proper long-term fix.