[OpenLayers-Commits] r3617 - sandbox/tschaub/geojson/lib/OpenLayers/Format

commits at openlayers.org commits at openlayers.org
Fri Jul 6 13:00:10 EDT 2007


Author: tschaub
Date: 2007-07-06 13:00:05 -0400 (Fri, 06 Jul 2007)
New Revision: 3617

Modified:
   sandbox/tschaub/geojson/lib/OpenLayers/Format/GeoJSON.js
Log:
nattydocs for geojson

Modified: sandbox/tschaub/geojson/lib/OpenLayers/Format/GeoJSON.js
===================================================================
--- sandbox/tschaub/geojson/lib/OpenLayers/Format/GeoJSON.js	2007-07-06 16:43:15 UTC (rev 3616)
+++ sandbox/tschaub/geojson/lib/OpenLayers/Format/GeoJSON.js	2007-07-06 17:00:05 UTC (rev 3617)
@@ -3,38 +3,61 @@
  * for the full text of the license. */
 
 /**
- * Read and write GeoJSON. 
  * @requires OpenLayers/Format/JSON.js
+ *
+ * Class: OpenLayers.Format.GeoJSON
+ * Read and write GeoJSON. Create a new parser with the
+ * <OpenLayers.Format.GeoJSON> constructor.
+ *
+ * Inherits from:
+ *  - <OpenLayers.Format.JSON>
  */
 OpenLayers.Format.GeoJSON = OpenLayers.Class.create();
 OpenLayers.Format.GeoJSON.prototype = 
   OpenLayers.Class.inherit(OpenLayers.Format.JSON, {
 
     /**
+     * Constructor: OpenLayers.Format.GeoJSON
+     * Create a new parser for GeoJSON
+     *
+     * Parameters:
+     * options - {Object} An optional object whose properties will be set on
+     *                    this instance.
+     */
+    initialize: function(options) {
+        OpenLayers.Format.JSON.prototype.initialize.apply(this, [options]);
+    },
+
+    /**
+     * APIMethod: read
      * Deserialize a GeoJSON string.
-     * @param {String} json A GeoJSON string
-     * @param {String} type Optional string that determines the structure of
-     *                      the output.  Supported values are "Geometry",
-     *                      "Feature", "GeometryCollection", and
-     *                      "FeatureCollection".  If absent or null, a
-     *                      default of "FeatureCollection" is assumed.
-     * @param {Function} filter A function which will be called for every key
-     *                          and value at every level of the final result.
-     *                          Each value will be replaced by the result of
-     *                          the filter function. This can be used to reform
-     *                          generic objects into instances of classes, or to
-     *                          transform date strings into Date objects.
-     * @returns {Object} The return depends on the value of the type argument.
-     *                   If type is "FeatureCollection" (the default), the
-     *                   return will be an array of OpenLayers.Feature.Vector.
-     *                   If type is "Geometry", the input json must represent a
-     *                   single geometry, and the return will be an
-     *                   OpenLayers.Geometry.  If type is "Feature", the input
-     *                   json must represent a single feature, and the return
-     *                   will be an OpenLayers.Feature.Vector.  If type is
-     *                   "GeometryCollection", the input json must represent
-     *                   a geometry collection, and the return will be an array
-     *                   of OpenLayers.Geometry.
+     *
+     * Parameters:
+     * json - {String} A GeoJSON string
+     * type {String} Optional string that determines the structure of
+     *     the output.  Supported values are "Geometry",
+     *     "Feature", "GeometryCollection", and
+     *     "FeatureCollection".  If absent or null, a
+     *     default of "FeatureCollection" is assumed.
+     * filter - {Function} A function which will be called for every key
+     *     and value at every level of the final result.
+     *     Each value will be replaced by the result of
+     *     the filter function. This can be used to reform
+     *     generic objects into instances of classes, or to
+     *     transform date strings into Date objects.
+     *
+     * Return: 
+     * {Object} The return depends on the value of the type argument.
+     *     If type is "FeatureCollection" (the default), the
+     *     return will be an array of OpenLayers.Feature.Vector.
+     *     If type is "Geometry", the input json must represent a
+     *     single geometry, and the return will be an
+     *     OpenLayers.Geometry.  If type is "Feature", the input
+     *     json must represent a single feature, and the return
+     *     will be an OpenLayers.Feature.Vector.  If type is
+     *     "GeometryCollection", the input json must represent
+     *     a geometry collection, and the return will be an array
+     *     of OpenLayers.Geometry.
      */
     read: function(json, type, filter) {
         type = (type) ? type : "FeatureCollection";
@@ -120,6 +143,13 @@
         return results;
     },
     
+    /**
+     * Method: isValidType
+     * Check if a GeoJSON object is a valid representative of the given type
+     *
+     * Return:
+     * {Boolean} The object is valid GeoJSON object of the given type
+     */
     isValidType: function(obj, type) {
         var valid = false;
         switch(type) {
@@ -151,10 +181,14 @@
     },
     
     /**
-     * Convert a feature object from GeoJSON into an OpenLayers.Feature.Vector.
-     * @param {Object} obj An object created from a GeoJSON object
-     * @returns {OpenLayers.Feature.Vector} A feature
-     * @private
+     * Method: parseFeature
+     * Convert a feature object from GeoJSON into an <OpenLayers.Feature.Vector>.
+     *
+     * Parameters:
+     * obj - {Object} An object created from a GeoJSON object
+     *
+     * Return:
+     * {OpenLayers.Feature.Vector} A feature
      */
     parseFeature: function(obj) {
         var feature, geometry, attributes;
@@ -170,10 +204,14 @@
     },
     
     /**
-     * Convert a geometry object from GeoJSON into an OpenLayers.Geometry.
-     * @param {Object} obj An object created from a GeoJSON object
-     * @returns {OpenLayers.Geometry} A geometry
-     * @private
+     * Method: parseGeometry
+     * Convert a geometry object from GeoJSON into an <OpenLayers.Geometry>.
+     *
+     * Parameters:
+     * obj - {Object} An object created from a GeoJSON object
+     *
+     * Return: 
+     * {OpenLayers.Geometry} A geometry
      */
     parseGeometry: function(obj) {
         var geometry;
@@ -193,16 +231,20 @@
     },
     
     /**
+     * Property: parseCoords
      * Object with properties corresponding to the GeoJSON geometry types.
      * Property values are functions that do the actual parsing.
-     * @private
      */
     parseCoords: {
         /**
+         * Method: parseCoords.point
          * Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
-         * @param {Object} array The coordinates array from the GeoJSON fragment
-         * @returns {OpenLayers.Geometry} A geometry
-         * @private
+         *
+         * Parameters:
+         * array - {Object} The coordinates array from the GeoJSON fragment
+         *
+         * Return:
+         * {OpenLayers.Geometry} A geometry
          */
         "point": function(array) {
             if(array.length != 2) {
@@ -212,10 +254,14 @@
         },
         
         /**
+         * Method: parseCoords.multipoint
          * Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
-         * @param {Object} array The coordinates array from the GeoJSON fragment
-         * @returns {OpenLayers.Geometry} A geometry
-         * @private
+         *
+         * Parameters:
+         * array {Object} The coordinates array from the GeoJSON fragment
+         *
+         * Return:
+         * {OpenLayers.Geometry} A geometry
          */
         "multipoint": function(array) {
             var points = [];
@@ -232,10 +278,14 @@
         },
 
         /**
+         * Method: parseCoords.linestring
          * Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
-         * @param {Object} array The coordinates array from the GeoJSON fragment
-         * @returns {OpenLayers.Geometry} A geometry
-         * @private
+         *
+         * Parameters:
+         * array - {Object} The coordinates array from the GeoJSON fragment
+         *
+         * Return:
+         * {OpenLayers.Geometry} A geometry
          */
         "linestring": function(array) {
             var points = [];
@@ -252,10 +302,14 @@
         },
         
         /**
+         * Method: parseCoords.multilinestring
          * Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
-         * @param {Object} array The coordinates array from the GeoJSON fragment
-         * @returns {OpenLayers.Geometry} A geometry
-         * @private
+         *
+         * Parameters:
+         * array - {Object} The coordinates array from the GeoJSON fragment
+         *
+         * Return:
+         * {OpenLayers.Geometry} A geometry
          */
         "multilinestring": function(array) {
             var lines = [];
@@ -272,10 +326,14 @@
         },
         
         /**
+         * Method: parseCoords.polygon
          * Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
-         * @param {Object} array The coordinates array from the GeoJSON fragment
-         * @returns {OpenLayers.Geometry} A geometry
-         * @private
+         *
+         * Return:
+         * array - {Object} The coordinates array from the GeoJSON fragment
+         *
+         * Return:
+         * {OpenLayers.Geometry} A geometry
          */
         "polygon": function(array) {
             var rings = [];
@@ -293,10 +351,14 @@
         },
 
         /**
+         * Method: parseCoords.multipolygon
          * Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
-         * @param {Object} array The coordinates array from the GeoJSON fragment
-         * @returns {OpenLayers.Geometry} A geometry
-         * @private
+         *
+         * Parameters:
+         * array - {Object} The coordinates array from the GeoJSON fragment
+         *
+         * Return:
+         * {OpenLayers.Geometry} A geometry
          */
         "multipolygon": function(array) {
             var polys = [];
@@ -313,10 +375,14 @@
         },
 
         /**
+         * Method: parseCoords.box
          * Convert a coordinate array from GeoJSON into an OpenLayers.Geometry.
-         * @param {Object} array The coordinates array from the GeoJSON fragment
-         * @returns {OpenLayers.Geometry} A geometry
-         * @private
+         *
+         * Parameters:
+         * array - {Object} The coordinates array from the GeoJSON fragment
+         *
+         * Return:
+         * {OpenLayers.Geometry} A geometry
          */
         "box": function(array) {
             if(array.length != 2) {
@@ -336,12 +402,17 @@
     },
 
     /**
+     * APIMethod: write
      * Serialize a feature, geometry, array of features, or array of geometries
-     * into a GeoJSON string.
-     * @param {Object} obj An OpenLayers.Feature.Vector, OpenLayers.Geometry,
-     *                    or an array of either features or geometries.
-     * @returns {String} The GeoJSON string representation of the input geometry,
-     *                   features, array of geometries, or array of features.
+     *     into a GeoJSON string.
+     *
+     * Parameters:
+     * obj - {Object} An OpenLayers.Feature.Vector, OpenLayers.Geometry,
+     *     or an array of either features or geometries.
+     *
+     * Return:
+     * {String} The GeoJSON string representation of the input geometry,
+     *     features, array of geometries, or array of features.
      */
     write: function(obj) {
         var geojson = {
@@ -400,15 +471,20 @@
     },
     
     /**
+     * Property: extract
      * Object with properties corresponding to the GeoJSON types.
      * Property values are functions that do the actual value extraction.
      */
     extract: {
         /**
+         * Method: extract.feature
          * Return a partial GeoJSON object representing a single feature.
-         * @param {OpenLayers.Feature.Vector} feature
-         * @returns {Object} An object representing the point
-         * @private
+         *
+         * Parameters:
+         * feature - {OpenLayers.Feature.Vector}
+         *
+         * Return:
+         * {Object} An object representing the point
          */
         'feature': function(feature) {
             var geom = this.extract.geometry.apply(this, [feature.geometry]);
@@ -421,10 +497,14 @@
         },
         
         /**
+         * Method: extract.geometry
          * Return a GeoJSON object representing a single geometry.
-         * @param {OpenLayers.Geometry} point
-         * @returns {Object} An object representing the geometry
-         * @private
+         *
+         * Parameters:
+         * geometry - {OpenLayers.Geometry}
+         *
+         * Return:
+         * {Object} An object representing the geometry
          */
         'geometry': function(geometry) {
             var geometryType = geometry.CLASS_NAME.split('.')[2];
@@ -436,21 +516,29 @@
         },
 
         /**
+         * Method: extract.poin
          * Return an array of coordinates from a point.
-         * @param {OpenLayers.Geometry.Point} point
-         * @returns {Array} An array of coordinates representing the point
-         * @private
+         *
+         * Parameters:
+         * point - {OpenLayers.Geometry.Point}
+         *
+         * Return: 
+         * {Array} An array of coordinates representing the point
          */
         'point': function(point) {
             return [point.x, point.y];
         },
 
         /**
+         * Method: extract.multipoint
          * Return an array of point coordinates from a multipoint.
-         * @param {OpenLayers.Geometry.MultiPoint} multipoint
-         * @returns {Array} An array of point coordinate arrays representing
-         *                  the multipoint
-         * @private
+         *
+         * Parameters:
+         * multipoint - {OpenLayers.Geometry.MultiPoint}
+         *
+         * Return:
+         * {Array} An array of point coordinate arrays representing
+         *     the multipoint
          */
         'multipoint': function(multipoint) {
             var array = [];
@@ -461,11 +549,15 @@
         },
         
         /**
+         * Method: extract.linestring
          * Return an array of coordinate arrays from a linestring.
-         * @param {OpenLayers.Geometry.LineString} linestring
-         * @returns {Array} An array of coordinate arrays representing
-         *                  the linestring
-         * @private
+         *
+         * Parameters:
+         * linestring - {OpenLayers.Geometry.LineString}
+         *
+         * Return:
+         * {Array} An array of coordinate arrays representing
+         *     the linestring
          */
         'linestring': function(linestring) {
             var array = [];
@@ -477,10 +569,13 @@
 
         /**
          * Return an array of linestring arrays from a linestring.
-         * @param {OpenLayers.Geometry.MultiLineString} linestring
-         * @returns {Array} An array of linestring arrays representing
-         *                  the multilinestring
-         * @private
+         * 
+         * Parameters:
+         * linestring - {OpenLayers.Geometry.MultiLineString}
+         * 
+         * Return:
+         * {Array} An array of linestring arrays representing
+         *     the multilinestring
          */
         'multilinestring': function(multilinestring) {
             var array = [];
@@ -492,9 +587,12 @@
         
         /**
          * Return an array of linear ring arrays from a polygon.
-         * @param {OpenLayers.Geometry.Polygon} polygon
-         * @returns {Array} An array of linear ring arrays representing the polygon
-         * @private
+         *
+         * Parameters:
+         * polygon - {OpenLayers.Geometry.Polygon}
+         * 
+         * Return:
+         * {Array} An array of linear ring arrays representing the polygon
          */
         'polygon': function(polygon) {
             var array = [];
@@ -506,10 +604,13 @@
 
         /**
          * Return an array of polygon arrays from a multipolygon.
-         * @param {OpenLayers.Geometry.MultiPolygon} multipolygon
-         * @returns {Array} An array of polygon arrays representing
-         *                  the multipolygon
-         * @private
+         * 
+         * Parameters:
+         * multipolygon - {OpenLayers.Geometry.MultiPolygon}
+         * 
+         * Return:
+         * {Array} An array of polygon arrays representing
+         *     the multipolygon
          */
         'multipolygon': function(multipolygon) {
             var array = [];



More information about the Commits mailing list