From 2106db6db91519a0108b8c93c3c57a043f591cdc Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Fri, 23 Sep 2016 12:40:51 -0700 Subject: [PATCH 01/21] source.change -> data --- js/source/geojson_source.js | 2 +- js/source/image_source.js | 2 +- js/source/source_cache.js | 10 ++++++---- js/source/video_source.js | 2 +- js/ui/control/attribution.js | 2 +- js/ui/map.js | 2 +- test/js/source/geojson_source.test.js | 4 ++-- test/js/source/source_cache.test.js | 10 +++++----- test/js/style/style.test.js | 8 ++++---- test/js/ui/map.test.js | 6 +++--- 10 files changed, 25 insertions(+), 23 deletions(-) diff --git a/js/source/geojson_source.js b/js/source/geojson_source.js index 189f5da436d..ce74da82d72 100644 --- a/js/source/geojson_source.js +++ b/js/source/geojson_source.js @@ -119,7 +119,7 @@ GeoJSONSource.prototype = util.inherit(Evented, /** @lends GeoJSONSource.prototy if (err) { return this.fire('error', { error: err }); } - this.fire('source.change'); + this.fire('data', {dataType: 'geoJSON'}); }.bind(this)); return this; diff --git a/js/source/image_source.js b/js/source/image_source.js index 9317ad22096..cf7c1b80bff 100644 --- a/js/source/image_source.js +++ b/js/source/image_source.js @@ -106,7 +106,7 @@ ImageSource.prototype = util.inherit(Evented, /** @lends ImageSource.prototype * Math.round((zoomedCoord.row - centerCoord.row) * EXTENT)); }); - this.fire('source.change'); + this.fire('data', {dataType: 'image'}); return this; }, diff --git a/js/source/source_cache.js b/js/source/source_cache.js index dacaa258cc7..81fc386eb45 100644 --- a/js/source/source_cache.js +++ b/js/source/source_cache.js @@ -50,10 +50,12 @@ function SourceCache(id, options, dispatcher) { this._sourceErrored = true; }); - this.on('source.change', function() { - this.reload(); - if (this.transform) { - this.update(this.transform, this.map && this.map.style.rasterFadeDuration); + this.on('data', function(event) { + if (this._sourceLoaded && ['image', 'video', 'geoJSON'].indexOf(event.dataType) !== -1) { + this.reload(); + if (this.transform) { + this.update(this.transform, this.map && this.map.style.rasterFadeDuration); + } } }); diff --git a/js/source/video_source.js b/js/source/video_source.js index 338819d4df3..00d231ecbd0 100644 --- a/js/source/video_source.js +++ b/js/source/video_source.js @@ -135,7 +135,7 @@ VideoSource.prototype = util.inherit(Evented, /** @lends VideoSource.prototype * Math.round((zoomedCoord.row - centerCoord.row) * EXTENT)); }); - this.fire('source.change'); + this.fire('data', {dataType: 'video'}); return this; }, diff --git a/js/ui/control/attribution.js b/js/ui/control/attribution.js index 8b10f6c7f34..0c03750899a 100644 --- a/js/ui/control/attribution.js +++ b/js/ui/control/attribution.js @@ -55,7 +55,7 @@ Attribution.prototype = util.inherit(Control, { this._update(); map.on('source.load', this._update.bind(this)); - map.on('source.change', this._update.bind(this)); + map.on('data', this._update.bind(this)); map.on('source.remove', this._update.bind(this)); map.on('moveend', this._updateEditLink.bind(this)); diff --git a/js/ui/map.js b/js/ui/map.js index 1c3c316f784..beae4728d2a 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -212,7 +212,7 @@ var Map = module.exports = function(options) { }); this.on('source.load', this._update); - this.on('source.change', this._update); + this.on('data', this._update); this.on('tile.load', this._update); }; diff --git a/test/js/source/geojson_source.test.js b/test/js/source/geojson_source.test.js index 84d1ccfd0b1..33de527f015 100644 --- a/test/js/source/geojson_source.test.js +++ b/test/js/source/geojson_source.test.js @@ -59,7 +59,7 @@ test('GeoJSONSource#setData', function(t) { } }; var source = new GeoJSONSource('id', {data: {}}, mockDispatcher); - source.on('source.change', function() { + source.on('data', function() { t.end(); }); source.setData({}); @@ -152,7 +152,7 @@ test('GeoJSONSource#update', function(t) { // Note: we register this before calling setData because `change` // is fired synchronously within that method. It may be worth // considering dezalgoing there. - source.on('source.change', function () { + source.on('data', function () { t.end(); }); source.setData({}); diff --git a/test/js/source/source_cache.test.js b/test/js/source/source_cache.test.js index f3c988334a5..24fa4362f33 100644 --- a/test/js/source/source_cache.test.js +++ b/test/js/source/source_cache.test.js @@ -206,7 +206,7 @@ test('SourceCache / Source lifecycle', function (t) { t.test('does not fire load or change before source load event', function (t) { createSourceCache({noLoad: true}) .on('source.load', t.fail) - .on('source.change', t.fail); + .on('data', t.fail); setTimeout(t.end, 1); }); @@ -215,8 +215,8 @@ test('SourceCache / Source lifecycle', function (t) { }); t.test('forward change event', function (t) { - var sourceCache = createSourceCache().on('source.change', t.end); - sourceCache.getSource().fire('source.change'); + var sourceCache = createSourceCache().on('data', t.end); + sourceCache.getSource().fire('data'); }); t.test('forward error event', function (t) { @@ -235,7 +235,7 @@ test('SourceCache / Source lifecycle', function (t) { }); }); - t.test('reloads tiles after source change event', function (t) { + t.test('reloads tiles after a geoJSON data event', function (t) { var transform = new Transform(); transform.resize(511, 511); transform.zoom = 0; @@ -253,7 +253,7 @@ test('SourceCache / Source lifecycle', function (t) { sourceCache.on('source.load', function () { sourceCache.update(transform); - sourceCache.getSource().fire('source.change'); + sourceCache.getSource().fire('data', {dataType: 'geoJSON'}); }); }); diff --git a/test/js/style/style.test.js b/test/js/style/style.test.js index 8fd77a4e2c9..04be82dbdc9 100644 --- a/test/js/style/style.test.js +++ b/test/js/style/style.test.js @@ -381,7 +381,7 @@ test('Style#addSource', function(t) { style.on('error', checkEvent); style.on('source.load', checkEvent); - style.on('source.change', checkEvent); + style.on('data', checkEvent); style.on('tile.add', checkEvent); style.on('tile.load', checkEvent); style.on('tile.remove', checkEvent); @@ -390,7 +390,7 @@ test('Style#addSource', function(t) { t.plan(6); style.addSource('source-id', source); // Fires load style.sources['source-id'].fire('error'); - style.sources['source-id'].fire('source.change'); + style.sources['source-id'].fire('data'); style.sources['source-id'].fire('tile.add'); style.sources['source-id'].fire('tile.load'); style.sources['source-id'].fire('tile.remove'); @@ -468,7 +468,7 @@ test('Style#removeSource', function(t) { style.on('source.load', t.fail); style.on('error', t.fail); - style.on('source.change', t.fail); + style.on('data', t.fail); style.on('tile.add', t.fail); style.on('tile.load', t.fail); style.on('error', t.fail); @@ -486,7 +486,7 @@ test('Style#removeSource', function(t) { source.fire('source.load'); source.fire('error'); - source.fire('source.change'); + source.fire('data'); source.fire('tile.add'); source.fire('tile.load'); source.fire('error'); diff --git a/test/js/ui/map.test.js b/test/js/ui/map.test.js index c9e4e42b0db..7230358e71b 100755 --- a/test/js/ui/map.test.js +++ b/test/js/ui/map.test.js @@ -138,14 +138,14 @@ test('Map', function(t) { map.on('error', recordEvent); map.on('style.change', recordEvent); map.on('source.load', recordEvent); - map.on('source.change', recordEvent); + map.on('data', recordEvent); map.on('tile.add', recordEvent); map.on('tile.remove', recordEvent); map.style.fire('error'); map.style.fire('style.change'); map.style.fire('source.load'); - map.style.fire('source.change'); + map.style.fire('data'); map.style.fire('tile.add'); map.style.fire('tile.remove'); @@ -153,7 +153,7 @@ test('Map', function(t) { 'error', 'style.change', 'source.load', - 'source.change', + 'data', 'tile.add', 'tile.remove' ]); From 24efa542ff3bee6d7b0f62f95e9fdcae2202b07f Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Fri, 23 Sep 2016 13:15:47 -0700 Subject: [PATCH 02/21] source.load -> sourceload & data --- js/source/geojson_source.js | 3 +- js/source/image_source.js | 3 +- js/source/raster_tile_source.js | 3 +- js/source/source_cache.js | 2 +- js/source/vector_tile_source.js | 3 +- js/source/video_source.js | 3 +- js/style/style.js | 2 +- js/ui/control/attribution.js | 1 - js/ui/map.js | 1 - test/js/source/geojson_source.test.js | 6 ++-- test/js/source/source_cache.test.js | 36 +++++++++++------------ test/js/source/vector_tile_source.test.js | 8 ++--- test/js/style/style.test.js | 10 +++---- test/js/ui/map.test.js | 6 ++-- 14 files changed, 45 insertions(+), 42 deletions(-) diff --git a/js/source/geojson_source.js b/js/source/geojson_source.js index ce74da82d72..de3a80023a7 100644 --- a/js/source/geojson_source.js +++ b/js/source/geojson_source.js @@ -88,7 +88,8 @@ function GeoJSONSource(id, options, dispatcher) { this.fire('error', {error: err}); return; } - this.fire('source.load'); + this.fire('data', {dataType: 'geojson'}); + this.fire('sourceload'); }.bind(this)); } diff --git a/js/source/image_source.js b/js/source/image_source.js index cf7c1b80bff..50a1d6f8c24 100644 --- a/js/source/image_source.js +++ b/js/source/image_source.js @@ -53,7 +53,8 @@ function ImageSource(id, options, dispatcher) { this.image = image; this._loaded = true; - this.fire('source.load'); + this.fire('data', {type: 'image'}); + this.fire('sourceload'); if (this.map) { this.setCoordinates(options.coordinates); diff --git a/js/source/raster_tile_source.js b/js/source/raster_tile_source.js index 88a2bd03ae1..6af334d5555 100644 --- a/js/source/raster_tile_source.js +++ b/js/source/raster_tile_source.js @@ -17,7 +17,8 @@ function RasterTileSource(id, options, dispatcher) { return this.fire('error', err); } util.extend(this, tileJSON); - this.fire('source.load'); + this.fire('data', {type: 'tileJSON'}); + this.fire('sourceload'); }.bind(this)); } diff --git a/js/source/source_cache.js b/js/source/source_cache.js index 81fc386eb45..ac74e4c576b 100644 --- a/js/source/source_cache.js +++ b/js/source/source_cache.js @@ -30,7 +30,7 @@ function SourceCache(id, options, dispatcher) { var source = this._source = Source.create(id, options, dispatcher); source.setEventedParent(this); - this.on('source.load', function() { + this.on('sourceload', function() { if (this.map && this._source.onAdd) { this._source.onAdd(this.map); } this._sourceLoaded = true; diff --git a/js/source/vector_tile_source.js b/js/source/vector_tile_source.js index 3b58adf02c4..d8d4112e726 100644 --- a/js/source/vector_tile_source.js +++ b/js/source/vector_tile_source.js @@ -23,7 +23,8 @@ function VectorTileSource(id, options, dispatcher) { return; } util.extend(this, tileJSON); - this.fire('source.load'); + this.fire('data', {dataType: 'tileJSON'}); + this.fire('sourceload'); }.bind(this)); } diff --git a/js/source/video_source.js b/js/source/video_source.js index 00d231ecbd0..4f28157bb1b 100644 --- a/js/source/video_source.js +++ b/js/source/video_source.js @@ -73,7 +73,8 @@ function VideoSource(id, options) { this.setCoordinates(options.coordinates); } - this.fire('source.load'); + this.fire('data', {dataType: 'video'}); + this.fire('sourceload'); }.bind(this)); } diff --git a/js/style/style.js b/js/style/style.js index d38666169dc..1979ad1a121 100644 --- a/js/style/style.js +++ b/js/style/style.js @@ -76,7 +76,7 @@ function Style(stylesheet, animationLoop, options) { browser.frame(stylesheetLoaded.bind(this, null, stylesheet)); } - this.on('source.load', function(event) { + this.on('sourceload', function(event) { var source = event.source; if (source && source.vectorLayerIds) { for (var layerId in this._layers) { diff --git a/js/ui/control/attribution.js b/js/ui/control/attribution.js index 0c03750899a..799cb719ef1 100644 --- a/js/ui/control/attribution.js +++ b/js/ui/control/attribution.js @@ -54,7 +54,6 @@ 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('data', this._update.bind(this)); map.on('source.remove', this._update.bind(this)); map.on('moveend', this._updateEditLink.bind(this)); diff --git a/js/ui/map.js b/js/ui/map.js index beae4728d2a..883faed226c 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -211,7 +211,6 @@ var Map = module.exports = function(options) { if (source.onRemove) source.onRemove(this); }); - this.on('source.load', this._update); this.on('data', this._update); this.on('tile.load', this._update); }; diff --git a/test/js/source/geojson_source.test.js b/test/js/source/geojson_source.test.js index 33de527f015..283b53c9e4f 100644 --- a/test/js/source/geojson_source.test.js +++ b/test/js/source/geojson_source.test.js @@ -119,7 +119,7 @@ test('GeoJSONSource#update', function(t) { var source = new GeoJSONSource('id', {data: {}}, mockDispatcher); - source.on('source.load', function() { + source.on('sourceload', function() { t.end(); }); }); @@ -148,7 +148,7 @@ test('GeoJSONSource#update', function(t) { var source = new GeoJSONSource('id', {data: {}}, mockDispatcher); - source.on('source.load', function() { + source.on('sourceload', function() { // Note: we register this before calling setData because `change` // is fired synchronously within that method. It may be worth // considering dezalgoing there. @@ -175,7 +175,7 @@ test('GeoJSONSource#update', function(t) { transform: {} }; - source.on('source.load', function () { + source.on('sourceload', function () { source.setData({}); source.loadTile(new Tile(new TileCoord(0, 0, 0), 512), function () {}); }); diff --git a/test/js/source/source_cache.test.js b/test/js/source/source_cache.test.js index 24fa4362f33..198675bd639 100644 --- a/test/js/source/source_cache.test.js +++ b/test/js/source/source_cache.test.js @@ -32,7 +32,7 @@ Source.setType('mock-source-type', function create (id, sourceOptions) { if (sourceOptions.error) { source.fire('error', { error: sourceOptions.error }); } else { - source.fire('source.load'); + source.fire('sourceload'); } }, 0); return source; @@ -53,7 +53,7 @@ test('SourceCache#attribution is set', function(t) { var sourceCache = createSourceCache({ attribution: 'Mapbox Heavy Industries' }); - sourceCache.on('source.load', function() { + sourceCache.on('sourceload', function() { t.equal(sourceCache.attribution, 'Mapbox Heavy Industries'); t.end(); }); @@ -205,13 +205,13 @@ test('SourceCache#removeTile', function(t) { test('SourceCache / Source lifecycle', function (t) { t.test('does not fire load or change before source load event', function (t) { createSourceCache({noLoad: true}) - .on('source.load', t.fail) + .on('sourceload', t.fail) .on('data', t.fail); setTimeout(t.end, 1); }); t.test('forward load event', function (t) { - createSourceCache({}).on('source.load', t.end); + createSourceCache({}).on('sourceload', t.end); }); t.test('forward change event', function (t) { @@ -251,7 +251,7 @@ test('SourceCache / Source lifecycle', function (t) { } }); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { sourceCache.update(transform); sourceCache.getSource().fire('data', {dataType: 'geoJSON'}); }); @@ -267,7 +267,7 @@ test('SourceCache#update', function(t) { transform.zoom = 0; var sourceCache = createSourceCache({}, false); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { sourceCache.update(transform); t.deepEqual(sourceCache.getIds(), []); @@ -281,7 +281,7 @@ test('SourceCache#update', function(t) { transform.zoom = 0; var sourceCache = createSourceCache({}); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { sourceCache.update(transform); t.deepEqual(sourceCache.getIds(), [new TileCoord(0, 0, 0).id]); t.end(); @@ -299,7 +299,7 @@ test('SourceCache#update', function(t) { } }); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { sourceCache.update(transform); t.deepEqual(sourceCache.getIds(), [new TileCoord(0, 0, 0).id]); @@ -330,7 +330,7 @@ test('SourceCache#update', function(t) { } }); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { sourceCache.update(transform); t.deepEqual(sourceCache.getIds(), [new TileCoord(0, 0, 0).id]); @@ -361,7 +361,7 @@ test('SourceCache#update', function(t) { } }); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { sourceCache.update(transform); t.deepEqual(sourceCache.getIds(), [new TileCoord(0, 0, 0, 1).id]); @@ -392,7 +392,7 @@ test('SourceCache#update', function(t) { } }); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { sourceCache.update(transform, 100); t.deepEqual(sourceCache.getIds(), [ new TileCoord(2, 1, 1).id, @@ -422,7 +422,7 @@ test('SourceCache#update', function(t) { } }); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { sourceCache.update(transform, 100); transform.zoom = 2; @@ -452,7 +452,7 @@ test('SourceCache#update', function(t) { } }); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { t.equal(sourceCache.maxzoom, 14); sourceCache.update(transform); @@ -531,7 +531,7 @@ test('SourceCache#tilesIn', function (t) { } }); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { sourceCache.update(transform); t.deepEqual(sourceCache.getIds(), [ @@ -572,7 +572,7 @@ test('SourceCache#tilesIn', function (t) { tileSize: 512 }); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { var transform = new Transform(); transform.resize(512, 512); transform.zoom = 2.0; @@ -616,7 +616,7 @@ test('SourceCache#tilesIn', function (t) { tileSize: 512 }); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { var transform = new Transform(); transform.resize(512, 512); transform.zoom = 2.0; @@ -638,7 +638,7 @@ test('SourceCache#loaded (no errors)', function (t) { } }); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { var coord = new TileCoord(0, 0, 0); sourceCache.addTile(coord); @@ -654,7 +654,7 @@ test('SourceCache#loaded (with errors)', function (t) { } }); - sourceCache.on('source.load', function () { + sourceCache.on('sourceload', function () { var coord = new TileCoord(0, 0, 0); sourceCache.addTile(coord); diff --git a/test/js/source/vector_tile_source.test.js b/test/js/source/vector_tile_source.test.js index 0208a619eb2..45ce770d288 100644 --- a/test/js/source/vector_tile_source.test.js +++ b/test/js/source/vector_tile_source.test.js @@ -38,7 +38,7 @@ test('VectorTileSource', function(t) { tiles: ["http://example.com/{z}/{x}/{y}.png"] }); - source.on('source.load', function() { + source.on('sourceload', function() { t.deepEqual(source.tiles, ["http://example.com/{z}/{x}/{y}.png"]); t.deepEqual(source.minzoom, 1); t.deepEqual(source.maxzoom, 10); @@ -52,7 +52,7 @@ test('VectorTileSource', function(t) { var source = createSource({ url: "/source.json" }); - source.on('source.load', function() { + source.on('sourceload', function() { t.deepEqual(source.tiles, ["http://example.com/{z}/{x}/{y}.png"]); t.deepEqual(source.minzoom, 1); t.deepEqual(source.maxzoom, 10); @@ -107,7 +107,7 @@ test('VectorTileSource', function(t) { t.end(); }; - source.on('source.load', function() { + source.on('sourceload', function() { source.loadTile({coord: new TileCoord(10, 5, 5, 0)}, function () {}); }); }); @@ -127,7 +127,7 @@ test('VectorTileSource', function(t) { return 1; }; - source.on('source.load', function () { + source.on('sourceload', function () { var tile = { coord: new TileCoord(10, 5, 5, 0), state: 'loading', diff --git a/test/js/style/style.test.js b/test/js/style/style.test.js index 04be82dbdc9..557b05b7ca5 100644 --- a/test/js/style/style.test.js +++ b/test/js/style/style.test.js @@ -380,14 +380,14 @@ test('Style#addSource', function(t) { } style.on('error', checkEvent); - style.on('source.load', checkEvent); - style.on('data', checkEvent); + style.on('sourceload', checkEvent); + style.on('data', checkEvent); style.on('tile.add', checkEvent); style.on('tile.load', checkEvent); style.on('tile.remove', checkEvent); style.on('style.load', function () { - t.plan(6); + t.plan(7); style.addSource('source-id', source); // Fires load style.sources['source-id'].fire('error'); style.sources['source-id'].fire('data'); @@ -466,7 +466,7 @@ test('Style#removeSource', function(t) { var style = new Style(createStyleJSON()), source = createSource(); - style.on('source.load', t.fail); + style.on('sourceload', t.fail); style.on('error', t.fail); style.on('data', t.fail); style.on('tile.add', t.fail); @@ -484,7 +484,7 @@ test('Style#removeSource', function(t) { source.on('error', function() {}); source.on('error', function() {}); - source.fire('source.load'); + source.fire('sourceload'); source.fire('error'); source.fire('data'); source.fire('tile.add'); diff --git a/test/js/ui/map.test.js b/test/js/ui/map.test.js index 7230358e71b..0fad968a024 100755 --- a/test/js/ui/map.test.js +++ b/test/js/ui/map.test.js @@ -137,14 +137,14 @@ test('Map', function(t) { map.on('error', recordEvent); map.on('style.change', recordEvent); - map.on('source.load', recordEvent); + map.on('sourceload', recordEvent); map.on('data', recordEvent); map.on('tile.add', recordEvent); map.on('tile.remove', recordEvent); map.style.fire('error'); map.style.fire('style.change'); - map.style.fire('source.load'); + map.style.fire('sourceload'); map.style.fire('data'); map.style.fire('tile.add'); map.style.fire('tile.remove'); @@ -152,7 +152,7 @@ test('Map', function(t) { t.deepEqual(events, [ 'error', 'style.change', - 'source.load', + 'sourceload', 'data', 'tile.add', 'tile.remove' From 3e4e80e1a5a740b37bfe574f27e847ba72f6f22e Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Fri, 23 Sep 2016 13:45:48 -0700 Subject: [PATCH 03/21] style.change -> data --- js/style/image_sprite.js | 6 +++--- js/style/style.js | 4 ++-- js/ui/map.js | 2 +- test/js/style/style.test.js | 7 +------ test/js/ui/map.test.js | 14 ++++++-------- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/js/style/image_sprite.js b/js/style/image_sprite.js index 28a4d1e2765..ef366ca5846 100644 --- a/js/style/image_sprite.js +++ b/js/style/image_sprite.js @@ -20,7 +20,7 @@ function ImageSprite(base) { } this.data = data; - if (this.img) this.fire('style.change'); + if (this.img) this.fire('data', {dataType: 'sprite'}); }.bind(this)); ajax.getImage(normalizeURL(base, format, '.png'), function(err, img) { @@ -41,7 +41,7 @@ function ImageSprite(base) { } this.img = img; - if (this.data) this.fire('style.change'); + if (this.data) this.fire('data', {dataType: 'sprite'}); }.bind(this)); } @@ -58,7 +58,7 @@ ImageSprite.prototype.loaded = function() { ImageSprite.prototype.resize = function(/*gl*/) { if (browser.devicePixelRatio > 1 !== this.retina) { var newSprite = new ImageSprite(this.base); - newSprite.on('style.change', function() { + newSprite.on('data', function() { this.img = newSprite.img; this.data = newSprite.data; this.retina = newSprite.retina; diff --git a/js/style/style.js b/js/style/style.js index 1979ad1a121..6ca736b7dc4 100644 --- a/js/style/style.js +++ b/js/style/style.js @@ -300,7 +300,7 @@ Style.prototype = util.inherit(Evented, { this._applyClasses(classes, options); if (this._updates.changed) { - this.fire('style.change'); + this.fire('data', {dataType: 'style'}); } this._resetUpdates(); @@ -718,7 +718,7 @@ Style.prototype = util.inherit(Evented, { spriteAtlas.setSprite(sprite); spriteAtlas.addIcons(params.icons, callback); } else { - sprite.on('style.change', function() { + sprite.on('data', function() { spriteAtlas.setSprite(sprite); spriteAtlas.addIcons(params.icons, callback); }); diff --git a/js/ui/map.js b/js/ui/map.js index 883faed226c..9f51dccc08c 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -197,7 +197,7 @@ var Map = module.exports = function(options) { this.style.update(this._classes, {transition: false}); }); - this.on('style.change', function() { + this.on('data', function() { this._update(true); }); diff --git a/test/js/style/style.test.js b/test/js/style/style.test.js index 557b05b7ca5..6dfdaa2b8b6 100644 --- a/test/js/style/style.test.js +++ b/test/js/style/style.test.js @@ -1171,12 +1171,7 @@ test('Style defers expensive methods', function(t) { style.update(); - // called per added layer, conflating 'change' events - t.equal(style.fire.callCount, 4, 'fire is called per action'); - t.equal(style.fire.args[0][0], 'layer.add', 'fire was called with layer.add'); - t.equal(style.fire.args[1][0], 'layer.add', 'fire was called with layer.add'); - t.equal(style.fire.args[2][0], 'layer.add', 'fire was called with layer.add'); - t.equal(style.fire.args[3][0], 'style.change', 'fire was called with style.change'); + t.ok(style.fire.calledWith('data'), 'a data event was fired'); // called per source t.ok(style._reloadSource.calledTwice, '_reloadSource is called per source'); diff --git a/test/js/ui/map.test.js b/test/js/ui/map.test.js index 0fad968a024..42e09157b92 100755 --- a/test/js/ui/map.test.js +++ b/test/js/ui/map.test.js @@ -136,14 +136,12 @@ test('Map', function(t) { } map.on('error', recordEvent); - map.on('style.change', recordEvent); map.on('sourceload', recordEvent); map.on('data', recordEvent); map.on('tile.add', recordEvent); map.on('tile.remove', recordEvent); map.style.fire('error'); - map.style.fire('style.change'); map.style.fire('sourceload'); map.style.fire('data'); map.style.fire('tile.add'); @@ -151,7 +149,6 @@ test('Map', function(t) { t.deepEqual(events, [ 'error', - 'style.change', 'sourceload', 'data', 'tile.add', @@ -744,7 +741,7 @@ test('Map', function(t) { t.end(); }); - t.test('fires a style.change event', function (t) { + t.test('fires a data event', function (t) { // background layers do not have a source var map = createMap({ style: { @@ -760,10 +757,11 @@ test('Map', function(t) { } }); - map.on('style.load', function () { - map.once('style.change', function (e) { - t.ok(e, 'change event'); - t.end(); + map.once('style.load', function () { + map.once('data', function (e) { + if (e.dataType === 'style') { + t.end(); + } }); map.setLayoutProperty('background', 'visibility', 'visible'); From fd04e20e2e1151c6f89d96a0bdbb0814ea6222aa Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Fri, 23 Sep 2016 14:11:26 -0700 Subject: [PATCH 04/21] style.load -> data, styleload --- js/style/style.js | 3 +- js/ui/map.js | 2 +- test/js/style/style.test.js | 138 +++++++++++++++--------------------- test/js/ui/map.test.js | 22 +++--- 4 files changed, 73 insertions(+), 92 deletions(-) diff --git a/js/style/style.js b/js/style/style.js index 6ca736b7dc4..216d36c0530 100644 --- a/js/style/style.js +++ b/js/style/style.js @@ -67,7 +67,8 @@ function Style(stylesheet, animationLoop, options) { this.glyphSource = new GlyphSource(stylesheet.glyphs); this._resolve(); - this.fire('style.load'); + this.fire('data', {dataType: 'style'}); + this.fire('styleload'); }.bind(this); if (typeof stylesheet === 'string') { diff --git a/js/ui/map.js b/js/ui/map.js index 9f51dccc08c..9d94166d5e8 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -190,7 +190,7 @@ var Map = module.exports = function(options) { if (options.style) this.setStyle(options.style); if (options.attributionControl) this.addControl(new Attribution(options.attributionControl)); - this.on('style.load', function() { + this.on('styleload', function() { if (this.transform.unmodified) { this.jumpTo(this.style.stylesheet); } diff --git a/test/js/style/style.test.js b/test/js/style/style.test.js index 6dfdaa2b8b6..34a1180f58c 100644 --- a/test/js/style/style.test.js +++ b/test/js/style/style.test.js @@ -53,7 +53,7 @@ test('Style', function(t) { window.useFakeXMLHttpRequest(); window.server.respondWith('/style.json', JSON.stringify(require('../../fixtures/style'))); var style = new Style('/style.json'); - style.on('style.load', function() { + style.on('styleload', function() { window.restore(); t.end(); }); @@ -69,7 +69,7 @@ test('Style', function(t) { } } })); - style.on('style.load', function() { + style.on('styleload', function() { t.ok(style.sources['mapbox'] instanceof SourceCache); t.end(); }); @@ -105,7 +105,7 @@ test('Style', function(t) { .on('error', function() { t.fail(); }) - .on('style.load', function() { + .on('styleload', function() { window.restore(); t.end(); }); @@ -127,7 +127,7 @@ test('Style', function(t) { }] })); - style.on('style.load', function() { + style.on('styleload', function() { style.removeSource('-source-id-'); var source = createSource(); @@ -162,7 +162,7 @@ test('Style', function(t) { t.end(); }); - style.on('style.load', function() { + style.on('styleload', function() { style._layers.background.fire('error', {mapbox: true}); }); }); @@ -188,7 +188,7 @@ test('Style#_updateWorkerLayers', function(t) { style.on('error', function(error) { t.error(error); }); - style.on('style.load', function() { + style.on('styleload', function() { style.addLayer({id: 'first', source: 'source', type: 'fill', 'source-layer': 'source-layer' }, 'second'); style.addLayer({id: 'third', source: 'source', type: 'fill', 'source-layer': 'source-layer' }); @@ -219,7 +219,7 @@ test('Style#_updateWorkerLayers with specific ids', function(t) { style.on('error', function(error) { t.error(error); }); - style.on('style.load', function() { + style.on('styleload', function() { style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value.map(function(layer) { return layer.id; }), ['second', 'third']); @@ -249,7 +249,7 @@ test('Style#_resolve', function(t) { style.on('error', function(error) { t.error(error); }); - style.on('style.load', function() { + style.on('styleload', function() { t.ok(style.getLayer('fill') instanceof StyleLayer); t.end(); }); @@ -277,7 +277,7 @@ test('Style#_resolve', function(t) { style.on('error', function(event) { t.error(event.error); }); - style.on('style.load', function() { + style.on('styleload', function() { var ref = style.getLayer('ref'), referent = style.getLayer('referent'); t.equal(ref.type, 'fill'); @@ -293,7 +293,7 @@ test('Style#addSource', function(t) { t.test('returns self', function(t) { var style = new Style(createStyleJSON()), source = createSource(); - style.on('style.load', function () { + style.on('styleload', function () { t.equal(style.addSource('source-id', source), style); t.end(); }); @@ -305,7 +305,7 @@ test('Style#addSource', function(t) { t.throws(function () { style.addSource('source-id', source); }, Error, /load/i); - style.on('style.load', function() { + style.on('styleload', function() { t.end(); }); }); @@ -316,7 +316,7 @@ test('Style#addSource', function(t) { delete source.type; - style.on('style.load', function() { + style.on('styleload', function() { t.throws(function () { style.addSource('source-id', source); }, Error, /type/i); @@ -331,7 +331,7 @@ test('Style#addSource', function(t) { t.same(e.source.serialize(), source); t.end(); }); - style.on('style.load', function () { + style.on('styleload', function () { style.addSource('source-id', source); style.update(); }); @@ -340,7 +340,7 @@ test('Style#addSource', function(t) { t.test('throws on duplicates', function(t) { var style = new Style(createStyleJSON()), source = createSource(); - style.on('style.load', function () { + style.on('styleload', function () { style.addSource('source-id', source); t.throws(function() { style.addSource('source-id', source); @@ -351,7 +351,7 @@ test('Style#addSource', function(t) { t.test('emits on invalid source', function(t) { var style = new Style(createStyleJSON()); - style.on('style.load', function() { + style.on('styleload', function() { style.on('error', function() { t.notOk(style.sources['source-id']); t.end(); @@ -375,25 +375,16 @@ test('Style#addSource', function(t) { })); var source = createSource(); - function checkEvent(e) { - t.same(e.source.serialize(), source); - } + style.on('styleload', function () { + t.plan(4); - style.on('error', checkEvent); - style.on('sourceload', checkEvent); - style.on('data', checkEvent); - style.on('tile.add', checkEvent); - style.on('tile.load', checkEvent); - style.on('tile.remove', checkEvent); + style.on('error', function() { t.ok(true); }); + style.on('data', function() { t.ok(true); }); + style.on('sourceload', function() { t.ok(true); }); - style.on('style.load', function () { - t.plan(7); - style.addSource('source-id', source); // Fires load + style.addSource('source-id', source); // Fires 'sourceload' and 'data' style.sources['source-id'].fire('error'); style.sources['source-id'].fire('data'); - style.sources['source-id'].fire('tile.add'); - style.sources['source-id'].fire('tile.load'); - style.sources['source-id'].fire('tile.remove'); }); }); @@ -404,7 +395,7 @@ test('Style#removeSource', function(t) { t.test('returns self', function(t) { var style = new Style(createStyleJSON()), source = createSource(); - style.on('style.load', function () { + style.on('styleload', function () { style.addSource('source-id', source); t.equal(style.removeSource('source-id'), style); t.end(); @@ -423,7 +414,7 @@ test('Style#removeSource', function(t) { t.throws(function () { style.removeSource('source-id'); }, Error, /load/i); - style.on('style.load', function() { + style.on('styleload', function() { t.end(); }); }); @@ -435,7 +426,7 @@ test('Style#removeSource', function(t) { t.same(e.source.serialize(), source); t.end(); }); - style.on('style.load', function () { + style.on('styleload', function () { style.addSource('source-id', source); style.removeSource('source-id'); style.update(); @@ -454,7 +445,7 @@ test('Style#removeSource', function(t) { t.test('throws on non-existence', function(t) { var style = new Style(createStyleJSON()); - style.on('style.load', function () { + style.on('styleload', function () { t.throws(function() { style.removeSource('source-id'); }, /There is no source with this ID/); @@ -466,31 +457,20 @@ test('Style#removeSource', function(t) { var style = new Style(createStyleJSON()), source = createSource(); - style.on('sourceload', t.fail); - style.on('error', t.fail); - style.on('data', t.fail); - style.on('tile.add', t.fail); - style.on('tile.load', t.fail); - style.on('error', t.fail); - style.on('tile.remove', t.fail); - - style.on('style.load', function () { + style.on('styleload', function () { style.addSource('source-id', source); source = style.sources['source-id']; style.removeSource('source-id'); - // Bind a listener to prevent fallback Evented error reporting. - source.on('error', function() {}); - source.on('error', function() {}); + // Suppress error reporting + source.on('error', function() {}); - source.fire('sourceload'); - source.fire('error'); + style.on('data', function() { t.ok(false); }); + style.on('error', function() { t.ok(false); }); source.fire('data'); - source.fire('tile.add'); - source.fire('tile.load'); source.fire('error'); - source.fire('tile.remove'); + t.end(); }); }); @@ -503,7 +483,7 @@ test('Style#addLayer', function(t) { var style = new Style(createStyleJSON()), layer = {id: 'background', type: 'background'}; - style.on('style.load', function() { + style.on('styleload', function() { t.equal(style.addLayer(layer), style); t.end(); }); @@ -515,7 +495,7 @@ test('Style#addLayer', function(t) { t.throws(function () { style.addLayer(layer); }, Error, /load/i); - style.on('style.load', function() { + style.on('styleload', function() { t.end(); }); }); @@ -529,7 +509,7 @@ test('Style#addLayer', function(t) { t.end(); }); - style.on('style.load', function() { + style.on('styleload', function() { style.addLayer({ id: 'background', type: 'background' @@ -546,7 +526,7 @@ test('Style#addLayer', function(t) { } })); - style.on('style.load', function() { + style.on('styleload', function() { var source = createSource(); source['vector_layers'] = [{id: 'green'}]; style.addSource('-source-id-', source); @@ -572,7 +552,7 @@ test('Style#addLayer', function(t) { t.test('emits error on invalid layer', function(t) { var style = new Style(createStyleJSON()); - style.on('style.load', function() { + style.on('styleload', function() { style.on('error', function() { t.notOk(style.getLayer('background')); t.end(); @@ -604,7 +584,7 @@ test('Style#addLayer', function(t) { "filter": ["==", "id", 0] }; - style.on('style.load', function() { + style.on('styleload', function() { style.sources['mapbox'].reload = t.end; style.addLayer(layer); @@ -621,7 +601,7 @@ test('Style#addLayer', function(t) { t.end(); }); - style.on('style.load', function() { + style.on('styleload', function() { style.addLayer(layer); style.update(); }); @@ -637,7 +617,7 @@ test('Style#addLayer', function(t) { t.end(); }); - style.on('style.load', function() { + style.on('styleload', function() { style.addLayer(layer); style.addLayer(layer); t.end(); @@ -656,7 +636,7 @@ test('Style#addLayer', function(t) { })), layer = {id: 'c', type: 'background'}; - style.on('style.load', function() { + style.on('styleload', function() { style.addLayer(layer); t.deepEqual(style._order, ['a', 'b', 'c']); t.end(); @@ -675,7 +655,7 @@ test('Style#addLayer', function(t) { })), layer = {id: 'c', type: 'background'}; - style.on('style.load', function() { + style.on('styleload', function() { style.addLayer(layer, 'a'); t.deepEqual(style._order, ['c', 'a', 'b']); t.end(); @@ -690,7 +670,7 @@ test('Style#removeLayer', function(t) { var style = new Style(createStyleJSON()), layer = {id: 'background', type: 'background'}; - style.on('style.load', function() { + style.on('styleload', function() { style.addLayer(layer); t.equal(style.removeLayer('background'), style); t.end(); @@ -704,7 +684,7 @@ test('Style#removeLayer', function(t) { t.throws(function () { style.removeLayer('background'); }, Error, /load/i); - style.on('style.load', function() { + style.on('styleload', function() { t.end(); }); }); @@ -718,7 +698,7 @@ test('Style#removeLayer', function(t) { t.end(); }); - style.on('style.load', function() { + style.on('styleload', function() { style.addLayer(layer); style.removeLayer('background'); style.update(); @@ -737,7 +717,7 @@ test('Style#removeLayer', function(t) { t.fail(); }); - style.on('style.load', function() { + style.on('styleload', function() { var layer = style._layers.background; style.removeLayer('background'); @@ -752,7 +732,7 @@ test('Style#removeLayer', function(t) { t.test('throws on non-existence', function(t) { var style = new Style(createStyleJSON()); - style.on('style.load', function() { + style.on('styleload', function() { t.throws(function () { style.removeLayer('background'); }, /There is no layer with this ID/); @@ -771,7 +751,7 @@ test('Style#removeLayer', function(t) { }] })); - style.on('style.load', function() { + style.on('styleload', function() { style.removeLayer('a'); t.deepEqual(style._order, ['b']); t.end(); @@ -789,7 +769,7 @@ test('Style#removeLayer', function(t) { }] })); - style.on('style.load', function() { + style.on('styleload', function() { style.removeLayer('a'); t.deepEqual(style.getLayer('a'), undefined); t.deepEqual(style.getLayer('b'), undefined); @@ -817,7 +797,7 @@ test('Style#setFilter', function(t) { t.test('sets filter', function(t) { var style = createStyle(); - style.on('style.load', function() { + style.on('styleload', function() { style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value[0].id, 'symbol'); @@ -834,7 +814,7 @@ test('Style#setFilter', function(t) { t.test('gets a clone of the filter', function(t) { var style = createStyle(); - style.on('style.load', function() { + style.on('styleload', function() { var filter1 = ['==', 'id', 1]; style.setFilter('symbol', filter1); var filter2 = style.getFilter('symbol'); @@ -851,7 +831,7 @@ test('Style#setFilter', function(t) { t.test('sets again mutated filter', function(t) { var style = createStyle(); - style.on('style.load', function() { + style.on('styleload', function() { var filter = ['==', 'id', 1]; style.setFilter('symbol', filter); style.update({}, {}); // flush pending operations @@ -871,7 +851,7 @@ test('Style#setFilter', function(t) { t.test('sets filter on parent', function(t) { var style = createStyle(); - style.on('style.load', function() { + style.on('styleload', function() { style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value.map(function(layer) { return layer.id; }), ['symbol']); @@ -896,7 +876,7 @@ test('Style#setFilter', function(t) { t.test('emits if invalid', function(t) { var style = createStyle(); - style.on('style.load', function() { + style.on('styleload', function() { style.on('error', function() { t.deepEqual(style.getLayer('symbol').serialize().filter, ['==', 'id', 0]); t.end(); @@ -929,7 +909,7 @@ test('Style#setLayerZoomRange', function(t) { t.test('sets zoom range', function(t) { var style = createStyle(); - style.on('style.load', function() { + style.on('styleload', function() { style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value.map(function(layer) { return layer.id; }), ['symbol']); @@ -945,7 +925,7 @@ test('Style#setLayerZoomRange', function(t) { t.test('sets zoom range on parent layer', function(t) { var style = createStyle(); - style.on('style.load', function() { + style.on('styleload', function() { style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value.map(function(layer) { return layer.id; }), ['symbol']); @@ -963,7 +943,7 @@ test('Style#setLayerZoomRange', function(t) { t.throws(function () { style.setLayerZoomRange('symbol', 5, 12); }, Error, /load/i); - style.on('style.load', function() { + style.on('styleload', function() { t.end(); }); }); @@ -1065,7 +1045,7 @@ test('Style#queryRenderedFeatures', function(t) { }] }); - style.on('style.load', function() { + style.on('styleload', function() { style._applyClasses([]); style._recalculate(0); @@ -1148,7 +1128,7 @@ test('Style defers expensive methods', function(t) { } })); - style.on('style.load', function() { + style.on('styleload', function() { style.update(); // spies to track defered methods @@ -1213,7 +1193,7 @@ test('Style#query*Features', function(t) { onError = sinon.spy(); style.on('error', onError) - .on('style.load', function() { + .on('styleload', function() { callback(); }); }); diff --git a/test/js/ui/map.test.js b/test/js/ui/map.test.js index 42e09157b92..432fbbfb529 100755 --- a/test/js/ui/map.test.js +++ b/test/js/ui/map.test.js @@ -176,7 +176,7 @@ test('Map', function(t) { t.equal(map.transform.zoom, 0.6983039737971012, 'map transform is constrained'); t.ok(map.transform.unmodified, 'map transform is not modified'); map.setStyle(createStyle()); - map.on('style.load', function () { + map.on('styleload', function () { t.deepEqual(fixedLngLat(map.transform.center), fixedLngLat({ lng: -73.9749, lat: 40.7736 })); t.equal(fixedNum(map.transform.zoom), 12.5); t.equal(fixedNum(map.transform.bearing), 29); @@ -189,7 +189,7 @@ test('Map', function(t) { var map = createMap({zoom: 10, center: [-77.0186, 38.8888]}); t.notOk(map.transform.unmodified, 'map transform is modified by options'); map.setStyle(createStyle()); - map.on('style.load', function () { + map.on('styleload', function () { t.deepEqual(fixedLngLat(map.transform.center), fixedLngLat({ lng: -77.0186, lat: 38.8888 })); t.equal(fixedNum(map.transform.zoom), 10); t.equal(fixedNum(map.transform.bearing), 0); @@ -205,7 +205,7 @@ test('Map', function(t) { map.setCenter([-77.0186, 38.8888]); t.notOk(map.transform.unmodified, 'map transform is modified via setters'); map.setStyle(createStyle()); - map.on('style.load', function () { + map.on('styleload', function () { t.deepEqual(fixedLngLat(map.transform.center), fixedLngLat({ lng: -77.0186, lat: 38.8888 })); t.equal(fixedNum(map.transform.zoom), 10); t.equal(fixedNum(map.transform.bearing), 0); @@ -672,7 +672,7 @@ test('Map', function(t) { } }); - map.on('style.load', function () { + map.on('styleload', function () { map.style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value.map(function(layer) { return layer.id; }), ['symbol']); @@ -712,7 +712,7 @@ test('Map', function(t) { } }); - map.on('style.load', function () { + map.on('styleload', function () { map.style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value.map(function(layer) { return layer.id; }), ['symbol']); @@ -757,7 +757,7 @@ test('Map', function(t) { } }); - map.once('style.load', function () { + map.once('styleload', function () { map.once('data', function (e) { if (e.dataType === 'style') { t.end(); @@ -784,7 +784,7 @@ test('Map', function(t) { } }); - map.on('style.load', function () { + map.on('styleload', function () { map.setLayoutProperty('background', 'visibility', 'visible'); t.deepEqual(map.getLayoutProperty('background', 'visibility'), 'visible'); t.end(); @@ -815,7 +815,7 @@ test('Map', function(t) { // Suppress errors because we're not loading tiles from a real URL. map.on('error', function() {}); - map.on('style.load', function () { + map.on('styleload', function () { map.setLayoutProperty('satellite', 'visibility', 'visible'); t.deepEqual(map.getLayoutProperty('satellite', 'visibility'), 'visible'); t.end(); @@ -849,7 +849,7 @@ test('Map', function(t) { } }); - map.on('style.load', function () { + map.on('styleload', function () { map.setLayoutProperty('shore', 'visibility', 'visible'); t.deepEqual(map.getLayoutProperty('shore', 'visibility'), 'visible'); t.end(); @@ -883,7 +883,7 @@ test('Map', function(t) { } }); - map.on('style.load', function () { + map.on('styleload', function () { map.setLayoutProperty('image', 'visibility', 'visible'); t.deepEqual(map.getLayoutProperty('image', 'visibility'), 'visible'); t.end(); @@ -906,7 +906,7 @@ test('Map', function(t) { } }); - map.on('style.load', function () { + map.on('styleload', function () { map.setPaintProperty('background', 'background-color', 'red'); t.deepEqual(map.getPaintProperty('background', 'background-color'), 'red'); t.end(); From 702df695cdcd53ea4f787ee7fe17741e9e28b653 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Fri, 23 Sep 2016 14:18:18 -0700 Subject: [PATCH 05/21] tile.add -> dataloading --- js/source/source_cache.js | 2 +- test/js/source/source_cache.test.js | 6 +++--- test/js/ui/map.test.js | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/js/source/source_cache.js b/js/source/source_cache.js index ac74e4c576b..3501c419ad6 100644 --- a/js/source/source_cache.js +++ b/js/source/source_cache.js @@ -409,7 +409,7 @@ SourceCache.prototype = util.inherit(Evented, { tile.uses++; this._tiles[coord.id] = tile; - this._source.fire('tile.add', {tile: tile}); + this._source.fire('dataloading', {tile: tile, dataType: 'tile'}); return tile; }, diff --git a/test/js/source/source_cache.test.js b/test/js/source/source_cache.test.js index 198675bd639..76ab03a4362 100644 --- a/test/js/source/source_cache.test.js +++ b/test/js/source/source_cache.test.js @@ -75,7 +75,7 @@ test('SourceCache#addTile', function(t) { t.test('adds tile when uncached', function(t) { var coord = new TileCoord(0, 0, 0); var sourceCache = createSourceCache({}) - .on('tile.add', function (data) { + .on('dataloading', function (data) { t.deepEqual(data.tile.coord, coord); t.equal(data.tile.uses, 1); t.end(); @@ -95,7 +95,7 @@ test('SourceCache#addTile', function(t) { callback(); } }) - .on('tile.add', function () { add++; }); + .on('dataloading', function () { add++; }); var tr = new Transform(); tr.width = 512; @@ -123,7 +123,7 @@ test('SourceCache#addTile', function(t) { callback(); } }) - .on('tile.add', function () { add++; }); + .on('dataloading', function () { add++; }); var t1 = sourceCache.addTile(coord); var t2 = sourceCache.addTile(new TileCoord(0, 0, 0, 1)); diff --git a/test/js/ui/map.test.js b/test/js/ui/map.test.js index 432fbbfb529..83c465deecb 100755 --- a/test/js/ui/map.test.js +++ b/test/js/ui/map.test.js @@ -138,20 +138,20 @@ test('Map', function(t) { map.on('error', recordEvent); map.on('sourceload', recordEvent); map.on('data', recordEvent); - map.on('tile.add', recordEvent); + map.on('dataloading', recordEvent); map.on('tile.remove', recordEvent); map.style.fire('error'); map.style.fire('sourceload'); map.style.fire('data'); - map.style.fire('tile.add'); + map.style.fire('dataloading'); map.style.fire('tile.remove'); t.deepEqual(events, [ 'error', 'sourceload', 'data', - 'tile.add', + 'dataloading', 'tile.remove' ]); From 73bf845d1d786968c805cf319783642cadd08d4c Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Fri, 23 Sep 2016 14:22:43 -0700 Subject: [PATCH 06/21] tile.load -> data --- js/source/source_cache.js | 2 +- js/source/tile.js | 2 +- js/ui/map.js | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/js/source/source_cache.js b/js/source/source_cache.js index 3501c419ad6..776d334cf55 100644 --- a/js/source/source_cache.js +++ b/js/source/source_cache.js @@ -168,7 +168,7 @@ SourceCache.prototype = util.inherit(Evented, { tile.source = this; tile.timeAdded = new Date().getTime(); - this._source.fire('tile.load', {tile: tile}); + this._source.fire('data', {tile: tile, dataType: 'tile'}); // HACK this is nescessary to fix https://github.com/mapbox/mapbox-gl-js/issues/2986 if (this.map) this.map.painter.tileExtentVAO.vao = null; diff --git a/js/source/tile.js b/js/source/tile.js index 5592d859fb1..64a3b3b5fc2 100644 --- a/js/source/tile.js +++ b/js/source/tile.js @@ -144,7 +144,7 @@ Tile.prototype = { function done(_, data) { this.reloadSymbolData(data, source.map.painter, source.map.style); - source.fire('tile.load', {tile: this}); + source.fire('data', {tile: this, dataType: 'tile'}); // HACK this is nescessary to fix https://github.com/mapbox/mapbox-gl-js/issues/2986 if (source.map) source.map.painter.tileExtentVAO.vao = null; diff --git a/js/ui/map.js b/js/ui/map.js index 9d94166d5e8..0b8b0cd9076 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -212,7 +212,6 @@ var Map = module.exports = function(options) { }); this.on('data', this._update); - this.on('tile.load', this._update); }; util.extend(Map.prototype, Evented); From d44480d99974437392144a2cdf732631c60eca5b Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Fri, 23 Sep 2016 14:45:42 -0700 Subject: [PATCH 07/21] tile.remove -> data --- js/source/source_cache.js | 2 +- test/js/source/source_cache.test.js | 14 ++++++++------ test/js/ui/map.test.js | 13 ++++--------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/js/source/source_cache.js b/js/source/source_cache.js index 776d334cf55..8df0e0f8e8d 100644 --- a/js/source/source_cache.js +++ b/js/source/source_cache.js @@ -427,7 +427,7 @@ SourceCache.prototype = util.inherit(Evented, { tile.uses--; delete this._tiles[id]; - this._source.fire('tile.remove', {tile: tile}); + this._source.fire('data', {tile: tile, dataType: 'tile', isDataRemoved: true}); if (tile.uses > 0) return; diff --git a/test/js/source/source_cache.test.js b/test/js/source/source_cache.test.js index 76ab03a4362..e1bd2289c5e 100644 --- a/test/js/source/source_cache.test.js +++ b/test/js/source/source_cache.test.js @@ -141,12 +141,14 @@ test('SourceCache#addTile', function(t) { test('SourceCache#removeTile', function(t) { t.test('removes tile', function(t) { var coord = new TileCoord(0, 0, 0); - var sourceCache = createSourceCache({}) - .on('tile.remove', function (data) { - var tile = data.tile; - t.deepEqual(tile.coord, coord); - t.equal(tile.uses, 0); - t.end(); + var sourceCache = createSourceCache({}); + sourceCache.on('data', function (event) { + if (event.isDataRemoved) { + var tile = event.tile; + t.deepEqual(tile.coord, coord); + t.equal(tile.uses, 0); + t.end(); + } }); sourceCache.addTile(coord); sourceCache.removeTile(coord.id); diff --git a/test/js/ui/map.test.js b/test/js/ui/map.test.js index 83c465deecb..7029eeae127 100755 --- a/test/js/ui/map.test.js +++ b/test/js/ui/map.test.js @@ -131,28 +131,23 @@ test('Map', function(t) { t.error(error); var events = []; - function recordEvent(event) { - events.push(event.type); - } + function recordEvent(event) { events.push(event.type); } - map.on('error', recordEvent); - map.on('sourceload', recordEvent); + map.on('error', recordEvent); + map.on('sourceload', recordEvent); map.on('data', recordEvent); - map.on('dataloading', recordEvent); - map.on('tile.remove', recordEvent); + map.on('dataloading', recordEvent); map.style.fire('error'); map.style.fire('sourceload'); map.style.fire('data'); map.style.fire('dataloading'); - map.style.fire('tile.remove'); t.deepEqual(events, [ 'error', 'sourceload', 'data', 'dataloading', - 'tile.remove' ]); t.end(); From 0650f8d153524c01f7f6f18261b98f12c9376a08 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 26 Sep 2016 12:12:36 -0700 Subject: [PATCH 08/21] Unrename "source.load" and "style.load" --- js/source/geojson_source.js | 2 +- js/source/image_source.js | 2 +- js/source/raster_tile_source.js | 2 +- js/source/source_cache.js | 2 +- js/source/vector_tile_source.js | 2 +- js/source/video_source.js | 2 +- js/style/style.js | 4 +- js/ui/map.js | 2 +- test/js/source/geojson_source.test.js | 6 +- test/js/source/source_cache.test.js | 36 ++++---- test/js/source/vector_tile_source.test.js | 8 +- test/js/style/style.test.js | 102 +++++++++++----------- test/js/ui/map.test.js | 28 +++--- 13 files changed, 99 insertions(+), 99 deletions(-) diff --git a/js/source/geojson_source.js b/js/source/geojson_source.js index de3a80023a7..d3bad3ba708 100644 --- a/js/source/geojson_source.js +++ b/js/source/geojson_source.js @@ -89,7 +89,7 @@ function GeoJSONSource(id, options, dispatcher) { return; } this.fire('data', {dataType: 'geojson'}); - this.fire('sourceload'); + this.fire('source.load'); }.bind(this)); } diff --git a/js/source/image_source.js b/js/source/image_source.js index 50a1d6f8c24..a7bf7a5b544 100644 --- a/js/source/image_source.js +++ b/js/source/image_source.js @@ -54,7 +54,7 @@ function ImageSource(id, options, dispatcher) { this.image = image; this._loaded = true; this.fire('data', {type: 'image'}); - this.fire('sourceload'); + this.fire('source.load'); if (this.map) { this.setCoordinates(options.coordinates); diff --git a/js/source/raster_tile_source.js b/js/source/raster_tile_source.js index 6af334d5555..af42eee5429 100644 --- a/js/source/raster_tile_source.js +++ b/js/source/raster_tile_source.js @@ -18,7 +18,7 @@ function RasterTileSource(id, options, dispatcher) { } util.extend(this, tileJSON); this.fire('data', {type: 'tileJSON'}); - this.fire('sourceload'); + this.fire('source.load'); }.bind(this)); } diff --git a/js/source/source_cache.js b/js/source/source_cache.js index 8df0e0f8e8d..fefec0a4523 100644 --- a/js/source/source_cache.js +++ b/js/source/source_cache.js @@ -30,7 +30,7 @@ function SourceCache(id, options, dispatcher) { var source = this._source = Source.create(id, options, dispatcher); source.setEventedParent(this); - this.on('sourceload', function() { + this.on('source.load', function() { if (this.map && this._source.onAdd) { this._source.onAdd(this.map); } this._sourceLoaded = true; diff --git a/js/source/vector_tile_source.js b/js/source/vector_tile_source.js index d8d4112e726..b178e5fad69 100644 --- a/js/source/vector_tile_source.js +++ b/js/source/vector_tile_source.js @@ -24,7 +24,7 @@ function VectorTileSource(id, options, dispatcher) { } util.extend(this, tileJSON); this.fire('data', {dataType: 'tileJSON'}); - this.fire('sourceload'); + this.fire('source.load'); }.bind(this)); } diff --git a/js/source/video_source.js b/js/source/video_source.js index 4f28157bb1b..e6422257e1a 100644 --- a/js/source/video_source.js +++ b/js/source/video_source.js @@ -74,7 +74,7 @@ function VideoSource(id, options) { } this.fire('data', {dataType: 'video'}); - this.fire('sourceload'); + this.fire('source.load'); }.bind(this)); } diff --git a/js/style/style.js b/js/style/style.js index 216d36c0530..50a9f7195df 100644 --- a/js/style/style.js +++ b/js/style/style.js @@ -68,7 +68,7 @@ function Style(stylesheet, animationLoop, options) { this.glyphSource = new GlyphSource(stylesheet.glyphs); this._resolve(); this.fire('data', {dataType: 'style'}); - this.fire('styleload'); + this.fire('style.load'); }.bind(this); if (typeof stylesheet === 'string') { @@ -77,7 +77,7 @@ function Style(stylesheet, animationLoop, options) { browser.frame(stylesheetLoaded.bind(this, null, stylesheet)); } - this.on('sourceload', function(event) { + this.on('source.load', function(event) { var source = event.source; if (source && source.vectorLayerIds) { for (var layerId in this._layers) { diff --git a/js/ui/map.js b/js/ui/map.js index 0b8b0cd9076..55869234390 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -190,7 +190,7 @@ var Map = module.exports = function(options) { if (options.style) this.setStyle(options.style); if (options.attributionControl) this.addControl(new Attribution(options.attributionControl)); - this.on('styleload', function() { + this.on('style.load', function() { if (this.transform.unmodified) { this.jumpTo(this.style.stylesheet); } diff --git a/test/js/source/geojson_source.test.js b/test/js/source/geojson_source.test.js index 283b53c9e4f..33de527f015 100644 --- a/test/js/source/geojson_source.test.js +++ b/test/js/source/geojson_source.test.js @@ -119,7 +119,7 @@ test('GeoJSONSource#update', function(t) { var source = new GeoJSONSource('id', {data: {}}, mockDispatcher); - source.on('sourceload', function() { + source.on('source.load', function() { t.end(); }); }); @@ -148,7 +148,7 @@ test('GeoJSONSource#update', function(t) { var source = new GeoJSONSource('id', {data: {}}, mockDispatcher); - source.on('sourceload', function() { + source.on('source.load', function() { // Note: we register this before calling setData because `change` // is fired synchronously within that method. It may be worth // considering dezalgoing there. @@ -175,7 +175,7 @@ test('GeoJSONSource#update', function(t) { transform: {} }; - source.on('sourceload', function () { + source.on('source.load', function () { source.setData({}); source.loadTile(new Tile(new TileCoord(0, 0, 0), 512), function () {}); }); diff --git a/test/js/source/source_cache.test.js b/test/js/source/source_cache.test.js index e1bd2289c5e..ab1a1d0da77 100644 --- a/test/js/source/source_cache.test.js +++ b/test/js/source/source_cache.test.js @@ -32,7 +32,7 @@ Source.setType('mock-source-type', function create (id, sourceOptions) { if (sourceOptions.error) { source.fire('error', { error: sourceOptions.error }); } else { - source.fire('sourceload'); + source.fire('source.load'); } }, 0); return source; @@ -53,7 +53,7 @@ test('SourceCache#attribution is set', function(t) { var sourceCache = createSourceCache({ attribution: 'Mapbox Heavy Industries' }); - sourceCache.on('sourceload', function() { + sourceCache.on('source.load', function() { t.equal(sourceCache.attribution, 'Mapbox Heavy Industries'); t.end(); }); @@ -207,13 +207,13 @@ test('SourceCache#removeTile', function(t) { test('SourceCache / Source lifecycle', function (t) { t.test('does not fire load or change before source load event', function (t) { createSourceCache({noLoad: true}) - .on('sourceload', t.fail) + .on('source.load', t.fail) .on('data', t.fail); setTimeout(t.end, 1); }); t.test('forward load event', function (t) { - createSourceCache({}).on('sourceload', t.end); + createSourceCache({}).on('source.load', t.end); }); t.test('forward change event', function (t) { @@ -253,7 +253,7 @@ test('SourceCache / Source lifecycle', function (t) { } }); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { sourceCache.update(transform); sourceCache.getSource().fire('data', {dataType: 'geoJSON'}); }); @@ -269,7 +269,7 @@ test('SourceCache#update', function(t) { transform.zoom = 0; var sourceCache = createSourceCache({}, false); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { sourceCache.update(transform); t.deepEqual(sourceCache.getIds(), []); @@ -283,7 +283,7 @@ test('SourceCache#update', function(t) { transform.zoom = 0; var sourceCache = createSourceCache({}); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { sourceCache.update(transform); t.deepEqual(sourceCache.getIds(), [new TileCoord(0, 0, 0).id]); t.end(); @@ -301,7 +301,7 @@ test('SourceCache#update', function(t) { } }); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { sourceCache.update(transform); t.deepEqual(sourceCache.getIds(), [new TileCoord(0, 0, 0).id]); @@ -332,7 +332,7 @@ test('SourceCache#update', function(t) { } }); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { sourceCache.update(transform); t.deepEqual(sourceCache.getIds(), [new TileCoord(0, 0, 0).id]); @@ -363,7 +363,7 @@ test('SourceCache#update', function(t) { } }); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { sourceCache.update(transform); t.deepEqual(sourceCache.getIds(), [new TileCoord(0, 0, 0, 1).id]); @@ -394,7 +394,7 @@ test('SourceCache#update', function(t) { } }); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { sourceCache.update(transform, 100); t.deepEqual(sourceCache.getIds(), [ new TileCoord(2, 1, 1).id, @@ -424,7 +424,7 @@ test('SourceCache#update', function(t) { } }); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { sourceCache.update(transform, 100); transform.zoom = 2; @@ -454,7 +454,7 @@ test('SourceCache#update', function(t) { } }); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { t.equal(sourceCache.maxzoom, 14); sourceCache.update(transform); @@ -533,7 +533,7 @@ test('SourceCache#tilesIn', function (t) { } }); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { sourceCache.update(transform); t.deepEqual(sourceCache.getIds(), [ @@ -574,7 +574,7 @@ test('SourceCache#tilesIn', function (t) { tileSize: 512 }); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { var transform = new Transform(); transform.resize(512, 512); transform.zoom = 2.0; @@ -618,7 +618,7 @@ test('SourceCache#tilesIn', function (t) { tileSize: 512 }); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { var transform = new Transform(); transform.resize(512, 512); transform.zoom = 2.0; @@ -640,7 +640,7 @@ test('SourceCache#loaded (no errors)', function (t) { } }); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { var coord = new TileCoord(0, 0, 0); sourceCache.addTile(coord); @@ -656,7 +656,7 @@ test('SourceCache#loaded (with errors)', function (t) { } }); - sourceCache.on('sourceload', function () { + sourceCache.on('source.load', function () { var coord = new TileCoord(0, 0, 0); sourceCache.addTile(coord); diff --git a/test/js/source/vector_tile_source.test.js b/test/js/source/vector_tile_source.test.js index 45ce770d288..0208a619eb2 100644 --- a/test/js/source/vector_tile_source.test.js +++ b/test/js/source/vector_tile_source.test.js @@ -38,7 +38,7 @@ test('VectorTileSource', function(t) { tiles: ["http://example.com/{z}/{x}/{y}.png"] }); - source.on('sourceload', function() { + source.on('source.load', function() { t.deepEqual(source.tiles, ["http://example.com/{z}/{x}/{y}.png"]); t.deepEqual(source.minzoom, 1); t.deepEqual(source.maxzoom, 10); @@ -52,7 +52,7 @@ test('VectorTileSource', function(t) { var source = createSource({ url: "/source.json" }); - source.on('sourceload', function() { + source.on('source.load', function() { t.deepEqual(source.tiles, ["http://example.com/{z}/{x}/{y}.png"]); t.deepEqual(source.minzoom, 1); t.deepEqual(source.maxzoom, 10); @@ -107,7 +107,7 @@ test('VectorTileSource', function(t) { t.end(); }; - source.on('sourceload', function() { + source.on('source.load', function() { source.loadTile({coord: new TileCoord(10, 5, 5, 0)}, function () {}); }); }); @@ -127,7 +127,7 @@ test('VectorTileSource', function(t) { return 1; }; - source.on('sourceload', function () { + source.on('source.load', function () { var tile = { coord: new TileCoord(10, 5, 5, 0), state: 'loading', diff --git a/test/js/style/style.test.js b/test/js/style/style.test.js index 34a1180f58c..b9f05eccf24 100644 --- a/test/js/style/style.test.js +++ b/test/js/style/style.test.js @@ -53,7 +53,7 @@ test('Style', function(t) { window.useFakeXMLHttpRequest(); window.server.respondWith('/style.json', JSON.stringify(require('../../fixtures/style'))); var style = new Style('/style.json'); - style.on('styleload', function() { + style.on('style.load', function() { window.restore(); t.end(); }); @@ -69,7 +69,7 @@ test('Style', function(t) { } } })); - style.on('styleload', function() { + style.on('style.load', function() { t.ok(style.sources['mapbox'] instanceof SourceCache); t.end(); }); @@ -105,7 +105,7 @@ test('Style', function(t) { .on('error', function() { t.fail(); }) - .on('styleload', function() { + .on('style.load', function() { window.restore(); t.end(); }); @@ -127,7 +127,7 @@ test('Style', function(t) { }] })); - style.on('styleload', function() { + style.on('style.load', function() { style.removeSource('-source-id-'); var source = createSource(); @@ -162,7 +162,7 @@ test('Style', function(t) { t.end(); }); - style.on('styleload', function() { + style.on('style.load', function() { style._layers.background.fire('error', {mapbox: true}); }); }); @@ -188,7 +188,7 @@ test('Style#_updateWorkerLayers', function(t) { style.on('error', function(error) { t.error(error); }); - style.on('styleload', function() { + style.on('style.load', function() { style.addLayer({id: 'first', source: 'source', type: 'fill', 'source-layer': 'source-layer' }, 'second'); style.addLayer({id: 'third', source: 'source', type: 'fill', 'source-layer': 'source-layer' }); @@ -219,7 +219,7 @@ test('Style#_updateWorkerLayers with specific ids', function(t) { style.on('error', function(error) { t.error(error); }); - style.on('styleload', function() { + style.on('style.load', function() { style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value.map(function(layer) { return layer.id; }), ['second', 'third']); @@ -249,7 +249,7 @@ test('Style#_resolve', function(t) { style.on('error', function(error) { t.error(error); }); - style.on('styleload', function() { + style.on('style.load', function() { t.ok(style.getLayer('fill') instanceof StyleLayer); t.end(); }); @@ -277,7 +277,7 @@ test('Style#_resolve', function(t) { style.on('error', function(event) { t.error(event.error); }); - style.on('styleload', function() { + style.on('style.load', function() { var ref = style.getLayer('ref'), referent = style.getLayer('referent'); t.equal(ref.type, 'fill'); @@ -293,7 +293,7 @@ test('Style#addSource', function(t) { t.test('returns self', function(t) { var style = new Style(createStyleJSON()), source = createSource(); - style.on('styleload', function () { + style.on('style.load', function () { t.equal(style.addSource('source-id', source), style); t.end(); }); @@ -305,7 +305,7 @@ test('Style#addSource', function(t) { t.throws(function () { style.addSource('source-id', source); }, Error, /load/i); - style.on('styleload', function() { + style.on('style.load', function() { t.end(); }); }); @@ -316,7 +316,7 @@ test('Style#addSource', function(t) { delete source.type; - style.on('styleload', function() { + style.on('style.load', function() { t.throws(function () { style.addSource('source-id', source); }, Error, /type/i); @@ -331,7 +331,7 @@ test('Style#addSource', function(t) { t.same(e.source.serialize(), source); t.end(); }); - style.on('styleload', function () { + style.on('style.load', function () { style.addSource('source-id', source); style.update(); }); @@ -340,7 +340,7 @@ test('Style#addSource', function(t) { t.test('throws on duplicates', function(t) { var style = new Style(createStyleJSON()), source = createSource(); - style.on('styleload', function () { + style.on('style.load', function () { style.addSource('source-id', source); t.throws(function() { style.addSource('source-id', source); @@ -351,7 +351,7 @@ test('Style#addSource', function(t) { t.test('emits on invalid source', function(t) { var style = new Style(createStyleJSON()); - style.on('styleload', function() { + style.on('style.load', function() { style.on('error', function() { t.notOk(style.sources['source-id']); t.end(); @@ -375,14 +375,14 @@ test('Style#addSource', function(t) { })); var source = createSource(); - style.on('styleload', function () { + style.on('style.load', function () { t.plan(4); style.on('error', function() { t.ok(true); }); style.on('data', function() { t.ok(true); }); - style.on('sourceload', function() { t.ok(true); }); + style.on('source.load', function() { t.ok(true); }); - style.addSource('source-id', source); // Fires 'sourceload' and 'data' + style.addSource('source-id', source); // Fires 'source.load' and 'data' style.sources['source-id'].fire('error'); style.sources['source-id'].fire('data'); }); @@ -395,7 +395,7 @@ test('Style#removeSource', function(t) { t.test('returns self', function(t) { var style = new Style(createStyleJSON()), source = createSource(); - style.on('styleload', function () { + style.on('style.load', function () { style.addSource('source-id', source); t.equal(style.removeSource('source-id'), style); t.end(); @@ -414,7 +414,7 @@ test('Style#removeSource', function(t) { t.throws(function () { style.removeSource('source-id'); }, Error, /load/i); - style.on('styleload', function() { + style.on('style.load', function() { t.end(); }); }); @@ -426,7 +426,7 @@ test('Style#removeSource', function(t) { t.same(e.source.serialize(), source); t.end(); }); - style.on('styleload', function () { + style.on('style.load', function () { style.addSource('source-id', source); style.removeSource('source-id'); style.update(); @@ -445,7 +445,7 @@ test('Style#removeSource', function(t) { t.test('throws on non-existence', function(t) { var style = new Style(createStyleJSON()); - style.on('styleload', function () { + style.on('style.load', function () { t.throws(function() { style.removeSource('source-id'); }, /There is no source with this ID/); @@ -457,7 +457,7 @@ test('Style#removeSource', function(t) { var style = new Style(createStyleJSON()), source = createSource(); - style.on('styleload', function () { + style.on('style.load', function () { style.addSource('source-id', source); source = style.sources['source-id']; @@ -483,7 +483,7 @@ test('Style#addLayer', function(t) { var style = new Style(createStyleJSON()), layer = {id: 'background', type: 'background'}; - style.on('styleload', function() { + style.on('style.load', function() { t.equal(style.addLayer(layer), style); t.end(); }); @@ -495,7 +495,7 @@ test('Style#addLayer', function(t) { t.throws(function () { style.addLayer(layer); }, Error, /load/i); - style.on('styleload', function() { + style.on('style.load', function() { t.end(); }); }); @@ -509,7 +509,7 @@ test('Style#addLayer', function(t) { t.end(); }); - style.on('styleload', function() { + style.on('style.load', function() { style.addLayer({ id: 'background', type: 'background' @@ -526,7 +526,7 @@ test('Style#addLayer', function(t) { } })); - style.on('styleload', function() { + style.on('style.load', function() { var source = createSource(); source['vector_layers'] = [{id: 'green'}]; style.addSource('-source-id-', source); @@ -552,7 +552,7 @@ test('Style#addLayer', function(t) { t.test('emits error on invalid layer', function(t) { var style = new Style(createStyleJSON()); - style.on('styleload', function() { + style.on('style.load', function() { style.on('error', function() { t.notOk(style.getLayer('background')); t.end(); @@ -584,7 +584,7 @@ test('Style#addLayer', function(t) { "filter": ["==", "id", 0] }; - style.on('styleload', function() { + style.on('style.load', function() { style.sources['mapbox'].reload = t.end; style.addLayer(layer); @@ -601,7 +601,7 @@ test('Style#addLayer', function(t) { t.end(); }); - style.on('styleload', function() { + style.on('style.load', function() { style.addLayer(layer); style.update(); }); @@ -617,7 +617,7 @@ test('Style#addLayer', function(t) { t.end(); }); - style.on('styleload', function() { + style.on('style.load', function() { style.addLayer(layer); style.addLayer(layer); t.end(); @@ -636,7 +636,7 @@ test('Style#addLayer', function(t) { })), layer = {id: 'c', type: 'background'}; - style.on('styleload', function() { + style.on('style.load', function() { style.addLayer(layer); t.deepEqual(style._order, ['a', 'b', 'c']); t.end(); @@ -655,7 +655,7 @@ test('Style#addLayer', function(t) { })), layer = {id: 'c', type: 'background'}; - style.on('styleload', function() { + style.on('style.load', function() { style.addLayer(layer, 'a'); t.deepEqual(style._order, ['c', 'a', 'b']); t.end(); @@ -670,7 +670,7 @@ test('Style#removeLayer', function(t) { var style = new Style(createStyleJSON()), layer = {id: 'background', type: 'background'}; - style.on('styleload', function() { + style.on('style.load', function() { style.addLayer(layer); t.equal(style.removeLayer('background'), style); t.end(); @@ -684,7 +684,7 @@ test('Style#removeLayer', function(t) { t.throws(function () { style.removeLayer('background'); }, Error, /load/i); - style.on('styleload', function() { + style.on('style.load', function() { t.end(); }); }); @@ -698,7 +698,7 @@ test('Style#removeLayer', function(t) { t.end(); }); - style.on('styleload', function() { + style.on('style.load', function() { style.addLayer(layer); style.removeLayer('background'); style.update(); @@ -717,7 +717,7 @@ test('Style#removeLayer', function(t) { t.fail(); }); - style.on('styleload', function() { + style.on('style.load', function() { var layer = style._layers.background; style.removeLayer('background'); @@ -732,7 +732,7 @@ test('Style#removeLayer', function(t) { t.test('throws on non-existence', function(t) { var style = new Style(createStyleJSON()); - style.on('styleload', function() { + style.on('style.load', function() { t.throws(function () { style.removeLayer('background'); }, /There is no layer with this ID/); @@ -751,7 +751,7 @@ test('Style#removeLayer', function(t) { }] })); - style.on('styleload', function() { + style.on('style.load', function() { style.removeLayer('a'); t.deepEqual(style._order, ['b']); t.end(); @@ -769,7 +769,7 @@ test('Style#removeLayer', function(t) { }] })); - style.on('styleload', function() { + style.on('style.load', function() { style.removeLayer('a'); t.deepEqual(style.getLayer('a'), undefined); t.deepEqual(style.getLayer('b'), undefined); @@ -797,7 +797,7 @@ test('Style#setFilter', function(t) { t.test('sets filter', function(t) { var style = createStyle(); - style.on('styleload', function() { + style.on('style.load', function() { style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value[0].id, 'symbol'); @@ -814,7 +814,7 @@ test('Style#setFilter', function(t) { t.test('gets a clone of the filter', function(t) { var style = createStyle(); - style.on('styleload', function() { + style.on('style.load', function() { var filter1 = ['==', 'id', 1]; style.setFilter('symbol', filter1); var filter2 = style.getFilter('symbol'); @@ -831,7 +831,7 @@ test('Style#setFilter', function(t) { t.test('sets again mutated filter', function(t) { var style = createStyle(); - style.on('styleload', function() { + style.on('style.load', function() { var filter = ['==', 'id', 1]; style.setFilter('symbol', filter); style.update({}, {}); // flush pending operations @@ -851,7 +851,7 @@ test('Style#setFilter', function(t) { t.test('sets filter on parent', function(t) { var style = createStyle(); - style.on('styleload', function() { + style.on('style.load', function() { style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value.map(function(layer) { return layer.id; }), ['symbol']); @@ -876,7 +876,7 @@ test('Style#setFilter', function(t) { t.test('emits if invalid', function(t) { var style = createStyle(); - style.on('styleload', function() { + style.on('style.load', function() { style.on('error', function() { t.deepEqual(style.getLayer('symbol').serialize().filter, ['==', 'id', 0]); t.end(); @@ -909,7 +909,7 @@ test('Style#setLayerZoomRange', function(t) { t.test('sets zoom range', function(t) { var style = createStyle(); - style.on('styleload', function() { + style.on('style.load', function() { style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value.map(function(layer) { return layer.id; }), ['symbol']); @@ -925,7 +925,7 @@ test('Style#setLayerZoomRange', function(t) { t.test('sets zoom range on parent layer', function(t) { var style = createStyle(); - style.on('styleload', function() { + style.on('style.load', function() { style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value.map(function(layer) { return layer.id; }), ['symbol']); @@ -943,7 +943,7 @@ test('Style#setLayerZoomRange', function(t) { t.throws(function () { style.setLayerZoomRange('symbol', 5, 12); }, Error, /load/i); - style.on('styleload', function() { + style.on('style.load', function() { t.end(); }); }); @@ -1045,7 +1045,7 @@ test('Style#queryRenderedFeatures', function(t) { }] }); - style.on('styleload', function() { + style.on('style.load', function() { style._applyClasses([]); style._recalculate(0); @@ -1128,7 +1128,7 @@ test('Style defers expensive methods', function(t) { } })); - style.on('styleload', function() { + style.on('style.load', function() { style.update(); // spies to track defered methods @@ -1193,7 +1193,7 @@ test('Style#query*Features', function(t) { onError = sinon.spy(); style.on('error', onError) - .on('styleload', function() { + .on('style.load', function() { callback(); }); }); diff --git a/test/js/ui/map.test.js b/test/js/ui/map.test.js index 7029eeae127..e6c9ed372e6 100755 --- a/test/js/ui/map.test.js +++ b/test/js/ui/map.test.js @@ -134,18 +134,18 @@ test('Map', function(t) { function recordEvent(event) { events.push(event.type); } map.on('error', recordEvent); - map.on('sourceload', recordEvent); + map.on('source.load', recordEvent); map.on('data', recordEvent); map.on('dataloading', recordEvent); map.style.fire('error'); - map.style.fire('sourceload'); + map.style.fire('source.load'); map.style.fire('data'); map.style.fire('dataloading'); t.deepEqual(events, [ 'error', - 'sourceload', + 'source.load', 'data', 'dataloading', ]); @@ -171,7 +171,7 @@ test('Map', function(t) { t.equal(map.transform.zoom, 0.6983039737971012, 'map transform is constrained'); t.ok(map.transform.unmodified, 'map transform is not modified'); map.setStyle(createStyle()); - map.on('styleload', function () { + map.on('style.load', function () { t.deepEqual(fixedLngLat(map.transform.center), fixedLngLat({ lng: -73.9749, lat: 40.7736 })); t.equal(fixedNum(map.transform.zoom), 12.5); t.equal(fixedNum(map.transform.bearing), 29); @@ -184,7 +184,7 @@ test('Map', function(t) { var map = createMap({zoom: 10, center: [-77.0186, 38.8888]}); t.notOk(map.transform.unmodified, 'map transform is modified by options'); map.setStyle(createStyle()); - map.on('styleload', function () { + map.on('style.load', function () { t.deepEqual(fixedLngLat(map.transform.center), fixedLngLat({ lng: -77.0186, lat: 38.8888 })); t.equal(fixedNum(map.transform.zoom), 10); t.equal(fixedNum(map.transform.bearing), 0); @@ -200,7 +200,7 @@ test('Map', function(t) { map.setCenter([-77.0186, 38.8888]); t.notOk(map.transform.unmodified, 'map transform is modified via setters'); map.setStyle(createStyle()); - map.on('styleload', function () { + map.on('style.load', function () { t.deepEqual(fixedLngLat(map.transform.center), fixedLngLat({ lng: -77.0186, lat: 38.8888 })); t.equal(fixedNum(map.transform.zoom), 10); t.equal(fixedNum(map.transform.bearing), 0); @@ -667,7 +667,7 @@ test('Map', function(t) { } }); - map.on('styleload', function () { + map.on('style.load', function () { map.style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value.map(function(layer) { return layer.id; }), ['symbol']); @@ -707,7 +707,7 @@ test('Map', function(t) { } }); - map.on('styleload', function () { + map.on('style.load', function () { map.style.dispatcher.broadcast = function(key, value) { t.equal(key, 'update layers'); t.deepEqual(value.map(function(layer) { return layer.id; }), ['symbol']); @@ -752,7 +752,7 @@ test('Map', function(t) { } }); - map.once('styleload', function () { + map.once('style.load', function () { map.once('data', function (e) { if (e.dataType === 'style') { t.end(); @@ -779,7 +779,7 @@ test('Map', function(t) { } }); - map.on('styleload', function () { + map.on('style.load', function () { map.setLayoutProperty('background', 'visibility', 'visible'); t.deepEqual(map.getLayoutProperty('background', 'visibility'), 'visible'); t.end(); @@ -810,7 +810,7 @@ test('Map', function(t) { // Suppress errors because we're not loading tiles from a real URL. map.on('error', function() {}); - map.on('styleload', function () { + map.on('style.load', function () { map.setLayoutProperty('satellite', 'visibility', 'visible'); t.deepEqual(map.getLayoutProperty('satellite', 'visibility'), 'visible'); t.end(); @@ -844,7 +844,7 @@ test('Map', function(t) { } }); - map.on('styleload', function () { + map.on('style.load', function () { map.setLayoutProperty('shore', 'visibility', 'visible'); t.deepEqual(map.getLayoutProperty('shore', 'visibility'), 'visible'); t.end(); @@ -878,7 +878,7 @@ test('Map', function(t) { } }); - map.on('styleload', function () { + map.on('style.load', function () { map.setLayoutProperty('image', 'visibility', 'visible'); t.deepEqual(map.getLayoutProperty('image', 'visibility'), 'visible'); t.end(); @@ -901,7 +901,7 @@ test('Map', function(t) { } }); - map.on('styleload', function () { + map.on('style.load', function () { map.setPaintProperty('background', 'background-color', 'red'); t.deepEqual(map.getPaintProperty('background', 'background-color'), 'red'); t.end(); From 58e0a6bd408b787df45300a25f04635630b5e78a Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 26 Sep 2016 13:09:29 -0700 Subject: [PATCH 09/21] source.add & source.remove -> data --- js/style/style.js | 9 +++++---- js/ui/control/attribution.js | 1 - js/ui/map.js | 13 +------------ test/js/style/style.test.js | 14 ++++---------- 4 files changed, 10 insertions(+), 27 deletions(-) diff --git a/js/style/style.js b/js/style/style.js index 50a9f7195df..e1d56678861 100644 --- a/js/style/style.js +++ b/js/style/style.js @@ -22,8 +22,9 @@ var getWorkerPool = require('../global_worker_pool'); module.exports = Style; -function Style(stylesheet, animationLoop, options) { - this.animationLoop = animationLoop || new AnimationLoop(); +function Style(stylesheet, map, options) { + this.map = map; + this.animationLoop = (map && map.animationLoop) || new AnimationLoop(); this.dispatcher = new Dispatcher(getWorkerPool(), this); this.spriteAtlas = new SpriteAtlas(1024, 1024); this.lineAtlas = new LineAtlas(256, 512); @@ -338,7 +339,7 @@ Style.prototype = util.inherit(Evented, { source.style = this; source.setEventedParent(this, {source: source}); - this._updates.events.push(['source.add', {source: source}]); + if (source.onAdd) source.onAdd(this.map); this._updates.changed = true; return this; @@ -362,7 +363,7 @@ Style.prototype = util.inherit(Evented, { delete this._updates.sources[id]; source.setEventedParent(null); - this._updates.events.push(['source.remove', {source: source}]); + if (source.onRemove) source.onRemove(this.map); this._updates.changed = true; return this; diff --git a/js/ui/control/attribution.js b/js/ui/control/attribution.js index 799cb719ef1..a285ae91621 100644 --- a/js/ui/control/attribution.js +++ b/js/ui/control/attribution.js @@ -55,7 +55,6 @@ Attribution.prototype = util.inherit(Control, { this._update(); map.on('data', this._update.bind(this)); - map.on('source.remove', this._update.bind(this)); map.on('moveend', this._updateEditLink.bind(this)); return container; diff --git a/js/ui/map.js b/js/ui/map.js index 55869234390..92b991e5292 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -201,16 +201,6 @@ var Map = module.exports = function(options) { this._update(true); }); - this.on('source.add', function(event) { - var source = event.source; - if (source.onAdd) source.onAdd(this); - }); - - this.on('source.remove', function(event) { - var source = event.source; - if (source.onRemove) source.onRemove(this); - }); - this.on('data', this._update); }; @@ -626,7 +616,7 @@ util.extend(Map.prototype, /** @lends Map.prototype */{ } else if (style instanceof Style) { this.style = style; } else { - this.style = new Style(style, this.animationLoop); + this.style = new Style(style, this); } this.style.setEventedParent(this, {style: this.style}); @@ -680,7 +670,6 @@ util.extend(Map.prototype, /** @lends Map.prototype */{ * Removes a source from the map's style. * * @param {string} id The ID of the source to remove. - * @fires source.remove * @returns {Map} `this` */ removeSource: function(id) { diff --git a/test/js/style/style.test.js b/test/js/style/style.test.js index b9f05eccf24..7c3d73be2cd 100644 --- a/test/js/style/style.test.js +++ b/test/js/style/style.test.js @@ -324,13 +324,10 @@ test('Style#addSource', function(t) { }); }); - t.test('fires source.add', function(t) { + t.test('fires "data" event', function(t) { var style = new Style(createStyleJSON()), source = createSource(); - style.on('source.add', function(e) { - t.same(e.source.serialize(), source); - t.end(); - }); + style.once('data', t.end); style.on('style.load', function () { style.addSource('source-id', source); style.update(); @@ -419,13 +416,10 @@ test('Style#removeSource', function(t) { }); }); - t.test('fires source.remove', function(t) { + t.test('fires "data" event', function(t) { var style = new Style(createStyleJSON()), source = createSource(); - style.on('source.remove', function(e) { - t.same(e.source.serialize(), source); - t.end(); - }); + style.once('data', t.end); style.on('style.load', function () { style.addSource('source-id', source); style.removeSource('source-id'); From 4abeca4baf4523747ef94b4249a395223920b0fc Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 26 Sep 2016 13:16:25 -0700 Subject: [PATCH 10/21] layer.add & layer.remove -> data --- js/style/style.js | 3 --- js/ui/map.js | 2 -- test/js/style/style.test.js | 14 ++++---------- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/js/style/style.js b/js/style/style.js index e1d56678861..eddac83f2a9 100644 --- a/js/style/style.js +++ b/js/style/style.js @@ -384,7 +384,6 @@ Style.prototype = util.inherit(Evented, { * ID `before`, or appended if `before` is omitted. * @param {StyleLayer|Object} layer * @param {string=} before ID of an existing layer to insert before - * @fires layer.add * @returns {Style} `this` * @private */ @@ -410,7 +409,6 @@ Style.prototype = util.inherit(Evented, { if (layer.source) { this._updates.sources[layer.source] = true; } - this._updates.events.push(['layer.add', {layer: layer}]); return this.updateClasses(layer.id); }, @@ -443,7 +441,6 @@ Style.prototype = util.inherit(Evented, { this._order.splice(this._order.indexOf(id), 1); this._updates.allLayers = true; - this._updates.events.push(['layer.remove', {layer: layer}]); this._updates.changed = true; return this; diff --git a/js/ui/map.js b/js/ui/map.js index 92b991e5292..0238a45f14b 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -699,7 +699,6 @@ util.extend(Map.prototype, /** @lends Map.prototype */{ * [layer definition](https://www.mapbox.com/mapbox-gl-style-spec/#layers). * @param {string} [before] The ID of an existing layer to insert the new layer before. * If this argument is omitted, the layer will be appended to the end of the layers array. - * @fires layer.add * @returns {Map} `this` */ addLayer: function(layer, before) { @@ -716,7 +715,6 @@ util.extend(Map.prototype, /** @lends Map.prototype */{ * * @param {string} id The ID of the layer to remove. * @throws {Error} if no layer with the specified `id` exists. - * @fires layer.remove * @returns {Map} `this` */ removeLayer: function(id) { diff --git a/test/js/style/style.test.js b/test/js/style/style.test.js index 7c3d73be2cd..6e62d234db5 100644 --- a/test/js/style/style.test.js +++ b/test/js/style/style.test.js @@ -586,14 +586,11 @@ test('Style#addLayer', function(t) { }); }); - t.test('fires layer.add', function(t) { + t.test('fires "data" event', function(t) { var style = new Style(createStyleJSON()), layer = {id: 'background', type: 'background'}; - style.on('layer.add', function (e) { - t.equal(e.layer.id, 'background'); - t.end(); - }); + style.once('data', t.end); style.on('style.load', function() { style.addLayer(layer); @@ -683,14 +680,11 @@ test('Style#removeLayer', function(t) { }); }); - t.test('fires layer.remove', function(t) { + t.test('fires "data" event', function(t) { var style = new Style(createStyleJSON()), layer = {id: 'background', type: 'background'}; - style.on('layer.remove', function(e) { - t.equal(e.layer.id, 'background'); - t.end(); - }); + style.once('data', t.end); style.on('style.load', function() { style.addLayer(layer); From 04ddd4126cae94964eee948bb763d37dba6493ad Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 26 Sep 2016 13:22:48 -0700 Subject: [PATCH 11/21] Remove isDataRemoved flag --- js/source/source_cache.js | 2 +- test/js/source/source_cache.test.js | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/js/source/source_cache.js b/js/source/source_cache.js index fefec0a4523..b599982ab6c 100644 --- a/js/source/source_cache.js +++ b/js/source/source_cache.js @@ -427,7 +427,7 @@ SourceCache.prototype = util.inherit(Evented, { tile.uses--; delete this._tiles[id]; - this._source.fire('data', {tile: tile, dataType: 'tile', isDataRemoved: true}); + this._source.fire('data', {dataType: 'tile'}); if (tile.uses > 0) return; diff --git a/test/js/source/source_cache.test.js b/test/js/source/source_cache.test.js index ab1a1d0da77..6e0bacdec18 100644 --- a/test/js/source/source_cache.test.js +++ b/test/js/source/source_cache.test.js @@ -142,11 +142,8 @@ test('SourceCache#removeTile', function(t) { t.test('removes tile', function(t) { var coord = new TileCoord(0, 0, 0); var sourceCache = createSourceCache({}); - sourceCache.on('data', function (event) { - if (event.isDataRemoved) { - var tile = event.tile; - t.deepEqual(tile.coord, coord); - t.equal(tile.uses, 0); + sourceCache.once('data', function (event) { + if (event.dataType === 'tile') { t.end(); } }); From 7e60cc6ceb88f9e6b45c68d6417999ae144fdc35 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 26 Sep 2016 14:03:32 -0700 Subject: [PATCH 12/21] Add documentation for "data" event --- documentation.yml | 1 + js/ui/map.js | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/documentation.yml b/documentation.yml index 3692bff2c4d..7ef29969e7b 100644 --- a/documentation.yml +++ b/documentation.yml @@ -56,6 +56,7 @@ toc: - MapMouseEvent - MapTouchEvent - MapBoxZoomEvent + - MapDataEvent - name: Types description: | These are types used in the documentation above to describe arguments, diff --git a/js/ui/map.js b/js/ui/map.js index 0238a45f14b..77f5687fe91 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -1370,7 +1370,7 @@ function removeNode(node) { */ /** - * Fired if any error occurs. This is GL JS's primary error reporting + * Fired when an error occurs. This is GL JS's primary error reporting * mechanism. We use an event instead of `throw` to better accommodate * asyncronous operations. If no listeners are bound to the `error` event, the * error will be printed to the console. @@ -1380,3 +1380,31 @@ function removeNode(node) { * @instance * @property {{error: {message: string}}} data */ + +/** + * Fired when any map data (style, source, tile, etc) loads or changes. See + * [`MapDataEvent`](#MapDataEvent) for more information. + * + * @event data + * @memberof Map + * @instance + * @property {MapDataEvent} data + */ + + /** + * A `MapDataEvent` object is attached to the [`Map#data`](#Map.event:data) event. + * The `Map#data` event is fired when any map data loads or changes. The types + * of map data are: + * + * - `'GeoJSON'`: [GeoJSON](http://geojson.org/) data associated with a `geojson` source. + * - `'TileJSON'`: [TileJSON](https://github.com/mapbox/tilejson-spec) metadata associated with a `vector` or `raster` source. + * - `'style'`: The [style](https://www.mapbox.com/mapbox-gl-style-spec/) used by the map + * - `'sprite'`: The icons and patterns used by the style + * - `'image'`: A `image` source's image and coordinates + * - `'video'`: A `video` source's video and coordinates + * - `'tile'`: A vector or raster tile + * + * @typedef {Object} MapDataEvent + * @property {string} type The event type. + * @property {string} dataType The type of data that has changed. One of `'geoJSON'`, `'tileJSON'`, `'style'`, `'sprite'`, `'image'`, `'video'`, or `'tile'`. + */ From 56a1efc3f7ceb75e49eee1c814056c69de685490 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 26 Sep 2016 14:45:37 -0700 Subject: [PATCH 13/21] Fix setDataPerf benchmark utility --- bench/lib/set_data_perf.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bench/lib/set_data_perf.js b/bench/lib/set_data_perf.js index ffb9925cafa..41472456a43 100644 --- a/bench/lib/set_data_perf.js +++ b/bench/lib/set_data_perf.js @@ -7,7 +7,9 @@ module.exports = function(source, numCalls, geojson, cb) { var startTime = null; var times = []; - source.on('tile.load', function tileCounter() { + source.on('data', function tileCounter(event) { + if (event.dataType !== 'tile') return; + tileCount++; if (tileCount === NUM_TILES) { tileCount = 0; @@ -20,7 +22,7 @@ module.exports = function(source, numCalls, geojson, cb) { var avgTileTime = times.reduce(function (v, t) { return v + t; }, 0) / times.length; - source.off('tile.load', tileCounter); + source.off('data', tileCounter); cb(null, avgTileTime); } } From 506014de553fd52ba3bfbfed49578a0dd933b698 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 26 Sep 2016 14:55:45 -0700 Subject: [PATCH 14/21] Minor doc fix --- js/ui/map.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/ui/map.js b/js/ui/map.js index 77f5687fe91..bbc7c497141 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -1396,8 +1396,8 @@ function removeNode(node) { * The `Map#data` event is fired when any map data loads or changes. The types * of map data are: * - * - `'GeoJSON'`: [GeoJSON](http://geojson.org/) data associated with a `geojson` source. - * - `'TileJSON'`: [TileJSON](https://github.com/mapbox/tilejson-spec) metadata associated with a `vector` or `raster` source. + * - `'geoJSON'`: [GeoJSON](http://geojson.org/) data associated with a `geojson` source. + * - `'tileJSON'`: [TileJSON](https://github.com/mapbox/tilejson-spec) metadata associated with a `vector` or `raster` source. * - `'style'`: The [style](https://www.mapbox.com/mapbox-gl-style-spec/) used by the map * - `'sprite'`: The icons and patterns used by the style * - `'image'`: A `image` source's image and coordinates From ef4f8b735f5b20b2a0c01040fe2b1a266c993033 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Tue, 27 Sep 2016 11:32:29 -0700 Subject: [PATCH 15/21] Add docs for dataloading event --- js/ui/map.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/js/ui/map.js b/js/ui/map.js index bbc7c497141..14e12215b8b 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -1392,9 +1392,20 @@ function removeNode(node) { */ /** - * A `MapDataEvent` object is attached to the [`Map#data`](#Map.event:data) event. - * The `Map#data` event is fired when any map data loads or changes. The types - * of map data are: + * Fired when any map data (style, source, tile, etc) begins loading or + * changing asyncronously. All `dataloading` events are followed by a `data` + * or `error` event. See [`MapDataEvent`](#MapDataEvent) for more information. + * + * @event dataloading + * @memberof Map + * @instance + * @property {MapDataEvent} data + */ + + /** + * A `MapDataEvent` object is emitted with the [`Map#data`](#Map.event:data) + * and [`Map#data`](#Map.event:dataloading) events. Possible values for + * `dataType`s are: * * - `'geoJSON'`: [GeoJSON](http://geojson.org/) data associated with a `geojson` source. * - `'tileJSON'`: [TileJSON](https://github.com/mapbox/tilejson-spec) metadata associated with a `vector` or `raster` source. From 8e9c10fc2fe1570b1a77d8f07c5745e238a44941 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Tue, 27 Sep 2016 11:56:58 -0700 Subject: [PATCH 16/21] merge 'sprite' and 'style' into 'style' --- js/style/image_sprite.js | 4 ++-- js/ui/map.js | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/js/style/image_sprite.js b/js/style/image_sprite.js index ef366ca5846..5895d2523b6 100644 --- a/js/style/image_sprite.js +++ b/js/style/image_sprite.js @@ -20,7 +20,7 @@ function ImageSprite(base) { } this.data = data; - if (this.img) this.fire('data', {dataType: 'sprite'}); + if (this.img) this.fire('data', {dataType: 'style'}); }.bind(this)); ajax.getImage(normalizeURL(base, format, '.png'), function(err, img) { @@ -41,7 +41,7 @@ function ImageSprite(base) { } this.img = img; - if (this.data) this.fire('data', {dataType: 'sprite'}); + if (this.data) this.fire('data', {dataType: 'style'}); }.bind(this)); } diff --git a/js/ui/map.js b/js/ui/map.js index 14e12215b8b..58e374297d6 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -1407,15 +1407,11 @@ function removeNode(node) { * and [`Map#data`](#Map.event:dataloading) events. Possible values for * `dataType`s are: * - * - `'geoJSON'`: [GeoJSON](http://geojson.org/) data associated with a `geojson` source. - * - `'tileJSON'`: [TileJSON](https://github.com/mapbox/tilejson-spec) metadata associated with a `vector` or `raster` source. + * - `'source'`: The non-tile data associated with any source * - `'style'`: The [style](https://www.mapbox.com/mapbox-gl-style-spec/) used by the map - * - `'sprite'`: The icons and patterns used by the style - * - `'image'`: A `image` source's image and coordinates - * - `'video'`: A `video` source's video and coordinates * - `'tile'`: A vector or raster tile * * @typedef {Object} MapDataEvent * @property {string} type The event type. - * @property {string} dataType The type of data that has changed. One of `'geoJSON'`, `'tileJSON'`, `'style'`, `'sprite'`, `'image'`, `'video'`, or `'tile'`. + * @property {string} dataType The type of data that has changed. One of `'source'`, `'style'`, or `'tile'`. */ From 6d71d523ac1cc07e34a0d4cd8107b8f460790c5e Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Tue, 27 Sep 2016 12:06:25 -0700 Subject: [PATCH 17/21] merge all several types into 'source' --- js/source/geojson_source.js | 4 ++-- js/source/image_source.js | 4 ++-- js/source/raster_tile_source.js | 2 +- js/source/source_cache.js | 2 +- js/source/vector_tile_source.js | 2 +- js/source/video_source.js | 4 ++-- test/js/source/source_cache.test.js | 4 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/js/source/geojson_source.js b/js/source/geojson_source.js index d3bad3ba708..50fc3a0d5eb 100644 --- a/js/source/geojson_source.js +++ b/js/source/geojson_source.js @@ -88,7 +88,7 @@ function GeoJSONSource(id, options, dispatcher) { this.fire('error', {error: err}); return; } - this.fire('data', {dataType: 'geojson'}); + this.fire('data', {dataType: 'source'}); this.fire('source.load'); }.bind(this)); } @@ -120,7 +120,7 @@ GeoJSONSource.prototype = util.inherit(Evented, /** @lends GeoJSONSource.prototy if (err) { return this.fire('error', { error: err }); } - this.fire('data', {dataType: 'geoJSON'}); + this.fire('data', {dataType: 'source'}); }.bind(this)); return this; diff --git a/js/source/image_source.js b/js/source/image_source.js index a7bf7a5b544..719f4bff7d0 100644 --- a/js/source/image_source.js +++ b/js/source/image_source.js @@ -53,7 +53,7 @@ function ImageSource(id, options, dispatcher) { this.image = image; this._loaded = true; - this.fire('data', {type: 'image'}); + this.fire('data', {dataType: 'source'}); this.fire('source.load'); if (this.map) { @@ -107,7 +107,7 @@ ImageSource.prototype = util.inherit(Evented, /** @lends ImageSource.prototype * Math.round((zoomedCoord.row - centerCoord.row) * EXTENT)); }); - this.fire('data', {dataType: 'image'}); + this.fire('data', {dataType: 'source'}); return this; }, diff --git a/js/source/raster_tile_source.js b/js/source/raster_tile_source.js index af42eee5429..1ace928b24f 100644 --- a/js/source/raster_tile_source.js +++ b/js/source/raster_tile_source.js @@ -17,7 +17,7 @@ function RasterTileSource(id, options, dispatcher) { return this.fire('error', err); } util.extend(this, tileJSON); - this.fire('data', {type: 'tileJSON'}); + this.fire('data', {dataType: 'source'}); this.fire('source.load'); }.bind(this)); } diff --git a/js/source/source_cache.js b/js/source/source_cache.js index b599982ab6c..bd52e58ed31 100644 --- a/js/source/source_cache.js +++ b/js/source/source_cache.js @@ -51,7 +51,7 @@ function SourceCache(id, options, dispatcher) { }); this.on('data', function(event) { - if (this._sourceLoaded && ['image', 'video', 'geoJSON'].indexOf(event.dataType) !== -1) { + if (this._sourceLoaded && event.dataType === 'source') { this.reload(); if (this.transform) { this.update(this.transform, this.map && this.map.style.rasterFadeDuration); diff --git a/js/source/vector_tile_source.js b/js/source/vector_tile_source.js index b178e5fad69..c5d34091076 100644 --- a/js/source/vector_tile_source.js +++ b/js/source/vector_tile_source.js @@ -23,7 +23,7 @@ function VectorTileSource(id, options, dispatcher) { return; } util.extend(this, tileJSON); - this.fire('data', {dataType: 'tileJSON'}); + this.fire('data', {dataType: 'source'}); this.fire('source.load'); }.bind(this)); } diff --git a/js/source/video_source.js b/js/source/video_source.js index e6422257e1a..b7d970e081f 100644 --- a/js/source/video_source.js +++ b/js/source/video_source.js @@ -73,7 +73,7 @@ function VideoSource(id, options) { this.setCoordinates(options.coordinates); } - this.fire('data', {dataType: 'video'}); + this.fire('data', {dataType: 'source'}); this.fire('source.load'); }.bind(this)); } @@ -136,7 +136,7 @@ VideoSource.prototype = util.inherit(Evented, /** @lends VideoSource.prototype * Math.round((zoomedCoord.row - centerCoord.row) * EXTENT)); }); - this.fire('data', {dataType: 'video'}); + this.fire('data', {dataType: 'source'}); return this; }, diff --git a/test/js/source/source_cache.test.js b/test/js/source/source_cache.test.js index 6e0bacdec18..1fd63028f47 100644 --- a/test/js/source/source_cache.test.js +++ b/test/js/source/source_cache.test.js @@ -234,7 +234,7 @@ test('SourceCache / Source lifecycle', function (t) { }); }); - t.test('reloads tiles after a geoJSON data event', function (t) { + t.test('reloads tiles after a "source" data event', function (t) { var transform = new Transform(); transform.resize(511, 511); transform.zoom = 0; @@ -252,7 +252,7 @@ test('SourceCache / Source lifecycle', function (t) { sourceCache.on('source.load', function () { sourceCache.update(transform); - sourceCache.getSource().fire('data', {dataType: 'geoJSON'}); + sourceCache.getSource().fire('data', {dataType: 'source'}); }); }); From 1ab2e442568aca267cc1271d34ae1f4f28753199 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Tue, 27 Sep 2016 12:58:22 -0700 Subject: [PATCH 18/21] Refactor "set data perf" benchmark utility --- bench/benchmarks/geojson_setdata_large.js | 3 +- bench/benchmarks/geojson_setdata_small.js | 4 +-- bench/lib/set_data_perf.js | 38 ++++++++++------------- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/bench/benchmarks/geojson_setdata_large.js b/bench/benchmarks/geojson_setdata_large.js index a55bfd39930..2cf446f12e1 100644 --- a/bench/benchmarks/geojson_setdata_large.js +++ b/bench/benchmarks/geojson_setdata_large.js @@ -30,9 +30,8 @@ module.exports = function() { map.on('load', function() { map = setupGeoJSONMap(map); - var source = map.getSource('geojson'); - setDataPerf(source, 50, data, function(err, ms) { + setDataPerf(map.style.sources['geojson'], data, function(err, ms) { if (err) return evented.fire('error', {error: err}); map.remove(); evented.fire('end', {message: formatNumber(ms) + ' ms', score: ms}); diff --git a/bench/benchmarks/geojson_setdata_small.js b/bench/benchmarks/geojson_setdata_small.js index 19c1a4c24db..d63c549b5d2 100644 --- a/bench/benchmarks/geojson_setdata_small.js +++ b/bench/benchmarks/geojson_setdata_small.js @@ -33,9 +33,7 @@ module.exports = function() { map.on('load', function() { map = setupGeoJSONMap(map); - var source = map.getSource('geojson'); - - setDataPerf(source, 50, featureCollection, function(err, ms) { + setDataPerf(map.style.sources['geojson'], featureCollection, function(err, ms) { map.remove(); if (err) return evented.fire('error', {error: err}); evented.fire('end', {message: formatNumber(ms) + ' ms', score: ms}); diff --git a/bench/lib/set_data_perf.js b/bench/lib/set_data_perf.js index 41472456a43..ad3dde0a674 100644 --- a/bench/lib/set_data_perf.js +++ b/bench/lib/set_data_perf.js @@ -1,33 +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('data', function tileCounter(event) { - if (event.dataType !== 'tile') return; + var samples = []; - tileCount++; - if (tileCount === NUM_TILES) { - tileCount = 0; - times.push(performance.now() - startTime); - - 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('data', 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; +} From b7bd4fef24e31e4425f5cd4afc6c92a847cad08a Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Tue, 27 Sep 2016 13:13:40 -0700 Subject: [PATCH 19/21] Ensure "Map#_update(true)" is only called after style mutations --- js/ui/map.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/js/ui/map.js b/js/ui/map.js index 58e374297d6..fcf683166ad 100755 --- a/js/ui/map.js +++ b/js/ui/map.js @@ -197,11 +197,13 @@ var Map = module.exports = function(options) { this.style.update(this._classes, {transition: false}); }); - this.on('data', function() { - this._update(true); + this.on('data', function(event) { + if (event.dataType === 'style') { + this._update(true); + } else { + this._update(); + } }); - - this.on('data', this._update); }; util.extend(Map.prototype, Evented); From 87a5f7b74c38468d1bab904a9e7b382d86782b91 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Thu, 29 Sep 2016 11:51:04 -0700 Subject: [PATCH 20/21] Ensure Attribution#_update is only called for "data[dataType=source]" events --- js/ui/control/attribution.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/js/ui/control/attribution.js b/js/ui/control/attribution.js index a285ae91621..f2a6967ab58 100644 --- a/js/ui/control/attribution.js +++ b/js/ui/control/attribution.js @@ -54,7 +54,11 @@ Attribution.prototype = util.inherit(Control, { container = this._container = DOM.create('div', className, map.getContainer()); this._update(); - map.on('data', this._update.bind(this)); + map.on('data', function(event) { + if (event.dataType === 'source') { + this._update(); + } + }.bind(this)); map.on('moveend', this._updateEditLink.bind(this)); return container; From 5f5085eed15b5c652ca5468a836baf6c7a60b4a1 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Thu, 29 Sep 2016 11:51:24 -0700 Subject: [PATCH 21/21] Attach Source, not SourceCache, to data events --- js/style/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/style/style.js b/js/style/style.js index eddac83f2a9..a6c941d0349 100644 --- a/js/style/style.js +++ b/js/style/style.js @@ -337,7 +337,7 @@ Style.prototype = util.inherit(Evented, { source = new SourceCache(id, source, this.dispatcher); this.sources[id] = source; source.style = this; - source.setEventedParent(this, {source: source}); + source.setEventedParent(this, {source: source.getSource()}); if (source.onAdd) source.onAdd(this.map); this._updates.changed = true;