Ticket #873: patch-graphicOpacity.diff
| File patch-graphicOpacity.diff, 8.6 kB (added by elemoine, 1 year ago) |
|---|
-
tests/Layer/test_Vector.html
old new 157 157 } 158 158 159 159 function test_Layer_Vector_externalGraphic(t) { 160 t.plan(8);161 // base layer is needed for getResolution() to return a value,162 // otherwise VML test will fail because style.left and style.top163 // cannot be set164 var baseLayer = new OpenLayers.Layer.WMS("Base Layer",165 "http://octo.metacarta.com/cgi-bin/mapserv",166 { map: '/mapdata/vmap_wms.map',167 layers: 'basic',168 format: 'image/png'});160 t.plan(9); 161 // base layer is needed for getResolution() to return a value, 162 // otherwise VML test will fail because style.left and style.top 163 // cannot be set 164 var baseLayer = new OpenLayers.Layer.WMS("Base Layer", 165 "http://octo.metacarta.com/cgi-bin/mapserv", 166 { map: '/mapdata/vmap_wms.map', 167 layers: 'basic', 168 format: 'image/png'}); 169 169 170 170 var layer = new OpenLayers.Layer.Vector("Test Layer"); 171 171 var map = new OpenLayers.Map('map'); … … 191 191 graphicWidth: 24, 192 192 graphicHeight: 16 193 193 }); 194 var customStyle5 = new Object({ 195 externalGraphic: 'test.png', 196 graphicWidth: 24, 197 graphicOpacity: 1 198 }); 194 199 195 200 var root = layer.renderer.root; 196 201 if (layer.renderer.CLASS_NAME == 'OpenLayers.Renderer.SVG') { … … 222 227 layer.drawFeature(feature); 223 228 t.eq(root.firstChild.getAttributeNS(null, 'height'), 224 229 customStyle4.graphicHeight.toString(), 225 "given graphicHeight and graphicWidth, both are set: height") 230 "given graphicHeight and graphicWidth, both are set: height"); 226 231 t.eq(root.firstChild.getAttributeNS(null, 'width'), 227 232 customStyle4.graphicWidth.toString(), 228 "given graphicHeight and graphicWidth, both are set: width") 233 "given graphicHeight and graphicWidth, both are set: width"); 234 feature.style = customStyle5; 235 layer.drawFeature(feature); 236 t.eq(root.firstChild.getAttributeNS(null, 'style'), 237 'opacity: '+customStyle5.graphicOpacity.toString()+';', 238 "graphicOpacity correctly set"); 229 239 } 230 240 if (layer.renderer.CLASS_NAME == 'OpenLayers.Renderer.VML') { 231 241 feature.style = customStyle1; … … 256 266 layer.drawFeature(feature); 257 267 t.eq(root.firstChild.style.height, 258 268 customStyle4.graphicHeight.toString()+'px', 259 "given graphicHeight and graphicWidth, both are set: height") 269 "given graphicHeight and graphicWidth, both are set: height"); 260 270 t.eq(root.firstChild.style.width, 261 271 customStyle4.graphicWidth.toString()+'px', 262 "given graphicHeight and graphicWidth, both are set: width") 272 "given graphicHeight and graphicWidth, both are set: width"); 273 feature.style = customStyle5; 274 layer.drawFeature(feature); 275 var fill = root.firstChild.getElementsByTagName("fill")[0]; 276 if (fill == null) fill = root.firstChild.getElementsByTagName("v:fill"); 277 var opacity = fill.getAttribute('opacity'); 278 t.eq(opacity, 279 customStyle5.graphicOpacity, 280 "graphicOpacity correctly set"); 281 263 282 } 264 283 } 265 284 -
lib/OpenLayers/Feature/Vector.js
old new 257 257 * - hoverPointRadius: 1, 258 258 * - hoverPointUnit: "%", 259 259 * - pointerEvents: "visiblePainted" 260 * 261 * Other style properties that have no default values: 262 * 263 * - externalGraphic, 264 * - graphicWidth, 265 * - graphicHeight, 266 * - graphicOpacity 260 267 */ 261 268 262 269 OpenLayers.Feature.Vector.style = { -
lib/OpenLayers/Renderer/VML.js
old new 210 210 fill = this.createNode('v:fill', node.id + "_fill"); 211 211 node.appendChild(fill); 212 212 } 213 if (style.fillOpacity) { 213 // if graphicOpacity is set use it in priority for external graphic 214 if (node._geometryClass == "OpenLayers.Geometry.Point" && 215 style.externalGraphic && 216 style.graphicOpacity) { 217 fill.setAttribute("opacity", style.graphicOpacity); 218 } else if (style.fillOpacity) { 214 219 fill.setAttribute("opacity", style.fillOpacity); 215 220 } 216 221 } -
lib/OpenLayers/Renderer/SVG.js
old new 206 206 var height = style.graphicHeight || style.graphicWidth; 207 207 width = width ? width : style.pointRadius*2; 208 208 height = height ? height : style.pointRadius*2; 209 var opacity = style.graphicOpacity || style.fillOpacity; 209 210 210 211 node.setAttributeNS(null, "x", x-(.5*width).toFixed()); 211 212 node.setAttributeNS(null, "y", -y-(.5*height).toFixed()); … … 213 214 node.setAttributeNS(null, "height", height); 214 215 node.setAttributeNS("http://www.w3.org/1999/xlink", "href", style.externalGraphic); 215 216 node.setAttributeNS(null, "transform", "scale(1,-1)"); 216 node.setAttributeNS(null, "style", "opacity: "+ style.fillOpacity);217 node.setAttributeNS(null, "style", "opacity: "+opacity); 217 218 } else { 218 219 node.setAttributeNS(null, "r", style.pointRadius); 219 220 } -
examples/vector-features.html
old new 17 17 var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", 18 18 "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ); 19 19 map.addLayer(layer); 20 21 /* 22 * Layer style 23 */ 24 // we want opaque external graphics and non-opaque internal graphics 25 var layer_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); 26 layer_style.fillOpacity = 0.2; 27 layer_style.graphicOpacity = 1; 20 28 21 var style_blue = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); 29 /* 30 * Blue style 31 */ 32 var style_blue = OpenLayers.Util.extend({}, layer_style); 22 33 style_blue.strokeColor = "blue"; 23 34 style_blue.fillColor = "blue"; 24 35 style_blue.externalGraphic = "../img/marker.png"; 25 26 36 // each of the three lines below means the same, if only one of 27 37 // them is active: the image will have a size of 24px, and the 28 38 // aspect ratio will be kept … … 30 40 //style_blue.graphicWidth = 24; 31 41 //style_blue.graphicHeight = 24; 32 42 33 style_blue.fillOpacity = 1; 43 /* 44 * Green style 45 */ 34 46 var style_green = { 35 47 strokeColor: "#00FF00", 36 48 strokeOpacity: 1, … … 38 50 pointRadius: 6, 39 51 pointerEvents: "visiblePainted" 40 52 }; 53 54 /* 55 * Mark style 56 */ 41 57 var style_mark = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']); 42 43 58 // if graphicWidth and graphicHeight are both set, the aspect ratio 44 59 // of the image will be ignored 45 60 style_mark.graphicWidth = 24; 46 61 style_mark.graphicHeight = 20; 47 48 62 style_mark.externalGraphic = "../img/marker.png"; 49 63 50 var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry" );64 var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {style: layer_style}); 51 65 52 66 // create a point feature 53 67 var point = new OpenLayers.Geometry.Point(-111.04, 45.68);
