diff --git a/src/quadFeature.js b/src/quadFeature.js index d350970c9b..388ee9d754 100644 --- a/src/quadFeature.js +++ b/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.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 = { @@ -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; } diff --git a/tests/gl-cases/glQuad.js b/tests/gl-cases/glQuad.js index 6d10b48686..73541840b5 100644 --- a/tests/gl-cases/glQuad.js +++ b/tests/gl-cases/glQuad.js @@ -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; @@ -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'; diff --git a/tests/gl-cases/points.js b/tests/gl-cases/points.js index dfc17d22f7..01aeb44390 100644 --- a/tests/gl-cases/points.js +++ b/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); });