Skip to content

Commit e3c6385

Browse files
committed
fix: Update a style from an array could fail
When updating a style from a buffer taking into account that there are multiple vertices per pixel, the fallback lookup could be wrong. The initial update worked, but subsequent updates could fail.
1 parent 978f782 commit e3c6385

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/feature.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,9 +612,11 @@ var feature = function (arg) {
612612
* @param {boolean} [refresh] `true` to redraw the feature when it has
613613
* been updated. If an object with styles is passed, the redraw is only
614614
* done once.
615+
* @param {number} [stride] If specified, the array should be sampled at this
616+
* spacing.
615617
* @returns {this} The feature instance.
616618
*/
617-
this.updateStyleFromArray = function (keyOrObject, styleArray, refresh) {
619+
this.updateStyleFromArray = function (keyOrObject, styleArray, refresh, stride) {
618620
if (typeof keyOrObject !== 'string') {
619621
$.each(keyOrObject, function (key, value) {
620622
m_this.updateStyleFromArray(key, value);
@@ -632,18 +634,18 @@ var feature = function (arg) {
632634
if (m_this._subfeatureStyles[keyOrObject]) {
633635
if (styleArray.length && Array.isArray(styleArray[0])) {
634636
m_this.style(keyOrObject, function (v, j, d, i) {
635-
var val = (styleArray[i] || [])[j];
637+
var val = (styleArray[stride ? Math.floor(i / stride) : i] || [])[j];
636638
return val !== undefined ? val : fallback;
637639
});
638640
} else {
639641
m_this.style(keyOrObject, function (v, j, d, i) {
640-
var val = styleArray[i];
642+
var val = styleArray[stride ? Math.floor(i / stride) : i];
641643
return val !== undefined ? val : fallback;
642644
});
643645
}
644646
} else {
645647
m_this.style(keyOrObject, function (d, i) {
646-
var val = styleArray[i];
648+
var val = styleArray[stride ? Math.floor(i / stride) : i];
647649
return val !== undefined ? val : fallback;
648650
});
649651
}

src/webgl/markerFeature.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,15 @@ var webgl_markerFeature = function (arg) {
299299
}
300300
$.each(keyOrObject, function (key, styleArray) {
301301
if (m_this.visible() && m_actor && bufferedKeys[key] && !needsRefresh && !m_this.clustering()) {
302-
var vpf, mapper, buffer, numPts, value, i, j, v, bpv, sbkey;
302+
var vpf, mapper, buffer, numPts, value, i, j, v, bpv, sbkey, stride;
303303
bpv = bufferedKeys[key];
304304
numPts = m_this.data().length;
305305
mapper = m_actor.mapper();
306306
sbkey = key === 'symbolComputed' ? 'symbol' : key === 'symbolValueComputed' ? 'symbolValue' : key;
307307
buffer = mapper.getSourceBuffer(sbkey);
308308
vpf = m_this.verticesPerFeature();
309309
if (!buffer || !numPts || numPts * vpf * bpv !== buffer.length) {
310+
stride = (vpf > 1) ? vpf : stride;
310311
needsRefresh = true;
311312
} else {
312313
switch (bufferedKeys[key]) {
@@ -345,7 +346,7 @@ var webgl_markerFeature = function (arg) {
345346
// don't allow modified to be adjusted if we don't need to refresh
346347
m_this.modified = () => {};
347348
}
348-
s_updateStyleFromArray(key, styleArray, false);
349+
s_updateStyleFromArray(key, styleArray, false, stride);
349350
m_this.modified = mod;
350351
}
351352
});

src/webgl/pointFeature.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,14 @@ var webgl_pointFeature = function (arg) {
274274
}
275275
$.each(keyOrObject, function (key, styleArray) {
276276
if (m_this.visible() && m_actor && bufferedKeys[key] && !needsRefresh && !m_this.clustering()) {
277-
var vpf, mapper, buffer, numPts, value, i, j, v, bpv;
277+
var vpf, mapper, buffer, numPts, value, i, j, v, bpv, stride;
278278
bpv = bufferedKeys[key] === 'bool' ? 1 : bufferedKeys[key];
279279
numPts = m_this.data().length;
280280
mapper = m_actor.mapper();
281281
buffer = mapper.getSourceBuffer(key);
282282
vpf = m_this.verticesPerFeature();
283283
if (!buffer || !numPts || numPts * vpf * bpv !== buffer.length) {
284+
stride = (vpf > 1) ? vpf : stride;
284285
needsRefresh = true;
285286
} else {
286287
switch (bufferedKeys[key]) {
@@ -326,7 +327,7 @@ var webgl_pointFeature = function (arg) {
326327
// don't allow modified to be adjusted if we don't need to refresh
327328
m_this.modified = () => {};
328329
}
329-
s_updateStyleFromArray(key, styleArray, false);
330+
s_updateStyleFromArray(key, styleArray, false, stride);
330331
m_this.modified = mod;
331332
});
332333
if (refresh) {

0 commit comments

Comments
 (0)