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 */ * @type OpenLayers.Pixel */
offset: null, offset: null,
/** Function to calculate the offset (based on the size)
* @type OpenLayers.Pixel */
calculateOffset: null,
/** @type DOMElement */ /** @type DOMElement */
image: null, imageDiv: null,
/** @type OpenLayers.Pixel */
px: null,
/** /**
* @constructor * @constructor
* *
* @param {String} url * @param {String} url
* @param {OpenLayers.Size} size * @param {OpenLayers.Size} size
* @param {OpenLayers.Pixel} offset * @param {Function} calculateOffset
*/ */
initialize: function(url, size, offset) { initialize: function(url, size, offset, calculateOffset) {
this.size = size;
this.url = url; this.url = url;
this.offset = (offset) ? offset this.size = size;
: new OpenLayers.Pixel(0,0); this.offset = (offset) ? offset : new OpenLayers.Pixel(0,0);
this.calculateOffset = calculateOffset;
this.image = OpenLayers.Util.createAlphaImageDiv(null, this.imageDiv = OpenLayers.Util.createAlphaImageDiv();
null,
this.size,
this.url,
"absolute"
);
}, },
/** /**
@@ -47,6 +49,16 @@ OpenLayers.Icon.prototype = {
return new OpenLayers.Icon(this.size, this.url, this.offset); 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 * @param {OpenLayers.Pixel} px
* *
@@ -54,18 +66,31 @@ OpenLayers.Icon.prototype = {
* @type DOMElement * @type DOMElement
*/ */
draw: function(px) { draw: function(px) {
OpenLayers.Util.modifyAlphaImageDiv(this.imageDiv,
null,
null,
this.size,
this.url,
"absolute");
this.moveTo(px); this.moveTo(px);
return this.image; return this.imageDiv;
}, },
/** /**
* @param {OpenLayers.Pixel} px * @param {OpenLayers.Pixel} px
*/ */
moveTo: function (px) { moveTo: function (px) {
if ((px != null) && (this.image != null)) { //if no px passed in, use stored location
offsetPx = px.offset(this.offset); if (px != null) {
this.image.style.left = offsetPx.x + "px"; this.px = px;
this.image.style.top = offsetPx.y + "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.lonlat = lonlat;
this.icon = (icon) ? icon : OpenLayers.Marker.defaultIcon(); 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); this.icon.moveTo(px);
} }
}, },
/** @final @type String */ /** @final @type String */
CLASS_NAME: "OpenLayers.Marker" CLASS_NAME: "OpenLayers.Marker"
}; };
@@ -62,7 +62,9 @@ OpenLayers.Marker.prototype = {
OpenLayers.Marker.defaultIcon = function() { OpenLayers.Marker.defaultIcon = function() {
var url = OpenLayers.Util.getImagesLocation() + "marker.png"; var url = OpenLayers.Util.getImagesLocation() + "marker.png";
var size = new OpenLayers.Size(21, 25); 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); return new OpenLayers.Icon(url, size, offset);
}; };