- Timestamp:
- Jan 18, 2011, 10:19:20 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/zoo-api/js/ZOO-api.js
r74 r81 115 115 }, 116 116 /** 117 * Function: rad 118 * 119 * Parameters: 120 * x - {Float} 121 * 122 * Returns: 123 * {Float} 124 */ 125 rad: function(x) {return x*Math.PI/180;}, 126 /** 127 * Function: distVincenty 128 * Given two objects representing points with geographic coordinates, this 129 * calculates the distance between those points on the surface of an 130 * ellipsoid. 131 * 132 * Parameters: 133 * p1 - {<ZOO.Geometry.Point>} (or any object with both .x, .y properties) 134 * p2 - {<ZOO.Geometry.Point>} (or any object with both .x, .y properties) 135 * 136 * Returns: 137 * {Float} The distance (in km) between the two input points as measured on an 138 * ellipsoid. Note that the input point objects must be in geographic 139 * coordinates (decimal degrees) and the return distance is in kilometers. 140 */ 141 distVincenty: function(p1, p2) { 142 var a = 6378137, b = 6356752.3142, f = 1/298.257223563; 143 var L = ZOO.rad(p2.x - p1.y); 144 var U1 = Math.atan((1-f) * Math.tan(ZOO.rad(p1.y))); 145 var U2 = Math.atan((1-f) * Math.tan(ZOO.rad(p2.y))); 146 var sinU1 = Math.sin(U1), cosU1 = Math.cos(U1); 147 var sinU2 = Math.sin(U2), cosU2 = Math.cos(U2); 148 var lambda = L, lambdaP = 2*Math.PI; 149 var iterLimit = 20; 150 while (Math.abs(lambda-lambdaP) > 1e-12 && --iterLimit>0) { 151 var sinLambda = Math.sin(lambda), cosLambda = Math.cos(lambda); 152 var sinSigma = Math.sqrt((cosU2*sinLambda) * (cosU2*sinLambda) + 153 (cosU1*sinU2-sinU1*cosU2*cosLambda) * (cosU1*sinU2-sinU1*cosU2*cosLambda)); 154 if (sinSigma==0) { 155 return 0; // co-incident points 156 } 157 var cosSigma = sinU1*sinU2 + cosU1*cosU2*cosLambda; 158 var sigma = Math.atan2(sinSigma, cosSigma); 159 var alpha = Math.asin(cosU1 * cosU2 * sinLambda / sinSigma); 160 var cosSqAlpha = Math.cos(alpha) * Math.cos(alpha); 161 var cos2SigmaM = cosSigma - 2*sinU1*sinU2/cosSqAlpha; 162 var C = f/16*cosSqAlpha*(4+f*(4-3*cosSqAlpha)); 163 lambdaP = lambda; 164 lambda = L + (1-C) * f * Math.sin(alpha) * 165 (sigma + C*sinSigma*(cos2SigmaM+C*cosSigma*(-1+2*cos2SigmaM*cos2SigmaM))); 166 } 167 if (iterLimit==0) { 168 return NaN; // formula failed to converge 169 } 170 var uSq = cosSqAlpha * (a*a - b*b) / (b*b); 171 var A = 1 + uSq/16384*(4096+uSq*(-768+uSq*(320-175*uSq))); 172 var B = uSq/1024 * (256+uSq*(-128+uSq*(74-47*uSq))); 173 var deltaSigma = B*sinSigma*(cos2SigmaM+B/4*(cosSigma*(-1+2*cos2SigmaM*cos2SigmaM)- 174 B/6*cos2SigmaM*(-3+4*sinSigma*sinSigma)*(-3+4*cos2SigmaM*cos2SigmaM))); 175 var s = b*A*(sigma-deltaSigma); 176 var d = s.toFixed(3)/1000; // round to 1mm precision 177 return d; 178 }, 179 /** 117 180 * Function: Class 118 181 * Method used to create ZOO classes. Includes support for … … 669 732 projCode: null, 670 733 /** 671 * Constructor: OpenLayers.Projection734 * Constructor: ZOO.Projection 672 735 * This class offers several methods for interacting with a wrapped 673 736 * zoo-pro4js projection object. … … 750 813 * point - {{ZOO.Geometry.Point> | Object} An object with x and y 751 814 * properties representing coordinates in those dimensions. 752 * sourceProj - { OpenLayers.Projection} Source map coordinate system753 * destProj - { OpenLayers.Projection} Destination map coordinate system815 * sourceProj - {ZOO.Projection} Source map coordinate system 816 * destProj - {ZOO.Projection} Destination map coordinate system 754 817 * 755 818 * Returns: … … 973 1036 }, 974 1037 /** 1038 * Property: extract 975 1039 * Object with properties corresponding to the geometry types. 976 1040 * Property values are functions that do the actual data extraction. … … 1057 1121 }, 1058 1122 /** 1123 * Property: parse 1059 1124 * Object with properties corresponding to the geometry types. 1060 * Property values are functions that do the actual parsing.1125 * Property values are functions that do the actual parsing. 1061 1126 */ 1062 1127 parse: { 1063 1128 /** 1129 * Method: parse.point 1064 1130 * Return point feature given a point WKT fragment. 1065 * @param {String} str A WKT fragment representing the point 1066 * @returns {<ZOO.Feature>} A point feature 1131 * 1132 * Parameters: 1133 * str - {String} A WKT fragment representing the point 1134 * Returns: 1135 * {<ZOO.Feature>} A point feature 1067 1136 */ 1068 1137 'point': function(str) { … … 1073 1142 }, 1074 1143 /** 1144 * Method: parse.multipoint 1075 1145 * Return a multipoint feature given a multipoint WKT fragment. 1076 * @param {String} A WKT fragment representing the multipoint 1077 * @returns {<ZOO.Feature>} A multipoint feature 1146 * 1147 * Parameters: 1148 * str - {String} A WKT fragment representing the multipoint 1149 * 1150 * Returns: 1151 * {<ZOO.Feature>} A multipoint feature 1078 1152 */ 1079 1153 'multipoint': function(str) { … … 1088 1162 }, 1089 1163 /** 1164 * Method: parse.linestring 1090 1165 * Return a linestring feature given a linestring WKT fragment. 1091 * @param {String} A WKT fragment representing the linestring 1092 * @returns {<ZOO.Feature>} A linestring feature 1166 * 1167 * Parameters: 1168 * str - {String} A WKT fragment representing the linestring 1169 * 1170 * Returns: 1171 * {<ZOO.Feature>} A linestring feature 1093 1172 */ 1094 1173 'linestring': function(str) { … … 1103 1182 }, 1104 1183 /** 1184 * Method: parse.multilinestring 1105 1185 * Return a multilinestring feature given a multilinestring WKT fragment. 1106 * @param {String} A WKT fragment representing the multilinestring 1107 * @returns {<ZOO.Feature>} A multilinestring feature 1186 * 1187 * Parameters: 1188 * str - {String} A WKT fragment representing the multilinestring 1189 * 1190 * Returns: 1191 * {<ZOO.Feature>} A multilinestring feature 1108 1192 */ 1109 1193 'multilinestring': function(str) { … … 1120 1204 }, 1121 1205 /** 1206 * Method: parse.polygon 1122 1207 * Return a polygon feature given a polygon WKT fragment. 1123 * @param {String} A WKT fragment representing the polygon 1124 * @returns {<ZOO.Feature>} A polygon feature 1208 * 1209 * Parameters: 1210 * str - {String} A WKT fragment representing the polygon 1211 * 1212 * Returns: 1213 * {<ZOO.Feature>} A polygon feature 1125 1214 */ 1126 1215 'polygon': function(str) { … … 1139 1228 }, 1140 1229 /** 1230 * Method: parse.multipolygon 1141 1231 * Return a multipolygon feature given a multipolygon WKT fragment. 1142 * @param {String} A WKT fragment representing the multipolygon 1143 * @returns {<ZOO.Feature>} A multipolygon feature 1144 * @private 1232 * 1233 * Parameters: 1234 * str - {String} A WKT fragment representing the multipolygon 1235 * 1236 * Returns: 1237 * {<ZOO.Feature>} A multipolygon feature 1145 1238 */ 1146 1239 'multipolygon': function(str) { … … 1157 1250 }, 1158 1251 /** 1252 * Method: parse.geometrycollection 1159 1253 * Return an array of features given a geometrycollection WKT fragment. 1160 * @param {String} A WKT fragment representing the geometrycollection 1161 * @returns {Array} An array of ZOO.Feature 1254 * 1255 * Parameters: 1256 * str - {String} A WKT fragment representing the geometrycollection 1257 * 1258 * Returns: 1259 * {Array} An array of ZOO.Feature 1162 1260 */ 1163 1261 'geometrycollection': function(str) { … … 1180 1278 * 1181 1279 * Inherits from: 1182 * - < OpenLayers.Format>1280 * - <ZOO.Format> 1183 1281 */ 1184 1282 ZOO.Format.JSON = ZOO.Class(ZOO.Format, { 1283 /** 1284 * Property: indent 1285 * {String} For "pretty" printing, the indent string will be used once for 1286 * each indentation level. 1287 */ 1185 1288 indent: " ", 1289 /** 1290 * Property: space 1291 * {String} For "pretty" printing, the space string will be used after 1292 * the ":" separating a name/value pair. 1293 */ 1186 1294 space: " ", 1295 /** 1296 * Property: newline 1297 * {String} For "pretty" printing, the newline string will be used at the 1298 * end of each name/value pair or array item. 1299 */ 1187 1300 newline: "\n", 1301 /** 1302 * Property: level 1303 * {Integer} For "pretty" printing, this is incremented/decremented during 1304 * serialization. 1305 */ 1188 1306 level: 0, 1307 /** 1308 * Property: pretty 1309 * {Boolean} Serialize with extra whitespace for structure. This is set 1310 * by the <write> method. 1311 */ 1189 1312 pretty: false, 1313 /** 1314 * Constructor: ZOO.Format.JSON 1315 * Create a new parser for JSON. 1316 * 1317 * Parameters: 1318 * options - {Object} An optional object whose properties will be set on 1319 * this instance. 1320 */ 1190 1321 initialize: function(options) { 1191 1322 ZOO.Format.prototype.initialize.apply(this, [options]); 1192 1323 }, 1324 /** 1325 * Method: read 1326 * Deserialize a json string. 1327 * 1328 * Parameters: 1329 * json - {String} A JSON string 1330 * filter - {Function} A function which will be called for every key and 1331 * value at every level of the final result. Each value will be 1332 * replaced by the result of the filter function. This can be used to 1333 * reform generic objects into instances of classes, or to transform 1334 * date strings into Date objects. 1335 * 1336 * Returns: 1337 * {Object} An object, array, string, or number . 1338 */ 1193 1339 read: function(json, filter) { 1340 /** 1341 * Parsing happens in three stages. In the first stage, we run the text 1342 * against a regular expression which looks for non-JSON 1343 * characters. We are especially concerned with '()' and 'new' 1344 * because they can cause invocation, and '=' because it can cause 1345 * mutation. But just to be safe, we will reject all unexpected 1346 * characters. 1347 */ 1194 1348 try { 1195 1349 if (/^[\],:{}\s]*$/.test(json.replace(/\\["\\\/bfnrtu]/g, '@'). 1196 1350 replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'). 1197 1351 replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { 1352 /** 1353 * In the second stage we use the eval function to compile the 1354 * text into a JavaScript structure. The '{' operator is 1355 * subject to a syntactic ambiguity in JavaScript - it can 1356 * begin a block or an object literal. We wrap the text in 1357 * parens to eliminate the ambiguity. 1358 */ 1198 1359 var object = eval('(' + json + ')'); 1360 /** 1361 * In the optional third stage, we recursively walk the new 1362 * structure, passing each name/value pair to a filter 1363 * function for possible transformation. 1364 */ 1199 1365 if(typeof filter === 'function') { 1200 1366 function walk(k, v) { … … 1220 1386 return null; 1221 1387 }, 1388 /** 1389 * Method: write 1390 * Serialize an object into a JSON string. 1391 * 1392 * Parameters: 1393 * value - {String} The object, array, string, number, boolean or date 1394 * to be serialized. 1395 * pretty - {Boolean} Structure the output with newlines and indentation. 1396 * Default is false. 1397 * 1398 * Returns: 1399 * {String} The JSON string representation of the input value. 1400 */ 1222 1401 write: function(value, pretty) { 1223 1402 this.pretty = !!pretty; … … 1233 1412 return json; 1234 1413 }, 1414 /** 1415 * Method: writeIndent 1416 * Output an indentation string depending on the indentation level. 1417 * 1418 * Returns: 1419 * {String} An appropriate indentation string. 1420 */ 1235 1421 writeIndent: function() { 1236 1422 var pieces = []; … … 1242 1428 return pieces.join(''); 1243 1429 }, 1430 /** 1431 * Method: writeNewline 1432 * Output a string representing a newline if in pretty printing mode. 1433 * 1434 * Returns: 1435 * {String} A string representing a new line. 1436 */ 1244 1437 writeNewline: function() { 1245 1438 return (this.pretty) ? this.newline : ''; 1246 1439 }, 1440 /** 1441 * Method: writeSpace 1442 * Output a string representing a space if in pretty printing mode. 1443 * 1444 * Returns: 1445 * {String} A space. 1446 */ 1247 1447 writeSpace: function() { 1248 1448 return (this.pretty) ? this.space : ''; 1249 1449 }, 1450 /** 1451 * Property: serialize 1452 * Object with properties corresponding to the serializable data types. 1453 * Property values are functions that do the actual serializing. 1454 */ 1250 1455 serialize: { 1456 /** 1457 * Method: serialize.object 1458 * Transform an object into a JSON string. 1459 * 1460 * Parameters: 1461 * object - {Object} The object to be serialized. 1462 * 1463 * Returns: 1464 * {String} A JSON string representing the object. 1465 */ 1251 1466 'object': function(object) { 1252 1467 // three special objects that we want to treat differently … … 1282 1497 return pieces.join(''); 1283 1498 }, 1499 /** 1500 * Method: serialize.array 1501 * Transform an array into a JSON string. 1502 * 1503 * Parameters: 1504 * array - {Array} The array to be serialized 1505 * 1506 * Returns: 1507 * {String} A JSON string representing the array. 1508 */ 1284 1509 'array': function(array) { 1285 1510 var json; … … 1300 1525 return pieces.join(''); 1301 1526 }, 1527 /** 1528 * Method: serialize.string 1529 * Transform a string into a JSON string. 1530 * 1531 * Parameters: 1532 * string - {String} The string to be serialized 1533 * 1534 * Returns: 1535 * {String} A JSON string representing the string. 1536 */ 1302 1537 'string': function(string) { 1303 1538 var m = { … … 1323 1558 return '"' + string + '"'; 1324 1559 }, 1560 /** 1561 * Method: serialize.number 1562 * Transform a number into a JSON string. 1563 * 1564 * Parameters: 1565 * number - {Number} The number to be serialized. 1566 * 1567 * Returns: 1568 * {String} A JSON string representing the number. 1569 */ 1325 1570 'number': function(number) { 1326 1571 return isFinite(number) ? String(number) : "null"; 1327 1572 }, 1573 /** 1574 * Method: serialize.boolean 1575 * Transform a boolean into a JSON string. 1576 * 1577 * Parameters: 1578 * bool - {Boolean} The boolean to be serialized. 1579 * 1580 * Returns: 1581 * {String} A JSON string representing the boolean. 1582 */ 1328 1583 'boolean': function(bool) { 1329 1584 return String(bool); 1330 1585 }, 1586 /** 1587 * Method: serialize.date 1588 * Transform a date into a JSON string. 1589 * 1590 * Parameters: 1591 * date - {Date} The date to be serialized. 1592 * 1593 * Returns: 1594 * {String} A JSON string representing the date. 1595 */ 1331 1596 'date': function(date) { 1332 1597 function format(number) { … … 1344 1609 CLASS_NAME: 'ZOO.Format.JSON' 1345 1610 }); 1611 /** 1612 * Class: ZOO.Format.GeoJSON 1613 * Read and write GeoJSON. Create a new parser with the 1614 * <ZOO.Format.GeoJSON> constructor. 1615 * 1616 * Inherits from: 1617 * - <ZOO.Format.JSON> 1618 */ 1346 1619 ZOO.Format.GeoJSON = ZOO.Class(ZOO.Format.JSON, { 1620 /** 1621 * Constructor: ZOO.Format.GeoJSON 1622 * Create a new parser for GeoJSON. 1623 * 1624 * Parameters: 1625 * options - {Object} An optional object whose properties will be set on 1626 * this instance. 1627 */ 1347 1628 initialize: function(options) { 1348 1629 ZOO.Format.JSON.prototype.initialize.apply(this, [options]); 1349 1630 }, 1631 /** 1632 * Method: read 1633 * Deserialize a GeoJSON string. 1634 * 1635 * Parameters: 1636 * json - {String} A GeoJSON string 1637 * type - {String} Optional string that determines the structure of 1638 * the output. Supported values are "Geometry", "Feature", and 1639 * "FeatureCollection". If absent or null, a default of 1640 * "FeatureCollection" is assumed. 1641 * filter - {Function} A function which will be called for every key and 1642 * value at every level of the final result. Each value will be 1643 * replaced by the result of the filter function. This can be used to 1644 * reform generic objects into instances of classes, or to transform 1645 * date strings into Date objects. 1646 * 1647 * Returns: 1648 * {Object} The return depends on the value of the type argument. If type 1649 * is "FeatureCollection" (the default), the return will be an array 1650 * of <ZOO.Feature>. If type is "Geometry", the input json 1651 * must represent a single geometry, and the return will be an 1652 * <ZOO.Geometry>. If type is "Feature", the input json must 1653 * represent a single feature, and the return will be an 1654 * <ZOO.Feature>. 1655 */ 1350 1656 read: function(json, type, filter) { 1351 1657 type = (type) ? type : "FeatureCollection"; … … 1357 1663 obj = json; 1358 1664 if(!obj) { 1359 // OpenLayers.Console.error("Bad JSON: " + json);1665 //ZOO.Console.error("Bad JSON: " + json); 1360 1666 } else if(typeof(obj.type) != "string") { 1361 // OpenLayers.Console.error("Bad GeoJSON - no type: " + json);1667 //ZOO.Console.error("Bad GeoJSON - no type: " + json); 1362 1668 } else if(this.isValidType(obj, type)) { 1363 1669 switch(type) { … … 1366 1672 results = this.parseGeometry(obj); 1367 1673 } catch(err) { 1368 // OpenLayers.Console.error(err);1674 //ZOO.Console.error(err); 1369 1675 } 1370 1676 break; … … 1374 1680 results.type = "Feature"; 1375 1681 } catch(err) { 1376 // OpenLayers.Console.error(err);1682 //ZOO.Console.error(err); 1377 1683 } 1378 1684 break; … … 1386 1692 } catch(err) { 1387 1693 results = null; 1388 // OpenLayers.Console.error(err);1694 //ZOO.Console.error(err); 1389 1695 } 1390 1696 break; … … 1395 1701 } catch(err) { 1396 1702 results = null; 1397 // OpenLayers.Console.error(err);1703 //ZOO.Console.error(err); 1398 1704 } 1399 1705 } … … 1405 1711 } catch(err) { 1406 1712 results = null; 1407 // OpenLayers.Console.error(err);1713 //ZOO.Console.error(err); 1408 1714 } 1409 1715 } … … 1413 1719 return results; 1414 1720 }, 1721 /** 1722 * Method: isValidType 1723 * Check if a GeoJSON object is a valid representative of the given type. 1724 * 1725 * Returns: 1726 * {Boolean} The object is valid GeoJSON object of the given type. 1727 */ 1415 1728 isValidType: function(obj, type) { 1416 1729 var valid = false; … … 1422 1735 obj.type) == -1) { 1423 1736 // unsupported geometry type 1424 // OpenLayers.Console.error("Unsupported geometry type: " +obj.type);1737 //ZOO.Console.error("Unsupported geometry type: " +obj.type); 1425 1738 } else { 1426 1739 valid = true; … … 1436 1749 valid = true; 1437 1750 } else { 1438 // OpenLayers.Console.error("Cannot convert types from " +obj.type + " to " + type);1751 //ZOO.Console.error("Cannot convert types from " +obj.type + " to " + type); 1439 1752 } 1440 1753 } 1441 1754 return valid; 1442 1755 }, 1756 /** 1757 * Method: parseFeature 1758 * Convert a feature object from GeoJSON into an 1759 * <ZOO.Feature>. 1760 * 1761 * Parameters: 1762 * obj - {Object} An object created from a GeoJSON object 1763 * 1764 * Returns: 1765 * {<ZOO.Feature>} A feature. 1766 */ 1443 1767 parseFeature: function(obj) { 1444 1768 var feature, geometry, attributes, bbox; … … 1458 1782 return feature; 1459 1783 }, 1784 /** 1785 * Method: parseGeometry 1786 * Convert a geometry object from GeoJSON into an <ZOO.Geometry>. 1787 * 1788 * Parameters: 1789 * obj - {Object} An object created from a GeoJSON object 1790 * 1791 * Returns: 1792 * {<ZOO.Geometry>} A geometry. 1793 */ 1460 1794 parseGeometry: function(obj) { 1461 1795 if (obj == null) … … 1499 1833 return geometry; 1500 1834 }, 1835 /** 1836 * Property: parseCoords 1837 * Object with properties corresponding to the GeoJSON geometry types. 1838 * Property values are functions that do the actual parsing. 1839 */ 1501 1840 parseCoords: { 1841 /** 1842 * Method: parseCoords.point 1843 * Convert a coordinate array from GeoJSON into an 1844 * <ZOO.Geometry.Point>. 1845 * 1846 * Parameters: 1847 * array - {Object} The coordinates array from the GeoJSON fragment. 1848 * 1849 * Returns: 1850 * {<ZOO.Geometry.Point>} A geometry. 1851 */ 1502 1852 "point": function(array) { 1503 1853 if(array.length != 2) { … … 1506 1856 return new ZOO.Geometry.Point(array[0], array[1]); 1507 1857 }, 1858 /** 1859 * Method: parseCoords.multipoint 1860 * Convert a coordinate array from GeoJSON into an 1861 * <ZOO.Geometry.MultiPoint>. 1862 * 1863 * Parameters: 1864 * array - {Object} The coordinates array from the GeoJSON fragment. 1865 * 1866 * Returns: 1867 * {<ZOO.Geometry.MultiPoint>} A geometry. 1868 */ 1508 1869 "multipoint": function(array) { 1509 1870 var points = []; … … 1519 1880 return new ZOO.Geometry.MultiPoint(points); 1520 1881 }, 1882 /** 1883 * Method: parseCoords.linestring 1884 * Convert a coordinate array from GeoJSON into an 1885 * <ZOO.Geometry.LineString>. 1886 * 1887 * Parameters: 1888 * array - {Object} The coordinates array from the GeoJSON fragment. 1889 * 1890 * Returns: 1891 * {<ZOO.Geometry.LineString>} A geometry. 1892 */ 1521 1893 "linestring": function(array) { 1522 1894 var points = []; … … 1532 1904 return new ZOO.Geometry.LineString(points); 1533 1905 }, 1906 /** 1907 * Method: parseCoords.multilinestring 1908 * Convert a coordinate array from GeoJSON into an 1909 * <ZOO.Geometry.MultiLineString>. 1910 * 1911 * Parameters: 1912 * array - {Object} The coordinates array from the GeoJSON fragment. 1913 * 1914 * Returns: 1915 * {<ZOO.Geometry.MultiLineString>} A geometry. 1916 */ 1534 1917 "multilinestring": function(array) { 1535 1918 var lines = []; … … 1545 1928 return new ZOO.Geometry.MultiLineString(lines); 1546 1929 }, 1930 /** 1931 * Method: parseCoords.polygon 1932 * Convert a coordinate array from GeoJSON into an 1933 * <ZOO.Geometry.Polygon>. 1934 * 1935 * Parameters: 1936 * array - {Object} The coordinates array from the GeoJSON fragment. 1937 * 1938 * Returns: 1939 * {<ZOO.Geometry.Polygon>} A geometry. 1940 */ 1547 1941 "polygon": function(array) { 1548 1942 var rings = []; … … 1559 1953 return new ZOO.Geometry.Polygon(rings); 1560 1954 }, 1955 /** 1956 * Method: parseCoords.multipolygon 1957 * Convert a coordinate array from GeoJSON into an 1958 * <ZOO.Geometry.MultiPolygon>. 1959 * 1960 * Parameters: 1961 * array - {Object} The coordinates array from the GeoJSON fragment. 1962 * 1963 * Returns: 1964 * {<ZOO.Geometry.MultiPolygon>} A geometry. 1965 */ 1561 1966 "multipolygon": function(array) { 1562 1967 var polys = []; … … 1572 1977 return new ZOO.Geometry.MultiPolygon(polys); 1573 1978 }, 1979 /** 1980 * Method: parseCoords.box 1981 * Convert a coordinate array from GeoJSON into an 1982 * <ZOO.Geometry.Polygon>. 1983 * 1984 * Parameters: 1985 * array - {Object} The coordinates array from the GeoJSON fragment. 1986 * 1987 * Returns: 1988 * {<ZOO.Geometry.Polygon>} A geometry. 1989 */ 1574 1990 "box": function(array) { 1575 1991 if(array.length != 2) { … … 1587 2003 } 1588 2004 }, 2005 /** 2006 * Method: write 2007 * Serialize a feature, geometry, array of features into a GeoJSON string. 2008 * 2009 * Parameters: 2010 * obj - {Object} An <ZOO.Feature>, <ZOO.Geometry>, 2011 * or an array of features. 2012 * pretty - {Boolean} Structure the output with newlines and indentation. 2013 * Default is false. 2014 * 2015 * Returns: 2016 * {String} The GeoJSON string representation of the input geometry, 2017 * features, or array of features. 2018 */ 1589 2019 write: function(obj, pretty) { 1590 2020 var geojson = { … … 1617 2047 [geojson, pretty]); 1618 2048 }, 2049 /** 2050 * Method: createCRSObject 2051 * Create the CRS object for an object. 2052 * 2053 * Parameters: 2054 * object - {<ZOO.Feature>} 2055 * 2056 * Returns: 2057 * {Object} An object which can be assigned to the crs property 2058 * of a GeoJSON object. 2059 */ 1619 2060 createCRSObject: function(object) { 1620 2061 //var proj = object.layer.projection.toString(); … … 1641 2082 return crs; 1642 2083 }, 2084 /** 2085 * Property: extract 2086 * Object with properties corresponding to the GeoJSON types. 2087 * Property values are functions that do the actual value extraction. 2088 */ 1643 2089 extract: { 2090 /** 2091 * Method: extract.feature 2092 * Return a partial GeoJSON object representing a single feature. 2093 * 2094 * Parameters: 2095 * feature - {<ZOO.Feature>} 2096 * 2097 * Returns: 2098 * {Object} An object representing the point. 2099 */ 1644 2100 'feature': function(feature) { 1645 2101 var geom = this.extract.geometry.apply(this, [feature.geometry]); … … 1651 2107 }; 1652 2108 }, 2109 /** 2110 * Method: extract.geometry 2111 * Return a GeoJSON object representing a single geometry. 2112 * 2113 * Parameters: 2114 * geometry - {<ZOO.Geometry>} 2115 * 2116 * Returns: 2117 * {Object} An object representing the geometry. 2118 */ 1653 2119 'geometry': function(geometry) { 1654 2120 if (geometry == null) … … 1674 2140 return json; 1675 2141 }, 2142 /** 2143 * Method: extract.point 2144 * Return an array of coordinates from a point. 2145 * 2146 * Parameters: 2147 * point - {<ZOO.Geometry.Point>} 2148 * 2149 * Returns: 2150 * {Array} An array of coordinates representing the point. 2151 */ 1676 2152 'point': function(point) { 1677 2153 return [point.x, point.y]; 1678 2154 }, 2155 /** 2156 * Method: extract.multipoint 2157 * Return an array of coordinates from a multipoint. 2158 * 2159 * Parameters: 2160 * multipoint - {<ZOO.Geometry.MultiPoint>} 2161 * 2162 * Returns: 2163 * {Array} An array of point coordinate arrays representing 2164 * the multipoint. 2165 */ 1679 2166 'multipoint': function(multipoint) { 1680 2167 var array = []; … … 1684 2171 return array; 1685 2172 }, 2173 /** 2174 * Method: extract.linestring 2175 * Return an array of coordinate arrays from a linestring. 2176 * 2177 * Parameters: 2178 * linestring - {<ZOO.Geometry.LineString>} 2179 * 2180 * Returns: 2181 * {Array} An array of coordinate arrays representing 2182 * the linestring. 2183 */ 1686 2184 'linestring': function(linestring) { 1687 2185 var array = []; … … 1691 2189 return array; 1692 2190 }, 2191 /** 2192 * Method: extract.multilinestring 2193 * Return an array of linestring arrays from a linestring. 2194 * 2195 * Parameters: 2196 * multilinestring - {<ZOO.Geometry.MultiLineString>} 2197 * 2198 * Returns: 2199 * {Array} An array of linestring arrays representing 2200 * the multilinestring. 2201 */ 1693 2202 'multilinestring': function(multilinestring) { 1694 2203 var array = []; … … 1698 2207 return array; 1699 2208 }, 2209 /** 2210 * Method: extract.polygon 2211 * Return an array of linear ring arrays from a polygon. 2212 * 2213 * Parameters: 2214 * polygon - {<ZOO.Geometry.Polygon>} 2215 * 2216 * Returns: 2217 * {Array} An array of linear ring arrays representing the polygon. 2218 */ 1700 2219 'polygon': function(polygon) { 1701 2220 var array = []; … … 1705 2224 return array; 1706 2225 }, 2226 /** 2227 * Method: extract.multipolygon 2228 * Return an array of polygon arrays from a multipolygon. 2229 * 2230 * Parameters: 2231 * multipolygon - {<ZOO.Geometry.MultiPolygon>} 2232 * 2233 * Returns: 2234 * {Array} An array of polygon arrays representing 2235 * the multipolygon 2236 */ 1707 2237 'multipolygon': function(multipolygon) { 1708 2238 var array = []; … … 1712 2242 return array; 1713 2243 }, 2244 /** 2245 * Method: extract.collection 2246 * Return an array of geometries from a geometry collection. 2247 * 2248 * Parameters: 2249 * collection - {<ZOO.Geometry.Collection>} 2250 * 2251 * Returns: 2252 * {Array} An array of geometry objects representing the geometry 2253 * collection. 2254 */ 1714 2255 'collection': function(collection) { 1715 2256 var len = collection.components.length; … … 1725 2266 CLASS_NAME: 'ZOO.Format.GeoJSON' 1726 2267 }); 2268 /** 2269 * Class: ZOO.Format.KML 2270 * Read/Write KML. Create a new instance with the <ZOO.Format.KML> 2271 * constructor. 2272 * 2273 * Inherits from: 2274 * - <ZOO.Format> 2275 */ 1727 2276 ZOO.Format.KML = ZOO.Class(ZOO.Format, { 2277 /** 2278 * Property: kmlns 2279 * {String} KML Namespace to use. Defaults to 2.2 namespace. 2280 */ 1728 2281 kmlns: "http://www.opengis.net/kml/2.2", 2282 /** 2283 * Property: foldersName 2284 * {String} Name of the folders. Default is "ZOO export". 2285 * If set to null, no name element will be created. 2286 */ 1729 2287 foldersName: "ZOO export", 2288 /** 2289 * Property: foldersDesc 2290 * {String} Description of the folders. Default is "Exported on [date]." 2291 * If set to null, no description element will be created. 2292 */ 1730 2293 foldersDesc: "Created on " + new Date(), 2294 /** 2295 * Property: placemarksDesc 2296 * {String} Name of the placemarks. Default is "No description available". 2297 */ 1731 2298 placemarksDesc: "No description available", 2299 /** 2300 * Property: extractAttributes 2301 * {Boolean} Extract attributes from KML. Default is true. 2302 * Extracting styleUrls requires this to be set to true 2303 */ 1732 2304 extractAttributes: true, 2305 /** 2306 * Constructor: ZOO.Format.KML 2307 * Create a new parser for KML. 2308 * 2309 * Parameters: 2310 * options - {Object} An optional object whose properties will be set on 2311 * this instance. 2312 */ 1733 2313 initialize: function(options) { 1734 2314 // compile regular expressions once instead of every time they are used … … 1742 2322 straightBracket: (/\$\[(.*?)\]/g) 1743 2323 }; 2324 // KML coordinates are always in longlat WGS84 2325 this.externalProjection = new ZOO.Projection("EPSG:4326"); 1744 2326 ZOO.Format.prototype.initialize.apply(this, [options]); 1745 2327 }, 2328 /** 2329 * APIMethod: read 2330 * Read data from a string, and return a list of features. 2331 * 2332 * Parameters: 2333 * data - {String} data to read/parse. 2334 * 2335 * Returns: 2336 * {Array(<ZOO.Feature>)} List of features. 2337 */ 1746 2338 read: function(data) { 1747 2339 this.features = []; … … 1752 2344 return this.features; 1753 2345 }, 2346 /** 2347 * Method: parseFeatures 2348 * Loop through all Placemark nodes and parse them. 2349 * Will create a list of features 2350 * 2351 * Parameters: 2352 * nodes - {Array} of {E4XElement} data to read/parse. 2353 * options - {Object} Hash of options 2354 * 2355 */ 1754 2356 parseFeatures: function(nodes) { 1755 2357 var features = new Array(nodes.length()); … … 1761 2363 this.features = this.features.concat(features); 1762 2364 }, 2365 /** 2366 * Method: parseFeature 2367 * This function is the core of the KML parsing code in ZOO. 2368 * It creates the geometries that are then attached to the returned 2369 * feature, and calls parseAttributes() to get attribute data out. 2370 * 2371 * Parameters: 2372 * node - {E4XElement} 2373 * 2374 * Returns: 2375 * {<ZOO.Feature>} A vector feature. 2376 */ 1763 2377 parseFeature: function(node) { 2378 // only accept one geometry per feature - look for highest "order" 1764 2379 var order = ["MultiGeometry", "Polygon", "LineString", "Point"]; 1765 2380 var type, nodeList, geometry, parser; … … 1776 2391 } 1777 2392 } 2393 // stop looking for different geometry types 1778 2394 break; 1779 2395 } 1780 2396 } 2397 // construct feature (optionally with attributes) 1781 2398 var attributes; 1782 2399 if(this.extractAttributes) { … … 1789 2406 return feature; 1790 2407 }, 2408 /** 2409 * Property: parseGeometry 2410 * Properties of this object are the functions that parse geometries based 2411 * on their type. 2412 */ 1791 2413 parseGeometry: { 2414 /** 2415 * Method: parseGeometry.point 2416 * Given a KML node representing a point geometry, create a ZOO 2417 * point geometry. 2418 * 2419 * Parameters: 2420 * node - {E4XElement} A KML Point node. 2421 * 2422 * Returns: 2423 * {<ZOO.Geometry.Point>} A point geometry. 2424 */ 1792 2425 'point': function(node) { 1793 2426 var coordString = node.*::coordinates.toString(); … … 1804 2437 return point; 1805 2438 }, 2439 /** 2440 * Method: parseGeometry.linestring 2441 * Given a KML node representing a linestring geometry, create a 2442 * ZOO linestring geometry. 2443 * 2444 * Parameters: 2445 * node - {E4XElement} A KML LineString node. 2446 * 2447 * Returns: 2448 * {<ZOO.Geometry.LineString>} A linestring geometry. 2449 */ 1806 2450 'linestring': function(node, ring) { 1807 2451 var line = null; … … 1838 2482 return line; 1839 2483 }, 2484 /** 2485 * Method: parseGeometry.polygon 2486 * Given a KML node representing a polygon geometry, create a 2487 * ZOO polygon geometry. 2488 * 2489 * Parameters: 2490 * node - {E4XElement} A KML Polygon node. 2491 * 2492 * Returns: 2493 * {<ZOO.Geometry.Polygon>} A polygon geometry. 2494 */ 1840 2495 'polygon': function(node) { 1841 2496 var nodeList = node..*::LinearRing; … … 1857 2512 return new ZOO.Geometry.Polygon(components); 1858 2513 }, 1859 multigeometry: function(node) { 2514 /** 2515 * Method: parseGeometry.multigeometry 2516 * Given a KML node representing a multigeometry, create a 2517 * ZOO geometry collection. 2518 * 2519 * Parameters: 2520 * node - {E4XElement} A KML MultiGeometry node. 2521 * 2522 * Returns: 2523 * {<ZOO.Geometry.Collection>} A geometry collection. 2524 */ 2525 'multigeometry': function(node) { 1860 2526 var child, parser; 1861 2527 var parts = []; … … 1872 2538 } 1873 2539 }, 2540 /** 2541 * Method: parseAttributes 2542 * 2543 * Parameters: 2544 * node - {E4XElement} 2545 * 2546 * Returns: 2547 * {Object} An attributes object. 2548 */ 1874 2549 parseAttributes: function(node) { 1875 2550 var attributes = {}; … … 1894 2569 return attributes; 1895 2570 }, 2571 /** 2572 * Method: parseExtendedData 2573 * Parse ExtendedData from KML. Limited support for schemas/datatypes. 2574 * See http://code.google.com/apis/kml/documentation/kmlreference.html#extendeddata 2575 * for more information on extendeddata. 2576 * 2577 * Parameters: 2578 * node - {E4XElement} 2579 * 2580 * Returns: 2581 * {Object} An attributes object. 2582 */ 1896 2583 parseExtendedData: function(node) { 1897 2584 var attributes = {}; … … 1911 2598 return attributes; 1912 2599 }, 2600 /** 2601 * Method: write 2602 * Accept Feature Collection, and return a string. 2603 * 2604 * Parameters: 2605 * features - {Array(<ZOO.Feature>} An array of features. 2606 * 2607 * Returns: 2608 * {String} A KML string. 2609 */ 1913 2610 write: function(features) { 1914 2611 if(!(features instanceof Array)) … … 1919 2616 folder.description = this.foldersDesc; 1920 2617 for(var i=0, len=features.length; i<len; ++i) { 1921 //folder.appendChild(this.createPlacemarkXML(features[i]));1922 2618 folder.Placemark[i] = this.createPlacemark(features[i]); 1923 2619 } 1924 2620 return kml.toXMLString(); 1925 2621 }, 2622 /** 2623 * Method: createPlacemark 2624 * Creates and returns a KML placemark node representing the given feature. 2625 * 2626 * Parameters: 2627 * feature - {<ZOO.Feature>} 2628 * 2629 * Returns: 2630 * {E4XElement} 2631 */ 1926 2632 createPlacemark: function(feature) { 1927 2633 var placemark = new XML('<Placemark xmlns="'+this.kmlns+'"></Placemark>'); … … 1935 2641 return placemark; 1936 2642 }, 2643 /** 2644 * Method: buildGeometryNode 2645 * Builds and returns a KML geometry node with the given geometry. 2646 * 2647 * Parameters: 2648 * geometry - {<ZOO.Geometry>} 2649 * 2650 * Returns: 2651 * {E4XElement} 2652 */ 1937 2653 buildGeometryNode: function(geometry) { 1938 2654 if (this.internalProjection && this.externalProjection) { … … 1950 2666 return node; 1951 2667 }, 2668 /** 2669 * Property: buildGeometry 2670 * Object containing methods to do the actual geometry node building 2671 * based on geometry type. 2672 */ 1952 2673 buildGeometry: { 2674 /** 2675 * Method: buildGeometry.point 2676 * Given a ZOO point geometry, create a KML point. 2677 * 2678 * Parameters: 2679 * geometry - {<ZOO.Geometry.Point>} A point geometry. 2680 * 2681 * Returns: 2682 * {E4XElement} A KML point node. 2683 */ 1953 2684 'point': function(geometry) { 1954 2685 var kml = new XML('<Point xmlns="'+this.kmlns+'"></Point>'); … … 1956 2687 return kml; 1957 2688 }, 2689 /** 2690 * Method: buildGeometry.multipoint 2691 * Given a ZOO multipoint geometry, create a KML 2692 * GeometryCollection. 2693 * 2694 * Parameters: 2695 * geometry - {<ZOO.Geometry.MultiPoint>} A multipoint geometry. 2696 * 2697 * Returns: 2698 * {E4XElement} A KML GeometryCollection node. 2699 */ 1958 2700 'multipoint': function(geometry) { 1959 2701 return this.buildGeometry.collection.apply(this, [geometry]); 1960 2702 }, 2703 /** 2704 * Method: buildGeometry.linestring 2705 * Given a ZOO linestring geometry, create a KML linestring. 2706 * 2707 * Parameters: 2708 * geometry - {<ZOO.Geometry.LineString>} A linestring geometry. 2709 * 2710 * Returns: 2711 * {E4XElement} A KML linestring node. 2712 */ 1961 2713 'linestring': function(geometry) { 1962 2714 var kml = new XML('<LineString xmlns="'+this.kmlns+'"></LineString>'); … … 1964 2716 return kml; 1965 2717 }, 2718 /** 2719 * Method: buildGeometry.multilinestring 2720 * Given a ZOO multilinestring geometry, create a KML 2721 * GeometryCollection. 2722 * 2723 * Parameters: 2724 * geometry - {<ZOO.Geometry.MultiLineString>} A multilinestring geometry. 2725 * 2726 * Returns: 2727 * {E4XElement} A KML GeometryCollection node. 2728 */ 1966 2729 'multilinestring': function(geometry) { 1967 2730 return this.buildGeometry.collection.apply(this, [geometry]); 1968 2731 }, 2732 /** 2733 * Method: buildGeometry.linearring 2734 * Given a ZOO linearring geometry, create a KML linearring. 2735 * 2736 * Parameters: 2737 * geometry - {<ZOO.Geometry.LinearRing>} A linearring geometry. 2738 * 2739 * Returns: 2740 * {E4XElement} A KML linearring node. 2741 */ 1969 2742 'linearring': function(geometry) { 1970 2743 var kml = new XML('<LinearRing xmlns="'+this.kmlns+'"></LinearRing>'); … … 1972 2745 return kml; 1973 2746 }, 2747 /** 2748 * Method: buildGeometry.polygon 2749 * Given a ZOO polygon geometry, create a KML polygon. 2750 * 2751 * Parameters: 2752 * geometry - {<ZOO.Geometry.Polygon>} A polygon geometry. 2753 * 2754 * Returns: 2755 * {E4XElement} A KML polygon node. 2756 */ 1974 2757 'polygon': function(geometry) { 1975 2758 var kml = new XML('<Polygon xmlns="'+this.kmlns+'"></Polygon>'); … … 1984 2767 return kml; 1985 2768 }, 2769 /** 2770 * Method: buildGeometry.multipolygon 2771 * Given a ZOO multipolygon geometry, create a KML 2772 * GeometryCollection. 2773 * 2774 * Parameters: 2775 * geometry - {<ZOO.Geometry.Point>} A multipolygon geometry. 2776 * 2777 * Returns: 2778 * {E4XElement} A KML GeometryCollection node. 2779 */ 1986 2780 'multipolygon': function(geometry) { 1987 2781 return this.buildGeometry.collection.apply(this, [geometry]); 1988 2782 }, 2783 /** 2784 * Method: buildGeometry.collection 2785 * Given a ZOO geometry collection, create a KML MultiGeometry. 2786 * 2787 * Parameters: 2788 * geometry - {<ZOO.Geometry.Collection>} A geometry collection. 2789 * 2790 * Returns: 2791 * {E4XElement} A KML MultiGeometry node. 2792 */ 1989 2793 'collection': function(geometry) { 1990 2794 var kml = new XML('<MultiGeometry xmlns="'+this.kmlns+'"></MultiGeometry>'); … … 1996 2800 } 1997 2801 }, 2802 /** 2803 * Method: buildCoordinatesNode 2804 * Builds and returns the KML coordinates node with the given geometry 2805 * <coordinates>...</coordinates> 2806 * 2807 * Parameters: 2808 * geometry - {<ZOO.Geometry>} 2809 * 2810 * Return: 2811 * {E4XElement} 2812 */ 1998 2813 buildCoordinatesNode: function(geometry) { 1999 2814 var cooridnates = new XML('<coordinates xmlns="'+this.kmlns+'"></coordinates>'); … … 2017 2832 CLASS_NAME: 'ZOO.Format.KML' 2018 2833 }); 2834 /** 2835 * Class: ZOO.Format.GML 2836 * Read/Write GML. Create a new instance with the <ZOO.Format.GML> 2837 * constructor. Supports the GML simple features profile. 2838 * 2839 * Inherits from: 2840 * - <ZOO.Format> 2841 */ 2019 2842 ZOO.Format.GML = ZOO.Class(ZOO.Format, { 2843 /** 2844 * Property: schemaLocation 2845 * {String} Schema location for a particular minor version. 2846 */ 2020 2847 schemaLocation: "http://www.opengis.net/gml http://schemas.opengis.net/gml/2.1.2/feature.xsd", 2848 /** 2849 * Property: namespaces 2850 * {Object} Mapping of namespace aliases to namespace URIs. 2851 */ 2021 2852 namespaces: { 2022 2853 ogr: "http://ogr.maptools.org/", … … 2026 2857 wfs: "http://www.opengis.net/wfs" // this is a convenience for reading wfs:FeatureCollection 2027 2858 }, 2859 /** 2860 * Property: defaultPrefix 2861 */ 2028 2862 defaultPrefix: 'ogr', 2863 /** 2864 * Property: collectionName 2865 * {String} Name of featureCollection element. 2866 */ 2029 2867 collectionName: "FeatureCollection", 2868 /* 2869 * Property: featureName 2870 * {String} Element name for features. Default is "sql_statement". 2871 */ 2030 2872 featureName: "sql_statement", 2873 /** 2874 * Property: geometryName 2875 * {String} Name of geometry element. Defaults to "geometryProperty". 2876 */ 2031 2877 geometryName: "geometryProperty", 2878 /** 2879 * Property: xy 2880 * {Boolean} Order of the GML coordinate true:(x,y) or false:(y,x) 2881 * Changing is not recommended, a new Format should be instantiated. 2882 */ 2032 2883 xy: true, 2884 /** 2885 * Constructor: ZOO.Format.GML 2886 * Create a new parser for GML. 2887 * 2888 * Parameters: 2889 * options - {Object} An optional object whose properties will be set on 2890 * this instance. 2891 */ 2033 2892 initialize: function(options) { 2034 2893 // compile regular expressions once instead of every time they are used … … 2041 2900 ZOO.Format.prototype.initialize.apply(this, [options]); 2042 2901 }, 2902 /** 2903 * Method: read 2904 * Read data from a string, and return a list of features. 2905 * 2906 * Parameters: 2907 * data - {String} data to read/parse. 2908 * 2909 * Returns: 2910 * {Array(<ZOO.Feature>)} An array of features. 2911 */ 2043 2912 read: function(data) { 2044 2913 this.features = []; … … 2057 2926 return features; 2058 2927 }, 2928 /** 2929 * Method: parseFeature 2930 * This function is the core of the GML parsing code in ZOO. 2931 * It creates the geometries that are then attached to the returned 2932 * feature, and calls parseAttributes() to get attribute data out. 2933 * 2934 * Parameters: 2935 * node - {E4XElement} A GML feature node. 2936 */ 2059 2937 parseFeature: function(node) { 2060 2938 // only accept one geometry per feature - look for highest "order" … … 2076 2954 } 2077 2955 } 2956 // stop looking for different geometry types 2078 2957 break; 2079 2958 } … … 2081 2960 var attributes; 2082 2961 if(this.extractAttributes) { 2083 //attributes = this.parseAttributes(node);2962 attributes = this.parseAttributes(node); 2084 2963 } 2085 2964 var feature = new ZOO.Feature(geometry, attributes); 2086 2965 return feature; 2087 2966 }, 2967 /** 2968 * Property: parseGeometry 2969 * Properties of this object are the functions that parse geometries based 2970 * on their type. 2971 */ 2088 2972 parseGeometry: { 2973 /** 2974 * Method: parseGeometry.point 2975 * Given a GML node representing a point geometry, create a ZOO 2976 * point geometry. 2977 * 2978 * Parameters: 2979 * node - {E4XElement} A GML node. 2980 * 2981 * Returns: 2982 * {<ZOO.Geometry.Point>} A point geometry. 2983 */ 2089 2984 'point': function(node) { 2090 2985 /** … … 2131 3026 return new ZOO.Geometry.Point(coords[1],coords[0],coords[2]); 2132 3027 }, 3028 /** 3029 * Method: parseGeometry.multipoint 3030 * Given a GML node representing a multipoint geometry, create a 3031 * ZOO multipoint geometry. 3032 * 3033 * Parameters: 3034 * node - {E4XElement} A GML node. 3035 * 3036 * Returns: 3037 * {<ZOO.Geometry.MultiPoint>} A multipoint geometry. 3038 */ 2133 3039 'multipoint': function(node) { 2134 3040 var nodeList = node..*::Point; … … 2144 3050 return new ZOO.Geometry.MultiPoint(components); 2145 3051 }, 3052 /** 3053 * Method: parseGeometry.linestring 3054 * Given a GML node representing a linestring geometry, create a 3055 * ZOO linestring geometry. 3056 * 3057 * Parameters: 3058 * node - {E4XElement} A GML node. 3059 * 3060 * Returns: 3061 * {<ZOO.Geometry.LineString>} A linestring geometry. 3062 */ 2146 3063 'linestring': function(node, ring) { 2147 3064 /** … … 2200 3117 return line; 2201 3118 }, 3119 /** 3120 * Method: parseGeometry.multilinestring 3121 * Given a GML node representing a multilinestring geometry, create a 3122 * ZOO multilinestring geometry. 3123 * 3124 * Parameters: 3125 * node - {E4XElement} A GML node. 3126 * 3127 * Returns: 3128 * {<ZOO.Geometry.MultiLineString>} A multilinestring geometry. 3129 */ 2202 3130 'multilinestring': function(node) { 2203 3131 var nodeList = node..*::LineString; … … 2213 3141 return new ZOO.Geometry.MultiLineString(components); 2214 3142 }, 3143 /** 3144 * Method: parseGeometry.polygon 3145 * Given a GML node representing a polygon geometry, create a 3146 * ZOO polygon geometry. 3147 * 3148 * Parameters: 3149 * node - {E4XElement} A GML node. 3150 * 3151 * Returns: 3152 * {<ZOO.Geometry.Polygon>} A polygon geometry. 3153 */ 2215 3154 'polygon': function(node) { 2216 3155 nodeList = node..*::LinearRing; … … 2227 3166 return new ZOO.Geometry.Polygon(components); 2228 3167 }, 3168 /** 3169 * Method: parseGeometry.multipolygon 3170 * Given a GML node representing a multipolygon geometry, create a 3171 * ZOO multipolygon geometry. 3172 * 3173 * Parameters: 3174 * node - {E4XElement} A GML node. 3175 * 3176 * Returns: 3177 * {<ZOO.Geometry.MultiPolygon>} A multipolygon geometry. 3178 */ 2229 3179 'multipolygon': function(node) { 2230 3180 var nodeList = node..*::Polygon; … … 2240 3190 return new ZOO.Geometry.MultiPolygon(components); 2241 3191 }, 3192 /** 3193 * Method: parseGeometry.polygon 3194 * Given a GML node representing an envelope, create a 3195 * ZOO polygon geometry. 3196 * 3197 * Parameters: 3198 * node - {E4XElement} A GML node. 3199 * 3200 * Returns: 3201 * {<ZOO.Geometry.Polygon>} A polygon geometry. 3202 */ 2242 3203 'envelope': function(node) { 2243 3204 var components = []; … … 2286 3247 } 2287 3248 }, 3249 /** 3250 * Method: parseAttributes 3251 * 3252 * Parameters: 3253 * node - {<E4XElement>} 3254 * 3255 * Returns: 3256 * {Object} An attributes object. 3257 */ 3258 parseAttributes: function(node) { 3259 var attributes = {}; 3260 // assume attributes are children of the first type 1 child 3261 var childNode = node.*::*[0]; 3262 var child, grandchildren; 3263 var children = childNode.*::*; 3264 for(var i=0, len=children.length(); i<len; ++i) { 3265 child = children[i]; 3266 grandchildren = child..*::*; 3267 if(grandchildren.length() == 1) { 3268 var name = child.localName(); 3269 var value = child.toString(); 3270 if (value) { 3271 value = value.replace(this.regExes.trimSpace, ""); 3272 attributes[name] = value; 3273 } else 3274 attributes[name] = null; 3275 } 3276 } 3277 return attributes; 3278 }, 3279 /** 3280 * Method: write 3281 * Generate a GML document string given a list of features. 3282 * 3283 * Parameters: 3284 * features - {Array(<ZOO.Feature>)} List of features to 3285 * serialize into a string. 3286 * 3287 * Returns: 3288 * {String} A string representing the GML document. 3289 */ 2288 3290 write: function(features) { 2289 3291 if(!(features instanceof Array)) { … … 2294 3296 var gml = new XML('<'+name+' xmlns:'+pfx+'="'+this.namespaces[pfx]+'" xmlns:gml="'+this.namespaces['gml']+'" xmlns:xsi="'+this.namespaces['xsi']+'" xsi:schemaLocation="'+this.schemaLocation+'"></'+name+'>'); 2295 3297 for(var i=0; i<features.length; i++) { 2296 gml.*::*[i] = this.createFeature XML(features[i]);3298 gml.*::*[i] = this.createFeature(features[i]); 2297 3299 } 2298 3300 return gml.toXMLString(); 2299 3301 }, 2300 createFeatureXML: function(feature) { 3302 /** 3303 * Method: createFeature 3304 * Accept an ZOO.Feature, and build a GML node for it. 3305 * 3306 * Parameters: 3307 * feature - {<ZOO.Feature>} The feature to be built as GML. 3308 * 3309 * Returns: 3310 * {E4XElement} A node reprensting the feature in GML. 3311 */ 3312 createFeature: function(feature) { 2301 3313 var pfx = this.defaultPrefix; 2302 3314 var name = pfx+':'+this.featureName; … … 2311 3323 return gml; 2312 3324 }, 3325 /** 3326 * Method: buildGeometryNode 3327 * 3328 * Parameters: 3329 * geometry - {<ZOO.Geometry>} The geometry to be built as GML. 3330 * 3331 * Returns: 3332 * {E4XElement} A node reprensting the geometry in GML. 3333 */ 2313 3334 buildGeometryNode: function(geometry) { 2314 3335 if (this.externalProjection && this.internalProjection) { … … 2327 3348 return gml; 2328 3349 }, 3350 /** 3351 * Property: buildGeometry 3352 * Object containing methods to do the actual geometry node building 3353 * based on geometry type. 3354 */ 2329 3355 buildGeometry: { 3356 /** 3357 * Method: buildGeometry.point 3358 * Given a ZOO point geometry, create a GML point. 3359 * 3360 * Parameters: 3361 * geometry - {<ZOO.Geometry.Point>} A point geometry. 3362 * 3363 * Returns: 3364 * {E4XElement} A GML point node. 3365 */ 2330 3366 'point': function(geometry) { 2331 3367 var gml = new XML('<gml:Point xmlns:gml="'+this.namespaces['gml']+'"></gml:Point>'); … … 2333 3369 return gml; 2334 3370 }, 3371 /** 3372 * Method: buildGeometry.multipoint 3373 * Given a ZOO multipoint geometry, create a GML multipoint. 3374 * 3375 * Parameters: 3376 * geometry - {<ZOO.Geometry.MultiPoint>} A multipoint geometry. 3377 * 3378 * Returns: 3379 * {E4XElement} A GML multipoint node. 3380 */ 2335 3381 'multipoint': function(geometry) { 2336 3382 var gml = new XML('<gml:MultiPoint xmlns:gml="'+this.namespaces['gml']+'"></gml:MultiPoint>'); … … 2344 3390 return gml; 2345 3391 }, 3392 /** 3393 * Method: buildGeometry.linestring 3394 * Given a ZOO linestring geometry, create a GML linestring. 3395 * 3396 * Parameters: 3397 * geometry - {<ZOO.Geometry.LineString>} A linestring geometry. 3398 * 3399 * Returns: 3400 * {E4XElement} A GML linestring node. 3401 */ 2346 3402 'linestring': function(geometry) { 2347 3403 var gml = new XML('<gml:LineString xmlns:gml="'+this.namespaces['gml']+'"></gml:LineString>'); … … 2349 3405 return gml; 2350 3406 }, 3407 /** 3408 * Method: buildGeometry.multilinestring 3409 * Given a ZOO multilinestring geometry, create a GML 3410 * multilinestring. 3411 * 3412 * Parameters: 3413 * geometry - {<ZOO.Geometry.MultiLineString>} A multilinestring 3414 * geometry. 3415 * 3416 * Returns: 3417 * {E4XElement} A GML multilinestring node. 3418 */ 2351 3419 'multilinestring': function(geometry) { 2352 3420 var gml = new XML('<gml:MultiLineString xmlns:gml="'+this.namespaces['gml']+'"></gml:MultiLineString>'); … … 2360 3428 return gml; 2361 3429 }, 3430 /** 3431 * Method: buildGeometry.linearring 3432 * Given a ZOO linearring geometry, create a GML linearring. 3433 * 3434 * Parameters: 3435 * geometry - {<ZOO.Geometry.LinearRing>} A linearring geometry. 3436 * 3437 * Returns: 3438 * {E4XElement} A GML linearring node. 3439 */ 2362 3440 'linearring': function(geometry) { 2363 3441 var gml = new XML('<gml:LinearRing xmlns:gml="'+this.namespaces['gml']+'"></gml:LinearRing>'); … … 2365 3443 return gml; 2366 3444 }, 3445 /** 3446 * Method: buildGeometry.polygon 3447 * Given an ZOO polygon geometry, create a GML polygon. 3448 * 3449 * Parameters: 3450 * geometry - {<ZOO.Geometry.Polygon>} A polygon geometry. 3451 * 3452 * Returns: 3453 * {E4XElement} A GML polygon node. 3454 */ 2367 3455 'polygon': function(geometry) { 2368 3456 var gml = new XML('<gml:Polygon xmlns:gml="'+this.namespaces['gml']+'"></gml:Polygon>'); … … 2377 3465 return gml; 2378 3466 }, 3467 /** 3468 * Method: buildGeometry.multipolygon 3469 * Given a ZOO multipolygon geometry, create a GML multipolygon. 3470 * 3471 * Parameters: 3472 * geometry - {<ZOO.Geometry.MultiPolygon>} A multipolygon 3473 * geometry. 3474 * 3475 * Returns: 3476 * {E4XElement} A GML multipolygon node. 3477 */ 2379 3478 'multipolygon': function(geometry) { 2380 3479 var gml = new XML('<gml:MultiPolygon xmlns:gml="'+this.namespaces['gml']+'"></gml:MultiPolygon>'); … … 2387 3486 } 2388 3487 return gml; 2389 }, 2390 'bounds': function(bounds) { 2391 var gml = new XML('<gml:Box xmlns:gml="'+this.namespaces['gml']+'"></gml:Box>'); 2392 gml.*::*[0] = this.buildCoordinatesNode(bounds); 2393 return gml; 2394 } 2395 }, 3488 } 3489 }, 3490 /** 3491 * Method: buildCoordinatesNode 3492 * builds the coordinates XmlNode 3493 * (code) 3494 * <gml:coordinates decimal="." cs="," ts=" ">...</gml:coordinates> 3495 * (end) 3496 * Parameters: 3497 * geometry - {<ZOO.Geometry>} 3498 * 3499 * Returns: 3500 * {E4XElement} created E4XElement 3501 */ 2396 3502 buildCoordinatesNode: function(geometry) { 2397 3503 var parts = []; … … 2409 3515 CLASS_NAME: 'ZOO.Format.GML' 2410 3516 }); 3517 /** 3518 * Class: ZOO.Format.WPS 3519 * Read/Write WPS. Create a new instance with the <ZOO.Format.WPS> 3520 * constructor. Supports only parseExecuteResponse. 3521 * 3522 * Inherits from: 3523 * - <ZOO.Format> 3524 */ 2411 3525 ZOO.Format.WPS = ZOO.Class(ZOO.Format, { 3526 /** 3527 * Property: schemaLocation 3528 * {String} Schema location for a particular minor version. 3529 */ 2412 3530 schemaLocation: "http://www.opengis.net/wps/1.0.0/../wpsExecute_request.xsd", 3531 /** 3532 * Property: namespaces 3533 * {Object} Mapping of namespace aliases to namespace URIs. 3534 */ 2413 3535 namespaces: { 2414 3536 ows: "http://www.opengis.net/ows/1.1", … … 2417 3539 xsi: "http://www.w3.org/2001/XMLSchema-instance", 2418 3540 }, 3541 /** 3542 * Method: read 3543 * 3544 * Parameters: 3545 * data - {String} A WPS xml document 3546 * 3547 * Returns: 3548 * {Object} Execute response. 3549 */ 2419 3550 read:function(data) { 2420 3551 data = data.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, ""); … … 2427 3558 } 2428 3559 }, 3560 /** 3561 * Method: parseExecuteResponse 3562 * 3563 * Parameters: 3564 * node - {E4XElement} A WPS ExecuteResponse document 3565 * 3566 * Returns: 3567 * {Object} Execute response. 3568 */ 2429 3569 parseExecuteResponse: function(node) { 2430 3570 var outputs = node.*::ProcessOutputs.*::Output; … … 2439 3579 return null; 2440 3580 }, 3581 /** 3582 * Property: parseData 3583 * Object containing methods to analyse data response. 3584 */ 2441 3585 parseData: { 3586 /** 3587 * Method: parseData.complexdata 3588 * Given an Object representing the WPS complex data response. 3589 * 3590 * Parameters: 3591 * node - {E4XElement} A WPS node. 3592 * 3593 * Returns: 3594 * {Object} A WPS complex data response. 3595 */ 2442 3596 'complexdata': function(node) { 2443 3597 var result = {value:node.toString()}; … … 2450 3604 return result; 2451 3605 }, 3606 /** 3607 * Method: parseData.literaldata 3608 * Given an Object representing the WPS literal data response. 3609 * 3610 * Parameters: 3611 * node - {E4XElement} A WPS node. 3612 * 3613 * Returns: 3614 * {Object} A WPS literal data response. 3615 */ 2452 3616 'literaldata': function(node) { 2453 3617 var result = {value:node.toString()}; … … 2462 3626 }); 2463 3627 2464 3628 /** 3629 * Class: ZOO.Feature 3630 * Vector features use the ZOO.Geometry classes as geometry description. 3631 * They have an 'attributes' property, which is the data object 3632 */ 2465 3633 ZOO.Feature = ZOO.Class({ 3634 /** 3635 * Property: fid 3636 * {String} 3637 */ 2466 3638 fid: null, 3639 /** 3640 * Property: geometry 3641 * {<ZOO.Geometry>} 3642 */ 2467 3643 geometry: null, 3644 /** 3645 * Property: attributes 3646 * {Object} This object holds arbitrary properties that describe the 3647 * feature. 3648 */ 2468 3649 attributes: null, 3650 /** 3651 * Property: bounds 3652 * {<ZOO.Bounds>} The box bounding that feature's geometry, that 3653 * property can be set by an <ZOO.Format> object when 3654 * deserializing the feature, so in most cases it represents an 3655 * information set by the server. 3656 */ 2469 3657 bounds: null, 3658 /** 3659 * Constructor: ZOO.Feature 3660 * Create a vector feature. 3661 * 3662 * Parameters: 3663 * geometry - {<ZOO.Geometry>} The geometry that this feature 3664 * represents. 3665 * attributes - {Object} An optional object that will be mapped to the 3666 * <attributes> property. 3667 */ 2470 3668 initialize: function(geometry, attributes) { 2471 3669 this.geometry = geometry ? geometry : null; … … 2474 3672 this.attributes = ZOO.extend(this.attributes,attributes); 2475 3673 }, 3674 /** 3675 * Method: destroy 3676 * nullify references to prevent circular references and memory leaks 3677 */ 2476 3678 destroy: function() { 2477 3679 this.geometry = null; 2478 3680 }, 3681 /** 3682 * Method: clone 3683 * Create a clone of this vector feature. Does not set any non-standard 3684 * properties. 3685 * 3686 * Returns: 3687 * {<ZOO.Feature>} An exact clone of this vector feature. 3688 */ 2479 3689 clone: function () { 2480 3690 return new ZOO.Feature(this.geometry ? this.geometry.clone() : null, 2481 3691 this.attributes); 2482 3692 }, 3693 /** 3694 * Method: move 3695 * Moves the feature and redraws it at its new location 3696 * 3697 * Parameters: 3698 * x - {Float} 3699 * y - {Float} 3700 */ 2483 3701 move: function(x, y) { 2484 3702 if(!this.geometry.move) … … 2491 3709 }); 2492 3710 3711 /** 3712 * Class: ZOO.Geometry 3713 * A Geometry is a description of a geographic object. Create an instance 3714 * of this class with the <ZOO.Geometry> constructor. This is a base class, 3715 * typical geometry types are described by subclasses of this class. 3716 */ 2493 3717 ZOO.Geometry = ZOO.Class({ 3718 /** 3719 * Property: id 3720 * {String} A unique identifier for this geometry. 3721 */ 2494 3722 id: null, 3723 /** 3724 * Property: parent 3725 * {<ZOO.Geometry>}This is set when a Geometry is added as component 3726 * of another geometry 3727 */ 2495 3728 parent: null, 3729 /** 3730 * Property: bounds 3731 * {<ZOO.Bounds>} The bounds of this geometry 3732 */ 2496 3733 bounds: null, 3734 /** 3735 * Constructor: ZOO.Geometry 3736 * Creates a geometry object. 3737 */ 2497 3738 initialize: function() { 2498 3739 //generate unique id 2499 3740 }, 3741 /** 3742 * Method: destroy 3743 * Destroy this geometry. 3744 */ 2500 3745 destroy: function() { 2501 3746 this.id = null; 2502 3747 this.bounds = null; 2503 3748 }, 3749 /** 3750 * Method: clone 3751 * Create a clone of this geometry. Does not set any non-standard 3752 * properties of the cloned geometry. 3753 * 3754 * Returns: 3755 * {<ZOO.Geometry>} An exact clone of this geometry. 3756 */ 2504 3757 clone: function() { 2505 3758 return new ZOO.Geometry(); 2506 3759 }, 3760 /** 3761 * Method: extendBounds 3762 * Extend the existing bounds to include the new bounds. 3763 * If geometry's bounds is not yet set, then set a new Bounds. 3764 * 3765 * Parameters: 3766 * newBounds - {<ZOO.Bounds>} 3767 */ 2507 3768 extendBounds: function(newBounds){ 2508 3769 var bounds = this.getBounds(); … … 2512 3773 this.bounds.extend(newBounds); 2513 3774 }, 3775 /** 3776 * Set the bounds for this Geometry. 3777 * 3778 * Parameters: 3779 * bounds - {<ZOO.Bounds>} 3780 */ 2514 3781 setBounds: function(bounds) { 2515 3782 if (bounds) 2516 3783 this.bounds = bounds.clone(); 2517 3784 }, 3785 /** 3786 * Method: clearBounds 3787 * Nullify this components bounds and that of its parent as well. 3788 */ 2518 3789 clearBounds: function() { 2519 3790 this.bounds = null; … … 2521 3792 this.parent.clearBounds(); 2522 3793 }, 3794 /** 3795 * Method: getBounds 3796 * Get the bounds for this Geometry. If bounds is not set, it 3797 * is calculated again, this makes queries faster. 3798 * 3799 * Returns: 3800 * {<ZOO.Bounds>} 3801 */ 2523 3802 getBounds: function() { 2524 3803 if (this.bounds == null) { … … 2527 3806 return this.bounds; 2528 3807 }, 3808 /** 3809 * Method: calculateBounds 3810 * Recalculate the bounds for the geometry. 3811 */ 2529 3812 calculateBounds: function() { 2530 return this.bounds = null; 3813 // This should be overridden by subclasses. 3814 return this.bounds; 2531 3815 }, 2532 3816 distanceTo: function(geometry, options) { … … 2543 3827 return null; 2544 3828 }, 3829 /** 3830 * Method: toString 3831 * Returns the Well-Known Text representation of a geometry 3832 * 3833 * Returns: 3834 * {String} Well-Known Text 3835 */ 2545 3836 toString: function() { 2546 3837 return ZOO.Format.WKT.prototype.write( … … 2550 3841 CLASS_NAME: 'ZOO.Geometry' 2551 3842 }); 3843 /** 3844 * Function: OpenLayers.Geometry.fromWKT 3845 * Generate a geometry given a Well-Known Text string. 3846 * 3847 * Parameters: 3848 * wkt - {String} A string representing the geometry in Well-Known Text. 3849 * 3850 * Returns: 3851 * {<ZOO.Geometry>} A geometry of the appropriate class. 3852 */ 2552 3853 ZOO.Geometry.fromWKT = function(wkt) { 2553 3854 var format = arguments.callee.format; … … 2683 3984 }; 2684 3985 }; 3986 /** 3987 * Class: OpenLayers.Geometry.Collection 3988 * A Collection is exactly what it sounds like: A collection of different 3989 * Geometries. These are stored in the local parameter <components> (which 3990 * can be passed as a parameter to the constructor). 3991 * 3992 * As new geometries are added to the collection, they are NOT cloned. 3993 * When removing geometries, they need to be specified by reference (ie you 3994 * have to pass in the *exact* geometry to be removed). 3995 * 3996 * The <getArea> and <getLength> functions here merely iterate through 3997 * the components, summing their respective areas and lengths. 3998 * 3999 * Create a new instance with the <ZOO.Geometry.Collection> constructor. 4000 * 4001 * Inerhits from: 4002 * - <ZOO.Geometry> 4003 */ 2685 4004 ZOO.Geometry.Collection = ZOO.Class(ZOO.Geometry, { 4005 /** 4006 * Property: components 4007 * {Array(<ZOO.Geometry>)} The component parts of this geometry 4008 */ 2686 4009 components: null, 4010 /** 4011 * Property: componentTypes 4012 * {Array(String)} An array of class names representing the types of 4013 * components that the collection can include. A null value means the 4014 * component types are not restricted. 4015 */ 2687 4016 componentTypes: null, 4017 /** 4018 * Constructor: ZOO.Geometry.Collection 4019 * Creates a Geometry Collection -- a list of geoms. 4020 * 4021 * Parameters: 4022 * components - {Array(<ZOO.Geometry>)} Optional array of geometries 4023 * 4024 */ 2688 4025 initialize: function (components) { 2689 4026 ZOO.Geometry.prototype.initialize.apply(this, arguments); … … 2693 4030 } 2694 4031 }, 4032 /** 4033 * Method: destroy 4034 * Destroy this geometry. 4035 */ 2695 4036 destroy: function () { 2696 4037 this.components.length = 0; 2697 4038 this.components = null; 2698 4039 }, 4040 /** 4041 * Method: clone 4042 * Clone this geometry. 4043 * 4044 * Returns: 4045 * {<ZOO.Geometry.Collection>} An exact clone of this collection 4046 */ 2699 4047 clone: function() { 2700 4048 var geometry = eval("new " + this.CLASS_NAME + "()"); … … 2704 4052 return geometry; 2705 4053 }, 4054 /** 4055 * Method: getComponentsString 4056 * Get a string representing the components for this collection 4057 * 4058 * Returns: 4059 * {String} A string representation of the components of this geometry 4060 */ 2706 4061 getComponentsString: function(){ 2707 4062 var strings = []; … … 2711 4066 return strings.join(","); 2712 4067 }, 4068 /** 4069 * Method: calculateBounds 4070 * Recalculate the bounds by iterating through the components and 4071 * calling calling extendBounds() on each item. 4072 */ 2713 4073 calculateBounds: function() { 2714 4074 this.bounds = null; … … 2721 4081 return this.bounds 2722 4082 }, 4083 /** 4084 * APIMethod: addComponents 4085 * Add components to this geometry. 4086 * 4087 * Parameters: 4088 * components - {Array(<ZOO.Geometry>)} An array of geometries to add 4089 */ 2723 4090 addComponents: function(components){ 2724 4091 if(!(components instanceof Array)) … … 2728 4095 } 2729 4096 }, 4097 /** 4098 * Method: addComponent 4099 * Add a new component (geometry) to the collection. If this.componentTypes 4100 * is set, then the component class name must be in the componentTypes array. 4101 * 4102 * The bounds cache is reset. 4103 * 4104 * Parameters: 4105 * component - {<ZOO.Geometry>} A geometry to add 4106 * index - {int} Optional index into the array to insert the component 4107 * 4108 * Returns: 4109 * {Boolean} The component geometry was successfully added 4110 */ 2730 4111 addComponent: function(component, index) { 2731 4112 var added = false; … … 2750 4131 return added; 2751 4132 }, 4133 /** 4134 * Method: removeComponents 4135 * Remove components from this geometry. 4136 * 4137 * Parameters: 4138 * components - {Array(<ZOO.Geometry>)} The components to be removed 4139 */ 2752 4140 removeComponents: function(components) { 2753 4141 if(!(components instanceof Array)) … … 2757 4145 } 2758 4146 }, 4147 /** 4148 * Method: removeComponent 4149 * Remove a component from this geometry. 4150 * 4151 * Parameters: 4152 * component - {<ZOO.Geometry>} 4153 */ 2759 4154 removeComponent: function(component) { 2760 4155 ZOO.removeItem(this.components, component); … … 2763 4158 this.clearBounds(); 2764 4159 }, 4160 /** 4161 * Method: getLength 4162 * Calculate the length of this geometry 4163 * 4164 * Returns: 4165 * {Float} The length of the geometry 4166 */ 2765 4167 getLength: function() { 2766 4168 var length = 0.0; … … 2770 4172 return length; 2771 4173 }, 4174 /** 4175 * APIMethod: getArea 4176 * Calculate the area of this geometry. Note how this function is 4177 * overridden in <ZOO.Geometry.Polygon>. 4178 * 4179 * Returns: 4180 * {Float} The area of the collection by summing its parts 4181 */ 2772 4182 getArea: function() { 2773 4183 var area = 0.0; … … 2777 4187 return area; 2778 4188 }, 4189 /** 4190 * APIMethod: getGeodesicArea 4191 * Calculate the approximate area of the polygon were it projected onto 4192 * the earth. 4193 * 4194 * Parameters: 4195 * projection - {<ZOO.Projection>} The spatial reference system 4196 * for the geometry coordinates. If not provided, Geographic/WGS84 is 4197 * assumed. 4198 * 4199 * Reference: 4200 * Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for 4201 * Polygons on a Sphere", JPL Publication 07-03, Jet Propulsion 4202 * Laboratory, Pasadena, CA, June 2007 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409 4203 * 4204 * Returns: 4205 * {float} The approximate geodesic area of the geometry in square meters. 4206 */ 4207 getGeodesicArea: function(projection) { 4208 var area = 0.0; 4209 for(var i=0, len=this.components.length; i<len; i++) { 4210 area += this.components[i].getGeodesicArea(projection); 4211 } 4212 return area; 4213 }, 4214 /** 4215 * Method: getCentroid 4216 * 4217 * Returns: 4218 * {<ZOO.Geometry.Point>} The centroid of the collection 4219 */ 2779 4220 getCentroid: function() { 2780 4221 return this.components.length && this.components[0].getCentroid(); 2781 4222 }, 4223 /** 4224 * Method: getGeodesicLength 4225 * Calculate the approximate length of the geometry were it projected onto 4226 * the earth. 4227 * 4228 * projection - {<ZOO.Projection>} The spatial reference system 4229 * for the geometry coordinates. If not provided, Geographic/WGS84 is 4230 * assumed. 4231 * 4232 * Returns: 4233 * {Float} The appoximate geodesic length of the geometry in meters. 4234 */ 4235 getGeodesicLength: function(projection) { 4236 var length = 0.0; 4237 for(var i=0, len=this.components.length; i<len; i++) { 4238 length += this.components[i].getGeodesicLength(projection); 4239 } 4240 return length; 4241 }, 4242 /** 4243 * Method: move 4244 * Moves a geometry by the given displacement along positive x and y axes. 4245 * This modifies the position of the geometry and clears the cached 4246 * bounds. 4247 * 4248 * Parameters: 4249 * x - {Float} Distance to move geometry in positive x direction. 4250 * y - {Float} Distance to move geometry in positive y direction. 4251 */ 2782 4252 move: function(x, y) { 2783 4253 for(var i=0, len=this.components.length; i<len; i++) { … … 2785 4255 } 2786 4256 }, 4257 /** 4258 * Method: rotate 4259 * Rotate a geometry around some origin 4260 * 4261 * Parameters: 4262 * angle - {Float} Rotation angle in degrees (measured counterclockwise 4263 * from the positive x-axis) 4264 * origin - {<ZOO.Geometry.Point>} Center point for the rotation 4265 */ 2787 4266 rotate: function(angle, origin) { 2788 4267 for(var i=0, len=this.components.length; i<len; ++i) { … … 2790 4269 } 2791 4270 }, 4271 /** 4272 * Method: resize 4273 * Resize a geometry relative to some origin. Use this method to apply 4274 * a uniform scaling to a geometry. 4275 * 4276 * Parameters: 4277 * scale - {Float} Factor by which to scale the geometry. A scale of 2 4278 * doubles the size of the geometry in each dimension 4279 * (lines, for example, will be twice as long, and polygons 4280 * will have four times the area). 4281 * origin - {<ZOO.Geometry.Point>} Point of origin for resizing 4282 * ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1. 4283 * 4284 * Returns: 4285 * {ZOO.Geometry} - The current geometry. 4286 */ 2792 4287 resize: function(scale, origin, ratio) { 2793 4288 for(var i=0; i<this.components.length; ++i) { … … 2813 4308 return best; 2814 4309 }, 4310 /** 4311 * Method: equals 4312 * Determine whether another geometry is equivalent to this one. Geometries 4313 * are considered equivalent if all components have the same coordinates. 4314 * 4315 * Parameters: 4316 * geom - {<ZOO.Geometry>} The geometry to test. 4317 * 4318 * Returns: 4319 * {Boolean} The supplied geometry is equivalent to this geometry. 4320 */ 2815 4321 equals: function(geometry) { 2816 4322 var equivalent = true; … … 2830 4336 return equivalent; 2831 4337 }, 4338 /** 4339 * Method: transform 4340 * Reproject the components geometry from source to dest. 4341 * 4342 * Parameters: 4343 * source - {<ZOO.Projection>} 4344 * dest - {<ZOO.Projection>} 4345 * 4346 * Returns: 4347 * {<ZOO.Geometry>} 4348 */ 2832 4349 transform: function(source, dest) { 2833 4350 if (source && dest) { … … 2840 4357 return this; 2841 4358 }, 4359 /** 4360 * Method: intersects 4361 * Determine if the input geometry intersects this one. 4362 * 4363 * Parameters: 4364 * geometry - {<ZOO.Geometry>} Any type of geometry. 4365 * 4366 * Returns: 4367 * {Boolean} The input geometry intersects this one. 4368 */ 2842 4369 intersects: function(geometry) { 2843 4370 var intersect = false; … … 2849 4376 return intersect; 2850 4377 }, 4378 /** 4379 * Method: getVertices 4380 * Return a list of all points in this geometry. 4381 * 4382 * Parameters: 4383 * nodes - {Boolean} For lines, only return vertices that are 4384 * endpoints. If false, for lines, only vertices that are not 4385 * endpoints will be returned. If not provided, all vertices will 4386 * be returned. 4387 * 4388 * Returns: 4389 * {Array} A list of all vertices in the geometry. 4390 */ 2851 4391 getVertices: function(nodes) { 2852 4392 var vertices = []; … … 2860 4400 CLASS_NAME: 'ZOO.Geometry.Collection' 2861 4401 }); 4402 /** 4403 * Class: ZOO.Geometry.Point 4404 * Point geometry class. 4405 * 4406 * Inherits from: 4407 * - <ZOO.Geometry> 4408 */ 2862 4409 ZOO.Geometry.Point = ZOO.Class(ZOO.Geometry, { 4410 /** 4411 * Property: x 4412 * {float} 4413 */ 2863 4414 x: null, 4415 /** 4416 * Property: y 4417 * {float} 4418 */ 2864 4419 y: null, 4420 /** 4421 * Constructor: ZOO.Geometry.Point 4422 * Construct a point geometry. 4423 * 4424 * Parameters: 4425 * x - {float} 4426 * y - {float} 4427 * 4428 */ 2865 4429 initialize: function(x, y) { 2866 4430 ZOO.Geometry.prototype.initialize.apply(this, arguments); … … 2868 4432 this.y = parseFloat(y); 2869 4433 }, 4434 /** 4435 * Method: clone 4436 * 4437 * Returns: 4438 * {<ZOO.Geometry.Point>} An exact clone of this ZOO.Geometry.Point 4439 */ 2870 4440 clone: function(obj) { 2871 4441 if (obj == null) 2872 4442 obj = new ZOO.Geometry.Point(this.x, this.y); 2873 4443 // catch any randomly tagged-on properties 2874 // OpenLayers.Util.applyDefaults(obj, this);4444 // ZOO.Util.applyDefaults(obj, this); 2875 4445 return obj; 2876 4446 }, 4447 /** 4448 * Method: calculateBounds 4449 * Create a new Bounds based on the x/y 4450 */ 2877 4451 calculateBounds: function () { 2878 4452 this.bounds = new ZOO.Bounds(this.x, this.y, … … 2904 4478 return result; 2905 4479 }, 4480 /** 4481 * Method: equals 4482 * Determine whether another geometry is equivalent to this one. Geometries 4483 * are considered equivalent if all components have the same coordinates. 4484 * 4485 * Parameters: 4486 * geom - {<ZOO.Geometry.Point>} The geometry to test. 4487 * 4488 * Returns: 4489 * {Boolean} The supplied geometry is equivalent to this geometry. 4490 */ 2906 4491 equals: function(geom) { 2907 4492 var equals = false; … … 2911 4496 return equals; 2912 4497 }, 4498 /** 4499 * Method: toShortString 4500 * 4501 * Returns: 4502 * {String} Shortened String representation of Point object. 4503 * (ex. <i>"5, 42"</i>) 4504 */ 2913 4505 toShortString: function() { 2914 4506 return (this.x + ", " + this.y); 2915 4507 }, 4508 /** 4509 * Method: move 4510 * Moves a geometry by the given displacement along positive x and y axes. 4511 * This modifies the position of the geometry and clears the cached 4512 * bounds. 4513 * 4514 * Parameters: 4515 * x - {Float} Distance to move geometry in positive x direction. 4516 * y - {Float} Distance to move geometry in positive y direction. 4517 */ 2916 4518 move: function(x, y) { 2917 4519 this.x = this.x + x; … … 2919 4521 this.clearBounds(); 2920 4522 }, 4523 /** 4524 * Method: rotate 4525 * Rotate a point around another. 4526 * 4527 * Parameters: 4528 * angle - {Float} Rotation angle in degrees (measured counterclockwise 4529 * from the positive x-axis) 4530 * origin - {<ZOO.Geometry.Point>} Center point for the rotation 4531 */ 2921 4532 rotate: function(angle, origin) { 2922 4533 angle *= Math.PI / 180; … … 2927 4538 this.clearBounds(); 2928 4539 }, 4540 /** 4541 * Method: getCentroid 4542 * 4543 * Returns: 4544 * {<ZOO.Geometry.Point>} The centroid of the collection 4545 */ 2929 4546 getCentroid: function() { 2930 4547 return new ZOO.Geometry.Point(this.x, this.y); 2931 4548 }, 4549 /** 4550 * Method: resize 4551 * Resize a point relative to some origin. For points, this has the effect 4552 * of scaling a vector (from the origin to the point). This method is 4553 * more useful on geometry collection subclasses. 4554 * 4555 * Parameters: 4556 * scale - {Float} Ratio of the new distance from the origin to the old 4557 * distance from the origin. A scale of 2 doubles the 4558 * distance between the point and origin. 4559 * origin - {<ZOO.Geometry.Point>} Point of origin for resizing 4560 * ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1. 4561 * 4562 * Returns: 4563 * {ZOO.Geometry} - The current geometry. 4564 */ 2932 4565 resize: function(scale, origin, ratio) { 2933 4566 ratio = (ratio == undefined) ? 1 : ratio; … … 2937 4570 return this; 2938 4571 }, 4572 /** 4573 * Method: intersects 4574 * Determine if the input geometry intersects this one. 4575 * 4576 * Parameters: 4577 * geometry - {<ZOO.Geometry>} Any type of geometry. 4578 * 4579 * Returns: 4580 * {Boolean} The input geometry intersects this one. 4581 */ 2939 4582 intersects: function(geometry) { 2940 4583 var intersect = false; … … 2946 4589 return intersect; 2947 4590 }, 4591 /** 4592 * Method: transform 4593 * Translate the x,y properties of the point from source to dest. 4594 * 4595 * Parameters: 4596 * source - {<ZOO.Projection>} 4597 * dest - {<ZOO.Projection>} 4598 * 4599 * Returns: 4600 * {<ZOO.Geometry>} 4601 */ 2948 4602 transform: function(source, dest) { 2949 4603 if ((source && dest)) { … … 2954 4608 return this; 2955 4609 }, 4610 /** 4611 * Method: getVertices 4612 * Return a list of all points in this geometry. 4613 * 4614 * Parameters: 4615 * nodes - {Boolean} For lines, only return vertices that are 4616 * endpoints. If false, for lines, only vertices that are not 4617 * endpoints will be returned. If not provided, all vertices will 4618 * be returned. 4619 * 4620 * Returns: 4621 * {Array} A list of all vertices in the geometry. 4622 */ 2956 4623 getVertices: function(nodes) { 2957 4624 return [this]; … … 2959 4626 CLASS_NAME: 'ZOO.Geometry.Point' 2960 4627 }); 4628 /** 4629 * Class: ZOO.Geometry.Surface 4630 * Surface geometry class. 4631 * 4632 * Inherits from: 4633 * - <ZOO.Geometry> 4634 */ 2961 4635 ZOO.Geometry.Surface = ZOO.Class(ZOO.Geometry, { 2962 4636 initialize: function() { … … 2965 4639 CLASS_NAME: "ZOO.Geometry.Surface" 2966 4640 }); 4641 /** 4642 * Class: ZOO.Geometry.MultiPoint 4643 * MultiPoint is a collection of Points. Create a new instance with the 4644 * <ZOO.Geometry.MultiPoint> constructor. 4645 * 4646 * Inherits from: 4647 * - <ZOO.Geometry.Collection> 4648 */ 2967 4649 ZOO.Geometry.MultiPoint = ZOO.Class( 2968 4650 ZOO.Geometry.Collection, { 4651 /** 4652 * Property: componentTypes 4653 * {Array(String)} An array of class names representing the types of 4654 * components that the collection can include. A null value means the 4655 * component types are not restricted. 4656 */ 2969 4657 componentTypes: ["ZOO.Geometry.Point"], 4658 /** 4659 * Constructor: ZOO.Geometry.MultiPoint 4660 * Create a new MultiPoint Geometry 4661 * 4662 * Parameters: 4663 * components - {Array(<ZOO.Geometry.Point>)} 4664 * 4665 * Returns: 4666 * {<ZOO.Geometry.MultiPoint>} 4667 */ 2970 4668 initialize: function(components) { 2971 4669 ZOO.Geometry.Collection.prototype.initialize.apply(this,arguments); 2972 4670 }, 4671 /** 4672 * Method: addPoint 4673 * Wrapper for <ZOO.Geometry.Collection.addComponent> 4674 * 4675 * Parameters: 4676 * point - {<ZOO.Geometry.Point>} Point to be added 4677 * index - {Integer} Optional index 4678 */ 2973 4679 addPoint: function(point, index) { 2974 4680 this.addComponent(point, index); 2975 4681 }, 4682 /** 4683 * Method: removePoint 4684 * Wrapper for <ZOO.Geometry.Collection.removeComponent> 4685 * 4686 * Parameters: 4687 * point - {<ZOO.Geometry.Point>} Point to be removed 4688 */ 2976 4689 removePoint: function(point){ 2977 4690 this.removeComponent(point); … … 2979 4692 CLASS_NAME: "ZOO.Geometry.MultiPoint" 2980 4693 }); 4694 /** 4695 * Class: ZOO.Geometry.Curve 4696 * A Curve is a MultiPoint, whose points are assumed to be connected. To 4697 * this end, we provide a "getLength()" function, which iterates through 4698 * the points, summing the distances between them. 4699 * 4700 * Inherits: 4701 * - <ZOO.Geometry.MultiPoint> 4702 */ 2981 4703 ZOO.Geometry.Curve = ZOO.Class(ZOO.Geometry.MultiPoint, { 4704 /** 4705 * Property: componentTypes 4706 * {Array(String)} An array of class names representing the types of 4707 * components that the collection can include. A null 4708 * value means the component types are not restricted. 4709 */ 2982 4710 componentTypes: ["ZOO.Geometry.Point"], 4711 /** 4712 * Constructor: ZOO.Geometry.Curve 4713 * 4714 * Parameters: 4715 * point - {Array(<ZOO.Geometry.Point>)} 4716 */ 2983 4717 initialize: function(points) { 2984 4718 ZOO.Geometry.MultiPoint.prototype.initialize.apply(this,arguments); 2985 4719 }, 4720 /** 4721 * Method: getLength 4722 * 4723 * Returns: 4724 * {Float} The length of the curve 4725 */ 2986 4726 getLength: function() { 2987 4727 var length = 0.0; … … 2993 4733 return length; 2994 4734 }, 4735 /** 4736 * APIMethod: getGeodesicLength 4737 * Calculate the approximate length of the geometry were it projected onto 4738 * the earth. 4739 * 4740 * projection - {<ZOO.Projection>} The spatial reference system 4741 * for the geometry coordinates. If not provided, Geographic/WGS84 is 4742 * assumed. 4743 * 4744 * Returns: 4745 * {Float} The appoximate geodesic length of the geometry in meters. 4746 */ 4747 getGeodesicLength: function(projection) { 4748 var geom = this; // so we can work with a clone if needed 4749 if(projection) { 4750 var gg = new ZOO.Projection("EPSG:4326"); 4751 if(!gg.equals(projection)) { 4752 geom = this.clone().transform(projection, gg); 4753 } 4754 } 4755 var length = 0.0; 4756 if(geom.components && (geom.components.length > 1)) { 4757 var p1, p2; 4758 for(var i=1, len=geom.components.length; i<len; i++) { 4759 p1 = geom.components[i-1]; 4760 p2 = geom.components[i]; 4761 // this returns km and requires x/y properties 4762 length += ZOO.distVincenty(p1,p2); 4763 } 4764 } 4765 // convert to m 4766 return length * 1000; 4767 }, 2995 4768 CLASS_NAME: "ZOO.Geometry.Curve" 2996 4769 }); 4770 /** 4771 * Class: ZOO.Geometry.LineString 4772 * A LineString is a Curve which, once two points have been added to it, can 4773 * never be less than two points long. 4774 * 4775 * Inherits from: 4776 * - <ZOO.Geometry.Curve> 4777 */ 2997 4778 ZOO.Geometry.LineString = ZOO.Class(ZOO.Geometry.Curve, { 4779 /** 4780 * Constructor: ZOO.Geometry.LineString 4781 * Create a new LineString geometry 4782 * 4783 * Parameters: 4784 * points - {Array(<ZOO.Geometry.Point>)} An array of points used to 4785 * generate the linestring 4786 * 4787 */ 2998 4788 initialize: function(points) { 2999 4789 ZOO.Geometry.Curve.prototype.initialize.apply(this, arguments); 3000 4790 }, 4791 /** 4792 * Method: removeComponent 4793 * Only allows removal of a point if there are three or more points in 4794 * the linestring. (otherwise the result would be just a single point) 4795 * 4796 * Parameters: 4797 * point - {<ZOO.Geometry.Point>} The point to be removed 4798 */ 3001 4799 removeComponent: function(point) { 3002 4800 if ( this.components && (this.components.length > 2)) 3003 4801 ZOO.Geometry.Collection.prototype.removeComponent.apply(this,arguments); 3004 4802 }, 4803 /** 4804 * Method: intersects 4805 * Test for instersection between two geometries. This is a cheapo 4806 * implementation of the Bently-Ottmann algorigithm. It doesn't 4807 * really keep track of a sweep line data structure. It is closer 4808 * to the brute force method, except that segments are sorted and 4809 * potential intersections are only calculated when bounding boxes 4810 * intersect. 4811 * 4812 * Parameters: 4813 * geometry - {<ZOO.Geometry>} 4814 * 4815 * Returns: 4816 * {Boolean} The input geometry intersects this geometry. 4817 */ 3005 4818 intersects: function(geometry) { 3006 4819 var intersect = false; … … 3050 4863 return intersect; 3051 4864 }, 4865 /** 4866 * Method: getSortedSegments 4867 * 4868 * Returns: 4869 * {Array} An array of segment objects. Segment objects have properties 4870 * x1, y1, x2, and y2. The start point is represented by x1 and y1. 4871 * The end point is represented by x2 and y2. Start and end are 4872 * ordered so that x1 < x2. 4873 */ 3052 4874 getSortedSegments: function() { 3053 4875 var numSeg = this.components.length - 1; … … 3077 4899 return segments.sort(byX1); 3078 4900 }, 4901 /** 4902 * Method: splitWithSegment 4903 * Split this geometry with the given segment. 4904 * 4905 * Parameters: 4906 * seg - {Object} An object with x1, y1, x2, and y2 properties referencing 4907 * segment endpoint coordinates. 4908 * options - {Object} Properties of this object will be used to determine 4909 * how the split is conducted. 4910 * 4911 * Valid options: 4912 * edge - {Boolean} Allow splitting when only edges intersect. Default is 4913 * true. If false, a vertex on the source segment must be within the 4914 * tolerance distance of the intersection to be considered a split. 4915 * tolerance - {Number} If a non-null value is provided, intersections 4916 * within the tolerance distance of one of the source segment's 4917 * endpoints will be assumed to occur at the endpoint. 4918 * 4919 * Returns: 4920 * {Object} An object with *lines* and *points* properties. If the given 4921 * segment intersects this linestring, the lines array will reference 4922 * geometries that result from the split. The points array will contain 4923 * all intersection points. Intersection points are sorted along the 4924 * segment (in order from x1,y1 to x2,y2). 4925 */ 3079 4926 splitWithSegment: function(seg, options) { 3080 4927 var edge = !(options && options.edge === false); … … 3137 4984 return result; 3138 4985 }, 4986 /** 4987 * Method: split 4988 * Use this geometry (the source) to attempt to split a target geometry. 4989 * 4990 * Parameters: 4991 * target - {<ZOO.Geometry>} The target geometry. 4992 * options - {Object} Properties of this object will be used to determine 4993 * how the split is conducted. 4994 * 4995 * Valid options: 4996 * mutual - {Boolean} Split the source geometry in addition to the target 4997 * geometry. Default is false. 4998 * edge - {Boolean} Allow splitting when only edges intersect. Default is 4999 * true. If false, a vertex on the source must be within the tolerance 5000 * distance of the intersection to be considered a split. 5001 * tolerance - {Number} If a non-null value is provided, intersections 5002 * within the tolerance distance of an existing vertex on the source 5003 * will be assumed to occur at the vertex. 5004 * 5005 * Returns: 5006 * {Array} A list of geometries (of this same type as the target) that 5007 * result from splitting the target with the source geometry. The 5008 * source and target geometry will remain unmodified. If no split 5009 * results, null will be returned. If mutual is true and a split 5010 * results, return will be an array of two arrays - the first will be 5011 * all geometries that result from splitting the source geometry and 5012 * the second will be all geometries that result from splitting the 5013 * target geometry. 5014 */ 3139 5015 split: function(target, options) { 3140 5016 var results = null; … … 3205 5081 return results; 3206 5082 }, 5083 /** 5084 * Method: splitWith 5085 * Split this geometry (the target) with the given geometry (the source). 5086 * 5087 * Parameters: 5088 * geometry - {<ZOO.Geometry>} A geometry used to split this 5089 * geometry (the source). 5090 * options - {Object} Properties of this object will be used to determine 5091 * how the split is conducted. 5092 * 5093 * Valid options: 5094 * mutual - {Boolean} Split the source geometry in addition to the target 5095 * geometry. Default is false. 5096 * edge - {Boolean} Allow splitting when only edges intersect. Default is 5097 * true. If false, a vertex on the source must be within the tolerance 5098 * distance of the intersection to be considered a split. 5099 * tolerance - {Number} If a non-null value is provided, intersections 5100 * within the tolerance distance of an existing vertex on the source 5101 * will be assumed to occur at the vertex. 5102 * 5103 * Returns: 5104 * {Array} A list of geometries (of this same type as the target) that 5105 * result from splitting the target with the source geometry. The 5106 * source and target geometry will remain unmodified. If no split 5107 * results, null will be returned. If mutual is true and a split 5108 * results, return will be an array of two arrays - the first will be 5109 * all geometries that result from splitting the source geometry and 5110 * the second will be all geometries that result from splitting the 5111 * target geometry. 5112 */ 3207 5113 splitWith: function(geometry, options) { 3208 5114 return geometry.split(this, options); 3209 5115 }, 5116 /** 5117 * Method: getVertices 5118 * Return a list of all points in this geometry. 5119 * 5120 * Parameters: 5121 * nodes - {Boolean} For lines, only return vertices that are 5122 * endpoints. If false, for lines, only vertices that are not 5123 * endpoints will be returned. If not provided, all vertices will 5124 * be returned. 5125 * 5126 * Returns: 5127 * {Array} A list of all vertices in the geometry. 5128 */ 3210 5129 getVertices: function(nodes) { 3211 5130 var vertices; … … 3323 5242 CLASS_NAME: "ZOO.Geometry.LineString" 3324 5243 }); 5244 /** 5245 * Class: ZOO.Geometry.LinearRing 5246 * 5247 * A Linear Ring is a special LineString which is closed. It closes itself 5248 * automatically on every addPoint/removePoint by adding a copy of the first 5249 * point as the last point. 5250 * 5251 * Also, as it is the first in the line family to close itself, a getArea() 5252 * function is defined to calculate the enclosed area of the linearRing 5253 * 5254 * Inherits: 5255 * - <OpenLayers.Geometry.LineString> 5256 */ 3325 5257 ZOO.Geometry.LinearRing = ZOO.Class( 3326 5258 ZOO.Geometry.LineString, { 5259 /** 5260 * Property: componentTypes 5261 * {Array(String)} An array of class names representing the types of 5262 * components that the collection can include. A null 5263 * value means the component types are not restricted. 5264 */ 3327 5265 componentTypes: ["ZOO.Geometry.Point"], 5266 /** 5267 * Constructor: OpenLayers.Geometry.LinearRing 5268 * Linear rings are constructed with an array of points. This array 5269 * can represent a closed or open ring. If the ring is open (the last 5270 * point does not equal the first point), the constructor will close 5271 * the ring. If the ring is already closed (the last point does equal 5272 * the first point), it will be left closed. 5273 * 5274 * Parameters: 5275 * points - {Array(<ZOO.Geometry.Point>)} points 5276 */ 3328 5277 initialize: function(points) { 3329 5278 ZOO.Geometry.LineString.prototype.initialize.apply(this,arguments); 3330 5279 }, 5280 /** 5281 * Method: addComponent 5282 * Adds a point to geometry components. If the point is to be added to 5283 * the end of the components array and it is the same as the last point 5284 * already in that array, the duplicate point is not added. This has 5285 * the effect of closing the ring if it is not already closed, and 5286 * doing the right thing if it is already closed. This behavior can 5287 * be overridden by calling the method with a non-null index as the 5288 * second argument. 5289 * 5290 * Parameter: 5291 * point - {<ZOO.Geometry.Point>} 5292 * index - {Integer} Index into the array to insert the component 5293 * 5294 * Returns: 5295 * {Boolean} Was the Point successfully added? 5296 */ 3331 5297 addComponent: function(point, index) { 3332 5298 var added = false; … … 3342 5308 return added; 3343 5309 }, 5310 /** 5311 * APIMethod: removeComponent 5312 * Removes a point from geometry components. 5313 * 5314 * Parameters: 5315 * point - {<ZOO.Geometry.Point>} 5316 */ 3344 5317 removeComponent: function(point) { 3345 5318 if (this.components.length > 4) { … … 3353 5326 } 3354 5327 }, 5328 /** 5329 * Method: move 5330 * Moves a geometry by the given displacement along positive x and y axes. 5331 * This modifies the position of the geometry and clears the cached 5332 * bounds. 5333 * 5334 * Parameters: 5335 * x - {Float} Distance to move geometry in positive x direction. 5336 * y - {Float} Distance to move geometry in positive y direction. 5337 */ 3355 5338 move: function(x, y) { 3356 5339 for(var i = 0, len=this.components.length; i<len - 1; i++) { … … 3358 5341 } 3359 5342 }, 5343 /** 5344 * Method: rotate 5345 * Rotate a geometry around some origin 5346 * 5347 * Parameters: 5348 * angle - {Float} Rotation angle in degrees (measured counterclockwise 5349 * from the positive x-axis) 5350 * origin - {<ZOO.Geometry.Point>} Center point for the rotation 5351 */ 3360 5352 rotate: function(angle, origin) { 3361 5353 for(var i=0, len=this.components.length; i<len - 1; ++i) { … … 3363 5355 } 3364 5356 }, 5357 /** 5358 * Method: resize 5359 * Resize a geometry relative to some origin. Use this method to apply 5360 * a uniform scaling to a geometry. 5361 * 5362 * Parameters: 5363 * scale - {Float} Factor by which to scale the geometry. A scale of 2 5364 * doubles the size of the geometry in each dimension 5365 * (lines, for example, will be twice as long, and polygons 5366 * will have four times the area). 5367 * origin - {<ZOO.Geometry.Point>} Point of origin for resizing 5368 * ratio - {Float} Optional x:y ratio for resizing. Default ratio is 1. 5369 * 5370 * Returns: 5371 * {ZOO.Geometry} - The current geometry. 5372 */ 3365 5373 resize: function(scale, origin, ratio) { 3366 5374 for(var i=0, len=this.components.length; i<len - 1; ++i) { … … 3369 5377 return this; 3370 5378 }, 5379 /** 5380 * Method: transform 5381 * Reproject the components geometry from source to dest. 5382 * 5383 * Parameters: 5384 * source - {<ZOO.Projection>} 5385 * dest - {<ZOO.Projection>} 5386 * 5387 * Returns: 5388 * {<ZOO.Geometry>} 5389 */ 3371 5390 transform: function(source, dest) { 3372 5391 if (source && dest) { … … 3379 5398 return this; 3380 5399 }, 5400 /** 5401 * Method: getCentroid 5402 * 5403 * Returns: 5404 * {<ZOO.Geometry.Point>} The centroid of the ring 5405 */ 3381 5406 getCentroid: function() { 3382 5407 if ( this.components && (this.components.length > 2)) { … … 3395 5420 return new ZOO.Geometry.Point(x, y); 3396 5421 }, 5422 /** 5423 * Method: getArea 5424 * Note - The area is positive if the ring is oriented CW, otherwise 5425 * it will be negative. 5426 * 5427 * Returns: 5428 * {Float} The signed area for a ring. 5429 */ 3397 5430 getArea: function() { 3398 5431 var area = 0.0; … … 3408 5441 return area; 3409 5442 }, 5443 /** 5444 * Method: getGeodesicArea 5445 * Calculate the approximate area of the polygon were it projected onto 5446 * the earth. Note that this area will be positive if ring is oriented 5447 * clockwise, otherwise it will be negative. 5448 * 5449 * Parameters: 5450 * projection - {<ZOO.Projection>} The spatial reference system 5451 * for the geometry coordinates. If not provided, Geographic/WGS84 is 5452 * assumed. 5453 * 5454 * Reference: 5455 * Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for 5456 * Polygons on a Sphere", JPL Publication 07-03, Jet Propulsion 5457 * Laboratory, Pasadena, CA, June 2007 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409 5458 * 5459 * Returns: 5460 * {float} The approximate signed geodesic area of the polygon in square 5461 * meters. 5462 */ 5463 getGeodesicArea: function(projection) { 5464 var ring = this; // so we can work with a clone if needed 5465 if(projection) { 5466 var gg = new ZOO.Projection("EPSG:4326"); 5467 if(!gg.equals(projection)) { 5468 ring = this.clone().transform(projection, gg); 5469 } 5470 } 5471 var area = 0.0; 5472 var len = ring.components && ring.components.length; 5473 if(len > 2) { 5474 var p1, p2; 5475 for(var i=0; i<len-1; i++) { 5476 p1 = ring.components[i]; 5477 p2 = ring.components[i+1]; 5478 area += ZOO.rad(p2.x - p1.x) * 5479 (2 + Math.sin(ZOO.rad(p1.y)) + 5480 Math.sin(ZOO.rad(p2.y))); 5481 } 5482 area = area * 6378137.0 * 6378137.0 / 2.0; 5483 } 5484 return area; 5485 }, 5486 /** 5487 * Method: containsPoint 5488 * Test if a point is inside a linear ring. For the case where a point 5489 * is coincident with a linear ring edge, returns 1. Otherwise, 5490 * returns boolean. 5491 * 5492 * Parameters: 5493 * point - {<ZOO.Geometry.Point>} 5494 * 5495 * Returns: 5496 * {Boolean | Number} The point is inside the linear ring. Returns 1 if 5497 * the point is coincident with an edge. Returns boolean otherwise. 5498 */ 3410 5499 containsPoint: function(point) { 3411 5500 var approx = OpenLayers.Number.limitSigDigs; … … 3506 5595 CLASS_NAME: "ZOO.Geometry.LinearRing" 3507 5596 }); 5597 /** 5598 * Class: ZOO.Geometry.MultiLineString 5599 * A MultiLineString is a geometry with multiple <ZOO.Geometry.LineString> 5600 * components. 5601 * 5602 * Inherits from: 5603 * - <ZOO.Geometry.Collection> 5604 */ 3508 5605 ZOO.Geometry.MultiLineString = ZOO.Class( 3509 5606 ZOO.Geometry.Collection, { 3510 5607 componentTypes: ["ZOO.Geometry.LineString"], 5608 /** 5609 * Constructor: ZOO.Geometry.MultiLineString 5610 * Constructor for a MultiLineString Geometry. 5611 * 5612 * Parameters: 5613 * components - {Array(<ZOO.Geometry.LineString>)} 5614 * 5615 */ 3511 5616 initialize: function(components) { 3512 5617 ZOO.Geometry.Collection.prototype.initialize.apply(this,arguments); … … 3663 5768 CLASS_NAME: "ZOO.Geometry.MultiLineString" 3664 5769 }); 5770 /** 5771 * Class: ZOO.Geometry.Polygon 5772 * Polygon is a collection of <ZOO.Geometry.LinearRing>. 5773 * 5774 * Inherits from: 5775 * - <ZOO.Geometry.Collection> 5776 */ 3665 5777 ZOO.Geometry.Polygon = ZOO.Class( 3666 5778 ZOO.Geometry.Collection, { 3667 5779 componentTypes: ["ZOO.Geometry.LinearRing"], 5780 /** 5781 * Constructor: OpenLayers.Geometry.Polygon 5782 * Constructor for a Polygon geometry. 5783 * The first ring (this.component[0])is the outer bounds of the polygon and 5784 * all subsequent rings (this.component[1-n]) are internal holes. 5785 * 5786 * 5787 * Parameters: 5788 * components - {Array(<ZOO.Geometry.LinearRing>)} 5789 */ 3668 5790 initialize: function(components) { 3669 5791 ZOO.Geometry.Collection.prototype.initialize.apply(this,arguments); 3670 5792 }, 5793 /** 5794 * Method: getArea 5795 * Calculated by subtracting the areas of the internal holes from the 5796 * area of the outer hole. 5797 * 5798 * Returns: 5799 * {float} The area of the geometry 5800 */ 3671 5801 getArea: function() { 3672 5802 var area = 0.0; … … 3679 5809 return area; 3680 5810 }, 5811 /** 5812 * APIMethod: getGeodesicArea 5813 * Calculate the approximate area of the polygon were it projected onto 5814 * the earth. 5815 * 5816 * Parameters: 5817 * projection - {<ZOO.Projection>} The spatial reference system 5818 * for the geometry coordinates. If not provided, Geographic/WGS84 is 5819 * assumed. 5820 * 5821 * Reference: 5822 * Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for 5823 * Polygons on a Sphere", JPL Publication 07-03, Jet Propulsion 5824 * Laboratory, Pasadena, CA, June 2007 http://trs-new.jpl.nasa.gov/dspace/handle/2014/40409 5825 * 5826 * Returns: 5827 * {float} The approximate geodesic area of the polygon in square meters. 5828 */ 5829 getGeodesicArea: function(projection) { 5830 var area = 0.0; 5831 if(this.components && (this.components.length > 0)) { 5832 area += Math.abs(this.components[0].getGeodesicArea(projection)); 5833 for(var i=1, len=this.components.length; i<len; i++) { 5834 area -= Math.abs(this.components[i].getGeodesicArea(projection)); 5835 } 5836 } 5837 return area; 5838 }, 5839 /** 5840 * Method: containsPoint 5841 * Test if a point is inside a polygon. Points on a polygon edge are 5842 * considered inside. 5843 * 5844 * Parameters: 5845 * point - {<ZOO.Geometry.Point>} 5846 * 5847 * Returns: 5848 * {Boolean | Number} The point is inside the polygon. Returns 1 if the 5849 * point is on an edge. Returns boolean otherwise. 5850 */ 3681 5851 containsPoint: function(point) { 3682 5852 var numRings = this.components.length; … … 3760 5930 CLASS_NAME: "ZOO.Geometry.Polygon" 3761 5931 }); 5932 /** 5933 * Method: createRegularPolygon 5934 * Create a regular polygon around a radius. Useful for creating circles 5935 * and the like. 5936 * 5937 * Parameters: 5938 * origin - {<ZOO.Geometry.Point>} center of polygon. 5939 * radius - {Float} distance to vertex, in map units. 5940 * sides - {Integer} Number of sides. 20 approximates a circle. 5941 * rotation - {Float} original angle of rotation, in degrees. 5942 */ 5943 OpenLayers.Geometry.Polygon.createRegularPolygon = function(origin, radius, sides, rotation) { 5944 var angle = Math.PI * ((1/sides) - (1/2)); 5945 if(rotation) { 5946 angle += (rotation / 180) * Math.PI; 5947 } 5948 var rotatedAngle, x, y; 5949 var points = []; 5950 for(var i=0; i<sides; ++i) { 5951 rotatedAngle = angle + (i * 2 * Math.PI / sides); 5952 x = origin.x + (radius * Math.cos(rotatedAngle)); 5953 y = origin.y + (radius * Math.sin(rotatedAngle)); 5954 points.push(new ZOO.Geometry.Point(x, y)); 5955 } 5956 var ring = new ZOO.Geometry.LinearRing(points); 5957 return new ZOO.Geometry.Polygon([ring]); 5958 }; 5959 /** 5960 * Class: ZOO.Geometry.MultiPolygon 5961 * MultiPolygon is a geometry with multiple <ZOO.Geometry.Polygon> 5962 * components. Create a new instance with the <ZOO.Geometry.MultiPolygon> 5963 * constructor. 5964 * 5965 * Inherits from: 5966 * - <ZOO.Geometry.Collection> 5967 */ 3762 5968 ZOO.Geometry.MultiPolygon = ZOO.Class( 3763 5969 ZOO.Geometry.Collection, { 3764 5970 componentTypes: ["ZOO.Geometry.Polygon"], 5971 /** 5972 * Constructor: OpenLayers.Geometry.MultiPolygon 5973 * Create a new MultiPolygon geometry 5974 * 5975 * Parameters: 5976 * components - {Array(<ZOO.Geometry.Polygon>)} An array of polygons 5977 * used to generate the MultiPolygon 5978 * 5979 */ 3765 5980 initialize: function(components) { 3766 5981 ZOO.Geometry.Collection.prototype.initialize.apply(this,arguments);
Note: See TracChangeset
for help on using the changeset viewer.