Have quad images use a promise.
onIdle should include these, too.
MODIFY
.travis.yml
.travis.yml
@@ -5,7 +5,7 @@ sudo: required
dist: trusty
node_js:
- - '0.12'
+ - 4
addons:
firefox: latest
@@ -31,7 +31,6 @@ cache:
- "$HOME/cache"
before_install:
- - nvm install 4
# Start xvfb with a specific resolution and pixel depth
- "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x24"
- CACHE="${HOME}/cache" CMAKE_VERSION=3.5.0 CMAKE_SHORT_VERSION=3.5 source ./scripts/install_cmake.sh

MODIFY
src/quadFeature.js
src/quadFeature.js
@@ -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);
@@ -337,10 +337,12 @@ var quadFeature = function (arg) {
origin = pos.ll;
origindiag2 = diag2;
}
- pos = [pos.ll[0], pos.ll[1], pos.ll[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]];
+ pos.ur[0], pos.ur[1], pos.ur[2]
+ ];
img = imgFunc.call(m_this, d, i);
if (!img) {
quad = {
@@ -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) {
@@ -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;
}

MODIFY
tests/gl-cases/glQuad.js
tests/gl-cases/glQuad.js
describe('glQuad', function () {
var imageTest = require('../image-test');
var common = require('../test-common');
- var geo = require('../test-utils').geo;
var myMap;
@@ -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';

MODIFY
tests/gl-cases/points.js
tests/gl-cases/points.js
@@ -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);
});

Have quad images use a promise.

onIdle should include these, too.