Use imgSize when provided

This commit is contained in:
Andreas Hocevar
2016-03-15 11:19:57 +01:00
parent 9db16bfa94
commit 339c7c5c23
3 changed files with 22 additions and 4 deletions

View File

@@ -6487,7 +6487,9 @@ olx.style.IconOptions.prototype.size;
/**
* Image size in pixel. Only required if `img` is set and `src` is not.
* Image size in pixels. Only required if `img` is set and `src` is not, and for
* SVG images in Internet Explorer 11. The provided `imgSize` needs to match
* the actual size of the image.
* @type {ol.Size|undefined}
* @api
*/

View File

@@ -106,9 +106,6 @@ ol.style.Icon = function(opt_options) {
goog.asserts.assert(!(src !== undefined && image),
'image and src can not provided at the same time');
goog.asserts.assert(
src === undefined || (src !== undefined && !imgSize),
'imgSize should not be set when src is provided');
goog.asserts.assert(
!image || (image && imgSize),
'imgSize must be set when image is provided');
@@ -513,6 +510,10 @@ ol.style.IconImage_.prototype.handleImageError_ = function() {
*/
ol.style.IconImage_.prototype.handleImageLoad_ = function() {
this.imageState_ = ol.style.ImageState.LOADED;
if (this.size_) {
this.image_.width = this.size_[0];
this.image_.height = this.size_[1];
}
this.size_ = [this.image_.width, this.image_.height];
this.unlistenImage_();
this.determineTainting_();

View File

@@ -8,6 +8,8 @@ goog.require('ol.style.IconOrigin');
describe('ol.style.Icon', function() {
var size = [36, 48];
var src = 'data:image/gif;base64,' +
'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs='
describe('constructor', function() {
@@ -21,6 +23,19 @@ describe('ol.style.Icon', function() {
canvas, goog.getUid(canvas), size, '').getImage()).to.eql(canvas);
});
it('imgSize overrides img.width and img.height', function(done) {
var style = new ol.style.Icon({
src: src,
imgSize: size
});
var iconImage = style.iconImage_;
iconImage.addEventListener('change', function() {
expect([iconImage.image_.width, iconImage.image_.height]).to.eql(size);
done();
});
style.load();
});
});
describe('#getAnchor', function() {