Add getters to ol.style.Image

This commit is contained in:
Éric Lemoine
2013-12-19 13:02:10 +01:00
parent e4f2a7552e
commit 5cd3ab06fc
3 changed files with 75 additions and 17 deletions

View File

@@ -455,18 +455,20 @@ ol.render.canvas.Immediate.prototype.setFillStrokeStyles_ = function() {
*/ */
ol.render.canvas.Immediate.prototype.setImageStyle = function(imageStyle) { ol.render.canvas.Immediate.prototype.setImageStyle = function(imageStyle) {
if (!goog.isNull(imageStyle)) { if (!goog.isNull(imageStyle)) {
goog.asserts.assert(!goog.isNull(imageStyle.anchor)); var anchor = imageStyle.getAnchor();
goog.asserts.assert(goog.isDef(imageStyle.size)); goog.asserts.assert(!goog.isNull(anchor));
var size = imageStyle.getSize();
goog.asserts.assert(!goog.isNull(size));
// FIXME pixel ratio // FIXME pixel ratio
var image = imageStyle.getImage(1); var image = imageStyle.getImage(1);
goog.asserts.assert(!goog.isNull(image)); goog.asserts.assert(!goog.isNull(image));
var state = this.state_; var state = this.state_;
state.anchorX = imageStyle.anchor[0]; state.anchorX = anchor[0];
state.anchorY = imageStyle.anchor[1]; state.anchorY = anchor[1];
state.image = image; state.image = image;
state.width = imageStyle.size[0]; state.width = size[0];
state.height = imageStyle.size[1]; state.height = size[1];
state.snapToPixel = imageStyle.snapToPixel; state.snapToPixel = imageStyle.getSnapToPixel();
} }
}; };

View File

@@ -602,20 +602,22 @@ ol.render.canvas.ImageReplay.prototype.finish = function() {
*/ */
ol.render.canvas.ImageReplay.prototype.setImageStyle = function(imageStyle) { ol.render.canvas.ImageReplay.prototype.setImageStyle = function(imageStyle) {
goog.asserts.assert(!goog.isNull(imageStyle)); goog.asserts.assert(!goog.isNull(imageStyle));
goog.asserts.assert(!goog.isNull(imageStyle.anchor)); var anchor = imageStyle.getAnchor();
goog.asserts.assert(goog.isDef(imageStyle.size)); goog.asserts.assert(!goog.isNull(anchor));
var size = imageStyle.getSize();
goog.asserts.assert(!goog.isNull(size));
// FIXME pixel ratio // FIXME pixel ratio
var hitDetectionImage = imageStyle.getHitDetectionImage(1); var hitDetectionImage = imageStyle.getHitDetectionImage(1);
goog.asserts.assert(!goog.isNull(hitDetectionImage)); goog.asserts.assert(!goog.isNull(hitDetectionImage));
var image = imageStyle.getImage(1); var image = imageStyle.getImage(1);
goog.asserts.assert(!goog.isNull(image)); goog.asserts.assert(!goog.isNull(image));
this.anchorX_ = imageStyle.anchor[0]; this.anchorX_ = anchor[0];
this.anchorY_ = imageStyle.anchor[1]; this.anchorY_ = anchor[1];
this.hitDetectionImage_ = hitDetectionImage; this.hitDetectionImage_ = hitDetectionImage;
this.image_ = image; this.image_ = image;
this.width_ = imageStyle.size[0]; this.width_ = size[0];
this.height_ = imageStyle.size[1]; this.height_ = size[1];
this.snapToPixel_ = imageStyle.snapToPixel; this.snapToPixel_ = imageStyle.getSnapToPixel();
}; };

View File

@@ -40,34 +40,40 @@ ol.style.Image = function(options) {
goog.base(this); goog.base(this);
/** /**
* @protected
* @type {ol.Pixel} * @type {ol.Pixel}
*/ */
this.anchor = options.anchor; this.anchor = options.anchor;
/** /**
* @protected
* @type {ol.style.ImageState} * @type {ol.style.ImageState}
*/ */
this.imageState = options.imageState; this.imageState = options.imageState;
/** /**
* @private
* @type {number|undefined} * @type {number|undefined}
*/ */
this.rotation = options.rotation; this.rotation_ = options.rotation;
/** /**
* @protected
* @type {ol.Size} * @type {ol.Size}
*/ */
this.size = options.size; this.size = options.size;
/** /**
* @private
* @type {boolean|undefined} * @type {boolean|undefined}
*/ */
this.snapToPixel = options.snapToPixel; this.snapToPixel_ = options.snapToPixel;
/** /**
* @private
* @type {boolean|undefined} * @type {boolean|undefined}
*/ */
this.subtractViewRotation = options.subtractViewRotation; this.subtractViewRotation_ = options.subtractViewRotation;
}; };
goog.inherits(ol.style.Image, goog.events.EventTarget); goog.inherits(ol.style.Image, goog.events.EventTarget);
@@ -81,6 +87,54 @@ ol.style.Image.prototype.dispatchChangeEvent = function() {
}; };
/**
* @return {ol.Pixel} Anchor.
*/
ol.style.Image.prototype.getAnchor = function() {
return this.anchor;
};
/**
* @return {ol.style.ImageState} Image state.
*/
ol.style.Image.prototype.getImageState = function() {
return this.imageState;
};
/**
* @return {number|undefined} Rotation.
*/
ol.style.Image.prototype.getRotation = function() {
return this.rotation_;
};
/**
* @return {ol.Size} Size.
*/
ol.style.Image.prototype.getSize = function() {
return this.size;
};
/**
* @return {boolean|undefined} Snap to pixel?
*/
ol.style.Image.prototype.getSnapToPixel = function() {
return this.snapToPixel_;
};
/**
* @return {boolean|undefined} Subtract view rotation?
*/
ol.style.Image.prototype.getSubtractViewRotation = function() {
return this.subtractViewRotation_;
};
/** /**
* @param {number} pixelRatio Pixel ratio. * @param {number} pixelRatio Pixel ratio.
* @return {HTMLCanvasElement|HTMLVideoElement|Image} Image element. * @return {HTMLCanvasElement|HTMLVideoElement|Image} Image element.