Changeset 4268
- Timestamp:
- 09/13/07 16:36:36 (1 year ago)
- Files:
-
- trunk/openlayers/examples/vector-features.html (modified) (1 diff)
- 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) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/examples/vector-features.html
r4222 r4268 59 59 style_mark.graphicWidth = 24; 60 60 style_mark.graphicHeight = 20; 61 style_mark.graphicXOffset = -(style_mark.graphicWidth/2); // this is the default value 62 style_mark.graphicYOffset = -style_mark.graphicHeight; 61 63 style_mark.externalGraphic = "../img/marker.png"; 62 64 trunk/openlayers/lib/OpenLayers/Feature/Vector.js
r4114 r4268 264 264 * - graphicHeight, 265 265 * - graphicOpacity 266 * - graphicXOffset 267 * - graphicYOffset 266 268 */ 267 269 OpenLayers.Feature.Vector.style = { trunk/openlayers/lib/OpenLayers/Renderer/SVG.js
r4114 r4268 185 185 // remove old node 186 186 var id = node.getAttributeNS(null, "id"); 187 var x = node.getAttributeNS(null, "cx");188 var y = node.getAttributeNS(null, "cy");187 var x = parseFloat(node.getAttributeNS(null, "cx")); 188 var y = parseFloat(node.getAttributeNS(null, "cy")); 189 189 var _featureId = node._featureId; 190 190 var _geometryClass = node._geometryClass; … … 207 207 width = width ? width : style.pointRadius*2; 208 208 height = height ? height : style.pointRadius*2; 209 var xOffset = (style.graphicXOffset != undefined) ? 210 style.graphicXOffset : -(0.5 * width); 211 var yOffset = (style.graphicYOffset != undefined) ? 212 style.graphicYOffset : -(0.5 * height); 209 213 var opacity = style.graphicOpacity || style.fillOpacity; 210 214 211 node.setAttributeNS(null, "x", x-(.5*width).toFixed());212 node.setAttributeNS(null, "y", -y-(.5*height).toFixed());215 node.setAttributeNS(null, "x", (x + xOffset).toFixed()); 216 node.setAttributeNS(null, "y", (-y + yOffset).toFixed()); 213 217 node.setAttributeNS(null, "width", width); 214 218 node.setAttributeNS(null, "height", height); trunk/openlayers/lib/OpenLayers/Renderer/VML.js
r4114 r4268 182 182 width = width ? width : style.pointRadius*2; 183 183 height = height ? height : style.pointRadius*2; 184 184 185 var resolution = this.getResolution(); 185 node.style.left = (geometry.x/resolution-.5*width).toFixed(); 186 node.style.top = (geometry.y/resolution-.5*height).toFixed(); 186 var xOffset = (style.graphicXOffset != undefined) ? 187 style.graphicXOffset : -(0.5 * width); 188 var yOffset = (style.graphicYOffset != undefined) ? 189 style.graphicYOffset : -(0.5 * height); 190 191 node.style.left = ((geometry.x/resolution)+xOffset).toFixed(); 192 node.style.top = ((geometry.y/resolution)-(yOffset+height)).toFixed(); 187 193 node.style.width = width; 188 194 node.style.height = height; trunk/openlayers/tests/Layer/test_Vector.html
r4220 r4268 159 159 160 160 function test_Layer_Vector_externalGraphic(t) { 161 t.plan( 9);161 t.plan(11); 162 162 // base layer is needed for getResolution() to return a value, 163 163 // otherwise VML test will fail because style.left and style.top … … 170 170 171 171 var layer = new OpenLayers.Layer.Vector("Test Layer"); 172 var renderer = layer.renderer; 172 173 var map = new OpenLayers.Map('map'); 173 174 map.addLayers([baseLayer, layer]); 174 175 175 var geometry = new OpenLayers.Geometry.Point(10, 10); 176 var geometryX = 10; 177 var geometryY = 10; 178 var geometry = new OpenLayers.Geometry.Point(geometryX, geometryY); 176 179 var feature = new OpenLayers.Feature.Vector(geometry); 180 181 map.zoomToMaxExtent(); 177 182 178 183 var customStyle1 = new Object({ … … 198 203 graphicOpacity: 1 199 204 }); 205 var customStyle6 = new Object({ 206 externalGraphic: 'test.png', 207 graphicWidth: 24, 208 graphicHeight: 16, 209 graphicXOffset: -24, 210 graphicYOffset: -16 211 }); 200 212 201 var root = layer.renderer.root;213 var root = renderer.root; 202 214 if (layer.renderer.CLASS_NAME == 'OpenLayers.Renderer.SVG') { 203 215 feature.style = customStyle1; … … 238 250 'opacity: '+customStyle5.graphicOpacity.toString()+';', 239 251 "graphicOpacity correctly set"); 252 feature.style = customStyle6; 253 layer.drawFeature(feature); 254 var x = geometryX / renderer.getResolution() + renderer.left; 255 var y = geometryY / renderer.getResolution() - renderer.top; 256 // SVG setStyle() gets x and y using getAttributeNS(), which returns 257 // a value with only 3 decimal digits. To mimic this we use toFixed(3) here 258 x = x.toFixed(3); 259 y = y.toFixed(3); 260 // toFixed() returns a string 261 x = parseFloat(x); 262 y = parseFloat(y); 263 t.eq(root.firstChild.getAttributeNS(null, 'x'), 264 (x + customStyle6.graphicXOffset).toFixed().toString(), 265 "graphicXOffset correctly set"); 266 t.eq(root.firstChild.getAttributeNS(null, 'y'), 267 (-y + customStyle6.graphicYOffset).toFixed().toString(), 268 "graphicYOffset correctly set"); 240 269 } 241 270 if (layer.renderer.CLASS_NAME == 'OpenLayers.Renderer.VML') { … … 280 309 customStyle5.graphicOpacity, 281 310 "graphicOpacity correctly set"); 311 feature.style = customStyle6; 312 layer.drawFeature(feature); 313 var x = geometryX / renderer.getResolution(); 314 var y = geometryY / renderer.getResolution(); 315 t.eq(root.firstChild.style.left, 316 (x + customStyle6.graphicXOffset).toFixed().toString()+'px', 317 "graphicXOffset correctly set"); 318 319 t.eq(root.firstChild.style.top, 320 (y - (customStyle6.graphicYOffset+parseInt(root.firstChild.style.height))).toFixed().toString()+'px', 321 "graphicYOffset correctly set"); 282 322 283 323 }
