Changeset 4114
- Timestamp:
- 08/30/07 01:59:29 (1 year ago)
- Files:
-
- trunk/openlayers/examples/vector-features.html (modified) (3 diffs)
- trunk/openlayers/lib/OpenLayers/Feature/Vector.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Renderer/SVG.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Renderer/VML.js (modified) (1 diff)
- trunk/openlayers/tests/Layer/test_Vector.html (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/examples/vector-features.html
r3729 r4114 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 … … 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", … … 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 trunk/openlayers/lib/OpenLayers/Feature/Vector.js
r4110 r4114 257 257 * - hoverPointUnit: "%", 258 258 * - pointerEvents: "visiblePainted" 259 * 260 * Other style properties that have no default values: 261 * 262 * - externalGraphic, 263 * - graphicWidth, 264 * - graphicHeight, 265 * - graphicOpacity 259 266 */ 260 267 OpenLayers.Feature.Vector.style = { trunk/openlayers/lib/OpenLayers/Renderer/SVG.js
r4110 r4114 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()); … … 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); trunk/openlayers/lib/OpenLayers/Renderer/VML.js
r4110 r4114 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 } trunk/openlayers/tests/Layer/test_Vector.html
r4059 r4114 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"); … … 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; … … 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') { … … 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 }
