fix for #77. alpha png transparency. and tests. yay.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@605 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-06-15 19:02:21 +00:00
parent 18d178d7d2
commit 836b47c192
3 changed files with 32 additions and 20 deletions
+10 -10
View File
@@ -7,7 +7,7 @@ OpenLayers.Tile.Image.prototype =
Object.extend( new OpenLayers.Tile(), { Object.extend( new OpenLayers.Tile(), {
/** @type DOMElement img */ /** @type DOMElement img */
img:null, imgDiv:null,
/** /**
* @constructor * @constructor
@@ -23,22 +23,22 @@ OpenLayers.Tile.Image.prototype =
}, },
destroy: function() { destroy: function() {
if ((this.img != null) && (this.img.parentNode == this.layer.div)) { if ((this.imgDiv != null) && (this.imgDiv.parentNode == this.layer.div)) {
this.layer.div.removeChild(this.img); this.layer.div.removeChild(this.imgDiv);
} }
this.img = null; this.imgDiv = null;
OpenLayers.Tile.prototype.destroy.apply(this, arguments); OpenLayers.Tile.prototype.destroy.apply(this, arguments);
}, },
/** /**
*/ */
draw:function() { draw:function() {
this.img = OpenLayers.Util.createImage(null, this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null,
this.position, this.position,
this.size, this.size,
this.url, this.url,
"absolute"); "absolute");
this.layer.div.appendChild(this.img); this.layer.div.appendChild(this.imgDiv);
}, },
/** @final @type String */ /** @final @type String */
+10 -5
View File
@@ -25,14 +25,19 @@
var pixel = new OpenLayers.Pixel(5,6); var pixel = new OpenLayers.Pixel(5,6);
var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel); var tile = layer.addTile(new OpenLayers.Bounds(1,2,3,4), pixel);
tile.draw(); tile.draw();
t.eq( tile.img.src, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=/mapdata/vmap_wms.map&LAYERS=basic&FORMAT=image/jpeg&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:4326&BBOX=1,2,3,4&WIDTH=256&HEIGHT=256", "image src is created correctly via addtile" );
t.eq( tile.img.style.top, "6px", "image top is set correctly via addtile" ); var img = tile.imgDiv.childNodes[0];
t.eq( tile.img.style.left, "5px", "image top is set correctly via addtile" );
t.eq( img.src, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=/mapdata/vmap_wms.map&LAYERS=basic&FORMAT=image/jpeg&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:4326&BBOX=1,2,3,4&WIDTH=256&HEIGHT=256", "image src is created correctly via addtile" );
t.eq( tile.imgDiv.style.top, "6px", "image top is set correctly via addtile" );
t.eq( tile.imgDiv.style.left, "5px", "image top is set correctly via addtile" );
var firstChild = layer.div.firstChild;
if (!isMozilla) if (!isMozilla)
t.ok( true, "skipping element test outside of Mozilla"); t.ok( true, "skipping element test outside of Mozilla");
else else
t.ok( layer.div.firstChild instanceof HTMLImageElement, "div first child is an image object" ); t.ok( firstChild instanceof HTMLElement, "div first child is an image object" );
t.eq( layer.div.firstChild.src, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=/mapdata/vmap_wms.map&LAYERS=basic&FORMAT=image/jpeg&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:4326&BBOX=1,2,3,4&WIDTH=256&HEIGHT=256", "div first child is correct image object" ); t.eq( firstChild.childNodes[0].src, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=/mapdata/vmap_wms.map&LAYERS=basic&FORMAT=image/jpeg&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application/vnd.ogc.se_inimage&SRS=EPSG:4326&BBOX=1,2,3,4&WIDTH=256&HEIGHT=256", "div first child is correct image object" );
var pos = tile.getPosition(); var pos = tile.getPosition();
t.eq( pos.toString(), "x=5,y=6", "Position of tile is set correctly." ); t.eq( pos.toString(), "x=5,y=6", "Position of tile is set correctly." );
} }
+12 -5
View File
@@ -23,7 +23,7 @@
t.ok( tile.size.equals(size), "tile.size is set correctly"); t.ok( tile.size.equals(size), "tile.size is set correctly");
} }
function test_02_Tile_Image_draw (t) { function test_02_Tile_Image_draw (t) {
t.plan( 4 ); t.plan( 5 );
var layer = new Object(); //bogus layer var layer = new Object(); //bogus layer
layer.div = document.createElement("div"); layer.div = document.createElement("div");
@@ -34,13 +34,20 @@
tile = new OpenLayers.Tile.Image(layer, position, bounds, url, size); tile = new OpenLayers.Tile.Image(layer, position, bounds, url, size);
tile.draw(); tile.draw();
var img = tile.imgDiv.childNodes[0];
if (!isMozilla) if (!isMozilla)
t.ok( true, "skipping element test outside of Mozilla"); t.ok( true, "skipping element test outside of Mozilla");
else else
t.ok( tile.img instanceof HTMLImageElement, "tile.draw creates an image"); t.ok( tile.imgDiv instanceof HTMLElement, "tile.draw creates an image");
t.eq( tile.img.src, "http://www.openlayers.org/dev/tests/tileimage", "tile.draw creates an image"); if (!isMozilla)
t.eq( tile.img.style.width, "5px", "Image width is correct" ); t.ok( true, "skipping element test outside of Mozilla");
t.eq( tile.img.style.height, "6px", "Image height is correct" ); else
t.ok( img instanceof HTMLImageElement, "tile.draw creates an image");
t.eq( img.src, "http://www.openlayers.org/dev/tests/tileimage", "tile.draw creates an image");
t.eq( tile.imgDiv.style.width, "5px", "Image width is correct" );
t.eq( tile.imgDiv.style.height, "6px", "Image height is correct" );
} }
// --> // -->