Skip to content

Commit d3cca07

Browse files
author
Lucas Wojciechowski
committed
Fix unstable symbol rendering order
1 parent a34972b commit d3cca07

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

js/style/style.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,9 @@ Style.prototype = util.inherit(Evented, {
172172
},
173173

174174
_broadcastLayers: function() {
175-
var ordered = [];
176-
177-
for (var id in this._layers) {
178-
ordered.push(this._layers[id].json());
179-
}
180-
181-
this.dispatcher.broadcast('set layers', ordered);
175+
this.dispatcher.broadcast('set layers', this._order.map(function(id) {
176+
return this._layers[id].json();
177+
}, this));
182178
},
183179

184180
_cascade: function(classes, options) {

test/js/style/style.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,38 @@ test('Style', function(t) {
113113
});
114114
});
115115

116+
test('Style#_broadcastLayers', function(t) {
117+
var style = new Style({
118+
'version': 8,
119+
'sources': {
120+
'source': {
121+
'type': 'vector'
122+
}
123+
},
124+
'layers': [{
125+
'id': 'second',
126+
'source': 'source',
127+
'source-layer': 'source-layer',
128+
'type': 'fill'
129+
}]
130+
});
131+
132+
style.on('error', function(error) { t.error(error); });
133+
134+
style.on('load', function() {
135+
style.addLayer({id: 'first', source: 'source', type: 'fill' }, 'second');
136+
style.addLayer({id: 'third', source: 'source', type: 'fill' });
137+
138+
style.dispatcher.broadcast = function(key, value) {
139+
t.equal(key, 'set layers');
140+
t.deepEqual(value.map(function(layer) { return layer.id; }), ['first', 'second', 'third']);
141+
t.end();
142+
};
143+
144+
style._broadcastLayers();
145+
});
146+
});
147+
116148
test('Style#_resolve', function(t) {
117149
t.test('creates StyleLayers', function(t) {
118150
var style = new Style({

0 commit comments

Comments
 (0)