From 29dece02a535bffea4362ca248147289b350011b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Junod?= Date: Mon, 23 Aug 2010 06:52:17 +0000 Subject: [PATCH] Use the graphicOpacity to set canvas.globalAlpha. Move the image source assignment after the onload. r=crschmidt (closes #2608) git-svn-id: http://svn.openlayers.org/trunk/openlayers@10673 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Renderer/Canvas.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Renderer/Canvas.js b/lib/OpenLayers/Renderer/Canvas.js index 8fb0e81dbf..0ad38f60aa 100644 --- a/lib/OpenLayers/Renderer/Canvas.js +++ b/lib/OpenLayers/Renderer/Canvas.js @@ -166,7 +166,6 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, { */ drawExternalGraphic: function(pt, style) { var img = new Image(); - img.src = style.externalGraphic; if(style.graphicTitle) { img.title=style.graphicTitle; @@ -180,19 +179,21 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, { style.graphicXOffset : -(0.5 * width); var yOffset = (style.graphicYOffset != undefined) ? style.graphicYOffset : -(0.5 * height); - var opacity = style.graphicOpacity || style.fillOpacity; var context = { img: img, x: (pt[0]+xOffset), y: (pt[1]+yOffset), width: width, height: height, + opacity: style.graphicOpacity || style.fillOpacity, canvas: this.canvas }; img.onload = OpenLayers.Function.bind( function() { + this.canvas.globalAlpha = this.opacity; this.canvas.drawImage(this.img, this.x, this.y, this.width, this.height); - }, context); + }, context); + img.src = style.externalGraphic; }, /**