Ticket #893: patch-893-A1.diff
| File patch-893-A1.diff, 6.4 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( 9);160 t.plan(11); 161 161 // base layer is needed for getResolution() to return a value, 162 162 // otherwise VML test will fail because style.left and style.top 163 163 // cannot be set … … 168 168 format: 'image/png'}); 169 169 170 170 var layer = new OpenLayers.Layer.Vector("Test Layer"); 171 var renderer = layer.renderer; 171 172 var map = new OpenLayers.Map('map'); 172 173 map.addLayers([baseLayer, layer]); 173 174 174 var geometry = new OpenLayers.Geometry.Point(10, 10); 175 var geometryX = 10; 176 var geometryY = 10; 177 var geometry = new OpenLayers.Geometry.Point(geometryX, geometryY); 175 178 var feature = new OpenLayers.Feature.Vector(geometry); 176 179 177 180 var customStyle1 = new Object({ … … 196 199 graphicWidth: 24, 197 200 graphicOpacity: 1 198 201 }); 202 var customStyle6 = new Object({ 203 externalGraphic: 'test.png', 204 graphicWidth: 24, 205 graphicHeight: 16, 206 graphicXOffset: 24, 207 graphicYOffset: 16 208 }); 199 209 200 210 var root = layer.renderer.root; 201 211 if (layer.renderer.CLASS_NAME == 'OpenLayers.Renderer.SVG') { … … 236 246 t.eq(root.firstChild.getAttributeNS(null, 'style'), 237 247 'opacity: '+customStyle5.graphicOpacity.toString()+';', 238 248 "graphicOpacity correctly set"); 249 feature.style = customStyle6; 250 layer.drawFeature(feature); 251 var x = (geometryX / renderer.getResolution() + renderer.left); 252 var y = (geometryY / renderer.getResolution() - renderer.top); 253 t.eq(root.firstChild.getAttributeNS(null, 'x'), 254 (x-customStyle6.graphicXOffset).toFixed().toString(), 255 "graphicXOffset correctly set"); 256 t.eq(root.firstChild.getAttributeNS(null, 'y'), 257 (-y-customStyle6.graphicYOffset).toFixed().toString(), 258 "graphicYOffset correctly set"); 239 259 } 240 260 if (layer.renderer.CLASS_NAME == 'OpenLayers.Renderer.VML') { 241 261 feature.style = customStyle1; … … 278 298 t.eq(opacity, 279 299 customStyle5.graphicOpacity, 280 300 "graphicOpacity correctly set"); 301 feature.style = customStyle6; 302 layer.drawFeature(feature); 303 var x = geometryX/renderer.getResolution(); 304 var y = geometryY/renderer.getResolution(); 305 t.eq(root.firstChild.style.left, 306 (x-customStyle6.graphicXOffset).toFixed().toString()+'px', 307 "graphicXOffset correctly set"); 308 t.eq(root.firstChild.style.top, 309 (y-customStyle6.graphicYOffset).toFixed().toString()+'px', 310 "graphicYOffset correctly set"); 281 311 282 312 } 283 313 } -
lib/OpenLayers/Feature/Vector.js
old new 263 263 * - graphicWidth, 264 264 * - graphicHeight, 265 265 * - graphicOpacity 266 * - graphicXOffset 267 * - graphicYOffset 266 268 */ 267 269 OpenLayers.Feature.Vector.style = { 268 270 'default': { -
lib/OpenLayers/Renderer/VML.js
old new 182 182 width = width ? width : style.pointRadius*2; 183 183 height = height ? height : style.pointRadius*2; 184 184 var resolution = this.getResolution(); 185 node.style.left = (geometry.x/resolution-.5*width).toFixed(); 186 node.style.top = (geometry.y/resolution-.5*height).toFixed(); 185 var xOffset = style.graphicXOffset || (0.5 * width); 186 var yOffset = style.graphicYOffset || (0.5 * height); 187 node.style.left = (geometry.x/resolution-xOffset).toFixed(); 188 node.style.top = (geometry.y/resolution-yOffset).toFixed(); 187 189 node.style.width = width; 188 190 node.style.height = height; 189 191 -
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 xOffset = style.graphicXOffset || (0.5 * width); 210 var yOffset = style.graphicYOffset || (0.5 * height); 209 211 var opacity = style.graphicOpacity || style.fillOpacity; 210 212 211 node.setAttributeNS(null, "x", x- (.5*width).toFixed());212 node.setAttributeNS(null, "y", -y- (.5*height).toFixed());213 node.setAttributeNS(null, "x", x-xOffset.toFixed()); 214 node.setAttributeNS(null, "y", -y-yOffset.toFixed()); 213 215 node.setAttributeNS(null, "width", width); 214 216 node.setAttributeNS(null, "height", height); 215 217 node.setAttributeNS("http://www.w3.org/1999/xlink", "href", style.externalGraphic); -
examples/vector-features.html
old new 59 59 // of the image will be ignored 60 60 style_mark.graphicWidth = 24; 61 61 style_mark.graphicHeight = 20; 62 style_mark.graphicXOffset = 0.5 * style_mark.graphicWidth; 63 style_mark.graphicYOffset = style_mark.graphicHeight; 62 64 style_mark.externalGraphic = "../img/marker.png"; 63 65 64 66 var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {style: layer_style});
