From 35775b21f3ee0b07e0c3ddc41a9e297402d7addb Mon Sep 17 00:00:00 2001 From: elenatorro Date: Tue, 26 Jun 2018 16:55:48 +0200 Subject: [PATCH 01/12] Load map depending on the data type of the event --- src/api/layer.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/api/layer.js b/src/api/layer.js index e08368cca..cc9e58ddf 100644 --- a/src/api/layer.js +++ b/src/api/layer.js @@ -9,6 +9,11 @@ import CartoValidationError from './error-handling/carto-validation-error'; import { cubic } from '../core/viz/functions'; import RenderLayer from '../core/renderLayer'; +const mapboxDataType = Object.freeze({ + STYLE: 'style', + SOURCE: 'source' +}); + /** * * LayerEvent objects are fired by {@link carto.Layer|Layer} objects. @@ -376,12 +381,25 @@ export default class Layer { } _addToMGLMap(map, beforeLayerID) { - if (map.isStyleLoaded()) { - this._onMapLoaded(map, beforeLayerID); - } else { - map.on('load', () => { - this._onMapLoaded(map, beforeLayerID); - }); + map.once('data', (event) => { + this._onMapData(event.dataType, map, beforeLayerID); + }); + } + + _onMapData(type, map, beforeLayerID) { + switch (type) { + case mapboxDataType.STYLE: + if (map.isStyleLoaded()) { + this._onMapLoaded(map, beforeLayerID); + } + break; + case mapboxDataType.SOURCE: + if (map.areTilesLoaded()) { + this._onMapLoaded(map, beforeLayerID); + } + break; + default: + throw new Error(`Unkown data type: ${type}`); } } From 2a6bcb716e32bde285da5c47920739ea2b4d46a0 Mon Sep 17 00:00:00 2001 From: elenatorro Date: Tue, 26 Jun 2018 17:10:36 +0200 Subject: [PATCH 02/12] Fix specs --- src/api/layer.js | 6 ++--- test/unit/api/layer.test.js | 44 ++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/api/layer.js b/src/api/layer.js index cc9e58ddf..a43bab70a 100644 --- a/src/api/layer.js +++ b/src/api/layer.js @@ -386,8 +386,8 @@ export default class Layer { }); } - _onMapData(type, map, beforeLayerID) { - switch (type) { + _onMapData(dataType, map, beforeLayerID) { + switch (dataType) { case mapboxDataType.STYLE: if (map.isStyleLoaded()) { this._onMapLoaded(map, beforeLayerID); @@ -399,7 +399,7 @@ export default class Layer { } break; default: - throw new Error(`Unkown data type: ${type}`); + throw new Error(`Unkown data type: ${dataType}`); } } diff --git a/test/unit/api/layer.test.js b/test/unit/api/layer.test.js index 25489184f..596540733 100644 --- a/test/unit/api/layer.test.js +++ b/test/unit/api/layer.test.js @@ -132,6 +132,21 @@ describe('api/layer', () => { describe('.addTo', () => { describe('._addToMGLMap', () => { let layer; + let eventId = 'data'; + const event = { + dataType: 'style' + }; + + const mapMock = { + isStyleLoaded: () => true, + areTilesLoaded: () => false, + once: (id, callback) => { + if (id === eventId) { + callback(event); + } + } + }; + beforeEach(() => { layer = new Layer('layer0', source, viz); layer._onMapLoaded = () => { }; @@ -139,39 +154,24 @@ describe('api/layer', () => { }); it('should call onMapLoaded when the map is loaded', () => { - const mapMock = { isStyleLoaded: () => true }; layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).toHaveBeenCalledWith(mapMock, undefined); + expect(layer._onMapLoaded).toHaveBeenCalled(); }); it('should not call onMapLoaded when the map is not loaded', () => { - const mapMock = { isStyleLoaded: () => false, on: () => { } }; + mapMock.isStyleLoaded = () => false; layer._addToMGLMap(mapMock); expect(layer._onMapLoaded).not.toHaveBeenCalled(); }); - it('should call onMapLoaded when the map `load` event is triggered', () => { - const mapMock = { - isStyleLoaded: () => false, - on: (id, callback) => { - if (id === 'load') { - callback(); - } - } - }; + it('should call onMapLoaded when the map `data` event is triggered', () => { + mapMock.isStyleLoaded = () => true; layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).toHaveBeenCalledWith(mapMock, undefined); + expect(layer._onMapLoaded).toHaveBeenCalled(); }); - it('should not call onMapLoaded when other the map event is triggered', () => { - const mapMock = { - isStyleLoaded: () => false, - on: (id, callback) => { - if (id === 'other') { - callback(); - } - } - }; + it('should not call onMapLoaded when other map event is triggered', () => { + eventId = 'other'; layer._addToMGLMap(mapMock); expect(layer._onMapLoaded).not.toHaveBeenCalled(); }); From 2f9a9da45a8b89e63cdf677b3991be0011bf0472 Mon Sep 17 00:00:00 2001 From: elenatorro Date: Wed, 27 Jun 2018 11:38:51 +0200 Subject: [PATCH 03/12] Add specs to test when dataType is source --- test/unit/api/layer.test.js | 131 +++++++++++++++++++++++++----------- 1 file changed, 92 insertions(+), 39 deletions(-) diff --git a/test/unit/api/layer.test.js b/test/unit/api/layer.test.js index 596540733..6a1765c37 100644 --- a/test/unit/api/layer.test.js +++ b/test/unit/api/layer.test.js @@ -131,51 +131,104 @@ describe('api/layer', () => { describe('.addTo', () => { describe('._addToMGLMap', () => { - let layer; - let eventId = 'data'; - const event = { - dataType: 'style' - }; - - const mapMock = { - isStyleLoaded: () => true, - areTilesLoaded: () => false, - once: (id, callback) => { - if (id === eventId) { - callback(event); + describe('and dataType is style', () => { + + let layer; + let eventId = 'data'; + const event = { + dataType: 'style' + }; + + const mapMock = { + isStyleLoaded: jasmine.createSpy('isStyleLoaded').and.returnValue(true), + areTilesLoaded: jasmine.createSpy('areTilesLoaded').and.returnValue(true), + once: (id, callback) => { + if (id === eventId) { + callback(event); + } } - } - }; - - beforeEach(() => { - layer = new Layer('layer0', source, viz); - layer._onMapLoaded = () => { }; - spyOn(layer, '_onMapLoaded'); - }); - - it('should call onMapLoaded when the map is loaded', () => { - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).toHaveBeenCalled(); + }; + + beforeEach(() => { + layer = new Layer('layer0', source, viz); + layer._onMapLoaded = () => { }; + spyOn(layer, '_onMapLoaded'); + }); + + it('should call onMapLoaded when the map is loaded', () => { + layer._addToMGLMap(mapMock); + expect(layer._onMapLoaded).toHaveBeenCalled(); + }); + + it('should not call onMapLoaded when the map is not loaded', () => { + mapMock.isStyleLoaded = jasmine.createSpy('isStyleLoaded').and.returnValue(false), + layer._addToMGLMap(mapMock); + expect(layer._onMapLoaded).not.toHaveBeenCalled(); + }); + + it('should call onMapLoaded when the map `data` event is triggered', () => { + mapMock.isStyleLoaded = jasmine.createSpy('isStyleLoaded').and.returnValue(true), + layer._addToMGLMap(mapMock); + expect(layer._onMapLoaded).toHaveBeenCalled(); + }); + + it('should not call onMapLoaded when other map event is triggered', () => { + eventId = 'other'; + layer._addToMGLMap(mapMock); + expect(layer._onMapLoaded).not.toHaveBeenCalled(); + }); }); - it('should not call onMapLoaded when the map is not loaded', () => { - mapMock.isStyleLoaded = () => false; - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).not.toHaveBeenCalled(); + describe('and dataType is source', () => { + + let layer; + let eventId = 'data'; + const event = { + dataType: 'source' + }; + + const mapMock = { + isStyleLoaded: jasmine.createSpy('isStyleLoaded').and.returnValue(false), + areTilesLoaded: jasmine.createSpy('areTilesLoaded').and.returnValue(true), + once: (id, callback) => { + if (id === eventId) { + callback(event); + } + } + }; + + beforeEach(() => { + layer = new Layer('layer0', source, viz); + layer._onMapLoaded = () => { }; + spyOn(layer, '_onMapLoaded'); + }); + + it('should call onMapLoaded when the map is loaded', () => { + layer._addToMGLMap(mapMock); + expect(layer._onMapLoaded).toHaveBeenCalled(); + }); + + it('should not call onMapLoaded when the map is not loaded', () => { + mapMock.areTilesLoaded = jasmine.createSpy('areTilesLoaded').and.returnValue(false), + layer._addToMGLMap(mapMock); + expect(layer._onMapLoaded).not.toHaveBeenCalled(); + }); + + it('should call onMapLoaded when the map `data` event is triggered', () => { + mapMock.areTilesLoaded = jasmine.createSpy('areTilesLoaded').and.returnValue(true), + layer._addToMGLMap(mapMock); + expect(layer._onMapLoaded).toHaveBeenCalled(); + }); + + it('should not call onMapLoaded when other map event is triggered', () => { + eventId = 'other'; + layer._addToMGLMap(mapMock); + expect(layer._onMapLoaded).not.toHaveBeenCalled(); + }); }); + }); - it('should call onMapLoaded when the map `data` event is triggered', () => { - mapMock.isStyleLoaded = () => true; - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).toHaveBeenCalled(); - }); - it('should not call onMapLoaded when other map event is triggered', () => { - eventId = 'other'; - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).not.toHaveBeenCalled(); - }); - }); }); describe('.getFeaturesAtPosition', () => { From 5e21827e9e0ba5d0ee5a8b03d4b569e4ccf8c60c Mon Sep 17 00:00:00 2001 From: elenatorro Date: Wed, 27 Jun 2018 16:23:46 +0200 Subject: [PATCH 04/12] Listen both load and sourcedata event --- src/api/layer.js | 30 ++++---- test/unit/api/layer.test.js | 141 +++++++++++++----------------------- 2 files changed, 62 insertions(+), 109 deletions(-) diff --git a/src/api/layer.js b/src/api/layer.js index a43bab70a..8834e7c24 100644 --- a/src/api/layer.js +++ b/src/api/layer.js @@ -381,25 +381,21 @@ export default class Layer { } _addToMGLMap(map, beforeLayerID) { - map.once('data', (event) => { - this._onMapData(event.dataType, map, beforeLayerID); - }); + this._isSourceLoaded = false; + + map.on('sourcedata', this._onMapSourcedata); + map.on('load', this._onMapLoad.bind(this, map, beforeLayerID)); } - _onMapData(dataType, map, beforeLayerID) { - switch (dataType) { - case mapboxDataType.STYLE: - if (map.isStyleLoaded()) { - this._onMapLoaded(map, beforeLayerID); - } - break; - case mapboxDataType.SOURCE: - if (map.areTilesLoaded()) { - this._onMapLoaded(map, beforeLayerID); - } - break; - default: - throw new Error(`Unkown data type: ${dataType}`); + _onMapSourcedata(event) { + this._isSourceLoaded = event.isSourceLoaded; + } + + _onMapLoad(map, beforeLayerID) { + if (map.isStyleLoaded() || this._isSourceLoaded) { + map.off('sourcedata', this._onMapSourcedata); + map.off('load', this._onMapLoad); + this._onMapLoaded(map, beforeLayerID); } } diff --git a/test/unit/api/layer.test.js b/test/unit/api/layer.test.js index 6a1765c37..96af94cb4 100644 --- a/test/unit/api/layer.test.js +++ b/test/unit/api/layer.test.js @@ -130,105 +130,62 @@ describe('api/layer', () => { }); describe('.addTo', () => { - describe('._addToMGLMap', () => { - describe('and dataType is style', () => { + fdescribe('._addToMGLMap', () => { + let layer; - let layer; - let eventId = 'data'; - const event = { - dataType: 'style' - }; - - const mapMock = { - isStyleLoaded: jasmine.createSpy('isStyleLoaded').and.returnValue(true), - areTilesLoaded: jasmine.createSpy('areTilesLoaded').and.returnValue(true), - once: (id, callback) => { - if (id === eventId) { - callback(event); - } + const sourcedataEvent = { + isSourceLoaded: false + }; + + const loadEvent = {}; + + const mapMock = { + isStyleLoaded: jasmine.createSpy('isStyleLoaded').and.returnValue(true), + on: (id, callback) => { + if (id === 'load') { + callback.call(layer, loadEvent); } - }; - - beforeEach(() => { - layer = new Layer('layer0', source, viz); - layer._onMapLoaded = () => { }; - spyOn(layer, '_onMapLoaded'); - }); - - it('should call onMapLoaded when the map is loaded', () => { - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).toHaveBeenCalled(); - }); - - it('should not call onMapLoaded when the map is not loaded', () => { - mapMock.isStyleLoaded = jasmine.createSpy('isStyleLoaded').and.returnValue(false), - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).not.toHaveBeenCalled(); - }); - - it('should call onMapLoaded when the map `data` event is triggered', () => { - mapMock.isStyleLoaded = jasmine.createSpy('isStyleLoaded').and.returnValue(true), - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).toHaveBeenCalled(); - }); - - it('should not call onMapLoaded when other map event is triggered', () => { - eventId = 'other'; - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).not.toHaveBeenCalled(); - }); - }); - describe('and dataType is source', () => { - - let layer; - let eventId = 'data'; - const event = { - dataType: 'source' - }; - - const mapMock = { - isStyleLoaded: jasmine.createSpy('isStyleLoaded').and.returnValue(false), - areTilesLoaded: jasmine.createSpy('areTilesLoaded').and.returnValue(true), - once: (id, callback) => { - if (id === eventId) { - callback(event); - } + if (id === 'sourcedata') { + callback.call(layer, sourcedataEvent); } - }; - - beforeEach(() => { - layer = new Layer('layer0', source, viz); - layer._onMapLoaded = () => { }; - spyOn(layer, '_onMapLoaded'); - }); - - it('should call onMapLoaded when the map is loaded', () => { - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).toHaveBeenCalled(); - }); - - it('should not call onMapLoaded when the map is not loaded', () => { - mapMock.areTilesLoaded = jasmine.createSpy('areTilesLoaded').and.returnValue(false), - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).not.toHaveBeenCalled(); - }); - - it('should call onMapLoaded when the map `data` event is triggered', () => { - mapMock.areTilesLoaded = jasmine.createSpy('areTilesLoaded').and.returnValue(true), - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).toHaveBeenCalled(); - }); - - it('should not call onMapLoaded when other map event is triggered', () => { - eventId = 'other'; - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).not.toHaveBeenCalled(); - }); + }, + + off: () => {} + }; + + beforeEach(() => { + layer = new Layer('layer0', source, viz); + layer._onMapLoaded = () => {}; + spyOn(layer, '_onMapLoaded'); + }); + + it('should call onMapLoaded when the map is loaded', () => { + layer._addToMGLMap(mapMock); + expect(layer._onMapLoaded).toHaveBeenCalled(); + }); + + it('should not call onMapLoaded when the map style and source are not loaded', () => { + sourcedataEvent.isSourceLoaded = false; + mapMock.isStyleLoaded = jasmine.createSpy('isStyleLoaded').and.returnValue(false), + layer._addToMGLMap(mapMock); + expect(layer._onMapLoaded).not.toHaveBeenCalled(); }); - }); + it('should call onMapLoaded when the style is loaded but the sourcedata is not', () => { + sourcedataEvent.isSourceLoaded = false; + mapMock.isStyleLoaded = jasmine.createSpy('isStyleLoaded').and.returnValue(true), + layer._addToMGLMap(mapMock); + expect(layer._onMapLoaded).toHaveBeenCalled(); + }); + it('should call onMapLoaded when the style is not loaded and the sourcedata is', () => { + sourcedataEvent.isSourceLoaded = true; + mapMock.isStyleLoaded = jasmine.createSpy('isStyleLoaded').and.returnValue(false), + layer._addToMGLMap(mapMock); + expect(layer._onMapLoaded).toHaveBeenCalled(); + }); + }); }); describe('.getFeaturesAtPosition', () => { From d22c8423d7ce7f9cdafd55e7e74acb23f4531190 Mon Sep 17 00:00:00 2001 From: elenatorro Date: Wed, 27 Jun 2018 16:28:48 +0200 Subject: [PATCH 05/12] Fix typo --- test/unit/api/layer.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/api/layer.test.js b/test/unit/api/layer.test.js index 96af94cb4..76ab3b15c 100644 --- a/test/unit/api/layer.test.js +++ b/test/unit/api/layer.test.js @@ -130,7 +130,7 @@ describe('api/layer', () => { }); describe('.addTo', () => { - fdescribe('._addToMGLMap', () => { + describe('._addToMGLMap', () => { let layer; const sourcedataEvent = { From 9ec494d5452bda9298a416ca29a20651f4b1e4d5 Mon Sep 17 00:00:00 2001 From: elenatorro Date: Wed, 27 Jun 2018 16:30:51 +0200 Subject: [PATCH 06/12] Remove unused variable --- src/api/layer.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/api/layer.js b/src/api/layer.js index 8834e7c24..1469b00da 100644 --- a/src/api/layer.js +++ b/src/api/layer.js @@ -9,11 +9,6 @@ import CartoValidationError from './error-handling/carto-validation-error'; import { cubic } from '../core/viz/functions'; import RenderLayer from '../core/renderLayer'; -const mapboxDataType = Object.freeze({ - STYLE: 'style', - SOURCE: 'source' -}); - /** * * LayerEvent objects are fired by {@link carto.Layer|Layer} objects. From 462dc1f7e5a04db6dd3d1dee4423ac212e3a536c Mon Sep 17 00:00:00 2001 From: elenatorro Date: Thu, 28 Jun 2018 17:02:34 +0200 Subject: [PATCH 07/12] Revert changes and use map._loaded to add a layer --- src/api/layer.js | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/api/layer.js b/src/api/layer.js index 1469b00da..733203f47 100644 --- a/src/api/layer.js +++ b/src/api/layer.js @@ -376,21 +376,12 @@ export default class Layer { } _addToMGLMap(map, beforeLayerID) { - this._isSourceLoaded = false; - - map.on('sourcedata', this._onMapSourcedata); - map.on('load', this._onMapLoad.bind(this, map, beforeLayerID)); - } - - _onMapSourcedata(event) { - this._isSourceLoaded = event.isSourceLoaded; - } - - _onMapLoad(map, beforeLayerID) { - if (map.isStyleLoaded() || this._isSourceLoaded) { - map.off('sourcedata', this._onMapSourcedata); - map.off('load', this._onMapLoad); + if (map._loaded) { this._onMapLoaded(map, beforeLayerID); + } else { + map.on('load', () => { + this._onMapLoaded(map, beforeLayerID); + }); } } From baa2abecebeb9bc8576c380b0f7856bf523cf885 Mon Sep 17 00:00:00 2001 From: elenatorro Date: Tue, 3 Jul 2018 15:11:59 +0200 Subject: [PATCH 08/12] Load the map if the styles have been properly loaded --- src/api/layer.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/api/layer.js b/src/api/layer.js index bb9e28741..f10f7c86b 100644 --- a/src/api/layer.js +++ b/src/api/layer.js @@ -378,12 +378,14 @@ export default class Layer { } _addToMGLMap(map, beforeLayerID) { - if (map._loaded) { + if (map.isStyleLoaded()) { this._onMapLoaded(map, beforeLayerID); } else { - map.on('load', () => { + try { this._onMapLoaded(map, beforeLayerID); - }); + } catch (error) { + map.on('load', this._onMapLoaded.bind(this)); + } } } From 4cffafe7d43727eaad0f3d013a2576615f526e01 Mon Sep 17 00:00:00 2001 From: elenatorro Date: Tue, 3 Jul 2018 18:54:15 +0200 Subject: [PATCH 09/12] Remove redundant check --- src/api/layer.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/api/layer.js b/src/api/layer.js index f10f7c86b..2f4db15ce 100644 --- a/src/api/layer.js +++ b/src/api/layer.js @@ -378,14 +378,10 @@ export default class Layer { } _addToMGLMap(map, beforeLayerID) { - if (map.isStyleLoaded()) { + try { this._onMapLoaded(map, beforeLayerID); - } else { - try { - this._onMapLoaded(map, beforeLayerID); - } catch (error) { - map.on('load', this._onMapLoaded.bind(this)); - } + } catch (error) { + map.on('load', this._onMapLoaded.bind(this)); } } From cf34620e2a0ee5b097732ca20bc0b06e57065760 Mon Sep 17 00:00:00 2001 From: elenatorro Date: Tue, 3 Jul 2018 18:59:07 +0200 Subject: [PATCH 10/12] Remove unnecessary checks --- test/unit/api/layer.test.js | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/test/unit/api/layer.test.js b/test/unit/api/layer.test.js index 76ab3b15c..b816077e0 100644 --- a/test/unit/api/layer.test.js +++ b/test/unit/api/layer.test.js @@ -132,11 +132,7 @@ describe('api/layer', () => { describe('.addTo', () => { describe('._addToMGLMap', () => { let layer; - - const sourcedataEvent = { - isSourceLoaded: false - }; - + const loadEvent = {}; const mapMock = { @@ -145,13 +141,7 @@ describe('api/layer', () => { if (id === 'load') { callback.call(layer, loadEvent); } - - if (id === 'sourcedata') { - callback.call(layer, sourcedataEvent); - } - }, - - off: () => {} + } }; beforeEach(() => { @@ -164,27 +154,6 @@ describe('api/layer', () => { layer._addToMGLMap(mapMock); expect(layer._onMapLoaded).toHaveBeenCalled(); }); - - it('should not call onMapLoaded when the map style and source are not loaded', () => { - sourcedataEvent.isSourceLoaded = false; - mapMock.isStyleLoaded = jasmine.createSpy('isStyleLoaded').and.returnValue(false), - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).not.toHaveBeenCalled(); - }); - - it('should call onMapLoaded when the style is loaded but the sourcedata is not', () => { - sourcedataEvent.isSourceLoaded = false; - mapMock.isStyleLoaded = jasmine.createSpy('isStyleLoaded').and.returnValue(true), - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).toHaveBeenCalled(); - }); - - it('should call onMapLoaded when the style is not loaded and the sourcedata is', () => { - sourcedataEvent.isSourceLoaded = true; - mapMock.isStyleLoaded = jasmine.createSpy('isStyleLoaded').and.returnValue(false), - layer._addToMGLMap(mapMock); - expect(layer._onMapLoaded).toHaveBeenCalled(); - }); }); }); From 9b7836347f900b765529f6619f1e3ad612efe0d0 Mon Sep 17 00:00:00 2001 From: elenatorro Date: Wed, 4 Jul 2018 10:56:29 +0200 Subject: [PATCH 11/12] Do not use bind --- src/Layer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Layer.js b/src/Layer.js index 38eeb2307..c424aca0d 100644 --- a/src/Layer.js +++ b/src/Layer.js @@ -381,7 +381,9 @@ export default class Layer { try { this._onMapLoaded(map, beforeLayerID); } catch (error) { - map.on('load', this._onMapLoaded.bind(this)); + map.on('load', () => { + this._onMapLoaded(map, beforeLayerID); + }); } } From 0d97a26ea47a04930187b1c4ed303e6f172c69d5 Mon Sep 17 00:00:00 2001 From: elenatorro Date: Wed, 4 Jul 2018 11:21:28 +0200 Subject: [PATCH 12/12] Check the given error --- src/Layer.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Layer.js b/src/Layer.js index c424aca0d..56c07ae4c 100644 --- a/src/Layer.js +++ b/src/Layer.js @@ -378,9 +378,15 @@ export default class Layer { } _addToMGLMap(map, beforeLayerID) { + const STYLE_ERROR_REGEX = /Style is not done loading/; + try { this._onMapLoaded(map, beforeLayerID); } catch (error) { + if (!STYLE_ERROR_REGEX.test(error)) { + throw new Error(error); + } + map.on('load', () => { this._onMapLoaded(map, beforeLayerID); });