Use imgSize when provided
This commit is contained in:
+3
-1
@@ -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}
|
* @type {ol.Size|undefined}
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -106,9 +106,6 @@ ol.style.Icon = function(opt_options) {
|
|||||||
|
|
||||||
goog.asserts.assert(!(src !== undefined && image),
|
goog.asserts.assert(!(src !== undefined && image),
|
||||||
'image and src can not provided at the same time');
|
'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(
|
goog.asserts.assert(
|
||||||
!image || (image && imgSize),
|
!image || (image && imgSize),
|
||||||
'imgSize must be set when image is provided');
|
'imgSize must be set when image is provided');
|
||||||
@@ -513,6 +510,10 @@ ol.style.IconImage_.prototype.handleImageError_ = function() {
|
|||||||
*/
|
*/
|
||||||
ol.style.IconImage_.prototype.handleImageLoad_ = function() {
|
ol.style.IconImage_.prototype.handleImageLoad_ = function() {
|
||||||
this.imageState_ = ol.style.ImageState.LOADED;
|
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.size_ = [this.image_.width, this.image_.height];
|
||||||
this.unlistenImage_();
|
this.unlistenImage_();
|
||||||
this.determineTainting_();
|
this.determineTainting_();
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ goog.require('ol.style.IconOrigin');
|
|||||||
|
|
||||||
describe('ol.style.Icon', function() {
|
describe('ol.style.Icon', function() {
|
||||||
var size = [36, 48];
|
var size = [36, 48];
|
||||||
|
var src = 'data:image/gif;base64,' +
|
||||||
|
'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs='
|
||||||
|
|
||||||
describe('constructor', function() {
|
describe('constructor', function() {
|
||||||
|
|
||||||
@@ -21,6 +23,19 @@ describe('ol.style.Icon', function() {
|
|||||||
canvas, goog.getUid(canvas), size, '').getImage()).to.eql(canvas);
|
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() {
|
describe('#getAnchor', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user