implement dynamic offset (pass in calculateOffset() function) and implement dynamic alpha-safe sizing. I realize some tests still fail. I have to run out for some errands, will be back in 3-4 hours to fix this (namely text layer still has issues. fear not, i will fix these)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@450 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -15,28 +15,30 @@ OpenLayers.Icon.prototype = {
|
||||
* @type OpenLayers.Pixel */
|
||||
offset: null,
|
||||
|
||||
/** Function to calculate the offset (based on the size)
|
||||
* @type OpenLayers.Pixel */
|
||||
calculateOffset: null,
|
||||
|
||||
/** @type DOMElement */
|
||||
image: null,
|
||||
imageDiv: null,
|
||||
|
||||
/** @type OpenLayers.Pixel */
|
||||
px: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {String} url
|
||||
* @param {OpenLayers.Size} size
|
||||
* @param {OpenLayers.Pixel} offset
|
||||
* @param {Function} calculateOffset
|
||||
*/
|
||||
initialize: function(url, size, offset) {
|
||||
this.size = size;
|
||||
initialize: function(url, size, offset, calculateOffset) {
|
||||
this.url = url;
|
||||
this.offset = (offset) ? offset
|
||||
: new OpenLayers.Pixel(0,0);
|
||||
this.size = size;
|
||||
this.offset = (offset) ? offset : new OpenLayers.Pixel(0,0);
|
||||
this.calculateOffset = calculateOffset;
|
||||
|
||||
this.image = OpenLayers.Util.createAlphaImageDiv(null,
|
||||
null,
|
||||
this.size,
|
||||
this.url,
|
||||
"absolute"
|
||||
);
|
||||
this.imageDiv = OpenLayers.Util.createAlphaImageDiv();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -47,6 +49,16 @@ OpenLayers.Icon.prototype = {
|
||||
return new OpenLayers.Icon(this.size, this.url, this.offset);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Size} size
|
||||
*/
|
||||
setSize: function(size) {
|
||||
if (size != null) {
|
||||
this.size = size;
|
||||
}
|
||||
this.draw();
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Pixel} px
|
||||
*
|
||||
@@ -54,18 +66,31 @@ OpenLayers.Icon.prototype = {
|
||||
* @type DOMElement
|
||||
*/
|
||||
draw: function(px) {
|
||||
OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv,
|
||||
null,
|
||||
null,
|
||||
this.size,
|
||||
this.url,
|
||||
"absolute");
|
||||
this.moveTo(px);
|
||||
return this.image;
|
||||
return this.imageDiv;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Pixel} px
|
||||
*/
|
||||
moveTo: function (px) {
|
||||
if ((px != null) && (this.image != null)) {
|
||||
offsetPx = px.offset(this.offset);
|
||||
this.image.style.left = offsetPx.x + "px";
|
||||
this.image.style.top = offsetPx.y + "px"
|
||||
//if no px passed in, use stored location
|
||||
if (px != null) {
|
||||
this.px = px;
|
||||
}
|
||||
|
||||
if ((this.px != null) && (this.imageDiv != null)) {
|
||||
if (this.calculateOffset) {
|
||||
this.offset = this.calculateOffset(this.size);
|
||||
}
|
||||
var offsetPx = this.px.offset(this.offset);
|
||||
OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv, null, offsetPx);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user