Skip to content

Commit

Permalink
Have quad images use a promise.
Browse files Browse the repository at this point in the history
onIdle should include these, too.
  • Loading branch information
manthey committed Mar 15, 2017
1 parent 5cbd243 commit 4e04eba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
29 changes: 24 additions & 5 deletions src/quadFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ var quadFeature = function (arg) {
}
return;
}
var quad, reload, image, prev_onload,
var quad, reload, image, prev_onload, prev_onerror,
pos, img, opacity, previewColor, previewImage, quadinfo = {};

pos = m_this._positionToQuad(posFunc, depthFunc, d, i);
Expand All @@ -337,10 +337,12 @@ var quadFeature = function (arg) {
origin = pos.ll;
origindiag2 = diag2;
}
pos = [pos.ll[0], pos.ll[1], pos.ll[2],
pos.lr[0], pos.lr[1], pos.lr[2],
pos.ul[0], pos.ul[1], pos.ul[2],
pos.ur[0], pos.ur[1], pos.ur[2]];
pos = [
pos.ll[0], pos.ll[1], pos.ll[2],
pos.lr[0], pos.lr[1], pos.lr[2],
pos.ul[0], pos.ul[1], pos.ul[2],
pos.ur[0], pos.ur[1], pos.ur[2]
];
img = imgFunc.call(m_this, d, i);
if (!img) {
quad = {
Expand Down Expand Up @@ -396,6 +398,8 @@ var quadFeature = function (arg) {
}
reload = loadedFunc.call(m_this, d, i);
if (reload) {
// add a promise to the layer if this image might complete
var defer = util.isReadyImage(image, true) ? null : $.Deferred();
prev_onload = image.onload;
image.onload = function () {
if (previewColor !== undefined) {
Expand All @@ -408,10 +412,25 @@ var quadFeature = function (arg) {
m_this.modified();
m_this._update();
m_this.layer().draw();
if (defer) {
defer.resolve();
}
if (prev_onload) {
return prev_onload.apply(this, arguments);
}
};
prev_onerror = image.onerror;
image.onerror = function () {
if (defer) {
defer.reject();
}
if (prev_onerror) {
return prev_onerror.apply(this, arguments);
}
};
if (defer) {
m_this.layer().addPromise(defer.promise());
}
} else if (previewColor === undefined && !quad.image) {
return;
}
Expand Down
23 changes: 1 addition & 22 deletions tests/gl-cases/glQuad.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
describe('glQuad', function () {
var imageTest = require('../image-test');
var common = require('../test-common');
var geo = require('../test-utils').geo;

var myMap;

Expand Down Expand Up @@ -114,32 +113,12 @@ describe('glQuad', function () {
return d.previewImage !== undefined ? d.previewImage : previewImage;
}
})
.geoOn(geo.event.feature.mouseover, function (evt) {
if (evt.data.orig_opacity === undefined) {
evt.data.orig_opacity = (evt.data.opacity || null);
}
evt.data.opacity = 0.5;
// we either have to clear the internal cache on the item, or have
// asked for it not to have been cached to begin with.
delete evt.data._cachedQuad;
this.modified();
layer.map().draw();
})
.geoOn(geo.event.feature.mouseout, function (evt) {
if (evt.data.orig_opacity === undefined) {
evt.data.orig_opacity = (evt.data.opacity || null);
}
evt.data.opacity = evt.data.orig_opacity || undefined;
delete evt.data._cachedQuad;
this.modified();
layer.map().draw();
})
.draw();

myMap.draw();

// use a short delay to allow all of the images to load
imageTest.imageTest('glQuad', null, 0.0015, done, myMap.onIdle, 1000, 2);
imageTest.imageTest('glQuad', null, 0.0015, done, myMap.onIdle, 0, 2);
};

previewImage.src = '/data/grid.jpg';
Expand Down
2 changes: 1 addition & 1 deletion tests/gl-cases/points.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('points', function () {
.style('strokeOpacity', 0.2);
myMap.draw();
// use a short delay to allow images to load
imageTest.imageTest('glPointsWithQuad', null, 0.0015, done, myMap.onIdle, 1000, 2);
imageTest.imageTest('glPointsWithQuad', null, 0.0015, done, myMap.onIdle, 0, 2);
}, 1000);
});

Expand Down

0 comments on commit 4e04eba

Please sign in to comment.