Changeset 7673
- Timestamp:
- 08/01/08 17:56:17 (1 month ago)
- Files:
-
- trunk/openlayers/examples/tasmania/sld-tasmania.xml (modified) (1 diff)
- trunk/openlayers/examples/vector-features.html (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Feature/Vector.js (modified) (4 diffs)
- trunk/openlayers/lib/OpenLayers/Format/SLD/v1.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Renderer/Elements.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Renderer/SVG.js (modified) (3 diffs)
- trunk/openlayers/lib/OpenLayers/Renderer/VML.js (modified) (2 diffs)
- trunk/openlayers/tests/Renderer/SVG.html (modified) (1 diff)
- trunk/openlayers/tests/Renderer/VML.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/examples/tasmania/sld-tasmania.xml
r7634 r7673 582 582 <ogc:Literal>1</ogc:Literal> 583 583 </sld:CssParameter> 584 <sld:CssParameter name="stroke-dasharray"> 585 <ogc:Literal>3 5 1 5</ogc:Literal> 586 </sld:CssParameter> 584 587 </sld:Stroke> 585 588 </sld:PolygonSymbolizer> trunk/openlayers/examples/vector-features.html
r7634 r7673 39 39 strokeColor: "#00FF00", 40 40 strokeWidth: 3, 41 strokeDashstyle: "dashdot", 41 42 pointRadius: 6, 42 43 pointerEvents: "visiblePainted" … … 75 76 var pointList = []; 76 77 var newPoint = point; 77 for(var p=0; p< 5; ++p) {78 for(var p=0; p<15; ++p) { 78 79 newPoint = new OpenLayers.Geometry.Point(newPoint.x + Math.random(1), 79 80 newPoint.y + Math.random(1)); trunk/openlayers/lib/OpenLayers/Feature/Vector.js
r7634 r7673 309 309 * - strokeOpacity: 1, 310 310 * - strokeWidth: 1, 311 * - strokeLinecap: "round", 311 * - strokeLinecap: "round", [butt | round | square] 312 * - strokeDashstyle: "solid", [dot | dash | dashdot | longdash | longdashdot | solid] 312 313 * - hoverStrokeColor: "red", 313 314 * - hoverStrokeOpacity: 1, … … 340 341 strokeWidth: 1, 341 342 strokeLinecap: "round", 343 strokeDashstyle: "solid", 342 344 hoverStrokeColor: "red", 343 345 hoverStrokeOpacity: 1, … … 358 360 strokeWidth: 2, 359 361 strokeLinecap: "round", 362 strokeDashstyle: "solid", 360 363 hoverStrokeColor: "red", 361 364 hoverStrokeOpacity: 1, … … 376 379 strokeLinecap: "round", 377 380 strokeWidth: 4, 381 strokeDashstyle: "solid", 378 382 hoverStrokeColor: "red", 379 383 hoverStrokeOpacity: 1, trunk/openlayers/lib/OpenLayers/Format/SLD/v1.js
r7651 r7673 53 53 strokeOpacity: 1, 54 54 strokeWidth: 1, 55 strokeDashstyle: "solid", 55 56 pointRadius: 3, 56 57 graphicName: "square" … … 294 295 "stroke-width": "strokeWidth", 295 296 "stroke-linecap": "strokeLinecap", 297 "stroke-dasharray": "strokeDashstyle", 296 298 "fill": "fillColor", 297 299 "fill-opacity": "fillOpacity", trunk/openlayers/lib/OpenLayers/Renderer/Elements.js
r7671 r7673 348 348 strokeLinecap: "round", 349 349 strokeOpacity: 1, 350 strokeDashstyle: "solid", 350 351 fillOpacity: 1, 351 352 pointRadius: 0 trunk/openlayers/lib/OpenLayers/Renderer/SVG.js
r7672 r7673 287 287 node.setAttributeNS(null, "stroke-width", style.strokeWidth * widthFactor); 288 288 node.setAttributeNS(null, "stroke-linecap", style.strokeLinecap); 289 // Hard-coded linejoin for now, to make it look the same as in VML. 290 // There is no strokeLinejoin property yet for symbolizers. 291 node.setAttributeNS(null, "stroke-linejoin", "round"); 292 node.setAttributeNS(null, "stroke-dasharray", this.dashStyle(style, 293 widthFactor)); 289 294 } else { 290 295 node.setAttributeNS(null, "stroke", "none"); … … 301 306 }, 302 307 308 /** 309 * Method: dashStyle 310 * 311 * Parameters: 312 * style - {Object} 313 * widthFactor - {Number} 314 * 315 * Returns: 316 * {String} A SVG compliant 'stroke-dasharray' value 317 */ 318 dashStyle: function(style, widthFactor) { 319 var w = style.strokeWidth * widthFactor; 320 321 switch (style.strokeDashstyle) { 322 case 'solid': 323 return 'none'; 324 case 'dot': 325 return [1, 4 * w].join(); 326 case 'dash': 327 return [4 * w, 4 * w].join(); 328 case 'dashdot': 329 return [4 * w, 4 * w, 1, 4 * w].join(); 330 case 'longdash': 331 return [8 * w, 4 * w].join(); 332 case 'longdashdot': 333 return [8 * w, 4 * w, 1, 4 * w].join(); 334 default: 335 return style.strokeDashstyle.replace(/ /g, ","); 336 } 337 }, 338 303 339 /** 304 340 * Method: createNode … … 633 669 634 670 node.setAttributeNS(null, "points", points); 635 // Hard-coded linejoin for now, to make it look the same as in VML.636 // There is no strokeLinejoin property yet for symbolizers.637 node.setAttributeNS(null, "stroke-linejoin", "round");638 671 639 672 var width = symbolExtent.getWidth(); trunk/openlayers/lib/OpenLayers/Renderer/VML.js
r7672 r7673 287 287 stroke.setAttribute("opacity", style.strokeOpacity); 288 288 stroke.setAttribute("endcap", !style.strokeLinecap || style.strokeLinecap == 'butt' ? 'flat' : style.strokeLinecap); 289 stroke.setAttribute("dashstyle", this.dashStyle(style)); 289 290 } 290 291 … … 456 457 } 457 458 }, 459 460 /** 461 * Method: dashStyle 462 * 463 * Parameters: 464 * style - {Object} 465 * 466 * Returns: 467 * {String} A VML compliant 'stroke-dasharray' value 468 */ 469 dashStyle: function(style) { 470 var dash = style.strokeDashstyle; 471 switch (dash) { 472 case 'solid': 473 case 'dot': 474 case 'dash': 475 case 'dashdot': 476 case 'longdash': 477 case 'longdashdot': 478 return dash; 479 default: 480 // very basic guessing of dash style patterns 481 var parts = dash.split(/[ ,]/); 482 if (parts.length == 2) { 483 if (1*parts[0] >= 2*parts[1]) { 484 return "longdash"; 485 } 486 return (parts[0] == 1 || parts[1] == 1) ? "dot" : "dash"; 487 } else if (parts.length == 4) { 488 return (1*parts[0] >= 2*parts[1]) ? "longdashdot" : 489 "dashdot" 490 } 491 return "solid"; 492 } 493 }, 458 494 459 495 /** trunk/openlayers/tests/Renderer/SVG.html
r7664 r7673 408 408 } 409 409 410 function test_svg_dashstyle(t) { 411 if (!OpenLayers.Renderer.SVG.prototype.supported()) { 412 t.plan(0); 413 return; 414 } 415 416 t.plan(5); 417 418 var r = new OpenLayers.Renderer.SVG(document.body); 419 420 t.eq(r.dashStyle({strokeWidth: 1, strokeDashstyle: "dot"}, 1), "1,4", "dot dasharray created correctly"); 421 t.eq(r.dashStyle({strokeWidth: 1, strokeDashstyle: "dash"}, 1), "4,4", "dash dasharray created correctly"); 422 t.eq(r.dashStyle({strokeWidth: 1, strokeDashstyle: "longdash"}, 1), "8,4", "longdash dasharray created correctly"); 423 t.eq(r.dashStyle({strokeWidth: 1, strokeDashstyle: "dashdot"}, 1), "4,4,1,4", "dashdot dasharray created correctly"); 424 t.eq(r.dashStyle({strokeWidth: 1, strokeDashstyle: "longdashdot"}, 1), "8,4,1,4", "dashdot dasharray created correctly"); 425 } 426 410 427 </script> 411 428 </head> trunk/openlayers/tests/Renderer/VML.html
r7634 r7673 371 371 372 372 } 373 374 function test_vml_dashstyle(t) { 375 if (!OpenLayers.Renderer.VML.prototype.supported()) { 376 t.plan(0); 377 return; 378 } 379 380 t.plan(5); 381 382 var r = new OpenLayers.Renderer.VML(document.body); 383 384 t.eq(r.dashStyle({strokeDashstyle: "1 4"}), "dot", "dot pattern recognized correctly."); 385 t.eq(r.dashStyle({strokeDashstyle: "4 4"}), "dash", "dash pattern recognized correctly."); 386 t.eq(r.dashStyle({strokeDashstyle: "8 4"}), "longdash", "longdash pattern recognized correctly."); 387 t.eq(r.dashStyle({strokeDashstyle: "4 4 1 4"}), "dashdot", "dashdot pattern recognized correctly."); 388 t.eq(r.dashStyle({strokeDashstyle: "8 4 1 4"}), "longdashdot", "longdashdot pattern recognized correctly."); 389 } 373 390 374 391 </script>
