[OpenLayers-Commits] r12100 - in sandbox/tschaub/editing: lib/OpenLayers/Geometry lib/OpenLayers/Layer tests/Geometry

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Fri Jun 17 14:26:25 EDT 2011


Author: tschaub
Date: 2011-06-17 11:26:24 -0700 (Fri, 17 Jun 2011)
New Revision: 12100

Modified:
   sandbox/tschaub/editing/lib/OpenLayers/Geometry/Polygon.js
   sandbox/tschaub/editing/lib/OpenLayers/Layer/PointGrid.js
   sandbox/tschaub/editing/tests/Geometry/Polygon.html
Log:
Updates based on bartvde's review.

Modified: sandbox/tschaub/editing/lib/OpenLayers/Geometry/Polygon.js
===================================================================
--- sandbox/tschaub/editing/lib/OpenLayers/Geometry/Polygon.js	2011-06-17 18:18:40 UTC (rev 12099)
+++ sandbox/tschaub/editing/lib/OpenLayers/Geometry/Polygon.js	2011-06-17 18:26:24 UTC (rev 12100)
@@ -257,25 +257,3 @@
     var ring = new OpenLayers.Geometry.LinearRing(points);
     return new OpenLayers.Geometry.Polygon([ring]);
 };
-
-/**
- * APIMethod: fromBounds
- * Generate a polygon for the given bounds.
- *
- * Parameters:
- * bounds - {<OpenLayers.Bounds>} A bounds object.
- *
- * Returns:
- * {<OpenLayers.Geometry.Polygon>} A polygon representing the given bounds.
- */
-OpenLayers.Geometry.Polygon.fromBounds = function(bounds) {
-    var Point = OpenLayers.Geometry.Point;
-    return new OpenLayers.Geometry.Polygon([
-        new OpenLayers.Geometry.LinearRing([
-            new Point(bounds.left, bounds.top),
-            new Point(bounds.right, bounds.top),
-            new Point(bounds.right, bounds.bottom),
-            new Point(bounds.left, bounds.bottom)
-        ])
-    ]);
-};

Modified: sandbox/tschaub/editing/lib/OpenLayers/Layer/PointGrid.js
===================================================================
--- sandbox/tschaub/editing/lib/OpenLayers/Layer/PointGrid.js	2011-06-17 18:18:40 UTC (rev 12099)
+++ sandbox/tschaub/editing/lib/OpenLayers/Layer/PointGrid.js	2011-06-17 18:26:24 UTC (rev 12100)
@@ -10,7 +10,20 @@
 
 /**
  * Class: OpenLayers.Layer.PointGrid
+ * A point grid layer dynamically generates a regularly spaced grid of point
+ *     features.  This is a specialty layer for cases where an application needs
+ *     a regular grid of points.  It can be used, for example, in an editing
+ *     environment to snap to a grid.
  *
+ * Create a new vector layer with the <OpenLayers.Layer.PointGrid> constructor.
+ * (code)
+ * // create a grid with points spaced at 10 map units
+ * var points = new OpenLayers.Layer.PointGrid({dx: 10, dy: 10});
+ *
+ * // create a grid with different x/y spacing rotated 15 degrees clockwise.
+ * var points = new OpenLayers.Layer.PointGrid({dx: 5, dy: 10, rotation: 15});
+ * (end)
+ *
  * Inherits from:
  *  - <OpenLayers.Layer.Vector>
  */
@@ -18,15 +31,15 @@
 
     /**
      * APIProperty: dx
-     * {Number} Point grid spacing in the x-axis direction.  Read-only.  Use the
-     * <setSpacing> method to modify this value.
+     * {Number} Point grid spacing in the x-axis direction (map units).  
+     * Read-only.  Use the <setSpacing> method to modify this value.
      */
     dx: null,
 
     /**
      * APIProperty: dy
-     * {Number} Point grid spacing in the y-axis direction.  Read-only.  Use the
-     * <setSpacing> method to modify this value.
+     * {Number} Point grid spacing in the y-axis direction (map units).  
+     * Read-only.  Use the <setSpacing> method to modify this value.
      */
     dy: null,
 
@@ -56,11 +69,12 @@
 
     /**
      * APIProperty: origin
-     * {OpenLayers.LonLat} Grid origin.  If not set at construction, the center
-     * of the map's maximum extent is used.  Read-only.  Use the <setOrigin> 
-     * method to modify this value.
+     * {OpenLayers.LonLat} Grid origin.  The grid lattice will be aligned with 
+     * the origin.  If not set at construction, the center of the map's maximum 
+     * extent is used.  Read-only.  Use the <setOrigin> method to modify this 
+     * value.
      */
-    origin: 0,
+    origin: null,
 
     /**
      * Property: gridBounds
@@ -109,7 +123,8 @@
     
     /**
      * APIMethod: setRatio
-     * Set the grid <ratio> property and update the grid.
+     * Set the grid <ratio> property and update the grid.  Can only be called
+     *     after the layer has been added to a map with a center/extent.
      *
      * Parameters:
      * ratio - {Number}
@@ -121,7 +136,8 @@
     
     /**
      * APIMethod: setMaxFeatures
-     * Set the grid <maxFeatures> property and update the grid.
+     * Set the grid <maxFeatures> property and update the grid.  Can only be 
+     *     called after the layer has been added to a map with a center/extent.
      *
      * Parameters:
      * maxFeatures - {Number}
@@ -134,7 +150,8 @@
     /**
      * APIMethod: setSpacing
      * Set the grid <dx> and <dy> properties and update the grid.  If only one
-     *     argument is provided, it will be set as <dx> and <dy>.
+     *     argument is provided, it will be set as <dx> and <dy>.  Can only be 
+     *     called after the layer has been added to a map with a center/extent.
      *
      * Parameters:
      * dx - {Number}
@@ -148,7 +165,8 @@
     
     /**
      * APIMethod: setOrigin
-     * Set the grid <origin> property and update the grid.
+     * Set the grid <origin> property and update the grid.  Can only be called
+     *     after the layer has been added to a map with a center/extent.
      *
      * Parameters:
      * origin - {<OpenLayers.LonLat>}
@@ -174,7 +192,10 @@
     
     /**
      * APIMethod: setRotation
-     * Set the grid <rotation> property and update the grid.
+     * Set the grid <rotation> property and update the grid.  Rotation values
+     *     are in degrees clockwise from the positive x-axis (negative values
+     *     for counter-clockwise rotation).  Can only be called after the layer 
+     *     has been added to a map with a center/extent.
      *
      * Parameters:
      * rotation - {Number} Degrees clockwise from the positive x-axis.
@@ -204,7 +225,7 @@
         if (this.rotation) {
             var origin = this.getOrigin();
             var rotationOrigin = new OpenLayers.Geometry.Point(origin.lon, origin.lat);
-            var rect = OpenLayers.Geometry.Polygon.fromBounds(bounds);
+            var rect = bounds.toGeometry();
             rect.rotate(-this.rotation, rotationOrigin);
             bounds = rect.getBounds();
         }
@@ -214,6 +235,10 @@
     /**
      * Method: updateGrid
      * Update the grid.
+     *
+     * Parameters:
+     * force - {Boolean} Update the grid even if the previous bounds are still
+     *     valid.
      */
     updateGrid: function(force) {
         if (force || this.invalidBounds()) {

Modified: sandbox/tschaub/editing/tests/Geometry/Polygon.html
===================================================================
--- sandbox/tschaub/editing/tests/Geometry/Polygon.html	2011-06-17 18:18:40 UTC (rev 12099)
+++ sandbox/tschaub/editing/tests/Geometry/Polygon.html	2011-06-17 18:26:24 UTC (rev 12100)
@@ -373,21 +373,7 @@
         
     }
     
-    function test_fromBounds(t) {
-        
-        t.plan(1);
 
-        var bounds = new OpenLayers.Bounds(0, 0, 100, 50);
-        var polygon = OpenLayers.Geometry.Polygon.fromBounds(bounds);
-        
-        var format = new OpenLayers.Format.WKT();
-        var wkt = format.write(new OpenLayers.Feature.Vector(polygon));
-        
-        t.eq(wkt, "POLYGON((0 50,100 50,100 0,0 0,0 50))", "correct polygon from bounds");
-        
-    }
-    
-
   </script>
 </head>
 <body>



More information about the Commits mailing list