OpenLayers OpenLayers

Changeset 4200

Show
Ignore:
Timestamp:
09/07/07 19:59:33 (1 year ago)
Author:
tschaub
Message:

clear bounds after modifying points - don't mess with the last point of a ring - test for correct bounds

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/tschaub/feature/lib/OpenLayers/Geometry/Polygon.js

    r4143 r4200  
    6464 * APIMethod: createRegularPolygon 
    6565 * Create a regular polygon around a radius. Useful for creating circles  
    66  * and the like. 
     66 *     and the like. 
    6767 * 
    6868 * Parameters: 
     
    7272 * rotation - {Float} original angle of rotation, in degrees. 
    7373 */ 
    74 OpenLayers.Geometry.Polygon.createRegularPolygon = function(origin, radius, sides, rotation) {   
     74OpenLayers.Geometry.Polygon.createRegularPolygon = function(origin, radius, 
     75                                                            sides, rotation) {   
    7576    var angle = Math.PI * ((1/sides) - (1/2)); 
    7677    if(rotation) { 
    77         angle += (rotation / 180) * Math.PI
     78        angle += rotation * (Math.PI / 180)
    7879    } 
    7980    var rotateAngle, x, y; 
  • sandbox/tschaub/feature/lib/OpenLayers/Handler/RegularPolygon.js

    r4196 r4200  
    123123    }, 
    124124     
    125    /** 
    126     * APIMethod: setOptions 
    127     *  
    128     * Parameters: 
    129     * newOptions - {Object}  
    130     */ 
     125    /** 
     126    * APIMethod: setOptions 
     127    *  
     128    * Parameters: 
     129    * newOptions - {Object}  
     130    */ 
    131131    setOptions: function (newOptions) { 
    132132        OpenLayers.Util.extend(this.options, newOptions); 
     
    278278            point.x = this.origin.x + (this.radius * Math.cos(angle)); 
    279279            point.y = this.origin.y + (this.radius * Math.sin(angle)); 
    280         } 
    281         ring.components[this.sides].x = ring.components[0].x; 
    282         ring.components[this.sides].y = ring.components[0].y; 
     280            point.clearBounds(); 
     281        } 
    283282    }, 
    284283     
  • sandbox/tschaub/feature/tests/Handler/test_RegularPolygon.html

    r4126 r4200  
    22<head> 
    33  <script src="../../lib/OpenLayers.js"></script> 
    4   <script type="text/javascript"><!-- 
     4  <script type="text/javascript"> 
    55    function test_Handler_RegularPolygon_constructor(t) { 
    66        t.plan(3); 
     
    5757        var evt = {xy: new OpenLayers.Pixel(175, 75), which: 1}; 
    5858        handler.move(evt); 
    59         t.eq(handler.feature.geometry.getBounds().toBBOX(), "-35.15625,-35.15625,35.15625,35.15625", "bounds"); 
    60         t.eq(handler.feature.geometry.components[0].components.length, 5, "geometry has 5 components"); 
    61         t.eq(handler.feature.geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "geometry is a polygon"); 
     59        t.eq(handler.feature.geometry.getBounds().toBBOX(), 
     60             "-35.15625,-35.15625,35.15625,35.15625", 
     61             "correct bounds after move"); 
     62        t.eq(handler.feature.geometry.components[0].components.length, 5, 
     63             "geometry has 5 components"); 
     64        t.eq(handler.feature.geometry.CLASS_NAME, 
     65             "OpenLayers.Geometry.Polygon", 
     66             "geometry is a polygon"); 
    6267        t.eq(handler.radius, 25*1.40625, "feature radius as set on handler"); 
    6368        var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1}; 
    6469        handler.move(evt); 
    65         t.eq(handler.feature.geometry.getBounds().toBBOX(), "-35.15625,-35.15625,35.15625,35.15625", "bounds"); 
     70        t.eq(handler.feature.geometry.getBounds().toBBOX(), 
     71             "-35.15625,-35.15625,35.15625,35.15625", 
     72             "correct bounds after move with a fixed radius"); 
    6673        handler.cancel(); 
    6774        handler.setOptions({radius:2 / Math.sqrt(2)}); 
     
    6976        handler.down(evt); 
    7077         
    71         t.eq(handler.feature.geometry.getBounds().toBBOX(), "-1,-1,1,1", "bounds with manual radius setting"); 
    72         var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1}; 
     78        t.eq(handler.feature.geometry.getBounds().toBBOX(), 
     79             "-1,-1,1,1", 
     80             "bounds with manual radius setting"); 
     81        var evt = {xy: new OpenLayers.Pixel(175, 90), which: 1}; 
    7382        handler.move(evt); 
    74         t.eq(handler.feature.geometry.getBounds().toBBOX(), "-1,-1,1,1", "bounds with manual radius setting and mousemove"); 
    75     }      
     83        t.eq(handler.feature.geometry.getBounds().toBBOX(), 
     84             "34.15625,-22.09375,36.15625,-20.09375", 
     85             "bounds with manual radius setting and mousemove"); 
     86    } 
     87 
    7688    function test_Handler_RegularPolygon_circle(t) { 
    7789        t.plan(7); 
     
    8799        var evt = {xy: new OpenLayers.Pixel(175, 75), which: 1}; 
    88100        handler.move(evt); 
    89         t.eq(handler.feature.geometry.getBounds().toBBOX(), "-35.15625,-35.15625,35.15625,35.15625", "bounds"); 
    90         t.eq(handler.feature.geometry.components[0].components.length, 41, "geometry has correct numbre of components"); 
    91         t.eq(handler.feature.geometry.CLASS_NAME, "OpenLayers.Geometry.Polygon", "geometry is a polygon"); 
     101        t.eq(handler.feature.geometry.getBounds().toBBOX(), 
     102             "-35.15625,-35.15625,35.15625,35.15625", 
     103             "correct bounds after move"); 
     104        t.eq(handler.feature.geometry.components[0].components.length, 41, 
     105             "geometry has correct numbre of components"); 
     106        t.eq(handler.feature.geometry.CLASS_NAME, 
     107             "OpenLayers.Geometry.Polygon", 
     108             "geometry is a polygon"); 
    92109        t.eq(handler.radius, 25*1.40625, "feature radius as set on handler"); 
    93110        var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1}; 
    94111        handler.move(evt); 
    95         t.eq(handler.feature.geometry.getBounds().toBBOX(), "-35.15625,-35.15625,35.15625,35.15625", "bounds"); 
     112        t.eq(handler.feature.geometry.getBounds().toBBOX(), 
     113             "-35.823348,-35.823348,35.823348,35.823348", 
     114             "correct bounds after move with fixed radius"); 
    96115        handler.cancel(); 
    97116        handler.setOptions({radius:1}); 
     
    99118        handler.down(evt); 
    100119         
    101         t.eq(handler.feature.geometry.getBounds().toBBOX(), "-0.996917,-0.996917,0.996917,0.996917", "bounds with manual radius setting"); 
     120        t.eq(handler.feature.geometry.getBounds().toBBOX(), 
     121             "-0.996917,-0.996917,0.996917,0.996917", 
     122             "bounds with manual radius setting"); 
    102123        var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1}; 
    103124        handler.move(evt); 
    104         t.eq(handler.feature.geometry.getBounds().toBBOX(), "-0.996917,-0.996917,0.996917,0.996917", "bounds with manual radius setting and mousemove"); 
     125        t.eq(handler.feature.geometry.getBounds().toBBOX(), 
     126             "34.159333,-8.028167,36.153167,-6.034333", 
     127             "bounds with manual radius setting and mousemove"); 
    105128    }      
    106          
    107      
    108129 
    109   // --> 
    110130  </script> 
    111131</head>