OpenLayers OpenLayers

Ticket #893: patch-893-A1.diff

File patch-893-A1.diff, 6.4 kB (added by elemoine, 1 year ago)

New patch fixing a stupid error in the tests. Still don't know if the tests pass on IE. I'll give it a try myself once I have IE handy.

  • tests/Layer/test_Vector.html

    old new  
    157157    } 
    158158 
    159159    function test_Layer_Vector_externalGraphic(t) { 
    160         t.plan(9); 
     160        t.plan(11); 
    161161        // base layer is needed for getResolution() to return a value, 
    162162        // otherwise VML test will fail because style.left and style.top 
    163163        // cannot be set 
     
    168168               format: 'image/png'}); 
    169169             
    170170        var layer = new OpenLayers.Layer.Vector("Test Layer"); 
     171        var renderer = layer.renderer; 
    171172        var map = new OpenLayers.Map('map'); 
    172173        map.addLayers([baseLayer, layer]); 
    173174 
    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); 
    175178        var feature = new OpenLayers.Feature.Vector(geometry); 
    176179 
    177180        var customStyle1 = new Object({ 
     
    196199                graphicWidth: 24, 
    197200                graphicOpacity: 1 
    198201        }); 
     202        var customStyle6 = new Object({ 
     203                externalGraphic: 'test.png', 
     204                graphicWidth: 24, 
     205                graphicHeight: 16, 
     206                graphicXOffset: 24, 
     207                graphicYOffset: 16 
     208        }); 
    199209                
    200210        var root = layer.renderer.root; 
    201211        if (layer.renderer.CLASS_NAME == 'OpenLayers.Renderer.SVG') { 
     
    236246                t.eq(root.firstChild.getAttributeNS(null, 'style'), 
    237247                            'opacity: '+customStyle5.graphicOpacity.toString()+';', 
    238248                            "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"); 
    239259        } 
    240260        if (layer.renderer.CLASS_NAME == 'OpenLayers.Renderer.VML') { 
    241261                feature.style = customStyle1; 
     
    278298                t.eq(opacity, 
    279299                            customStyle5.graphicOpacity, 
    280300                            "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"); 
    281311 
    282312        } 
    283313    } 
  • lib/OpenLayers/Feature/Vector.js

    old new  
    263263 *  - graphicWidth, 
    264264 *  - graphicHeight, 
    265265 *  - graphicOpacity 
     266 *  - graphicXOffset 
     267 *  - graphicYOffset 
    266268 */  
    267269OpenLayers.Feature.Vector.style = { 
    268270    'default': { 
  • lib/OpenLayers/Renderer/VML.js

    old new  
    182182                width = width ? width : style.pointRadius*2; 
    183183                height = height ? height : style.pointRadius*2; 
    184184                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(); 
    187189                node.style.width = width; 
    188190                node.style.height = height;     
    189191                 
  • lib/OpenLayers/Renderer/SVG.js

    old new  
    206206                var height = style.graphicHeight || style.graphicWidth; 
    207207                width = width ? width : style.pointRadius*2; 
    208208                height = height ? height : style.pointRadius*2; 
     209                var xOffset = style.graphicXOffset || (0.5 * width); 
     210                var yOffset = style.graphicYOffset || (0.5 * height); 
    209211                var opacity = style.graphicOpacity || style.fillOpacity; 
    210212                 
    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()); 
    213215                node.setAttributeNS(null, "width", width); 
    214216                node.setAttributeNS(null, "height", height); 
    215217                node.setAttributeNS("http://www.w3.org/1999/xlink", "href", style.externalGraphic); 
  • examples/vector-features.html

    old new  
    5959            // of the image will be ignored 
    6060            style_mark.graphicWidth = 24; 
    6161            style_mark.graphicHeight = 20; 
     62            style_mark.graphicXOffset = 0.5 * style_mark.graphicWidth; 
     63            style_mark.graphicYOffset = style_mark.graphicHeight; 
    6264            style_mark.externalGraphic = "../img/marker.png"; 
    6365             
    6466            var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {style: layer_style});