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:
euzuro
2006-05-29 13:54:38 +00:00
parent 77e618482a
commit 51aaf18b59
2 changed files with 47 additions and 20 deletions

View File

@@ -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);
}
},

View File

@@ -27,7 +27,7 @@ OpenLayers.Marker.prototype = {
this.lonlat = lonlat;
this.icon = (icon) ? icon : OpenLayers.Marker.defaultIcon();
this.events = new OpenLayers.Events(this, this.icon.image, null);
this.events = new OpenLayers.Events(this, this.icon.imageDiv, null);
},
/**
@@ -49,7 +49,7 @@ OpenLayers.Marker.prototype = {
this.icon.moveTo(px);
}
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Marker"
};
@@ -62,7 +62,9 @@ OpenLayers.Marker.prototype = {
OpenLayers.Marker.defaultIcon = function() {
var url = OpenLayers.Util.getImagesLocation() + "marker.png";
var size = new OpenLayers.Size(21, 25);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var offset = function(size) {
return OpenLayers.Pixel(-(size.w/2), -size.h);
};
return new OpenLayers.Icon(url, size, offset);
};