Commit 17aeead23f9985d5def380b3a7862d90c9dbe3cd

Authored by Edmar Moretti
1 parent 823e9694

Atualização do pacote wiket

pacotes/wicket/LICENSE 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +Copyright (C) 2012 K. Arthur Endsley (kaendsle@mtu.edu)
  2 +Michigan Tech Research Institute (MTRI)
  3 +3600 Green Court, Suite 100, Ann Arbor, MI, 48105
  4 +
  5 +This program is free software: you can redistribute it and/or modify
  6 +it under the terms of the GNU General Public License as published by
  7 +the Free Software Foundation, either version 3 of the License, or
  8 +(at your option) any later version.
  9 +
  10 +This program is distributed in the hope that it will be useful,
  11 +but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 +GNU General Public License for more details.
  14 +
  15 +You should have received a copy of the GNU General Public License
  16 +along with this program. If not, see <http://www.gnu.org/licenses/>.
... ...
pacotes/wicket/README.md
1   -##########
2 1 # Wicket #
3   -##########
4 2  
5   -Updated **April 8, 2012** by K. Arthur Endsley
  3 +![Build Stats](https://travis-ci.org/arthur-e/Wicket.svg?branch=master)
6 4  
7   -################
8   -## Motivation ##
9   -################
  5 +Wicket is a lightweight library for translating between [Well-Known Text (WKT)](http://en.wikipedia.org/wiki/Well-known_text) and various client-side mapping frameworks:
  6 +* Leaflet [(demo)](http://arthur-e.github.com/Wicket/)
  7 +* Google Maps API [(demo)](http://arthur-e.github.com/Wicket/sandbox-gmaps3.html)
  8 +* ESRI ArcGIS JavaScript API [(demo)](http://arthur-e.github.com/Wicket/sandbox-arcgis.html)
  9 +* Potentially any other web mapping framework through serialization and de-serialization of GeoJSON (with `JSON.parse`)
10 10  
11   -Wicket was created out of the need for a lightweight Javascript library that can translate Well-Known Text (WKT) strings into geographic features. This problem arose in the context of [OpenClimateGIS](https://github.com/arthur-e/OpenClimateGIS), a web framework for accessing and subsetting online climate data.
  11 +The core Wicket library and the Leaflet extension are both compatible with Node.js; the Google Maps and ArcGIS API extensions will not work in Node.js because they require a browser.
12 12  
13   -OpenClimateGIS emits WKT representations of user-defined geometry. Our [API explorer](http://www.openclimategis.org/builder/) allows users to define arbitrary areas-of-interest (AOIs) and view predefined AOIs on a Google Maps API instance. So, initially, the problem was converting between WKT strings and Google Maps API features. While other mapping libraries, such as [OpenLayers](http://www.openlayers.org), have very nice WKT libraries built-in, the Google Maps API, as of this writing, does not. In the (apparent) absence of lightweight, easy-to-use WKT library in Javascript, I set out to create one.
  13 +If you are looking for [Apache Wicket](http://wicket.apache.org/), the web-app development framework for Java, [you'll find it here](http://wicket.apache.org/).
14 14  
15   -That is what Wicket aspires to be: lightweight, framework-agnostic, and useful. I hope it achieves these goals. If you find it isn't living up to that and you have ideas on how to improve it, please fork the code or [drop me a line](mailto:kaendsle@mtu.edu).
  15 +## License ##
  16 +
  17 +Wicket is released under the [GNU General Public License version 3 (GPLv3)](http://www.gnu.org/licenses/gpl.html).
  18 +Accordingly:
  19 +
  20 +> This program is free software: you can redistribute it and/or modify
  21 +> it under the terms of the GNU General Public License as published by
  22 +> the Free Software Foundation, either version 3 of the License, or
  23 +> (at your option) any later version.
  24 +
  25 +## Example ##
  26 +
  27 +The following examples work in any of the mapping environments, as Wicket has a uniform API regardless of the client-side mapping library you're using.
  28 +
  29 + // Create a new Wicket instance
  30 + var wkt = new Wkt.Wkt();
  31 +
  32 + // Read in any kind of WKT string
  33 + wkt.read("POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))");
  34 +
  35 + // Or a GeoJSON string
  36 + wkt.read('{"coordinates": [[[30, 10], [10, 20], [20, 40], [40, 40], [30, 10]]], "type": "Polygon"}');
  37 +
  38 + // Access and modify the underlying geometry
  39 + console.log(wkt.components);
  40 + // "[ [ {x: 30, y: 10}, {x: 10, y: 30}, ...] ]"
  41 + wkt.components[0][1].x = 15;
  42 +
  43 + wkt.merge(new Wkt.Wkt('POLYGON((35 15,15 25,25 45,45 45,35 15))'));
  44 + wkt.write();
  45 + // MULTIPOLYGON(((30 10,10 20,20 40,40 40,30 10)),((35 15,15 25,25 45,45 45,35 15)))
  46 +
  47 + // Create a geometry object, ready to be mapped!
  48 + wkt.toObject();
  49 +
  50 +Wicket will read from the geometry objects of any mapping client it understands.
  51 +**Note:** Don't use the `deconstruct()` method! This is used internally by `Wkt.Wkt()` instances.
  52 +Use `fromObject()` instead, as in the following example.
  53 +
  54 + var wkt = new Wkt.Wkt();
  55 +
  56 + // Deconstruct an existing point feature e.g. google.maps.Marker instance
  57 + wkt.fromObject(somePointObject);
  58 +
  59 + console.log(wkt.components);
  60 + // "[ {x: 10, y: 30} ]"
  61 +
  62 + // Serialize a WKT string from that geometry
  63 + wkt.write();
  64 + // "POINT(10 30)"
  65 +
  66 +## See Also ##
  67 +
  68 +* [wellknown](https://github.com/mapbox/wellknown)
  69 +* [OpenLayers WKT](https://github.com/openlayers/openlayers/blob/master/lib/OpenLayers/Format/WKT.js)
  70 +* [wkt-parser](http://terraformer.io/wkt-parser/)
  71 +
  72 +## Dependencies and Build Information ##
  73 +
  74 +**Wicket has zero dependencies**, however, JSON parsing (from strings) is not provided.
  75 +Wicket looks for the function `JSON.parse`, which is provided in most modern browsers (get it with [this library](https://github.com/douglascrockford/JSON-js/blob/master/json2.js), if you need to support older browsers).
  76 +
  77 +Minified versions can be generated via:
  78 +
  79 + npm run build
  80 +
  81 +### Testing ###
  82 +
  83 + npm test
  84 +
  85 +The Google Maps API extension cannot be tested by Node.js at the command line; it requires a browser. The Google Maps API tests are run by Jasmine; navigate to the file `tests/wicket-gmap3.html` in a web browser.
  86 +
  87 +## Documentation ##
  88 +
  89 +Read the documentation [here](http://arthur-e.github.io/Wicket/doc/out/). Documentation can be generated with [JSDoc 3](https://github.com/jsdoc3/jsdoc).
  90 +
  91 + git clone git://github.com/jsdoc3/jsdoc.git
  92 + ./jsdoc /var/www/static/wicket/wicket.src.js
  93 +
  94 +Or, with Node installed:
  95 +
  96 + sudo npm install -g git://github.com/jsdoc3/jsdoc.git
  97 + jsdoc /var/www/static/wicket/wicket.src.js
  98 +
  99 +Either way, make sure you invoke `jsdoc` from a directory in which you have write access; it will output documentation to your current working directory.
16 100  
17   -##############
18 101 ## Colophon ##
19   -##############
20 102  
21   -########################
  103 +### Motivation ###
  104 +
  105 +Wicket was created out of the need for a lightweight Javascript library that can translate Well-Known Text (WKT) strings into geographic features.
  106 +This problem arose in the context of [OpenClimateGIS](https://github.com/arthur-e/OpenClimateGIS), a web framework for accessing and subsetting online climate data.
  107 +
  108 +OpenClimateGIS emits WKT representations of user-defined geometry.
  109 +The API Explorer allowed users to define arbitrary areas-of-interest (AOIs) and view predefined AOIs on a Google Maps API instance.
  110 +So, initially, the problem was converting between WKT strings and Google Maps API features.
  111 +While other mapping libraries, such as [OpenLayers](http://www.openlayers.org), have very nice WKT libraries built-in, the Google Maps API, as of this writing, does not.
  112 +In the (apparent) absence of a lightweight, easy-to-use WKT library in Javascript, I set out to create one.
  113 +
  114 +That is what Wicket aspires to be: lightweight, framework-agnostic, and useful.
  115 +I hope it achieves these goals.
  116 +If you find it isn't living up to that and you have ideas on how to improve it, please fork the code or [drop me a line](mailto:kaendsle@mtu.edu).
  117 +
22 118 ### Acknowledgements ###
23   -########################
24 119  
25   -The following open sources were borrowed from; they retain all their original rights:
  120 +Wicket borrows heavily from the experiences of others who came before us:
26 121  
27 122 * The OpenLayers 2.7 WKT module (OpenLayers.Format.WKT)
28 123 * Chris Pietshmann's [article on converting Bing Maps shapes (VEShape) to WKT](http://pietschsoft.com/post/2009/04/04/Virtual-Earth-Shapes-%28VEShape%29-to-WKT-%28Well-Known-Text%29-and-Back-using-JavaScript.aspx)
29 124 * Charles R. Schmidt's and the Python Spatial Analysis Laboratory's (PySAL) WKT writer
30 125  
31   -###################
32 126 ### Conventions ###
33   -###################
34   -
35   -The conventions I've adopted in writing this library:
36 127  
37   -* The Crockford-ian module pattern with a single global (namespace) variable
38   -* The most un-Crockford-ian use of new to instantiate new Objects (when this is required, the Object begins with a capital letter e.g. new Wkt())
39   -* The namespace is the only name beginning with a capital letter that doesn't need to and shouldn't be preceded by new
40   -* The namespace is the result of a function allowing for private members
41   -* Tricky operators (++ and --) and type-coercing operators (== and !=) are not used
  128 +The base library, wicket.js, contains the Wkt.Wkt base object.
  129 +This object doesn't do anything on its own except read in WKT strings, allow the underlying geometry to be manipulated programmatically, and write WKT strings.
  130 +By loading additional libraries, such as wicket-gmap3.js, users can transform between between WKT and the features of a given framework (e.g. google.maps.Polygon instances).
  131 +The intent is to add support for new frameworks as additional Javascript files that alter the Wkt.Wkt prototype.
42 132  
43   -The base library, wicket.js, contains the Wkt.Wkt base object. This object doesn't do anything on its own except read in WKT strings, allow the underlying geometry to be manipulated programmatically, and write WKT strings. By loading additional libraries, such as wicket-gmap3.js, users can transform between between WKT and the features of a given framework (e.g. google.maps.Polygon instances). The intent is to add support for new frameworks as additional Javascript files that alter the Wkt.Wkt prototype.
  133 +**To extend Wicket**, nominally by writing bindings for a new mapping library, add a new file with a name like wicket-libname.src.js (and corresponding minified version wicket-libname.js) where "libname" is some reasonably short, well-known name for the mapping library.
44 134  
45   -##############
46 135 ## Concepts ##
47   -##############
48 136  
49   -WKT geometries are stored internally using the following convention. The atomic unit of geometry is the coordinate pair (e.g. latitude and longitude) which is represented by an Object with x and y properties. An Array with a single coordinate pair represents a a single point (i.e. POINT feature)
  137 +WKT geometries are stored internally using the following convention. The atomic unit of geometry is the coordinate pair (e.g. latitude and longitude) which is represented by an Object with x and y properties. An Array with a single coordinate pair represents a a single point (i.e. POINT feature):
50 138  
51 139 [ {x: -83.123, y: 42.123} ]
  140 +
  141 + // POINT(-83.123 42.123)
52 142  
53 143 An Array of multiple points (an Array of Arrays) specifies a "collection" of points (i.e. a MULTIPOINT feature):
54 144  
... ... @@ -56,6 +146,7 @@ An Array of multiple points (an Array of Arrays) specifies a &quot;collection&quot; of poi
56 146 [ {x: -83.123, y: 42.123} ],
57 147 [ {x: -83.234, y: 42.234} ]
58 148 ]
  149 + // MULTIPOINT(-83.123 42.123,-83.234 42.234)
59 150  
60 151 An Array of multiple coordinates specifies a collection of connected points in an ordered sequence (i.e. LINESTRING feature):
61 152  
... ... @@ -64,8 +155,10 @@ An Array of multiple coordinates specifies a collection of connected points in a
64 155 {x: -83.23, y: 42.23},
65 156 {x: -83.34, y: 42.34}
66 157 ]
  158 + // LINESTRING(-83.12 42.12,-83.23 42.23,-83.34 42.34)
67 159  
68   -An Array can also contain other Arrays. In these cases, the contained Array(s) can each represent one of two geometry types. The contained Array might reprsent a single polygon (i.e. POLYGON feature):
  160 +An Array can also contain other Arrays. In these cases, the contained Array(s) can each represent one of two geometry types.
  161 +The contained Array might reprsent a single polygon (i.e. POLYGON feature):
69 162  
70 163 [
71 164 [
... ... @@ -76,8 +169,9 @@ An Array can also contain other Arrays. In these cases, the contained Array(s) c
76 169 {x: -83, y: 42}
77 170 ]
78 171 ]
  172 + // POLYGON(-83 42,-83 43,-82 43,-82 42,-83 42)
79 173  
80   -It might also represent a LINESTRING feature. Both POLYGON and LINESTRING features are internally represented the same way. The difference between the two is specified elsewhere (in the Wkt instance's type) and must be retained. In this particular example (above), we can see that the first coordinate in the Array is repeated at the end, meaning that the geometry is closed. We can therefore infer it represents a POLYGON and not a LINESTRING even before we plot it. Wicket retains the *type* of the feature and will always remember which it is.
  174 +The above example cannot represent a LINESTRING feature (one of the few type-based constraints on the internal representations), however it may represent a MULTILINESTRING feature. Both POLYGON and MULTILINESTRING features are internally represented the same way. The difference between the two is specified elsewhere (in the Wkt instance's type) and must be retained. In this particular example (above), we can see that the first coordinate in the Array is repeated at the end, meaning that the geometry is closed. We can therefore infer it represents a POLYGON and not a MULTILINESTRING even before we plot it. Wicket retains the *type* of the feature and will always remember which it is.
81 175  
82 176 Similarly, multiple nested Arrays might reprsent a MULTIPOLYGON feature:
83 177  
... ... @@ -101,6 +195,7 @@ Similarly, multiple nested Arrays might reprsent a MULTIPOLYGON feature:
101 195 ]
102 196 ]
103 197 ]
  198 + // MULTIPOLYGON(((-83 42,-83 43,-82 43,-82 42,-83 42),(-70 40,-70 41,-69 41,-69 40,-70 40)))
104 199  
105 200 Or a POLYGON with inner rings (holes) in it where the outer ring is the polygon envelope and comes first; subsequent Arrays are inner rings (holes):
106 201  
... ... @@ -119,5 +214,6 @@ Or a POLYGON with inner rings (holes) in it where the outer ring is the polygon
119 214 {x: 20, y: 30}
120 215 ]
121 216 ]
  217 + // POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 35,30 20,20 30))
122 218  
123 219 Or they might represent a MULTILINESTRING where each nested Array is a different LINESTRING in the collection. Again, Wicket remembers the correct *type* of feature even though the internal representation is ambiguous.
... ...
pacotes/wicket/bower.json 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +{
  2 + "name": "Wicket",
  3 + "version": "1.2",
  4 + "main": [
  5 + "wicket.js",
  6 + "wicket-arcgis.js",
  7 + "wicket-gmap3.js",
  8 + "wicket-leaflet.js"
  9 + ],
  10 + "ignore": [
  11 + "doc/*",
  12 + "tests/*"
  13 + ]
  14 +}
... ...
pacotes/wicket/doc/arcgis.html 0 → 100644
... ... @@ -0,0 +1,221 @@
  1 +<html>
  2 +<head>
  3 + <link rel="stylesheet" type="text/css" href="/static/font/Cabin.css" />
  4 + <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5 + <!-- Conditional commenting for non-IE browsers -->
  6 + <!--[if !IE]><!-->
  7 + <link rel="stylesheet" type="text/css" href="/static/wicket/doc/index.css" />
  8 + <!--<![endif]-->
  9 + <!-- Conditional commenting for IE 6.x -->
  10 + <!--[if IE]>
  11 + <link rel="stylesheet" type="text/css" href="/static/wicket/doc/index.ie.css" />
  12 + <![endif]-->
  13 + <link rel="stylesheet" href="/static/leaflet/0.5.1/dist/leaflet.css" />
  14 + <!--[if lte IE 8]>
  15 + <link rel="stylesheet" href="/static/leaflet/0.5.1/dist/leaflet.ie.css" />
  16 + <![endif]-->
  17 +</head>
  18 +<title>Wicket - Lightweight Javascript for WKT [ESRI ArcGIS Sandbox]</title>
  19 +<link href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/dojo/dijit/themes/claro/claro.css" rel="stylesheet" type="text/css" >
  20 +<link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css" />
  21 +<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/" type="text/javascript"></script>
  22 +<script src="../wicket.js" type="text/javascript"></script>
  23 +<script src="../wicket-arcgis.js" type="text/javascript"></script>
  24 +<script type="text/javascript">
  25 +var app = (function () {
  26 +
  27 + return {
  28 + features: [],
  29 +
  30 + /**
  31 + * Clears the map contents.
  32 + */
  33 + clearMap: function () {
  34 + var i;
  35 +
  36 + // Reset the remembered last string (so that we can clear the map,
  37 + // paste the same string, and see it again)
  38 + document.getElementById('wkt').last = '';
  39 +
  40 + for (i = 0; i < this.features.length; i += 1) {
  41 + this.map.graphics.remove(this.features[i]);
  42 + }
  43 +
  44 + //this.features.length = 0;
  45 + },
  46 +
  47 + /**
  48 + * Clears the current contents of the textarea.
  49 + */
  50 + clearText: function () {
  51 + document.getElementById('wkt').value = '';
  52 + },
  53 +
  54 + /**
  55 + * Maps the current contents of the textarea.
  56 + * @param editable {Boolean} Indicates that the feature drawn should be editable
  57 + * @param focus {Boolean} Indicates that the map should pan and/or zoom to new features
  58 + * @return {Object} Some sort of geometry object
  59 + */
  60 + mapIt: function (editable, focus) {
  61 + var config, el, graphic, obj, symbol, wkt;
  62 +
  63 + // Indicates that the map should pan and/or zoom to new features
  64 + focus = focus || false;
  65 +
  66 + if (editable === undefined) {
  67 + editable = true;
  68 + }
  69 +
  70 + el = document.getElementById('wkt');
  71 + wkt = new Wkt.Wkt();
  72 +
  73 + if (el.last === el.value) { // Remember the last string
  74 + return; // Do nothing if the WKT string hasn't changed
  75 + } else {
  76 + el.last = el.value;
  77 + }
  78 +
  79 + try { // Catch any malformed WKT strings
  80 + wkt.read(el.value);
  81 + } catch (e1) {
  82 + try {
  83 + wkt.read(el.value.replace('\n', '').replace('\r', '').replace('\t', ''));
  84 + } catch (e2) {
  85 + if (e2.name === 'WKTError') {
  86 + alert('Wicket could not understand the WKT string you entered. Check that you have parentheses balanced, and try removing tabs and newline characters.');
  87 + return;
  88 + }
  89 + }
  90 + }
  91 +
  92 + config = {
  93 + spatialReference: {
  94 + wkid: 4326 // WGS84 unprojected
  95 + },
  96 + editable: editable
  97 + };
  98 +
  99 + obj = wkt.toObject(config); // Make an object
  100 +
  101 + switch (obj.type) {
  102 + case "point":
  103 + symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 1), new dojo.Color([0,255,0,0.25]));
  104 + break;
  105 + case "polyline":
  106 + symbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255,0,0]), 1);
  107 + break;
  108 + case "polygon":
  109 + symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]));
  110 + break;
  111 + case "extent":
  112 + symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]));
  113 + break;
  114 + case "multipoint":
  115 + symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND, 20, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,0,0]), 1), new dojo.Color([255,255,0,0.5]));
  116 + break;
  117 + }
  118 +
  119 + graphic = new esri.Graphic(obj, symbol);
  120 + this.map.graphics.add(graphic); // Add to map
  121 + this.features.push(graphic); // Remember it for later
  122 +
  123 + return obj;
  124 + },
  125 +
  126 + /**
  127 + * Updates the textarea based on the first available feature.
  128 + */
  129 + updateText: function () {
  130 + var wkt = new Wkt.Wkt();
  131 + wkt.fromObject(this.features[0]);
  132 + document.getElementById('wkt').value = wkt.write();
  133 + },
  134 +
  135 + /**
  136 + * Formats the textarea contents for a URL.
  137 + * @param checked {Boolean} The check state of the associated checkbox
  138 + */
  139 + urlify: function (checked) {
  140 + var wkt = new Wkt.Wkt();
  141 + wkt.read(document.getElementById('wkt').value);
  142 + wkt.delimiter = (checked) ? '+' : ' ';
  143 + document.getElementById('wkt').value = wkt.write();
  144 + return wkt;
  145 + },
  146 +
  147 + /**
  148 + * Application entry point.
  149 + * @return {<L.map>} The Leaflet instance
  150 + */
  151 + init: function () {
  152 + var map = new esri.Map('canvas', {
  153 + center: [10, 20],
  154 + zoom: 2,
  155 + basemap: 'oceans'
  156 + });
  157 +
  158 + // Set event handlers //////////////////////////////////////////////
  159 + dojo.connect(map, 'onLoad', function() {
  160 + document.getElementById('wkt').value = 'MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 45 20, 30 5, 10 10, 10 30, 20 35), (30 20, 20 25, 20 15, 30 20)))';
  161 + });
  162 +
  163 + return map;
  164 + }
  165 +
  166 + };
  167 +
  168 +}());
  169 +
  170 +dojo.require('esri.map');
  171 +//dojo.addOnLoad(app.init); // Not necessary; see <body> tag
  172 +
  173 +</script>
  174 +<body onload="app.map=app.init();"><!--app.mapIt(false, false);">-->
  175 + <div id="head">
  176 + <div class="wrapper">
  177 + </div>
  178 + </div>
  179 + <div id="ribbon">
  180 + <div class="wrapper">
  181 + <a href="http://github.com/arthur-e/Wicket">
  182 + <div id="forkme">&nbsp;
  183 + </div>
  184 + </a>
  185 + <div id="canvas">
  186 + </div>
  187 + <div id="controls">
  188 + <div class="title">
  189 + <div class="brand">Wicket</div>
  190 + &nbsp;It whispers WKT in your application's ear.
  191 + </div>
  192 + <div class="text">
  193 + Wicket is a lightweight Javascript library that reads and writes <a href="http://en.wikipedia.org/wiki/Well-known_text#Geometric_objects" target="_blaknk">Well-Known Text (WKT)</a> strings. It can also be extended to parse and to create geometric objects from various mapping frameworks, such as <a href="http://http://leafletjs.com/" target="_blank">Leaflet</a> and the Google Maps API.
  194 + </div>
  195 + <div id="form">
  196 + <textarea type="text" name="wkt" id="wkt"></textarea>
  197 + <label><input type="checkbox" name="urlify" id="urlify" onchange="app.urlify(this.checked);" />Format for URLs</label>
  198 + <input type="submit" id="submit" value="Map It!" onclick="app.clearMap();app.mapIt(true, true);" />
  199 + <input type="reset" id="reset" value="Clear Map" onclick="app.clearText();app.clearMap();" />
  200 + </div>
  201 + </div>
  202 + </div>
  203 + </div>
  204 + <div id="foot">
  205 + <div class="wrapper">
  206 + <div class="menu" id="nav">
  207 + <a href="/">Home</a>
  208 + <a href="mailto:kaendsle@mtu.edu">Contact Me</a>
  209 + <a href="http://github.com/arthur-e/Wicket">"Fork me on GitHub!"</a>
  210 + </div>
  211 + <div class="attribute">
  212 + Design &copy; 2012-2013 <a href="mailto:kaendsle@mtu.edu">K. Arthur Endsley</a>
  213 + <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_GB">
  214 + <img alt="Wicket is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License" style="float:right;border-width:0;vertical-align:middle;" src="http://i.creativecommons.org/l/by-sa/3.0/80x15.png" />
  215 + </a><br />
  216 + Wicket is released under the <a href="https://github.com/arthur-e/Wicket/blob/master/LICENSE" target="_blank">GPL v3</a>
  217 + </div>
  218 + </div>
  219 + </div>
  220 +</body>
  221 +</html>
... ...
pacotes/wicket/doc/index.css
... ... @@ -5,7 +5,11 @@ label:hover {color:#333;}
5 5 a:link,
6 6 a:visited {color:#460;text-decoration:none;}
7 7  
8   -.attribute {float:right;padding:10px 0;}
  8 +.leaflet-container .leaflet-control-attribution {color:white;background:none !important;box-shadow:none !important;}
  9 +.leaflet-container .leaflet-control-attribution a:link,
  10 +.leaflet-container .leaflet-control-attribution a:visited {color:#8C0;}
  11 +
  12 +.attribute {width:290px;float:right;padding:10px 0;text-align:left;font-size:10px;line-height:16px;}
9 13 .menu {float:left;margin:0;padding:0;list-style:none;}
10 14 .menu a {display:inline-block;margin:0;padding:5px 0 10px;margin:0 25px 0 0;border-top:5px solid transparent;}
11 15 .menu a:hover,
... ... @@ -20,7 +24,7 @@ a:visited {color:#460;text-decoration:none;}
20 24 #controls .text {margin:90px 0 0;}
21 25 #controls a:hover,
22 26 #controls a:active {text-decoration:underline;}
23   -#forkme {width:141px;height:141px;z-index:9999;position:absolute;left:0;top:0;background:transparent url(/static/ForkMe_Blk.png) no-repeat left top;}
  27 +#forkme {width:141px;height:141px;z-index:9999;position:absolute;left:0;top:4px;background:transparent url(https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png) no-repeat left top;}
24 28 #form {margin:10px 0 0;font-size:14px;color:#666;font-family:CabinItalic,sans-serif;}
25 29 #form #wkt {width:100%;height:150px;border:1px solid #999;padding:3px;resize:none;}
26 30 #form #urlify {vertical-align:baseline;margin:10px 5px 0 0;}
... ...
pacotes/wicket/doc/index.html
... ... @@ -4,7 +4,7 @@
4 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5 5 <!-- Conditional commenting for non-IE browsers -->
6 6 <!--[if !IE]><!-->
7   - <link rel="stylesheet" type="text/css" href="index.css" />
  7 + <link rel="stylesheet" type="text/css" href="/static/wicket/doc/index.css" />
8 8 <!--<![endif]-->
9 9 <!-- Conditional commenting for IE 6.x -->
10 10 <!--[if IE]>
... ... @@ -29,6 +29,11 @@ var app = (function () {
29 29 */
30 30 clearMap: function () {
31 31 var i;
  32 +
  33 + // Reset the remembered last string (so that we can clear the map,
  34 + // paste the same string, and see it again)
  35 + document.getElementById('wkt').last = '';
  36 +
32 37 for (i in this.features) {
33 38 if (this.features.hasOwnProperty(i)) {
34 39 this.features[i].setMap(null);
... ... @@ -74,7 +79,7 @@ var app = (function () {
74 79 obj = wkt.toObject(this.gmap.defaults); // Make an object
75 80  
76 81 // Add listeners for overlay editing events
77   - if (wkt.type === 'polygon' || wkt.type === 'linestring') {
  82 + if (!Wkt.isArray(obj) && wkt.type !== 'point') {
78 83 // New vertex is inserted
79 84 google.maps.event.addListener(obj.getPath(), 'insert_at', function (n) {
80 85 app.updateText();
... ... @@ -95,13 +100,45 @@ var app = (function () {
95 100 for (i in obj) {
96 101 if (obj.hasOwnProperty(i) && !Wkt.isArray(obj[i])) {
97 102 obj[i].setMap(this.gmap);
98   - this.features.push(obj[i]);
  103 + }
  104 +
  105 + if (wkt.type !== 'point') {
  106 + // New vertex is inserted
  107 + google.maps.event.addListener(obj[i].getPath(), 'insert_at', function (n) {
  108 + app.updateTextPart();
  109 + });
  110 + // Existing vertex is removed (insertion is undone)
  111 + google.maps.event.addListener(obj[i].getPath(), 'remove_at', function (n) {
  112 + app.updateTextPart();
  113 + });
  114 + // Existing vertex is moved (set elsewhere)
  115 + google.maps.event.addListener(obj[i].getPath(), 'set_at', function (n) {
  116 + app.updateTextPart();
  117 + });
99 118 }
100 119 }
  120 +
  121 + this.features = this.features.concat(obj);
101 122 } else {
102 123 obj.setMap(this.gmap); // Add it to the map
103 124 this.features.push(obj);
104 125 }
  126 +
  127 + // Pan the map to the feature
  128 + if (obj.getBounds !== undefined && typeof obj.getBounds === 'function') {
  129 + // For objects that have defined bounds or a way to get them
  130 + this.gmap.fitBounds(obj.getBounds());
  131 + } else {
  132 + if (obj.getPath !== undefined && typeof obj.getPath === 'function') {
  133 + // For Polygons and Polylines
  134 + this.gmap.panTo(obj.getPath().getAt(0));
  135 + } else { // But points (Markers) are different
  136 + if (obj.getPosition !== undefined && typeof obj.getPosition === 'function') {
  137 + this.gmap.panTo(obj.getPosition());
  138 + }
  139 + }
  140 + }
  141 +
105 142 return obj;
106 143 },
107 144 /**
... ... @@ -112,6 +149,20 @@ var app = (function () {
112 149 wkt.fromObject(this.features[0]);
113 150 document.getElementById('wkt').value = wkt.write();
114 151 },
  152 + updateTextPart: function () {
  153 + var i, w, v;
  154 +
  155 + w = new Wkt.Wkt(this.features[0]);
  156 +
  157 + i = 1;
  158 + while (i < this.features.length) {
  159 + v = new Wkt.Wkt(this.features[i]);
  160 + w.merge(v);
  161 + i += 1;
  162 + }
  163 +
  164 + document.getElementById('wkt').value = w.write();
  165 + },
115 166 /**
116 167 * Formats the textarea contents for a URL.
117 168 * @param checked {Boolean} The check state of the associated checkbox
... ... @@ -160,9 +211,10 @@ var app = (function () {
160 211 google.maps.event.addListener(gmap, 'tilesloaded', function () {
161 212 if (!this.loaded) {
162 213 this.loaded = true;
  214 + // NOTE: We start with a MULTIPOLYGON; these aren't easily deconstructed, so we won't set this object to be editable in this example
163 215 document.getElementById('wkt').value = 'MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 45 20, 30 5, 10 10, 10 30, 20 35), (30 20, 20 25, 20 15, 30 20)))';
164 216 app.mapIt();
165   - }
  217 + }
166 218 });
167 219  
168 220 gmap.drawingManager = new google.maps.drawing.DrawingManager({
... ... @@ -226,7 +278,6 @@ var app = (function () {
226 278 }()); // Execute immediately
227 279 </script>
228 280 <body onload="app.gmap=app.init();">
229   -<body>
230 281 <a href="http://github.com/arthur-e/Wicket">
231 282 <div id="forkme">&nbsp;
232 283 </div>
... ... @@ -245,7 +296,7 @@ var app = (function () {
245 296 &nbsp;It whispers WKT in your application's ear.
246 297 </div>
247 298 <div class="text">
248   - Wicket is a lightweight Javascript library that reads and writes <a href="http://en.wikipedia.org/wiki/Well-known_text#Geometric_objects" target="_blaknk">Well-Known Text (WKT)</a> strings. It can also be extended to parse and to create geometric objects from various mapping frameworks, such as the Google Maps API.
  299 + Wicket is a lightweight Javascript library that reads and writes <a href="http://en.wikipedia.org/wiki/Well-known_text#Geometric_objects" target="_blaknk">Well-Known Text (WKT)</a> strings. It can also be extended to parse and to create geometric objects from various mapping frameworks, such as <a href="http://http://leafletjs.com/" target="_blank">Leaflet</a> and the Google Maps API.
249 300 </div>
250 301 <div id="form">
251 302 <textarea type="text" name="wkt" id="wkt"></textarea>
... ... @@ -264,7 +315,11 @@ var app = (function () {
264 315 <a href="http://github.com/arthur-e/Wicket">"Fork me on GitHub!"</a>
265 316 </div>
266 317 <div class="attribute">
267   - &copy; 2012 K. Arthur Endsley
  318 + Design &copy; 2012-2013 <a href="mailto:kaendsle@mtu.edu">K. Arthur Endsley</a>
  319 + <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_GB">
  320 + <img alt="Wicket is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License" style="float:right;border-width:0;vertical-align:middle;" src="http://i.creativecommons.org/l/by-sa/3.0/80x15.png" />
  321 + </a><br />
  322 + Wicket is released under the <a href="https://github.com/arthur-e/Wicket/blob/master/LICENSE" target="_blank">GPL v3</a><br />
268 323 </div>
269 324 </div>
270 325 </div>
... ...
pacotes/wicket/doc/index.ie.css
... ... @@ -5,7 +5,11 @@ label:hover {color:#333;}
5 5 a:link,
6 6 a:visited {color:#460;text-decoration:none;}
7 7  
8   -.attribute {float:right;padding:10px 0;}
  8 +.leaflet-container .leaflet-control-attribution {color:white;background:none !important;box-shadow:none !important;}
  9 +.leaflet-container .leaflet-control-attribution a:link,
  10 +.leaflet-container .leaflet-control-attribution a:visited {color:#8C0;}
  11 +
  12 +.attribute {width:290px;float:right;padding:10px 0;text-align:left;font-size:10px;line-height:16px;}
9 13 .menu {float:left;margin:0;padding:0;list-style:none;}
10 14 .menu a {display:inline-block;margin:0;padding:5px 0 10px;margin:0 25px 0 0;border-top:5px solid transparent;}
11 15 .menu a:hover,
... ... @@ -20,7 +24,7 @@ a:visited {color:#460;text-decoration:none;}
20 24 #controls .text {margin:90px 0 0;}
21 25 #controls a:hover,
22 26 #controls a:active {text-decoration:underline;}
23   -#forkme {width:141px;height:141px;z-index:9999;position:absolute;left:0;top:0;background:transparent url(/static/ForkMe_Blk.png) no-repeat left top;}
  27 +#forkme {width:141px;height:141px;z-index:9999;position:absolute;left:0;top:4px;background:transparent url(https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png) no-repeat left top;}
24 28 #form {margin:10px 0 0;font-size:14px;color:#666;font-family:CabinItalic,sans-serif;}
25 29 #form #wkt {width:100%;height:150px;border:1px solid #999;padding:3px;resize:none;}
26 30 #form #urlify {vertical-align:baseline;margin:10px 5px 0 0;}
... ...
pacotes/wicket/doc/leaflet.html 0 → 100644
... ... @@ -0,0 +1,266 @@
  1 +<html>
  2 +<head>
  3 + <link rel="stylesheet" type="text/css" href="/static/font/Cabin.css" />
  4 + <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5 + <!-- Conditional commenting for non-IE browsers -->
  6 + <!--[if !IE]><!-->
  7 + <link rel="stylesheet" type="text/css" href="/static/wicket/doc/index.css" />
  8 + <!--<![endif]-->
  9 + <!-- Conditional commenting for IE 6.x -->
  10 + <!--[if IE]>
  11 + <link rel="stylesheet" type="text/css" href="/static/wicket/doc/index.ie.css" />
  12 + <![endif]-->
  13 + <link rel="stylesheet" href="/static/leaflet/0.5.1/dist/leaflet.css" />
  14 + <!--[if lte IE 8]>
  15 + <link rel="stylesheet" href="/static/leaflet/0.5.1/dist/leaflet.ie.css" />
  16 + <![endif]-->
  17 +</head>
  18 +<title>Wicket - Lightweight Javascript for WKT [Leaflet Sandbox]</title>
  19 +<script src="/static/leaflet/0.5.1/dist/leaflet.js"></script>
  20 +<!--See https://github.com/seelmann/leaflet-providers for below-->
  21 +<script src="/static/leaflet/plugins/leaflet-providers.js"></script>
  22 +<script src="../wicket.js" type="text/javascript"></script>
  23 +<script src="../wicket-leaflet.js" type="text/javascript"></script>
  24 +<script type="text/javascript">
  25 +var app = (function () {
  26 + return {
  27 + features: [],
  28 +
  29 + /**
  30 + * Clears the map contents.
  31 + */
  32 + clearMap: function () {
  33 + var i;
  34 +
  35 + // Reset the remembered last string (so that we can clear the map,
  36 + // paste the same string, and see it again)
  37 + document.getElementById('wkt').last = '';
  38 +
  39 + for (i in this.features) {
  40 + if (this.features.hasOwnProperty(i)) {
  41 + this.map.removeLayer(this.features[i]);
  42 + }
  43 + }
  44 + this.features.length = 0;
  45 + },
  46 +
  47 + /**
  48 + * Clears the current contents of the textarea.
  49 + */
  50 + clearText: function () {
  51 + document.getElementById('wkt').value = '';
  52 + },
  53 +
  54 + /**
  55 + * Maps the current contents of the textarea.
  56 + * @param editable {Boolean} Indicates that the feature drawn should be editable
  57 + * @param focus {Boolean} Indicates that the map should pan and/or zoom to new features
  58 + * @return {Object} Some sort of geometry object
  59 + */
  60 + mapIt: function (editable, focus) {
  61 + var config, el, obj, wkt;
  62 +
  63 + // Indicates that the map should pan and/or zoom to new features
  64 + focus = focus || false;
  65 +
  66 + if (editable === undefined) {
  67 + editable = true;
  68 + }
  69 +
  70 + el = document.getElementById('wkt');
  71 + wkt = new Wkt.Wkt();
  72 +
  73 + if (el.last === el.value) { // Remember the last string
  74 + return; // Do nothing if the WKT string hasn't changed
  75 + } else {
  76 + el.last = el.value;
  77 + }
  78 +
  79 + try { // Catch any malformed WKT strings
  80 + wkt.read(el.value);
  81 + } catch (e1) {
  82 + try {
  83 + wkt.read(el.value.replace('\n', '').replace('\r', '').replace('\t', ''));
  84 + } catch (e2) {
  85 + if (e2.name === 'WKTError') {
  86 + alert('Wicket could not understand the WKT string you entered. Check that you have parentheses balanced, and try removing tabs and newline characters.');
  87 + return;
  88 + }
  89 + }
  90 + }
  91 +
  92 + config = this.map.defaults;
  93 + config.editable = editable;
  94 +
  95 + obj = wkt.toObject(this.map.defaults); // Make an object
  96 +
  97 + // Add listeners for overlay editing events
  98 + if (wkt.type === 'polygon' || wkt.type === 'linestring') {
  99 + }
  100 +
  101 + if (Wkt.isArray(obj)) { // Distinguish multigeometries (Arrays) from objects
  102 + for (i in obj) {
  103 + if (obj.hasOwnProperty(i) && !Wkt.isArray(obj[i])) {
  104 + obj[i].addTo(this.map);
  105 + this.features.push(obj[i]);
  106 + }
  107 + }
  108 + } else {
  109 + obj.addTo(this.map); // Add it to the map
  110 + this.features.push(obj);
  111 + }
  112 +
  113 + // Pan the map to the feature
  114 + if (focus && obj.getBounds !== undefined && typeof obj.getBounds === 'function') {
  115 + // For objects that have defined bounds or a way to get them
  116 + this.map.fitBounds(obj.getBounds());
  117 + } else {
  118 + if (focus && obj.getLatLng !== undefined && typeof obj.getLatLng === 'function') {
  119 + this.map.panTo(obj.getLatLng());
  120 + }
  121 + }
  122 +
  123 + return obj;
  124 + },
  125 +
  126 + /**
  127 + * Updates the textarea based on the first available feature.
  128 + */
  129 + updateText: function () {
  130 + var wkt = new Wkt.Wkt();
  131 + wkt.fromObject(this.features[0]);
  132 + document.getElementById('wkt').value = wkt.write();
  133 + },
  134 +
  135 + /**
  136 + * Formats the textarea contents for a URL.
  137 + * @param checked {Boolean} The check state of the associated checkbox
  138 + */
  139 + urlify: function (checked) {
  140 + var wkt = new Wkt.Wkt();
  141 + wkt.read(document.getElementById('wkt').value);
  142 + wkt.delimiter = (checked) ? '+' : ' ';
  143 + document.getElementById('wkt').value = wkt.write();
  144 + return wkt;
  145 + },
  146 +
  147 + /**
  148 + * Application entry point.
  149 + * @return {<L.map>} The Leaflet instance
  150 + */
  151 + init: function () {
  152 + var leaflet, that;
  153 +
  154 + that = this;
  155 +
  156 + leaflet = {
  157 + baseLayers: undefined,
  158 + overlays: undefined
  159 + };
  160 +
  161 + // Stamen //////////////////////////////////////////////////////////////////////
  162 +
  163 + leaflet.baseLayers = {
  164 + 'Stamen Toner Map': L.tileLayer.provider('Stamen.Toner')
  165 + };
  166 +
  167 + // Configure map ///////////////////////////////////////////////////
  168 + leaflet.map = L.map('canvas', {
  169 + zoomControl: true,
  170 + attributionControl: true,
  171 + layers: [
  172 + leaflet.baseLayers['Stamen Toner Map'],
  173 + ]
  174 + });
  175 +
  176 + leaflet.map.defaults = {
  177 + icon: new L.Icon({
  178 + iconUrl: 'red_dot.png',
  179 + iconSize: [16, 16],
  180 + iconAnchor: [8, 8],
  181 + shadowUrl: 'dot_shadow.png',
  182 + shadowSize: [16, 16],
  183 + shadowAnchor: [8, 8]
  184 + }),
  185 + editable: true,
  186 + color: '#AA0000',
  187 + weight: 3,
  188 + opacity: 1.0,
  189 + editable: true,
  190 + fillColor: '#AA0000',
  191 + fillOpacity: 0.2
  192 + };
  193 +
  194 + // Set event handlers //////////////////////////////////////////////
  195 + leaflet.map.loaded = false;
  196 + leaflet.map.on('load', function () {
  197 + if (!this.loaded) {
  198 + this.loaded = true;
  199 + document.getElementById('wkt').value = 'MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 45 20, 30 5, 10 10, 10 30, 20 35), (30 20, 20 25, 20 15, 30 20)))';
  200 + }
  201 + });
  202 +
  203 + // There are no 'edit' events, so let's catch editing at its most
  204 + // fundamental: the mouseup event on the map
  205 + leaflet.map.on('mouseup', function () {
  206 + that.updateText()
  207 + });
  208 +
  209 + // Initialize the map //////////////////////////////////////////////
  210 + leaflet.map.setView([10, 20], 2);
  211 +
  212 + return leaflet.map;
  213 + }
  214 +
  215 + };
  216 +
  217 +}());
  218 +</script>
  219 +<body onload="app.map=app.init();app.mapIt(true, false);">
  220 + <div id="head">
  221 + <div class="wrapper">
  222 + </div>
  223 + </div>
  224 + <div id="ribbon">
  225 + <div class="wrapper">
  226 + <a href="http://github.com/arthur-e/Wicket">
  227 + <div id="forkme">&nbsp;
  228 + </div>
  229 + </a>
  230 + <div id="canvas">
  231 + </div>
  232 + <div id="controls">
  233 + <div class="title">
  234 + <div class="brand">Wicket</div>
  235 + &nbsp;It whispers WKT in your application's ear.
  236 + </div>
  237 + <div class="text">
  238 + Wicket is a lightweight Javascript library that reads and writes <a href="http://en.wikipedia.org/wiki/Well-known_text#Geometric_objects" target="_blaknk">Well-Known Text (WKT)</a> strings. It can also be extended to parse and to create geometric objects from various mapping frameworks, such as <a href="http://http://leafletjs.com/" target="_blank">Leaflet</a> and the Google Maps API.
  239 + </div>
  240 + <div id="form">
  241 + <textarea type="text" name="wkt" id="wkt"></textarea>
  242 + <label><input type="checkbox" name="urlify" id="urlify" onchange="app.urlify(this.checked);" />Format for URLs</label>
  243 + <input type="submit" id="submit" value="Map It!" onclick="app.clearMap();app.mapIt(true, true);" />
  244 + <input type="reset" id="reset" value="Clear Map" onclick="app.clearText();app.clearMap();" />
  245 + </div>
  246 + </div>
  247 + </div>
  248 + </div>
  249 + <div id="foot">
  250 + <div class="wrapper">
  251 + <div class="menu" id="nav">
  252 + <a href="/">Home</a>
  253 + <a href="mailto:kaendsle@mtu.edu">Contact Me</a>
  254 + <a href="http://github.com/arthur-e/Wicket">"Fork me on GitHub!"</a>
  255 + </div>
  256 + <div class="attribute">
  257 + Design &copy; 2012-2013 <a href="mailto:kaendsle@mtu.edu">K. Arthur Endsley</a>
  258 + <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_GB">
  259 + <img alt="Wicket is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License" style="float:right;border-width:0;vertical-align:middle;" src="http://i.creativecommons.org/l/by-sa/3.0/80x15.png" />
  260 + </a><br />
  261 + Wicket is released under the <a href="https://github.com/arthur-e/Wicket/blob/master/LICENSE" target="_blank">GPL v3</a>
  262 + </div>
  263 + </div>
  264 + </div>
  265 +</body>
  266 +</html>
... ...
pacotes/wicket/package.json 0 → 100644
... ... @@ -0,0 +1,67 @@
  1 +{
  2 + "name": "wicket",
  3 + "version": "1.1.0",
  4 + "description": "A modest library for moving between Well-Known Text (WKT) and various framework geometries",
  5 + "homepage": "https://github.com/arthur-e/Wicket",
  6 + "keywords": [
  7 + "wkt",
  8 + "map",
  9 + "mapping",
  10 + "geometry",
  11 + "leaflet"
  12 + ],
  13 + "maintainers": [{
  14 + "name": "K. Arthur Endsley",
  15 + "email": "kaendsle@mtu.edu",
  16 + "web": "https://github.com/arthur-e"
  17 + }],
  18 + "contributors": [{
  19 + "name": "K. Arthur Endsley",
  20 + "email": "kaendsle@mtu.edu",
  21 + "web": "https://github.com/arthur-e"
  22 + }, {
  23 + "name": "cuyahoga",
  24 + "web": "https://github.com/cuyahoga"
  25 + }, {
  26 + "name": "Tom Nightingale",
  27 + "web": "https://github.com/thegreat"
  28 + }, {
  29 + "name": "Aaron Ogle",
  30 + "web": "https://github.com/atogle"
  31 + }, {
  32 + "name": "James Seppi",
  33 + "web": "https://github.com/jseppi"
  34 + }, {
  35 + "name": "tchannel",
  36 + "web": "https://github.com/tchannel"
  37 + }, {
  38 + "name": "Felipe Figueroa",
  39 + "web": "https://github.com/amenadiel"
  40 + }, {
  41 + "name": "Matthijs van Henten",
  42 + "web": "https://github.com/mvhenten"
  43 + }],
  44 + "bugs": {
  45 + "mail": "kaendsle@mtu.edu",
  46 + "url": "https://github.com/arthur-e/Wicket/issues"
  47 + },
  48 + "licenses": [{
  49 + "type": "GPLv3",
  50 + "url": "https://raw.github.com/arthur-e/Wicket/master/LICENSE"
  51 + }],
  52 + "repository": {
  53 + "type": "git",
  54 + "url": "https://github.com/arthur-e/Wicket"
  55 + },
  56 + "scripts": {
  57 + "postinstall": "export PATH=$PATH:/usr/local/lib/node_modules/uglify-js/bin/;unzip ./node_modules/jasmine-core/dist/jasmine-standalone-2.0.0.zip -d ./node_modules/jasmine-core/dist/",
  58 + "build": "uglifyjs wicket.js -o wicket.min.js;uglifyjs wicket-gmap3.js -o wicket-gmap3.min.js;uglifyjs wicket-arcgis.js -o wicket-arcgis.min.js;uglifyjs wicket-leaflet.js -o wicket-leaflet.min.js;",
  59 + "test": "./node_modules/mocha/bin/mocha -R tap tests/wicket-spec.js"
  60 + },
  61 + "devDependencies": {
  62 + "chai": "*",
  63 + "mocha": "*",
  64 + "uglify-js": "2.4.x",
  65 + "jasmine": "git://github.com/pivotal/jasmine#master"
  66 + }
  67 +}
... ...
pacotes/wicket/tests/wicket-gmap3-spec.js 0 → 100644
... ... @@ -0,0 +1,880 @@
  1 +describe('Standard WKT Test Cases: ', function () {
  2 + var cases, wkt;
  3 +
  4 + wkt = new Wkt.Wkt();
  5 +
  6 + cases = {
  7 +
  8 + point: {
  9 + str: 'POINT(30 10)',
  10 + cmp: [{
  11 + x: 30,
  12 + y: 10
  13 + }],
  14 + obj: new google.maps.Point(30, 10),
  15 + json: {
  16 + 'coordinates': [30, 10],
  17 + 'type': 'Point'
  18 + },
  19 + },
  20 +
  21 + marker: {
  22 + str: 'POINT(30 10)',
  23 + cmp: [{
  24 + x: 30,
  25 + y: 10
  26 + }],
  27 + obj: new google.maps.Marker({
  28 + position: new google.maps.LatLng(10, 30)
  29 + })
  30 + },
  31 +
  32 + linestring: {
  33 + str: 'LINESTRING(30 10,10 30,40 40)',
  34 + cmp: [{
  35 + x: 30,
  36 + y: 10
  37 + }, {
  38 + x: 10,
  39 + y: 30
  40 + }, {
  41 + x: 40,
  42 + y: 40
  43 + }],
  44 + obj: new google.maps.Polyline({
  45 + editable: false,
  46 + path: [
  47 + new google.maps.LatLng(10, 30),
  48 + new google.maps.LatLng(30, 10),
  49 + new google.maps.LatLng(40, 40)
  50 + ]
  51 + }),
  52 + json: {
  53 + 'coordinates': [
  54 + [30, 10],
  55 + [10, 30],
  56 + [40, 40]
  57 + ],
  58 + 'type': 'LineString'
  59 + },
  60 + },
  61 +
  62 +
  63 + polygon: {
  64 + str: 'POLYGON((30 10,10 20,20 40,40 40,30 10))',
  65 + cmp: [
  66 + [{
  67 + x: 30,
  68 + y: 10
  69 + }, {
  70 + x: 10,
  71 + y: 20
  72 + }, {
  73 + x: 20,
  74 + y: 40
  75 + }, {
  76 + x: 40,
  77 + y: 40
  78 + }, {
  79 + x: 30,
  80 + y: 10
  81 + }]
  82 + ],
  83 + obj: new google.maps.Polygon({
  84 + editable: false,
  85 + paths: [
  86 + [
  87 + new google.maps.LatLng(10, 30),
  88 + new google.maps.LatLng(20, 10),
  89 + new google.maps.LatLng(40, 20),
  90 + new google.maps.LatLng(40, 40)
  91 + ]
  92 + ]
  93 + }),
  94 + json: {
  95 + 'coordinates': [
  96 + [
  97 + [30, 10],
  98 + [10, 20],
  99 + [20, 40],
  100 + [40, 40],
  101 + [30, 10]
  102 + ]
  103 + ],
  104 + 'type': 'Polygon'
  105 + },
  106 +
  107 + },
  108 +
  109 + polygon2: {
  110 + str: 'POLYGON((35 10,10 20,15 40,45 45,35 10),(25 30,35 35,30 20,25 30))',
  111 + cmp: [
  112 + [{
  113 + x: 35,
  114 + y: 10
  115 + }, {
  116 + x: 10,
  117 + y: 20
  118 + }, {
  119 + x: 15,
  120 + y: 40
  121 + }, {
  122 + x: 45,
  123 + y: 45
  124 + }, {
  125 + x: 35,
  126 + y: 10
  127 + }],
  128 + [{
  129 + x: 25,
  130 + y: 30
  131 + }, {
  132 + x: 35,
  133 + y: 35
  134 + }, {
  135 + x: 30,
  136 + y: 20
  137 + }, {
  138 + x: 25,
  139 + y: 30
  140 + }]
  141 + ],
  142 + obj: new google.maps.Polygon({
  143 + editable: false,
  144 + paths: [
  145 + [
  146 + new google.maps.LatLng(10, 35),
  147 + new google.maps.LatLng(20, 10),
  148 + new google.maps.LatLng(40, 15),
  149 + new google.maps.LatLng(45, 45)
  150 + ],
  151 + [ // Order in inner rings is reversed
  152 + new google.maps.LatLng(20, 30),
  153 + new google.maps.LatLng(35, 35),
  154 + new google.maps.LatLng(30, 25)
  155 + ]
  156 + ]
  157 + }),
  158 + json: {
  159 + 'coordinates': [
  160 + [
  161 + [35, 10],
  162 + [10, 20],
  163 + [15, 40],
  164 + [45, 45],
  165 + [35, 10]
  166 + ],
  167 + [
  168 + [25, 30],
  169 + [35, 35],
  170 + [30, 20],
  171 + [25, 30]
  172 + ]
  173 + ],
  174 + 'type': 'Polygon'
  175 + },
  176 + jsonStr: '{"coordinates": [[[35, 10], [45, 45], [15, 40], [10, 20], [35, 10]], [[20, 30], [35, 35], [30, 20], [20, 30]]], "type": "Polygon"}'
  177 + },
  178 +
  179 + multipoint: {
  180 + str: 'MULTIPOINT((10 40),(40 30),(20 20),(30 10))',
  181 + cmp: [
  182 + [{
  183 + x: 10,
  184 + y: 40
  185 + }],
  186 + [{
  187 + x: 40,
  188 + y: 30
  189 + }],
  190 + [{
  191 + x: 20,
  192 + y: 20
  193 + }],
  194 + [{
  195 + x: 30,
  196 + y: 10
  197 + }]
  198 + ],
  199 + obj: [
  200 + new google.maps.Marker({
  201 + position: new google.maps.LatLng(40, 10)
  202 + }),
  203 + new google.maps.Marker({
  204 + position: new google.maps.LatLng(30, 40)
  205 + }),
  206 + new google.maps.Marker({
  207 + position: new google.maps.LatLng(20, 20)
  208 + }),
  209 + new google.maps.Marker({
  210 + position: new google.maps.LatLng(10, 30)
  211 + }),
  212 + ],
  213 + json: {
  214 + 'coordinates': [
  215 + [10, 40],
  216 + [40, 30],
  217 + [20, 20],
  218 + [30, 10]
  219 + ],
  220 + 'type': 'MultiPoint'
  221 + },
  222 + jsonStr: '{"coordinates": [[10, 40], [40, 30], [20, 20], [30, 10]], "type": "MultiPoint"}'
  223 + },
  224 +
  225 + multilinestring: {
  226 + str: 'MULTILINESTRING((10 10,20 20,10 40),(40 40,30 30,40 20,30 10))',
  227 + cmp: [
  228 + [{
  229 + x: 10,
  230 + y: 10
  231 + }, {
  232 + x: 20,
  233 + y: 20
  234 + }, {
  235 + x: 10,
  236 + y: 40
  237 + }],
  238 + [{
  239 + x: 40,
  240 + y: 40
  241 + }, {
  242 + x: 30,
  243 + y: 30
  244 + }, {
  245 + x: 40,
  246 + y: 20
  247 + }, {
  248 + x: 30,
  249 + y: 10
  250 + }]
  251 + ],
  252 + obj: [
  253 + new google.maps.Polyline({
  254 + editable: false,
  255 + path: [
  256 + new google.maps.LatLng(10, 10),
  257 + new google.maps.LatLng(20, 20),
  258 + new google.maps.LatLng(40, 10)
  259 + ]
  260 + }),
  261 + new google.maps.Polyline({
  262 + editable: false,
  263 + path: [
  264 + new google.maps.LatLng(40, 40),
  265 + new google.maps.LatLng(30, 30),
  266 + new google.maps.LatLng(20, 40),
  267 + new google.maps.LatLng(10, 30)
  268 + ]
  269 + })
  270 + ],
  271 + json: {
  272 + 'coordinates': [
  273 + [
  274 + [10, 10],
  275 + [20, 20],
  276 + [10, 40]
  277 + ],
  278 + [
  279 + [40, 40],
  280 + [30, 30],
  281 + [40, 20],
  282 + [30, 10]
  283 + ]
  284 + ],
  285 + 'type': 'MultiLineString'
  286 + },
  287 + jsonStr: '{"coordinates": [[[10, 10], [20, 20], [10, 40]], [[40, 40], [30, 30], [40, 20], [30, 10]]], "type": "MultiLineString"}'
  288 + },
  289 +
  290 + multipolygon: {
  291 + str: 'MULTIPOLYGON(((30 20,10 40,45 40,30 20)),((15 5,40 10,10 20,5 10,15 5)))',
  292 + cmp: [
  293 + [
  294 + [{
  295 + x: 30,
  296 + y: 20
  297 + }, {
  298 + x: 10,
  299 + y: 40
  300 + }, {
  301 + x: 45,
  302 + y: 40
  303 + }, {
  304 + x: 30,
  305 + y: 20
  306 + }, ]
  307 + ],
  308 + [
  309 + [{
  310 + x: 15,
  311 + y: 5
  312 + }, {
  313 + x: 40,
  314 + y: 10
  315 + }, {
  316 + x: 10,
  317 + y: 20
  318 + }, {
  319 + x: 5,
  320 + y: 10
  321 + }, {
  322 + x: 15,
  323 + y: 5
  324 + }]
  325 + ]
  326 + ],
  327 + obj: [
  328 + new google.maps.Polygon({
  329 + editable: false,
  330 + paths: [
  331 + [
  332 + new google.maps.LatLng(20, 30),
  333 + new google.maps.LatLng(40, 10),
  334 + new google.maps.LatLng(40, 45)
  335 + ]
  336 + ]
  337 + }),
  338 + new google.maps.Polygon({
  339 + editable: false,
  340 + paths: [
  341 + [
  342 + new google.maps.LatLng(5, 15),
  343 + new google.maps.LatLng(10, 40),
  344 + new google.maps.LatLng(20, 10),
  345 + new google.maps.LatLng(10, 5)
  346 + ]
  347 + ]
  348 + })
  349 + ],
  350 + json: {
  351 + 'coordinates': [
  352 + [
  353 + [
  354 + [30, 20],
  355 + [10, 40],
  356 + [45, 40],
  357 + [30, 20]
  358 + ]
  359 + ],
  360 + [
  361 + [
  362 + [15, 5],
  363 + [40, 10],
  364 + [10, 20],
  365 + [5, 10],
  366 + [15, 5]
  367 + ]
  368 + ]
  369 + ],
  370 + 'type': 'MultiPolygon'
  371 + },
  372 + jsonStr: '{"coordinates": [[[[30, 20], [10, 40], [45, 40], [30, 20]]], [[[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]]], "type": "MultiPolygon"}'
  373 + },
  374 +
  375 + multipolygon2: {
  376 + str: 'MULTIPOLYGON(((40 40,20 45,45 30,40 40)),((20 35,45 20,30 5,10 10,10 30,20 35),(30 20,20 25,20 15,30 20)))',
  377 + cmp: [
  378 + [
  379 + [{
  380 + x: 40,
  381 + y: 40
  382 + }, {
  383 + x: 20,
  384 + y: 45
  385 + }, {
  386 + x: 45,
  387 + y: 30
  388 + }, {
  389 + x: 40,
  390 + y: 40
  391 + }, ]
  392 + ],
  393 + [
  394 + [{
  395 + x: 20,
  396 + y: 35
  397 + }, {
  398 + x: 45,
  399 + y: 20
  400 + }, {
  401 + x: 30,
  402 + y: 5
  403 + }, {
  404 + x: 10,
  405 + y: 10
  406 + }, {
  407 + x: 10,
  408 + y: 30
  409 + }, {
  410 + x: 20,
  411 + y: 35
  412 + }, ],
  413 + [{
  414 + x: 30,
  415 + y: 20
  416 + }, {
  417 + x: 20,
  418 + y: 25
  419 + }, {
  420 + x: 20,
  421 + y: 15
  422 + }, {
  423 + x: 30,
  424 + y: 20
  425 + }]
  426 + ]
  427 + ],
  428 + obj: [
  429 + new google.maps.Polygon({
  430 + editable: false,
  431 + paths: [
  432 + [
  433 + new google.maps.LatLng(40, 40),
  434 + new google.maps.LatLng(45, 20),
  435 + new google.maps.LatLng(30, 45)
  436 + ]
  437 + ]
  438 + }),
  439 + new google.maps.Polygon({
  440 + editable: false,
  441 + paths: [
  442 + [
  443 + new google.maps.LatLng(35, 20),
  444 + new google.maps.LatLng(20, 45),
  445 + new google.maps.LatLng(5, 30),
  446 + new google.maps.LatLng(10, 10),
  447 + new google.maps.LatLng(30, 10)
  448 + ],
  449 + [
  450 + new google.maps.LatLng(15, 20),
  451 + new google.maps.LatLng(25, 20),
  452 + new google.maps.LatLng(20, 30)
  453 + ]
  454 + ]
  455 + })
  456 + ],
  457 + json: {
  458 + 'coordinates': [
  459 + [
  460 + [
  461 + [40, 40],
  462 + [20, 45],
  463 + [45, 30],
  464 + [40, 40]
  465 + ]
  466 + ],
  467 + [
  468 + [
  469 + [20, 35],
  470 + [45, 20],
  471 + [30, 5],
  472 + [10, 10],
  473 + [10, 30],
  474 + [20, 35]
  475 + ],
  476 + [
  477 + [30, 20],
  478 + [20, 25],
  479 + [20, 15],
  480 + [30, 20]
  481 + ]
  482 + ]
  483 + ],
  484 + 'type': 'MultiPolygon'
  485 + },
  486 + jsonStr: '{"coordinates": [[[[40, 40], [20, 45], [45, 30], [40, 40]]], [[[20, 35], [10, 30], [10, 10], [30, 5], [45, 20], [20, 35]], [[30, 20], [20, 15], [20, 25], [30, 20]]]], "type": "MultiPolygon"}'
  487 + },
  488 +
  489 + rectangle: {
  490 + str: 'POLYGON((-50 20,0 20,0 0,-50 0,-50 20))',
  491 + cmp: [
  492 + [{
  493 + x: -50,
  494 + y: 20
  495 + }, {
  496 + x: 0,
  497 + y: 20
  498 + }, {
  499 + x: 0,
  500 + y: 0
  501 + }, {
  502 + x: -50,
  503 + y: 0
  504 + }, {
  505 + x: -50,
  506 + y: 20
  507 + }]
  508 + ],
  509 + obj: new google.maps.Rectangle({
  510 + bounds: new google.maps.LatLngBounds(new google.maps.LatLng(0, -50),
  511 + new google.maps.LatLng(20, 0))
  512 + })
  513 + },
  514 +
  515 +
  516 +
  517 + box: {
  518 + str: 'BOX(0 0,20 20)',
  519 + cmp: [{
  520 + x: 0,
  521 + y: 0
  522 + }, {
  523 + x: 20,
  524 + y: 20
  525 + }],
  526 + obj: new google.maps.Rectangle({
  527 + bounds: new google.maps.LatLngBounds(new google.maps.LatLng(0, 0),
  528 + new google.maps.LatLng(20, 20))
  529 + }),
  530 + json: {
  531 + 'coordinates': [
  532 + [
  533 + [0, 0],
  534 + [0, 20],
  535 + [20, 20],
  536 + [20, 0],
  537 + [0, 0]
  538 + ]
  539 + ],
  540 + 'type': 'Polygon',
  541 + 'bbox': [0, 0, 20, 20]
  542 + }
  543 + },
  544 +
  545 + geometrycollection: {
  546 + str: 'GEOMETRYCOLLECTION(POINT(30 10),LINESTRING(30 10,10 30,40 40),POLYGON((30 10,10 20,20 40,40 40,30 10)))',
  547 + json: {
  548 + "type": "GeometryCollection",
  549 + "geometries": [{
  550 + "type": "Point",
  551 + "coordinates": [30, 10]
  552 + }, {
  553 + 'type': 'LineString',
  554 + 'coordinates': [
  555 + [30, 10],
  556 + [10, 30],
  557 + [40, 40]
  558 + ]
  559 + },
  560 +
  561 + {
  562 + "type": "Polygon",
  563 + "coordinates": [
  564 + [
  565 + [30, 10],
  566 + [10, 20],
  567 + [20, 40],
  568 + [40, 40],
  569 + [30, 10]
  570 + ]
  571 + ]
  572 + }
  573 + ]
  574 + }
  575 + }
  576 +
  577 + };
  578 +
  579 + dataObjects = new google.maps.Data;
  580 +
  581 +
  582 +
  583 +
  584 +
  585 + describe('Converting objects into WKT strings: ', function () {
  586 +
  587 + afterEach(function () {
  588 + wkt.delimiter = ' ';
  589 + });
  590 +
  591 + it('should convert a Marker instance into a basic POINT string', function () {
  592 + wkt.fromObject(cases.point.obj);
  593 + expect(wkt.type).toBe('point');
  594 + expect(wkt.isCollection()).toBe(false);
  595 + expect(wkt.components).toEqual(cases.point.cmp);
  596 + expect(wkt.write()).toBe(cases.point.str);
  597 + });
  598 +
  599 + it('should convert a Polyline instance into a basic LINESTRING string', function () {
  600 + wkt.fromObject(cases.linestring.obj);
  601 + expect(wkt.type).toBe('linestring');
  602 + expect(wkt.isCollection()).toBe(false);
  603 + expect(wkt.components).toEqual(cases.linestring.cmp);
  604 + expect(wkt.write()).toBe(cases.linestring.str);
  605 + });
  606 +
  607 + it('should convert a Polygon instance into a basic POLYGON string', function () {
  608 + wkt.fromObject(cases.polygon.obj);
  609 + expect(wkt.type).toBe('polygon');
  610 + expect(wkt.isCollection()).toBe(true);
  611 + expect(wkt.components).toEqual(cases.polygon.cmp);
  612 + expect(wkt.write()).toBe(cases.polygon.str);
  613 + });
  614 +
  615 + it('should convert a Polygon instance with a hole into a POLYGON string with the same hole', function () {
  616 + wkt.fromObject(cases.polygon2.obj);
  617 + expect(wkt.type).toBe('polygon');
  618 + expect(wkt.isCollection()).toBe(true);
  619 + expect(wkt.components).toEqual(cases.polygon2.cmp);
  620 + expect(wkt.write()).toBe(cases.polygon2.str);
  621 + });
  622 +
  623 + it('should convert a Rectangle instance into a POLYGON string', function () {
  624 + wkt.fromObject(cases.rectangle.obj);
  625 + expect(wkt.type).toBe('polygon');
  626 + expect(wkt.isRectangle).toBe(true);
  627 + expect(wkt.isCollection()).toBe(true);
  628 + expect(wkt.components).toEqual(cases.rectangle.cmp);
  629 + expect(wkt.write()).toBe(cases.rectangle.str);
  630 + });
  631 +
  632 + it('should convert an Array of Marker instances into a MULTIPOINT string', function () {
  633 + wkt.fromObject(cases.multipoint.obj);
  634 + expect(wkt.type).toBe('multipoint');
  635 + expect(wkt.isCollection()).toBe(true);
  636 + expect(wkt.components).toEqual(cases.multipoint.cmp);
  637 + expect(wkt.write()).toBe(cases.multipoint.str);
  638 + });
  639 +
  640 + it('should convert an Array of Polyline instances into a MULTILINESTRING string', function () {
  641 + wkt.fromObject(cases.multilinestring.obj);
  642 + expect(wkt.type).toBe('multilinestring');
  643 + expect(wkt.isCollection()).toBe(true);
  644 + expect(wkt.components).toEqual(cases.multilinestring.cmp);
  645 + expect(wkt.write()).toBe(cases.multilinestring.str);
  646 + });
  647 +
  648 + it('should convert an Array of Polygon instances into a MULTIPOLYGON string', function () {
  649 + wkt.fromObject(cases.multipolygon.obj);
  650 + expect(wkt.type).toBe('multipolygon');
  651 + expect(wkt.isCollection()).toBe(true);
  652 + expect(wkt.components).toEqual(cases.multipolygon.cmp);
  653 + expect(wkt.write()).toBe(cases.multipolygon.str);
  654 + });
  655 +
  656 + it('should convert an Array of Polygon instances, some with holes, into a MULTIPOLYGON string with the same hole', function () {
  657 + wkt.fromObject(cases.multipolygon2.obj);
  658 + expect(wkt.type).toBe('multipolygon');
  659 + expect(wkt.isCollection()).toBe(true);
  660 + expect(wkt.components).toEqual(cases.multipolygon2.cmp);
  661 + expect(wkt.write()).toBe(cases.multipolygon2.str);
  662 + });
  663 +
  664 + });
  665 +
  666 + describe('Converting google.maps.Data objects into WKT strings: ', function () {
  667 +
  668 + afterEach(function () {
  669 + wkt.delimiter = ' ';
  670 + });
  671 +
  672 + it('should convert a google.maps.Data.Point instance into a basic POINT string', function () {
  673 + var dataPoint = dataObjects.addGeoJson({
  674 + "type": "Feature",
  675 + geometry: cases.point.json
  676 + })[0];
  677 + wkt.fromObject(dataPoint.getGeometry());
  678 + expect(wkt.type).toBe('point');
  679 + expect(wkt.isCollection()).toBe(false);
  680 + expect(wkt.components).toEqual(cases.point.cmp);
  681 + expect(wkt.write()).toBe(cases.point.str);
  682 + });
  683 +
  684 + it('should convert a google.maps.Data.LineString instance into a basic LINESTRING string', function () {
  685 + var dataLineString = dataObjects.addGeoJson({
  686 + "type": "Feature",
  687 + geometry: cases.linestring.json
  688 + })[0];
  689 + wkt.fromObject(dataLineString.getGeometry());
  690 + expect(wkt.type).toBe('linestring');
  691 + expect(wkt.isCollection()).toBe(false);
  692 + expect(wkt.components).toEqual(cases.linestring.cmp);
  693 + expect(wkt.write()).toBe(cases.linestring.str);
  694 + });
  695 +
  696 + it('should convert a google.maps.Data.Polygon instance into a basic POLYGON string', function () {
  697 + var dataPolygon = dataObjects.addGeoJson({
  698 + "type": "Feature",
  699 + geometry: cases.polygon.json
  700 + })[0];
  701 + wkt.fromObject(dataPolygon.getGeometry());
  702 + expect(wkt.type).toBe('polygon');
  703 + expect(wkt.isCollection()).toBe(true);
  704 + expect(wkt.components).toEqual(cases.polygon.cmp);
  705 + expect(wkt.write()).toBe(cases.polygon.str);
  706 + });
  707 +
  708 + it('should convert a google.maps.Data.Polygon instance with a hole into a POLYGON string with the same hole', function () {
  709 + var dataPolygon2 = dataObjects.addGeoJson({
  710 + "type": "Feature",
  711 + geometry: cases.polygon2.json
  712 + })[0];
  713 + wkt.fromObject(dataPolygon2.getGeometry());
  714 + expect(wkt.type).toBe('polygon');
  715 + expect(wkt.isCollection()).toBe(true);
  716 + expect(wkt.components).toEqual(cases.polygon2.cmp);
  717 + expect(wkt.write()).toBe(cases.polygon2.str);
  718 + });
  719 +
  720 +
  721 + it('should convert a google.maps.Data.MultiPoint instance into a MULTIPOINT string', function () {
  722 + var dataMultiPoint = dataObjects.addGeoJson({
  723 + "type": "Feature",
  724 + geometry: cases.multipoint.json
  725 + })[0];
  726 + wkt.fromObject(dataMultiPoint.getGeometry());
  727 + expect(wkt.type).toBe('multipoint');
  728 + expect(wkt.isCollection()).toBe(true);
  729 + expect(wkt.components).toEqual(cases.multipoint.cmp);
  730 + expect(wkt.write()).toBe(cases.multipoint.str);
  731 + });
  732 +
  733 + it('should convert a google.maps.Data.MultiLineString instance into a MULTILINESTRING string', function () {
  734 + var dataMultiLineString = dataObjects.addGeoJson({
  735 + "type": "Feature",
  736 + geometry: cases.multilinestring.json
  737 + })[0];
  738 + wkt.fromObject(dataMultiLineString.getGeometry());
  739 + expect(wkt.type).toBe('multilinestring');
  740 + expect(wkt.isCollection()).toBe(true);
  741 + expect(wkt.components).toEqual(cases.multilinestring.cmp);
  742 + expect(wkt.write()).toBe(cases.multilinestring.str);
  743 + });
  744 +
  745 + it('should convert a google.maps.Data.MultiPolygon instance into a MULTIPOLYGON string', function () {
  746 + var dataMultiPolygon = dataObjects.addGeoJson({
  747 + "type": "Feature",
  748 + geometry: cases.multipolygon.json
  749 + })[0];
  750 + wkt.fromObject(dataMultiPolygon.getGeometry());
  751 + expect(wkt.type).toBe('multipolygon');
  752 + expect(wkt.isCollection()).toBe(true);
  753 + expect(wkt.components).toEqual(cases.multipolygon.cmp);
  754 + expect(wkt.write()).toBe(cases.multipolygon.str);
  755 + });
  756 +
  757 + it('should convert a google.maps.Data.MultiPolygon with holes, into a MULTIPOLYGON string with the same holes', function () {
  758 + var dataMultiPolygon2 = dataObjects.addGeoJson({
  759 + "type": "Feature",
  760 + geometry: cases.multipolygon2.json
  761 + })[0];
  762 + wkt.fromObject(dataMultiPolygon2.getGeometry());
  763 + expect(wkt.type).toBe('multipolygon');
  764 + expect(wkt.isCollection()).toBe(true);
  765 + expect(wkt.components).toEqual(cases.multipolygon2.cmp);
  766 + expect(wkt.write()).toBe(cases.multipolygon2.str);
  767 + });
  768 +
  769 + it('should convert a google.maps.Data.GeometryCollection into a GEOMETRYCOLLECTION string', function () {
  770 + var dataGeometryCollection = dataObjects.addGeoJson({
  771 + "type": "Feature",
  772 + geometry: cases.geometrycollection.json
  773 + })[0];
  774 +
  775 + wkt.fromObject(dataGeometryCollection.getGeometry());
  776 + expect(wkt.type).toBe('geometrycollection');
  777 + //expect(wkt.isCollection()).toBe(true);
  778 +
  779 + });
  780 +
  781 + });
  782 +
  783 +
  784 + describe('Coverting WKT strings into objects: ', function () {
  785 +
  786 + afterEach(function () {
  787 + wkt.delimiter = ' ';
  788 + });
  789 +
  790 + it('should convert a basic POINT string to a Marker instance', function () {
  791 + wkt.read(cases.marker.str);
  792 + expect(wkt.type).toBe('point');
  793 + expect(wkt.isCollection()).toBe(false);
  794 + expect(wkt.components).toEqual(cases.marker.cmp);
  795 + expect(wkt.toObject().getPosition()).toEqual(cases.marker.obj.getPosition());
  796 + });
  797 +
  798 + it('should convert a basic LINESTRING string to a Polyline instance', function () {
  799 + wkt.read(cases.linestring.str);
  800 + expect(wkt.type).toBe('linestring');
  801 + expect(wkt.isCollection()).toBe(false);
  802 + expect(wkt.components).toEqual(cases.linestring.cmp);
  803 + expect(wkt.toObject().getPath()).toEqual(cases.linestring.obj.getPath());
  804 + });
  805 +
  806 + it('should convert a basic POLYGON string to a Polygon instance', function () {
  807 + wkt.read(cases.polygon.str);
  808 + expect(wkt.type).toBe('polygon');
  809 + expect(wkt.isCollection()).toBe(true);
  810 + expect(wkt.components).toEqual(cases.polygon.cmp);
  811 + expect(wkt.toObject().getPaths()).toEqual(cases.polygon.obj.getPaths());
  812 + });
  813 +
  814 + it('should convert a POLYGON string with a hole to a Polygon instance with the same hole', function () {
  815 + wkt.read(cases.polygon2.str);
  816 + expect(wkt.type).toBe('polygon');
  817 + expect(wkt.isCollection()).toBe(true);
  818 + expect(wkt.components).toEqual(cases.polygon2.cmp);
  819 + expect(wkt.toObject().getPaths()).toEqual(cases.polygon2.obj.getPaths());
  820 + });
  821 +
  822 + it('should convert a POLYGON string, with isRectangle=true, into a Rectangle instance', function () {
  823 + wkt.read(cases.rectangle.str);
  824 + wkt.isRectangle = true;
  825 + expect(wkt.type).toBe('polygon');
  826 + expect(wkt.isCollection()).toBe(true);
  827 + expect(wkt.components).toEqual(cases.rectangle.cmp);
  828 + expect(wkt.toObject().getBounds()).toEqual(cases.rectangle.obj.getBounds());
  829 + expect(wkt.toObject().constructor).toEqual(google.maps.Rectangle);
  830 + });
  831 +
  832 + it('should convert a MULTIPOINT string into an Array of Marker instances', function () {
  833 + var m;
  834 +
  835 + wkt.read(cases.multipoint.str);
  836 + expect(wkt.type).toBe('multipoint');
  837 + expect(wkt.isCollection()).toBe(true);
  838 + expect(wkt.components).toEqual(cases.multipoint.cmp);
  839 +
  840 + markers = wkt.toObject();
  841 + for (m = 0; m < markers.length; m += 1) {
  842 + expect(markers[m].getPosition()).toEqual(cases.multipoint.obj[m].getPosition());
  843 + }
  844 + });
  845 +
  846 + it('should convert a MULTILINESTRING string into an Array of Polyline instances', function () {
  847 + wkt.read(cases.multilinestring.str);
  848 + expect(wkt.type).toBe('multilinestring');
  849 + expect(wkt.isCollection()).toBe(true);
  850 + expect(wkt.components).toEqual(cases.multilinestring.cmp);
  851 + expect(wkt.toObject()).toEqual(cases.multilinestring.obj);
  852 + });
  853 +
  854 + it('should convert a MULTIPOLYGON string into an Array of Polygon instances', function () {
  855 + wkt.read(cases.multipolygon.str);
  856 + expect(wkt.type).toBe('multipolygon');
  857 + expect(wkt.isCollection()).toBe(true);
  858 + expect(wkt.components).toEqual(cases.multipolygon.cmp);
  859 + expect(wkt.toObject()).toEqual(cases.multipolygon.obj);
  860 + });
  861 +
  862 + it('should convert a MULTIPOLYGON string with holes into an Array of Polygon instances with the same holes', function () {
  863 + wkt.read(cases.multipolygon2.str);
  864 + expect(wkt.type).toBe('multipolygon');
  865 + expect(wkt.isCollection()).toBe(true);
  866 + expect(wkt.components).toEqual(cases.multipolygon2.cmp);
  867 + expect(wkt.toObject()).toEqual(cases.multipolygon2.obj);
  868 + });
  869 +
  870 + it('should convert a PostGIS 2DBOX string into a Rectangle instance', function () {
  871 + wkt.read(cases.box.str);
  872 + expect(wkt.type).toBe('box');
  873 + expect(wkt.isCollection()).toBe(false);
  874 + expect(wkt.components).toEqual(cases.box.cmp);
  875 + expect(wkt.toObject().getBounds()).toEqual(cases.box.obj.getBounds());
  876 + });
  877 +
  878 + });
  879 +
  880 +});
0 881 \ No newline at end of file
... ...
pacotes/wicket/tests/wicket-gmap3.html 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +<!DOCTYPE HTML>
  2 +<html>
  3 +<head>
  4 + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5 + <title>Jasmine Spec Runner v2.0.0</title>
  6 +
  7 + <link rel="shortcut icon" type="image/png" href="../node_modules/jasmine-core/dist/lib/jasmine-2.0.0/jasmine_favicon.png">
  8 + <link rel="stylesheet" type="text/css" href="../node_modules/jasmine-core/dist/lib/jasmine-2.0.0/jasmine.css">
  9 +
  10 + <!-- Get Jasmine: https://github.com/pivotal/jasmine -->
  11 + <script type="text/javascript" src="../node_modules/jasmine-core/dist/lib/jasmine-2.0.0/jasmine.js"></script>
  12 + <script type="text/javascript" src="../node_modules/jasmine-core/dist/lib/jasmine-2.0.0/jasmine-html.js"></script>
  13 + <script type="text/javascript" src="../node_modules/jasmine-core/dist/lib/jasmine-2.0.0/boot.js"></script>
  14 +
  15 + <script src="http://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false" type="text/javascript"></script>
  16 +
  17 + <!-- include source files here... -->
  18 + <script type="text/javascript" src="../wicket.js"></script>
  19 + <script type="text/javascript" src="../wicket-gmap3.js"></script>
  20 + <!--<script type="text/javascript" src="/static/wicket/wicket-leaflet.src.js"></script>-->
  21 + <!--<script type="text/javascript" src="/static/wicket/wicket-arcgis.src.js"></script>-->
  22 +
  23 + <!-- include spec files here... -->
  24 + <script type="text/javascript" src="wicket-gmap3-spec.js"></script>
  25 +
  26 +</head>
  27 +
  28 +<body>
  29 +</body>
  30 +</html>
... ...
pacotes/wicket/tests/wicket-spec.js 0 → 100644
... ... @@ -0,0 +1,1952 @@
  1 +var Wkt = require('../wicket');
  2 +var expect = require('chai').expect;
  3 +
  4 +describe('Consistent Design Patterns', function() {
  5 +
  6 + it('should read WKT string when instantiated', function() {
  7 + var wkt = new Wkt.Wkt('POINT(30 10)');
  8 +
  9 + expect(wkt.components).deep.equal([{
  10 + x: 30,
  11 + y: 10
  12 + }]);
  13 + });
  14 +
  15 + it('should correctly identify an Array', function() {
  16 + expect(Wkt.isArray([0, 1])).equal(true);
  17 + expect(Wkt.isArray({
  18 + x: 0,
  19 + y: 1
  20 + })).equal(false);
  21 + expect(Wkt.isArray(0)).equal(false);
  22 + expect(Wkt.isArray(new Date())).equal(false);
  23 + });
  24 +
  25 +});
  26 +
  27 +describe('Standard WKT Test Cases: ', function() {
  28 + var cases, wkt;
  29 +
  30 + wkt = new Wkt.Wkt();
  31 +
  32 + cases = {
  33 +
  34 + point: {
  35 + str: 'POINT(30 10)',
  36 + cmp: [{
  37 + x: 30,
  38 + y: 10
  39 + }]
  40 + },
  41 +
  42 + linestring: {
  43 + str: 'LINESTRING(30 10,10 30,40 40)',
  44 + cmp: [{
  45 + x: 30,
  46 + y: 10
  47 + }, {
  48 + x: 10,
  49 + y: 30
  50 + }, {
  51 + x: 40,
  52 + y: 40
  53 + }]
  54 + },
  55 +
  56 + polygon: {
  57 + str: 'POLYGON((30 10,10 20,20 40,40 40,30 10))',
  58 + cmp: [
  59 + [{
  60 + x: 30,
  61 + y: 10
  62 + }, {
  63 + x: 10,
  64 + y: 20
  65 + }, {
  66 + x: 20,
  67 + y: 40
  68 + }, {
  69 + x: 40,
  70 + y: 40
  71 + }, {
  72 + x: 30,
  73 + y: 10
  74 + }]
  75 + ]
  76 + },
  77 +
  78 + polygon2: {
  79 + str: 'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 35,30 20,20 30))',
  80 + cmp: [
  81 + [{
  82 + x: 35,
  83 + y: 10
  84 + }, {
  85 + x: 10,
  86 + y: 20
  87 + }, {
  88 + x: 15,
  89 + y: 40
  90 + }, {
  91 + x: 45,
  92 + y: 45
  93 + }, {
  94 + x: 35,
  95 + y: 10
  96 + }],
  97 + [{
  98 + x: 20,
  99 + y: 30
  100 + }, {
  101 + x: 35,
  102 + y: 35
  103 + }, {
  104 + x: 30,
  105 + y: 20
  106 + }, {
  107 + x: 20,
  108 + y: 30
  109 + }]
  110 + ]
  111 + },
  112 +
  113 + multipoint: {
  114 + str: 'MULTIPOINT((10 40),(40 30),(20 20),(30 10))',
  115 + cmp: [
  116 + [{
  117 + x: 10,
  118 + y: 40
  119 + }],
  120 + [{
  121 + x: 40,
  122 + y: 30
  123 + }],
  124 + [{
  125 + x: 20,
  126 + y: 20
  127 + }],
  128 + [{
  129 + x: 30,
  130 + y: 10
  131 + }]
  132 + ]
  133 + },
  134 +
  135 + multipoint2: {
  136 + str: 'MULTIPOINT(10 40,40 30,20 20,30 10)',
  137 + cmp: [
  138 + [{
  139 + x: 10,
  140 + y: 40
  141 + }],
  142 + [{
  143 + x: 40,
  144 + y: 30
  145 + }],
  146 + [{
  147 + x: 20,
  148 + y: 20
  149 + }],
  150 + [{
  151 + x: 30,
  152 + y: 10
  153 + }]
  154 + ]
  155 + },
  156 +
  157 + multilinestring: {
  158 + str: 'MULTILINESTRING((10 10,20 20,10 40),(40 40,30 30,40 20,30 10))',
  159 + cmp: [
  160 + [{
  161 + x: 10,
  162 + y: 10
  163 + }, {
  164 + x: 20,
  165 + y: 20
  166 + }, {
  167 + x: 10,
  168 + y: 40
  169 + }],
  170 + [{
  171 + x: 40,
  172 + y: 40
  173 + }, {
  174 + x: 30,
  175 + y: 30
  176 + }, {
  177 + x: 40,
  178 + y: 20
  179 + }, {
  180 + x: 30,
  181 + y: 10
  182 + }]
  183 + ]
  184 + },
  185 +
  186 + multipolygon: {
  187 + str: 'MULTIPOLYGON(((30 20,10 40,45 40,30 20)),((15 5,40 10,10 20,5 10,15 5)))',
  188 + cmp: [
  189 + [
  190 + [{
  191 + x: 30,
  192 + y: 20
  193 + }, {
  194 + x: 10,
  195 + y: 40
  196 + }, {
  197 + x: 45,
  198 + y: 40
  199 + }, {
  200 + x: 30,
  201 + y: 20
  202 + }, ]
  203 + ],
  204 + [
  205 + [{
  206 + x: 15,
  207 + y: 5
  208 + }, {
  209 + x: 40,
  210 + y: 10
  211 + }, {
  212 + x: 10,
  213 + y: 20
  214 + }, {
  215 + x: 5,
  216 + y: 10
  217 + }, {
  218 + x: 15,
  219 + y: 5
  220 + }]
  221 + ]
  222 + ]
  223 + },
  224 +
  225 + multipolygon2: {
  226 + str: 'MULTIPOLYGON(((40 40,20 45,45 30,40 40)),((20 35,45 20,30 5,10 10,10 30,20 35),(30 20,20 25,20 15,30 20)))',
  227 + cmp: [
  228 + [
  229 + [{
  230 + x: 40,
  231 + y: 40
  232 + }, {
  233 + x: 20,
  234 + y: 45
  235 + }, {
  236 + x: 45,
  237 + y: 30
  238 + }, {
  239 + x: 40,
  240 + y: 40
  241 + }, ]
  242 + ],
  243 + [
  244 + [{
  245 + x: 20,
  246 + y: 35
  247 + }, {
  248 + x: 45,
  249 + y: 20
  250 + }, {
  251 + x: 30,
  252 + y: 5
  253 + }, {
  254 + x: 10,
  255 + y: 10
  256 + }, {
  257 + x: 10,
  258 + y: 30
  259 + }, {
  260 + x: 20,
  261 + y: 35
  262 + }, ],
  263 + [{
  264 + x: 30,
  265 + y: 20
  266 + }, {
  267 + x: 20,
  268 + y: 25
  269 + }, {
  270 + x: 20,
  271 + y: 15
  272 + }, {
  273 + x: 30,
  274 + y: 20
  275 + }]
  276 + ]
  277 + ]
  278 + },
  279 +
  280 + box: {
  281 + str: 'BOX(0 0,20 20)',
  282 + cmp: [{
  283 + x: 0,
  284 + y: 0
  285 + }, {
  286 + x: 20,
  287 + y: 20
  288 + }]
  289 + }
  290 +
  291 + };
  292 +
  293 + describe('Reading WKT Strings: ', function() {
  294 +
  295 + afterEach(function() {
  296 + wkt.delimiter = ' ';
  297 + });
  298 +
  299 + it('should read basic POINT string', function() {
  300 + wkt.read(cases.point.str);
  301 +
  302 + expect(wkt.type).equal('point');
  303 + expect(wkt.isCollection()).equal(false);
  304 + expect(wkt.components).deep.equal(cases.point.cmp);
  305 +
  306 + // Now try it for URLs
  307 + wkt.delimiter = '+';
  308 + wkt.read(cases.point.str.replace(/ /g, '+'));
  309 + expect(wkt.components).deep.equal(cases.point.cmp);
  310 + });
  311 +
  312 + it('should read basic LINESTRING string', function() {
  313 + wkt.read(cases.linestring.str);
  314 +
  315 + expect(wkt.type).equal('linestring');
  316 + expect(wkt.isCollection()).equal(false);
  317 + expect(wkt.components).deep.equal(cases.linestring.cmp);
  318 +
  319 + // Now try it for URLs
  320 + wkt.delimiter = '+';
  321 + wkt.read(cases.linestring.str.replace(/ /g, '+'));
  322 + expect(wkt.components).deep.equal(cases.linestring.cmp);
  323 + });
  324 +
  325 + it('should read basic POLYGON string', function() {
  326 + wkt.read(cases.polygon.str);
  327 +
  328 + expect(wkt.type).equal('polygon');
  329 + expect(wkt.isCollection()).equal(true);
  330 + expect(wkt.components).deep.equal(cases.polygon.cmp);
  331 +
  332 + // Now try it for URLs
  333 + wkt.delimiter = '+';
  334 + wkt.read(cases.polygon.str.replace(/ /g, '+'));
  335 + expect(wkt.components).deep.equal(cases.polygon.cmp);
  336 + });
  337 +
  338 + it('should read basic POLYGON string with one (1) hole', function() {
  339 + wkt.read(cases.polygon2.str);
  340 +
  341 + expect(wkt.type).equal('polygon');
  342 + expect(wkt.isCollection()).equal(true);
  343 + expect(wkt.components).deep.equal(cases.polygon2.cmp);
  344 +
  345 + // Now try it for URLs
  346 + wkt.delimiter = '+';
  347 + wkt.read(cases.polygon2.str.replace(/ /g, '+'));
  348 + expect(wkt.components).deep.equal(cases.polygon2.cmp);
  349 + });
  350 +
  351 + it('should read basic MULTIPOINT string with wrapped vertices', function() {
  352 + wkt.read(cases.multipoint.str);
  353 +
  354 + expect(wkt.type).equal('multipoint');
  355 + expect(wkt.isCollection()).equal(true);
  356 + expect(wkt.components).deep.equal(cases.multipoint.cmp);
  357 +
  358 + // Now try it for URLs
  359 + wkt.delimiter = '+';
  360 + wkt.read(cases.multipoint.str.replace(/ /g, '+'));
  361 + expect(wkt.components).deep.equal(cases.multipoint.cmp);
  362 + });
  363 +
  364 + it('should read basic MULTIPOINT string without wrapped vertices', function() {
  365 + wkt.read(cases.multipoint2.str);
  366 +
  367 + expect(wkt.type).equal('multipoint');
  368 + expect(wkt.isCollection()).equal(true);
  369 + expect(wkt.components).deep.equal(cases.multipoint2.cmp);
  370 +
  371 + // Now try it for URLs
  372 + wkt.delimiter = '+';
  373 + wkt.read(cases.multipoint2.str.replace(/ /g, '+'));
  374 + expect(wkt.components).deep.equal(cases.multipoint2.cmp);
  375 + });
  376 +
  377 + it('should read basic MULTILINESTRING string', function() {
  378 + wkt.read(cases.multilinestring.str);
  379 +
  380 + expect(wkt.type).equal('multilinestring');
  381 + expect(wkt.isCollection()).equal(true);
  382 + expect(wkt.components).deep.equal(cases.multilinestring.cmp);
  383 +
  384 + // Now try it for URLs
  385 + wkt.delimiter = '+';
  386 + wkt.read(cases.multilinestring.str.replace(/ /g, '+'));
  387 + expect(wkt.components).deep.equal(cases.multilinestring.cmp);
  388 + });
  389 +
  390 + it('should read basic MULTIPOLYGON string', function() {
  391 + wkt.read(cases.multipolygon.str);
  392 +
  393 + expect(wkt.type).equal('multipolygon');
  394 + expect(wkt.isCollection()).equal(true);
  395 + expect(wkt.components).deep.equal(cases.multipolygon.cmp);
  396 +
  397 + // Now try it for URLs
  398 + wkt.delimiter = '+';
  399 + wkt.read(cases.multipolygon.str.replace(/ /g, '+'));
  400 + expect(wkt.components).deep.equal(cases.multipolygon.cmp);
  401 + });
  402 +
  403 + it('should read basic MULTIPOLYGON string with two (2) polygons, one with one (1) hole', function() {
  404 + wkt.read(cases.multipolygon2.str);
  405 +
  406 + expect(wkt.type).equal('multipolygon');
  407 + expect(wkt.isCollection()).equal(true);
  408 + expect(wkt.components).deep.equal(cases.multipolygon2.cmp);
  409 +
  410 + // Now try it for URLs
  411 + wkt.delimiter = '+';
  412 + wkt.read(cases.multipolygon2.str.replace(/ /g, '+'));
  413 + expect(wkt.components).deep.equal(cases.multipolygon2.cmp);
  414 + });
  415 +
  416 + it('should read basic PostGIS 2DBOX string', function() {
  417 + wkt.read(cases.box.str);
  418 +
  419 + expect(wkt.type).equal('box');
  420 + expect(wkt.isCollection()).equal(false);
  421 + expect(wkt.components).deep.equal(cases.box.cmp);
  422 +
  423 + // Now try it for URLs
  424 + wkt.delimiter = '+';
  425 + wkt.read(cases.box.str.replace(/ /g, '+'));
  426 + expect(wkt.components).deep.equal(cases.box.cmp);
  427 + });
  428 +
  429 + }); // eo describe()
  430 +
  431 + describe('Writing Well-Formed WKT Strings: ', function() {
  432 +
  433 + afterEach(function() {
  434 + wkt.wrapVertices = false;
  435 + wkt.delimiter = ' ';
  436 + });
  437 +
  438 + it('should write basic POINT string', function() {
  439 + wkt.components = cases.point.cmp;
  440 + wkt.type = 'point';
  441 +
  442 + expect(wkt.write()).equal(cases.point.str);
  443 +
  444 + // Now try it for URLs
  445 + wkt.delimiter = '+';
  446 + expect(wkt.write()).equal(cases.point.str.replace(/ /g, '+'));
  447 + });
  448 +
  449 + it('should write basic LINESTRING string', function() {
  450 + wkt.components = cases.linestring.cmp;
  451 + wkt.type = 'linestring';
  452 +
  453 + expect(wkt.write()).equal(cases.linestring.str);
  454 +
  455 + // Now try it for URLs
  456 + wkt.delimiter = '+';
  457 + expect(wkt.write()).equal(cases.linestring.str.replace(/ /g, '+'));
  458 + });
  459 +
  460 + it('should write basic POLYGON string', function() {
  461 + wkt.components = cases.polygon.cmp;
  462 + wkt.type = 'polygon';
  463 +
  464 + expect(wkt.write()).equal(cases.polygon.str);
  465 +
  466 + // Now try it for URLs
  467 + wkt.delimiter = '+';
  468 + expect(wkt.write()).equal(cases.polygon.str.replace(/ /g, '+'));
  469 + });
  470 +
  471 + it('should write basic POLYGON string with one (1) hole', function() {
  472 + wkt.components = cases.polygon2.cmp;
  473 + wkt.type = 'polygon';
  474 +
  475 + expect(wkt.write()).equal(cases.polygon2.str);
  476 +
  477 + // Now try it for URLs
  478 + wkt.delimiter = '+';
  479 + expect(wkt.write()).equal(cases.polygon2.str.replace(/ /g, '+'));
  480 + });
  481 +
  482 + it('should write basic MULTIPOINT string with wrapped vertices', function() {
  483 + wkt.components = cases.multipoint.cmp;
  484 + wkt.type = 'multipoint';
  485 + wkt.wrapVertices = true;
  486 +
  487 + expect(wkt.write()).equal(cases.multipoint.str);
  488 +
  489 + // Now try it for URLs
  490 + wkt.delimiter = '+';
  491 + expect(wkt.write()).equal(cases.multipoint.str.replace(/ /g, '+'));
  492 + });
  493 +
  494 + it('should write basic MULTIPOINT string without wrapped vertices', function() {
  495 + wkt.components = cases.multipoint2.cmp;
  496 + wkt.type = 'multipoint';
  497 + wkt.wrapVertices = false;
  498 +
  499 + expect(wkt.write()).equal(cases.multipoint2.str);
  500 +
  501 + // Now try it for URLs
  502 + wkt.delimiter = '+';
  503 + expect(wkt.write()).equal(cases.multipoint2.str.replace(/ /g, '+'));
  504 + });
  505 +
  506 + it('should write basic MULTILINESTRING string', function() {
  507 + wkt.components = cases.multilinestring.cmp;
  508 + wkt.type = 'multilinestring';
  509 +
  510 + expect(wkt.write()).equal(cases.multilinestring.str);
  511 +
  512 + // Now try it for URLs
  513 + wkt.delimiter = '+';
  514 + expect(wkt.write()).equal(cases.multilinestring.str.replace(/ /g, '+'));
  515 + });
  516 +
  517 + it('should write basic MULTIPOLYGON string', function() {
  518 + wkt.components = cases.multipolygon.cmp;
  519 + wkt.type = 'multipolygon';
  520 +
  521 + expect(wkt.write()).equal(cases.multipolygon.str);
  522 +
  523 + // Now try it for URLs
  524 + wkt.delimiter = '+';
  525 + expect(wkt.write()).equal(cases.multipolygon.str.replace(/ /g, '+'));
  526 + });
  527 +
  528 + it('should write basic MULTIPOLYGON string with two (2) polygons, one with one (1) hole', function() {
  529 + wkt.components = cases.multipolygon2.cmp;
  530 + wkt.type = 'multipolygon';
  531 +
  532 + expect(wkt.write()).equal(cases.multipolygon2.str);
  533 +
  534 + // Now try it for URLs
  535 + wkt.delimiter = '+';
  536 + expect(wkt.write()).equal(cases.multipolygon2.str.replace(/ /g, '+'));
  537 + });
  538 +
  539 + it('should write basic PostGIS 2DBOX string', function() {
  540 + wkt.components = cases.box.cmp;
  541 + wkt.type = 'box';
  542 +
  543 + expect(wkt.write()).equal(cases.box.str);
  544 +
  545 + // Now try it for URLs
  546 + wkt.delimiter = '+';
  547 + expect(wkt.write()).equal(cases.box.str.replace(/ /g, '+'));
  548 + });
  549 +
  550 + });
  551 +
  552 +}); // eo describe()
  553 +
  554 +describe('Arbitrary WKT Test Cases: ', function() {
  555 + var cases, wkt;
  556 +
  557 + wkt = new Wkt.Wkt();
  558 +
  559 + function randomLat(a, b) {
  560 + var n;
  561 +
  562 + a = a || 0;
  563 + b = b || 90;
  564 + n = Math.random() * (a + (b - a));
  565 + return (Math.random() < 0.5) ? -n : n;
  566 + };
  567 +
  568 + function randomLng(a, b) {
  569 + var n;
  570 +
  571 + a = a || 0;
  572 + b = b || 180;
  573 + n = Math.random() * (a + (b - a));
  574 + return (Math.random() < 0.5) ? -n : n;
  575 + };
  576 +
  577 + function randomCoords(n, a1, b1, a2, b2) {
  578 + var i, c, cs;
  579 +
  580 + i = 0;
  581 + a1 = a1 || 0;
  582 + b1 = b1 || 180;
  583 + a2 = a2 || 0;
  584 + b2 = b2 || 90;
  585 + cs = [];
  586 +
  587 + while (i < n) {
  588 + cs.push({
  589 + x: randomLng(a1, b1),
  590 + y: randomLat(a2, b2)
  591 + });
  592 + i += 1;
  593 + }
  594 +
  595 + return cs;
  596 + };
  597 +
  598 + it('should be able to read WKT strings with bizarre whitespace', function() {
  599 + wkt.read(' LINESTRING ( 30 10, 10 30, 40 40) ');
  600 + expect(wkt.write()).equal('LINESTRING(30 10,10 30,40 40)');
  601 + });
  602 +
  603 + it('should be able to read WKT strings with (somewhat) arbitrary precision', function() {
  604 + wkt.read('MULTIPOINT((9.12345 40),(40 30),(20 19.999999),(30 10.000001))');
  605 + expect(wkt.write()).equal('MULTIPOINT((9.12345 40),(40 30),(20 19.999999),(30 10.000001))');
  606 + });
  607 +
  608 + describe('Working with Random Coordinates: ', function() {
  609 + var c;
  610 +
  611 + it('should read and write arbitrary POINT string', function() {
  612 + c = wkt.components = randomCoords(1);
  613 + wkt.type = 'point';
  614 +
  615 + expect(wkt.read(wkt.write()).components).deep.equal(c);
  616 + });
  617 +
  618 + it('should read and write long, arbitrary LINESTRING string', function() {
  619 + c = wkt.components = randomCoords(100);
  620 + wkt.type = 'linestring';
  621 +
  622 + expect(wkt.read(wkt.write()).components).deep.equal(c);
  623 + });
  624 +
  625 + it('should read and write long, arbitrary POLYGON string', function() {
  626 + c = wkt.components = [randomCoords(100)];
  627 + wkt.type = 'polygon';
  628 +
  629 + expect(wkt.read(wkt.write()).components).deep.equal(c);
  630 + });
  631 +
  632 + });
  633 +});
  634 +
  635 +describe('Edge Cases: ', function() {
  636 + var wkt = new Wkt.Wkt();
  637 +
  638 + afterEach(function() {
  639 + wkt.wrapVertices = false;
  640 + wkt.delimiter = ' ';
  641 + });
  642 +
  643 + it('should read a POINT string with single-digit coordinates', function() {
  644 + var test = {
  645 + str: 'POINT(4 4)',
  646 + cmp: [{
  647 + x: 4,
  648 + y: 4
  649 + }]
  650 + };
  651 +
  652 + wkt.read(test.str);
  653 +
  654 + expect(wkt.type).equal('point');
  655 + expect(wkt.isCollection()).equal(false);
  656 + expect(wkt.components).deep.equal(test.cmp);
  657 +
  658 + // Now try it for URLs
  659 + wkt.delimiter = '+';
  660 + wkt.read(test.str.replace(/ /g, '+'));
  661 + expect(wkt.components).deep.equal(test.cmp);
  662 + });
  663 +
  664 + it('should read a LINESTRING string with single-digit coordinates', function() {
  665 + var test = {
  666 + str: 'LINESTRING(4 4,3 5,6 7)',
  667 + cmp: [{
  668 + x: 4,
  669 + y: 4
  670 + }, {
  671 + x: 3,
  672 + y: 5
  673 + }, {
  674 + x: 6,
  675 + y: 7
  676 + }]
  677 + };
  678 +
  679 + wkt.read(test.str);
  680 +
  681 + expect(wkt.type).equal('linestring');
  682 + expect(wkt.isCollection()).equal(false);
  683 + expect(wkt.components).deep.equal(test.cmp);
  684 +
  685 + // Now try it for URLs
  686 + wkt.delimiter = '+';
  687 + wkt.read(test.str.replace(/ /g, '+'));
  688 + expect(wkt.components).deep.equal(test.cmp);
  689 + });
  690 +
  691 + it('should read a POLYGON string with single-digit coordinates', function() {
  692 + var test = {
  693 + str: 'POLYGON((4 4,3 5,6 7,7 5,4 4))',
  694 + cmp: [
  695 + [{
  696 + x: 4,
  697 + y: 4
  698 + }, {
  699 + x: 3,
  700 + y: 5
  701 + }, {
  702 + x: 6,
  703 + y: 7
  704 + }, {
  705 + x: 7,
  706 + y: 5
  707 + }, {
  708 + x: 4,
  709 + y: 4
  710 + }]
  711 + ]
  712 + };
  713 +
  714 + wkt.read(test.str);
  715 +
  716 + expect(wkt.type).equal('polygon');
  717 + expect(wkt.isCollection()).equal(true);
  718 + expect(wkt.components).deep.equal(test.cmp);
  719 +
  720 + // Now try it for URLs
  721 + wkt.delimiter = '+';
  722 + wkt.read(test.str.replace(/ /g, '+'));
  723 + expect(wkt.components).deep.equal(test.cmp);
  724 + });
  725 +
  726 + it('should read a POLYGON string with excess precision', function() {
  727 + var test = {
  728 + str: 'POLYGON((4.1234 4,3 5,6 7,7 5.5678,4 4))',
  729 + cmp: [
  730 + [{
  731 + x: 4.1234,
  732 + y: 4
  733 + }, {
  734 + x: 3,
  735 + y: 5
  736 + }, {
  737 + x: 6,
  738 + y: 7
  739 + }, {
  740 + x: 7,
  741 + y: 5.5678
  742 + }, {
  743 + x: 4,
  744 + y: 4
  745 + }]
  746 + ]
  747 + };
  748 +
  749 + wkt.read(test.str);
  750 +
  751 + expect(wkt.type).equal('polygon');
  752 + expect(wkt.isCollection()).equal(true);
  753 + expect(wkt.components).deep.equal(test.cmp);
  754 +
  755 + // Now try it for URLs
  756 + wkt.delimiter = '+';
  757 + wkt.read(test.str.replace(/ /g, '+'));
  758 + expect(wkt.components).deep.equal(test.cmp);
  759 + });
  760 +
  761 +}); // eo describe()
  762 +
  763 +describe('Merged WKT Test Cases: ', function() {
  764 + var cases = {
  765 +
  766 + pointA: {
  767 + str: 'POINT(30 10)',
  768 + cmp: [{
  769 + x: 30,
  770 + y: 10
  771 + }]
  772 + },
  773 +
  774 + pointB: {
  775 + str: 'POINT(25 45)',
  776 + cmp: [{
  777 + x: 25,
  778 + y: 45
  779 + }]
  780 + },
  781 +
  782 + linestringA: {
  783 + str: 'LINESTRING(25 15,15 35,35 35)',
  784 + cmp: [{
  785 + x: 25,
  786 + y: 15
  787 + }, {
  788 + x: 15,
  789 + y: 35
  790 + }, {
  791 + x: 35,
  792 + y: 35
  793 + }]
  794 + },
  795 +
  796 + linestringB: {
  797 + str: 'LINESTRING(30 10,10 30,40 40)',
  798 + cmp: [{
  799 + x: 30,
  800 + y: 10
  801 + }, {
  802 + x: 10,
  803 + y: 30
  804 + }, {
  805 + x: 40,
  806 + y: 40
  807 + }]
  808 + },
  809 +
  810 + polygonA: {
  811 + str: 'POLYGON((30 10,10 20,20 40,40 40,30 10))',
  812 + cmp: [
  813 + [{
  814 + x: 30,
  815 + y: 10
  816 + }, {
  817 + x: 10,
  818 + y: 20
  819 + }, {
  820 + x: 20,
  821 + y: 40
  822 + }, {
  823 + x: 40,
  824 + y: 40
  825 + }, {
  826 + x: 30,
  827 + y: 10
  828 + }]
  829 + ]
  830 + },
  831 +
  832 + polygonB: {
  833 + str: 'POLYGON((35 15,15 25,25 45,45 45,35 15))',
  834 + cmp: [
  835 + [{
  836 + x: 35,
  837 + y: 15
  838 + }, {
  839 + x: 15,
  840 + y: 25
  841 + }, {
  842 + x: 25,
  843 + y: 45
  844 + }, {
  845 + x: 45,
  846 + y: 45
  847 + }, {
  848 + x: 35,
  849 + y: 15
  850 + }]
  851 + ]
  852 + },
  853 +
  854 + polygon2A: {
  855 + str: 'POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30,35 35,30 20,20 30))',
  856 + cmp: [
  857 + [{
  858 + x: 35,
  859 + y: 10
  860 + }, {
  861 + x: 10,
  862 + y: 20
  863 + }, {
  864 + x: 15,
  865 + y: 40
  866 + }, {
  867 + x: 45,
  868 + y: 45
  869 + }, {
  870 + x: 35,
  871 + y: 10
  872 + }],
  873 + [{
  874 + x: 20,
  875 + y: 30
  876 + }, {
  877 + x: 35,
  878 + y: 35
  879 + }, {
  880 + x: 30,
  881 + y: 20
  882 + }, {
  883 + x: 20,
  884 + y: 30
  885 + }]
  886 + ]
  887 + },
  888 +
  889 + polygon2B: {
  890 + str: 'POLYGON((135 110,110 120,115 140,145 145,135 110),(120 130,135 135,130 120,120 130))',
  891 + cmp: [
  892 + [{
  893 + x: 135,
  894 + y: 110
  895 + }, {
  896 + x: 110,
  897 + y: 120
  898 + }, {
  899 + x: 115,
  900 + y: 140
  901 + }, {
  902 + x: 145,
  903 + y: 145
  904 + }, {
  905 + x: 135,
  906 + y: 110
  907 + }],
  908 + [{
  909 + x: 120,
  910 + y: 130
  911 + }, {
  912 + x: 135,
  913 + y: 135
  914 + }, {
  915 + x: 130,
  916 + y: 120
  917 + }, {
  918 + x: 120,
  919 + y: 130
  920 + }]
  921 + ]
  922 + },
  923 +
  924 + multipointA: {
  925 + str: 'MULTIPOINT((10 40),(40 30),(20 20),(30 10))',
  926 + cmp: [
  927 + [{
  928 + x: 10,
  929 + y: 40
  930 + }],
  931 + [{
  932 + x: 40,
  933 + y: 30
  934 + }],
  935 + [{
  936 + x: 20,
  937 + y: 20
  938 + }],
  939 + [{
  940 + x: 30,
  941 + y: 10
  942 + }]
  943 + ]
  944 + },
  945 +
  946 + multipointB: {
  947 + str: 'MULTIPOINT((15 45),(45 35),(25 25),(35 15))',
  948 + cmp: [
  949 + [{
  950 + x: 15,
  951 + y: 45
  952 + }],
  953 + [{
  954 + x: 45,
  955 + y: 35
  956 + }],
  957 + [{
  958 + x: 25,
  959 + y: 25
  960 + }],
  961 + [{
  962 + x: 35,
  963 + y: 15
  964 + }]
  965 + ]
  966 + },
  967 +
  968 + multilinestringA: {
  969 + str: 'MULTILINESTRING((10 10,20 20,10 40),(40 40,30 30,40 20,30 10))',
  970 + cmp: [
  971 + [{
  972 + x: 10,
  973 + y: 10
  974 + }, {
  975 + x: 20,
  976 + y: 20
  977 + }, {
  978 + x: 10,
  979 + y: 40
  980 + }],
  981 + [{
  982 + x: 40,
  983 + y: 40
  984 + }, {
  985 + x: 30,
  986 + y: 30
  987 + }, {
  988 + x: 40,
  989 + y: 20
  990 + }, {
  991 + x: 30,
  992 + y: 10
  993 + }]
  994 + ]
  995 + },
  996 +
  997 + multilinestringB: {
  998 + str: 'MULTILINESTRING((15 15,25 25,15 45),(45 45,35 35,45 25,35 15))',
  999 + cmp: [
  1000 + [{
  1001 + x: 15,
  1002 + y: 15
  1003 + }, {
  1004 + x: 25,
  1005 + y: 25
  1006 + }, {
  1007 + x: 15,
  1008 + y: 45
  1009 + }],
  1010 + [{
  1011 + x: 45,
  1012 + y: 45
  1013 + }, {
  1014 + x: 35,
  1015 + y: 35
  1016 + }, {
  1017 + x: 45,
  1018 + y: 25
  1019 + }, {
  1020 + x: 35,
  1021 + y: 15
  1022 + }]
  1023 + ]
  1024 + },
  1025 +
  1026 + multipolygonA: {
  1027 + str: 'MULTIPOLYGON(((30 20,10 40,45 40,30 20)),((15 5,40 10,10 20,5 10,15 5)))',
  1028 + cmp: [
  1029 + [
  1030 + [{
  1031 + x: 30,
  1032 + y: 20
  1033 + }, {
  1034 + x: 10,
  1035 + y: 40
  1036 + }, {
  1037 + x: 45,
  1038 + y: 40
  1039 + }, {
  1040 + x: 30,
  1041 + y: 20
  1042 + }, ]
  1043 + ],
  1044 + [
  1045 + [{
  1046 + x: 15,
  1047 + y: 5
  1048 + }, {
  1049 + x: 40,
  1050 + y: 10
  1051 + }, {
  1052 + x: 10,
  1053 + y: 20
  1054 + }, {
  1055 + x: 5,
  1056 + y: 10
  1057 + }, {
  1058 + x: 15,
  1059 + y: 5
  1060 + }]
  1061 + ]
  1062 + ]
  1063 + },
  1064 +
  1065 + multipolygonB: {
  1066 + str: 'MULTIPOLYGON(((130 120,110 140,145 140,130 120)),((115 15,140 110,110 120,15 110,115 15)))',
  1067 + cmp: [
  1068 + [
  1069 + [{
  1070 + x: 130,
  1071 + y: 120
  1072 + }, {
  1073 + x: 110,
  1074 + y: 140
  1075 + }, {
  1076 + x: 145,
  1077 + y: 140
  1078 + }, {
  1079 + x: 130,
  1080 + y: 120
  1081 + }, ]
  1082 + ],
  1083 + [
  1084 + [{
  1085 + x: 115,
  1086 + y: 15
  1087 + }, {
  1088 + x: 140,
  1089 + y: 110
  1090 + }, {
  1091 + x: 110,
  1092 + y: 120
  1093 + }, {
  1094 + x: 15,
  1095 + y: 110
  1096 + }, {
  1097 + x: 115,
  1098 + y: 15
  1099 + }]
  1100 + ]
  1101 + ]
  1102 + }
  1103 +
  1104 + };
  1105 +
  1106 + it('should merge POINT strings together', function() {
  1107 + var a = new Wkt.Wkt(cases.pointA.str),
  1108 + b = new Wkt.Wkt(cases.pointB.str);
  1109 +
  1110 + a.merge(b);
  1111 + expect(a.type).equal('multipoint');
  1112 + expect(b.type).equal('point');
  1113 + expect(a.isCollection()).equal(true);
  1114 + expect(b.isCollection()).equal(false);
  1115 + expect(a.write()).equal('MULTIPOINT((30 10),(25 45))');
  1116 + expect(a.components).deep.equal([
  1117 + [{
  1118 + x: 30,
  1119 + y: 10
  1120 + }, {
  1121 + x: 25,
  1122 + y: 45
  1123 + }]
  1124 + ]);
  1125 +
  1126 + });
  1127 +
  1128 + it('should merge LINESTRING strings together', function() {
  1129 + var a = new Wkt.Wkt(cases.linestringA.str),
  1130 + b = new Wkt.Wkt(cases.linestringB.str);
  1131 +
  1132 + a.merge(b);
  1133 + expect(a.type).equal('multilinestring');
  1134 + expect(b.type).equal('linestring');
  1135 + expect(a.isCollection()).equal(true);
  1136 + expect(b.isCollection()).equal(false);
  1137 + expect(a.write()).equal('MULTILINESTRING((25 15,15 35,35 35),(30 10,10 30,40 40))');
  1138 + expect(a.components).deep.equal([
  1139 + [{
  1140 + x: 25,
  1141 + y: 15
  1142 + }, {
  1143 + x: 15,
  1144 + y: 35
  1145 + }, {
  1146 + x: 35,
  1147 + y: 35
  1148 + }],
  1149 + [{
  1150 + x: 30,
  1151 + y: 10
  1152 + }, {
  1153 + x: 10,
  1154 + y: 30
  1155 + }, {
  1156 + x: 40,
  1157 + y: 40
  1158 + }]
  1159 + ]);
  1160 +
  1161 + });
  1162 +
  1163 + it('should merge POLYGON strings together', function() {
  1164 + var a = new Wkt.Wkt(cases.polygonA.str),
  1165 + b = new Wkt.Wkt(cases.polygonB.str);
  1166 +
  1167 + a.merge(b);
  1168 + expect(a.type).equal('multipolygon');
  1169 + expect(b.type).equal('polygon');
  1170 + expect(a.isCollection()).equal(true);
  1171 + expect(b.isCollection()).equal(true);
  1172 + expect(a.write()).equal('MULTIPOLYGON(((30 10,10 20,20 40,40 40,30 10)),((35 15,15 25,25 45,45 45,35 15)))');
  1173 + expect(a.components).deep.equal([
  1174 + [
  1175 + [{
  1176 + x: 30,
  1177 + y: 10
  1178 + }, {
  1179 + x: 10,
  1180 + y: 20
  1181 + }, {
  1182 + x: 20,
  1183 + y: 40
  1184 + }, {
  1185 + x: 40,
  1186 + y: 40
  1187 + }, {
  1188 + x: 30,
  1189 + y: 10
  1190 + }]
  1191 + ],
  1192 + [
  1193 + [{
  1194 + x: 35,
  1195 + y: 15
  1196 + }, {
  1197 + x: 15,
  1198 + y: 25
  1199 + }, {
  1200 + x: 25,
  1201 + y: 45
  1202 + }, {
  1203 + x: 45,
  1204 + y: 45
  1205 + }, {
  1206 + x: 35,
  1207 + y: 15
  1208 + }]
  1209 + ]
  1210 + ]);
  1211 +
  1212 + });
  1213 +
  1214 + it('should merge POLYGON strings together even if they have holes', function() {
  1215 + var a = new Wkt.Wkt(cases.polygon2A.str),
  1216 + b = new Wkt.Wkt(cases.polygon2B.str);
  1217 +
  1218 + a.merge(b);
  1219 + expect(a.type).equal('multipolygon');
  1220 + expect(b.type).equal('polygon');
  1221 + expect(a.isCollection()).equal(true);
  1222 + expect(b.isCollection()).equal(true);
  1223 + expect(a.write()).equal('MULTIPOLYGON(((35 10,10 20,15 40,45 45,35 10),(20 30,35 35,30 20,20 30)),((135 110,110 120,115 140,145 145,135 110),(120 130,135 135,130 120,120 130)))');
  1224 + expect(a.components).deep.equal([
  1225 + [
  1226 + [{
  1227 + x: 35,
  1228 + y: 10
  1229 + }, {
  1230 + x: 10,
  1231 + y: 20
  1232 + }, {
  1233 + x: 15,
  1234 + y: 40
  1235 + }, {
  1236 + x: 45,
  1237 + y: 45
  1238 + }, {
  1239 + x: 35,
  1240 + y: 10
  1241 + }],
  1242 + [{
  1243 + x: 20,
  1244 + y: 30
  1245 + }, {
  1246 + x: 35,
  1247 + y: 35
  1248 + }, {
  1249 + x: 30,
  1250 + y: 20
  1251 + }, {
  1252 + x: 20,
  1253 + y: 30
  1254 + }]
  1255 + ],
  1256 + [
  1257 + [{
  1258 + x: 135,
  1259 + y: 110
  1260 + }, {
  1261 + x: 110,
  1262 + y: 120
  1263 + }, {
  1264 + x: 115,
  1265 + y: 140
  1266 + }, {
  1267 + x: 145,
  1268 + y: 145
  1269 + }, {
  1270 + x: 135,
  1271 + y: 110
  1272 + }],
  1273 + [{
  1274 + x: 120,
  1275 + y: 130
  1276 + }, {
  1277 + x: 135,
  1278 + y: 135
  1279 + }, {
  1280 + x: 130,
  1281 + y: 120
  1282 + }, {
  1283 + x: 120,
  1284 + y: 130
  1285 + }]
  1286 + ]
  1287 + ]);
  1288 +
  1289 + });
  1290 +
  1291 + it('should merge MULTIPOINT strings together', function() {
  1292 + var a = new Wkt.Wkt(cases.multipointA.str),
  1293 + b = new Wkt.Wkt(cases.multipointB.str);
  1294 +
  1295 + a.merge(b);
  1296 + expect(a.type).equal('multipoint');
  1297 + expect(b.type).equal('multipoint');
  1298 + expect(a.isCollection()).equal(true);
  1299 + expect(b.isCollection()).equal(true);
  1300 + expect(a.write()).equal('MULTIPOINT((10 40),(40 30),(20 20),(30 10),(15 45),(45 35),(25 25),(35 15))');
  1301 + expect(a.components).deep.equal([
  1302 + [{
  1303 + x: 10,
  1304 + y: 40
  1305 + }],
  1306 + [{
  1307 + x: 40,
  1308 + y: 30
  1309 + }],
  1310 + [{
  1311 + x: 20,
  1312 + y: 20
  1313 + }],
  1314 + [{
  1315 + x: 30,
  1316 + y: 10
  1317 + }],
  1318 + [{
  1319 + x: 15,
  1320 + y: 45
  1321 + }],
  1322 + [{
  1323 + x: 45,
  1324 + y: 35
  1325 + }],
  1326 + [{
  1327 + x: 25,
  1328 + y: 25
  1329 + }],
  1330 + [{
  1331 + x: 35,
  1332 + y: 15
  1333 + }]
  1334 + ]);
  1335 +
  1336 + });
  1337 +
  1338 + it('should merge MULTILINESTRING strings together', function() {
  1339 + var a = new Wkt.Wkt(cases.multilinestringA.str),
  1340 + b = new Wkt.Wkt(cases.multilinestringB.str);
  1341 +
  1342 + a.merge(b);
  1343 + expect(a.type).equal('multilinestring');
  1344 + expect(b.type).equal('multilinestring');
  1345 + expect(a.isCollection()).equal(true);
  1346 + expect(b.isCollection()).equal(true);
  1347 + expect(a.write()).equal('MULTILINESTRING((10 10,20 20,10 40),(40 40,30 30,40 20,30 10),(15 15,25 25,15 45),(45 45,35 35,45 25,35 15))');
  1348 + expect(a.components).deep.equal([
  1349 + [{
  1350 + x: 10,
  1351 + y: 10
  1352 + }, {
  1353 + x: 20,
  1354 + y: 20
  1355 + }, {
  1356 + x: 10,
  1357 + y: 40
  1358 + }],
  1359 + [{
  1360 + x: 40,
  1361 + y: 40
  1362 + }, {
  1363 + x: 30,
  1364 + y: 30
  1365 + }, {
  1366 + x: 40,
  1367 + y: 20
  1368 + }, {
  1369 + x: 30,
  1370 + y: 10
  1371 + }],
  1372 + [{
  1373 + x: 15,
  1374 + y: 15
  1375 + }, {
  1376 + x: 25,
  1377 + y: 25
  1378 + }, {
  1379 + x: 15,
  1380 + y: 45
  1381 + }],
  1382 + [{
  1383 + x: 45,
  1384 + y: 45
  1385 + }, {
  1386 + x: 35,
  1387 + y: 35
  1388 + }, {
  1389 + x: 45,
  1390 + y: 25
  1391 + }, {
  1392 + x: 35,
  1393 + y: 15
  1394 + }]
  1395 + ]);
  1396 +
  1397 + });
  1398 +
  1399 + it('should merge MULTIPOLYGON strings together', function() {
  1400 + var a = new Wkt.Wkt(cases.multipolygonA.str),
  1401 + b = new Wkt.Wkt(cases.multipolygonB.str);
  1402 +
  1403 + a.merge(b);
  1404 + expect(a.type).equal('multipolygon');
  1405 + expect(b.type).equal('multipolygon');
  1406 + expect(a.isCollection()).equal(true);
  1407 + expect(b.isCollection()).equal(true);
  1408 + expect(a.write()).equal('MULTIPOLYGON(((30 20,10 40,45 40,30 20)),((15 5,40 10,10 20,5 10,15 5)),((130 120,110 140,145 140,130 120)),((115 15,140 110,110 120,15 110,115 15)))');
  1409 + expect(a.components).deep.equal([
  1410 + [
  1411 + [{
  1412 + x: 30,
  1413 + y: 20
  1414 + }, {
  1415 + x: 10,
  1416 + y: 40
  1417 + }, {
  1418 + x: 45,
  1419 + y: 40
  1420 + }, {
  1421 + x: 30,
  1422 + y: 20
  1423 + }, ]
  1424 + ],
  1425 + [
  1426 + [{
  1427 + x: 15,
  1428 + y: 5
  1429 + }, {
  1430 + x: 40,
  1431 + y: 10
  1432 + }, {
  1433 + x: 10,
  1434 + y: 20
  1435 + }, {
  1436 + x: 5,
  1437 + y: 10
  1438 + }, {
  1439 + x: 15,
  1440 + y: 5
  1441 + }]
  1442 + ],
  1443 + [
  1444 + [{
  1445 + x: 130,
  1446 + y: 120
  1447 + }, {
  1448 + x: 110,
  1449 + y: 140
  1450 + }, {
  1451 + x: 145,
  1452 + y: 140
  1453 + }, {
  1454 + x: 130,
  1455 + y: 120
  1456 + }, ]
  1457 + ],
  1458 + [
  1459 + [{
  1460 + x: 115,
  1461 + y: 15
  1462 + }, {
  1463 + x: 140,
  1464 + y: 110
  1465 + }, {
  1466 + x: 110,
  1467 + y: 120
  1468 + }, {
  1469 + x: 15,
  1470 + y: 110
  1471 + }, {
  1472 + x: 115,
  1473 + y: 15
  1474 + }]
  1475 + ]
  1476 + ]);
  1477 +
  1478 + });
  1479 +
  1480 + it('should merge POINT strings into MULTIPOINT strings', function() {
  1481 + var a = new Wkt.Wkt(cases.multipointA.str),
  1482 + b = new Wkt.Wkt(cases.pointB.str);
  1483 +
  1484 + a.merge(b);
  1485 + expect(a.type).equal('multipoint');
  1486 + expect(b.type).equal('point');
  1487 + expect(a.isCollection()).equal(true);
  1488 + expect(b.isCollection()).equal(false);
  1489 + expect(a.write()).equal('MULTIPOINT((10 40),(40 30),(20 20),(30 10),(25 45))');
  1490 + expect(a.components).deep.equal([
  1491 + [{
  1492 + x: 10,
  1493 + y: 40
  1494 + }],
  1495 + [{
  1496 + x: 40,
  1497 + y: 30
  1498 + }],
  1499 + [{
  1500 + x: 20,
  1501 + y: 20
  1502 + }],
  1503 + [{
  1504 + x: 30,
  1505 + y: 10
  1506 + }],
  1507 + [{
  1508 + x: 25,
  1509 + y: 45
  1510 + }]
  1511 + ]);
  1512 +
  1513 + });
  1514 +
  1515 + it('should merge LINESTRING strings into MULTILINESTRING strings', function() {
  1516 + var a = new Wkt.Wkt(cases.multilinestringA.str),
  1517 + b = new Wkt.Wkt(cases.linestringB.str);
  1518 +
  1519 + a.merge(b);
  1520 + expect(a.type).equal('multilinestring');
  1521 + expect(b.type).equal('linestring');
  1522 + expect(a.isCollection()).equal(true);
  1523 + expect(b.isCollection()).equal(false);
  1524 + expect(a.write()).equal('MULTILINESTRING((10 10,20 20,10 40),(40 40,30 30,40 20,30 10),(30 10,10 30,40 40))');
  1525 + expect(a.components).deep.equal([
  1526 + [{
  1527 + x: 10,
  1528 + y: 10
  1529 + }, {
  1530 + x: 20,
  1531 + y: 20
  1532 + }, {
  1533 + x: 10,
  1534 + y: 40
  1535 + }],
  1536 + [{
  1537 + x: 40,
  1538 + y: 40
  1539 + }, {
  1540 + x: 30,
  1541 + y: 30
  1542 + }, {
  1543 + x: 40,
  1544 + y: 20
  1545 + }, {
  1546 + x: 30,
  1547 + y: 10
  1548 + }],
  1549 + [{
  1550 + x: 30,
  1551 + y: 10
  1552 + }, {
  1553 + x: 10,
  1554 + y: 30
  1555 + }, {
  1556 + x: 40,
  1557 + y: 40
  1558 + }]
  1559 + ]);
  1560 +
  1561 + });
  1562 +
  1563 + it('should merge POLYGON strings into MULTIPOLYGON strings', function() {
  1564 + var a = new Wkt.Wkt(cases.multipolygonA.str),
  1565 + b = new Wkt.Wkt(cases.polygonB.str);
  1566 +
  1567 + a.merge(b);
  1568 + expect(a.type).equal('multipolygon');
  1569 + expect(b.type).equal('polygon');
  1570 + expect(a.isCollection()).equal(true);
  1571 + expect(b.isCollection()).equal(true);
  1572 + expect(a.write()).equal('MULTIPOLYGON(((30 20,10 40,45 40,30 20)),((15 5,40 10,10 20,5 10,15 5)),((35 15,15 25,25 45,45 45,35 15)))');
  1573 + expect(a.components).deep.equal([
  1574 + [
  1575 + [{
  1576 + x: 30,
  1577 + y: 20
  1578 + }, {
  1579 + x: 10,
  1580 + y: 40
  1581 + }, {
  1582 + x: 45,
  1583 + y: 40
  1584 + }, {
  1585 + x: 30,
  1586 + y: 20
  1587 + }, ]
  1588 + ],
  1589 + [
  1590 + [{
  1591 + x: 15,
  1592 + y: 5
  1593 + }, {
  1594 + x: 40,
  1595 + y: 10
  1596 + }, {
  1597 + x: 10,
  1598 + y: 20
  1599 + }, {
  1600 + x: 5,
  1601 + y: 10
  1602 + }, {
  1603 + x: 15,
  1604 + y: 5
  1605 + }]
  1606 + ],
  1607 + [
  1608 + [{
  1609 + x: 35,
  1610 + y: 15
  1611 + }, {
  1612 + x: 15,
  1613 + y: 25
  1614 + }, {
  1615 + x: 25,
  1616 + y: 45
  1617 + }, {
  1618 + x: 45,
  1619 + y: 45
  1620 + }, {
  1621 + x: 35,
  1622 + y: 15
  1623 + }]
  1624 + ]
  1625 + ]);
  1626 +
  1627 + });
  1628 +
  1629 +});
  1630 +
  1631 +describe('GeoJSON Cases:', function() {
  1632 + var cases = { // See: http://en.wikipedia.org/wiki/GeoJSON#Geometries
  1633 +
  1634 + point: {
  1635 + str: 'POINT(30 10)',
  1636 + json: {
  1637 + 'coordinates': [30, 10],
  1638 + 'type': 'Point'
  1639 + },
  1640 + jsonStr: '{"coordinates": [30, 10], "type": "Point"}'
  1641 + },
  1642 +
  1643 + linestring: {
  1644 + str: 'LINESTRING(30 10,10 30,40 40)',
  1645 + json: {
  1646 + 'coordinates': [
  1647 + [30, 10],
  1648 + [10, 30],
  1649 + [40, 40]
  1650 + ],
  1651 + 'type': 'LineString'
  1652 + },
  1653 + jsonStr: '{"coordinates": [[30, 10], [10, 30], [40, 40]], "type": "LineString"}'
  1654 + },
  1655 +
  1656 + polygon: {
  1657 + str: 'POLYGON((30 10,10 20,20 40,40 40,30 10))',
  1658 + json: {
  1659 + 'coordinates': [
  1660 + [
  1661 + [30, 10],
  1662 + [10, 20],
  1663 + [20, 40],
  1664 + [40, 40],
  1665 + [30, 10]
  1666 + ]
  1667 + ],
  1668 + 'type': 'Polygon'
  1669 + },
  1670 + jsonStr: '{"coordinates": [[[30, 10], [10, 20], [20, 40], [40, 40], [30, 10]]], "type": "Polygon"}'
  1671 + },
  1672 +
  1673 + polygon2: {
  1674 + str: 'POLYGON((35 10,45 45,15 40,10 20,35 10),(20 30,35 35,30 20,20 30))',
  1675 + json: {
  1676 + 'coordinates': [
  1677 + [
  1678 + [35, 10],
  1679 + [45, 45],
  1680 + [15, 40],
  1681 + [10, 20],
  1682 + [35, 10]
  1683 + ],
  1684 + [
  1685 + [20, 30],
  1686 + [35, 35],
  1687 + [30, 20],
  1688 + [20, 30]
  1689 + ]
  1690 + ],
  1691 + 'type': 'Polygon'
  1692 + },
  1693 + jsonStr: '{"coordinates": [[[35, 10], [45, 45], [15, 40], [10, 20], [35, 10]], [[20, 30], [35, 35], [30, 20], [20, 30]]], "type": "Polygon"}'
  1694 + },
  1695 +
  1696 + multipolygon: {
  1697 + str: 'MULTIPOLYGON(((30 20,10 40,45 40,30 20)),((15 5,40 10,10 20,5 10,15 5)))',
  1698 + json: {
  1699 + 'coordinates': [
  1700 + [
  1701 + [
  1702 + [30, 20],
  1703 + [10, 40],
  1704 + [45, 40],
  1705 + [30, 20]
  1706 + ]
  1707 + ],
  1708 + [
  1709 + [
  1710 + [15, 5],
  1711 + [40, 10],
  1712 + [10, 20],
  1713 + [5, 10],
  1714 + [15, 5]
  1715 + ]
  1716 + ]
  1717 + ],
  1718 + 'type': 'MultiPolygon'
  1719 + },
  1720 + jsonStr: '{"coordinates": [[[[30, 20], [10, 40], [45, 40], [30, 20]]], [[[15, 5], [40, 10], [10, 20], [5, 10], [15, 5]]]], "type": "MultiPolygon"}'
  1721 + },
  1722 +
  1723 + multipolygon2: {
  1724 + str: 'MULTIPOLYGON(((40 40,20 45,45 30,40 40)),((20 35,10 30,10 10,30 5,45 20,20 35),(30 20,20 15,20 25,30 20)))',
  1725 + json: {
  1726 + 'coordinates': [
  1727 + [
  1728 + [
  1729 + [40, 40],
  1730 + [20, 45],
  1731 + [45, 30],
  1732 + [40, 40]
  1733 + ]
  1734 + ],
  1735 + [
  1736 + [
  1737 + [20, 35],
  1738 + [10, 30],
  1739 + [10, 10],
  1740 + [30, 5],
  1741 + [45, 20],
  1742 + [20, 35]
  1743 + ],
  1744 + [
  1745 + [30, 20],
  1746 + [20, 15],
  1747 + [20, 25],
  1748 + [30, 20]
  1749 + ]
  1750 + ]
  1751 + ],
  1752 + 'type': 'MultiPolygon'
  1753 + },
  1754 + jsonStr: '{"coordinates": [[[[40, 40], [20, 45], [45, 30], [40, 40]]], [[[20, 35], [10, 30], [10, 10], [30, 5], [45, 20], [20, 35]], [[30, 20], [20, 15], [20, 25], [30, 20]]]], "type": "MultiPolygon"}'
  1755 + },
  1756 +
  1757 + multipoint: {
  1758 + str: 'MULTIPOINT((10 40),(40 30),(20 20),(30 10))',
  1759 + json: {
  1760 + 'coordinates': [
  1761 + [10, 40],
  1762 + [40, 30],
  1763 + [20, 20],
  1764 + [30, 10]
  1765 + ],
  1766 + 'type': 'MultiPoint'
  1767 + },
  1768 + jsonStr: '{"coordinates": [[10, 40], [40, 30], [20, 20], [30, 10]], "type": "MultiPoint"}'
  1769 + },
  1770 +
  1771 + multilinestring: {
  1772 + str: 'MULTILINESTRING((10 10,20 20,10 40),(40 40,30 30,40 20,30 10))',
  1773 + json: {
  1774 + 'coordinates': [
  1775 + [
  1776 + [10, 10],
  1777 + [20, 20],
  1778 + [10, 40]
  1779 + ],
  1780 + [
  1781 + [40, 40],
  1782 + [30, 30],
  1783 + [40, 20],
  1784 + [30, 10]
  1785 + ]
  1786 + ],
  1787 + 'type': 'MultiLineString'
  1788 + },
  1789 + jsonStr: '{"coordinates": [[[10, 10], [20, 20], [10, 40]], [[40, 40], [30, 30], [40, 20], [30, 10]]], "type": "MultiLineString"}'
  1790 + },
  1791 +
  1792 + box: {
  1793 + str: 'BOX(0 0,20 20)',
  1794 + json: {
  1795 + 'coordinates': [
  1796 + [
  1797 + [0, 0],
  1798 + [0, 20],
  1799 + [20, 20],
  1800 + [20, 0],
  1801 + [0, 0]
  1802 + ]
  1803 + ],
  1804 + 'type': 'Polygon',
  1805 + 'bbox': [0, 0, 20, 20]
  1806 + }
  1807 + }
  1808 +
  1809 + };
  1810 +
  1811 + describe('GeoJSON Construction:', function() {
  1812 +
  1813 + it('should create valid JSON for WKT Point type', function() {
  1814 + var a = new Wkt.Wkt(cases.point.str);
  1815 + expect(a.toJson()).deep.equal(cases.point.json);
  1816 + });
  1817 +
  1818 + it('should create valid JSON for WKT LineString type', function() {
  1819 + var a = new Wkt.Wkt(cases.linestring.str);
  1820 + expect(a.toJson()).deep.equal(cases.linestring.json);
  1821 + });
  1822 +
  1823 + it('should create valid JSON for WKT Polygon type', function() {
  1824 + var a = new Wkt.Wkt(cases.polygon.str);
  1825 + expect(a.toJson()).deep.equal(cases.polygon.json);
  1826 + });
  1827 +
  1828 + it('should create valid JSON for WKT Polygon type with a hole', function() {
  1829 + var a = new Wkt.Wkt(cases.polygon2.str);
  1830 + expect(a.toJson()).deep.equal(cases.polygon2.json);
  1831 + });
  1832 +
  1833 + it('should create valid JSON for WKT MultiPolygon type', function() {
  1834 + var a = new Wkt.Wkt(cases.multipolygon.str);
  1835 + expect(a.toJson()).deep.equal(cases.multipolygon.json);
  1836 + });
  1837 +
  1838 + it('should create valid JSON for WKT MultiPolygon type with a hole', function() {
  1839 + var a = new Wkt.Wkt(cases.multipolygon2.str);
  1840 + expect(a.toJson()).deep.equal(cases.multipolygon2.json);
  1841 + });
  1842 +
  1843 + it('should create valid JSON for WKT MultiPoint type', function() {
  1844 + var a = new Wkt.Wkt(cases.multipoint.str);
  1845 + expect(a.toJson()).deep.equal(cases.multipoint.json);
  1846 + });
  1847 +
  1848 + it('should create valid JSON for WKT MultiLineString type', function() {
  1849 + var a = new Wkt.Wkt(cases.multilinestring.str);
  1850 + expect(a.toJson()).deep.equal(cases.multilinestring.json);
  1851 + });
  1852 +
  1853 + it('should create valid JSON for WKT Box type', function() {
  1854 + var a = new Wkt.Wkt(cases.box.str);
  1855 + expect(a.toJson()).deep.equal(cases.box.json);
  1856 + });
  1857 +
  1858 + });
  1859 +
  1860 + describe('GeoJSON Deconstruction (from Objects):', function() {
  1861 +
  1862 + it('should write the WKT string corresponding to a GeoJSON Point', function() {
  1863 + var a = new Wkt.Wkt(cases.point.json);
  1864 + expect(a.write()).deep.equal(cases.point.str);
  1865 + });
  1866 +
  1867 + it('should write the WKT string corresponding to a GeoJSON LineString', function() {
  1868 + var a = new Wkt.Wkt(cases.linestring.json);
  1869 + expect(a.write()).deep.equal(cases.linestring.str);
  1870 + });
  1871 +
  1872 + it('should write the WKT string corresponding to a GeoJSON Polygon', function() {
  1873 + var a = new Wkt.Wkt(cases.polygon.json);
  1874 + expect(a.write()).deep.equal(cases.polygon.str);
  1875 + });
  1876 +
  1877 + it('should write the WKT string corresponding to a GeoJSON Polygon with a hole', function() {
  1878 + var a = new Wkt.Wkt(cases.polygon2.json);
  1879 + expect(a.write()).deep.equal(cases.polygon2.str);
  1880 + });
  1881 +
  1882 + it('should write the WKT string corresponding to a GeoJSON MultiPolygon', function() {
  1883 + var a = new Wkt.Wkt(cases.multipolygon.json);
  1884 + expect(a.write()).deep.equal(cases.multipolygon.str);
  1885 + });
  1886 +
  1887 + it('should write the WKT string corresponding to a GeoJSON MultiPolygon with a hole', function() {
  1888 + var a = new Wkt.Wkt(cases.multipolygon2.json);
  1889 + expect(a.write()).deep.equal(cases.multipolygon2.str);
  1890 + });
  1891 +
  1892 + it('should write the WKT string corresponding to a GeoJSON MultiPoint', function() {
  1893 + var a = new Wkt.Wkt(cases.multipoint.json);
  1894 + expect(a.write()).deep.equal(cases.multipoint.str);
  1895 + });
  1896 +
  1897 + it('should write the WKT string corresponding to a GeoJSON MultiLineString', function() {
  1898 + var a = new Wkt.Wkt(cases.multilinestring.json);
  1899 + expect(a.write()).deep.equal(cases.multilinestring.str);
  1900 + });
  1901 +
  1902 + });
  1903 +
  1904 + describe('GeoJSON Deconstruction (from Strings):', function() {
  1905 + it('should provide support for JSON.parse() in the environment...', function() {
  1906 + expect(typeof JSON).deep.equal('object');
  1907 + expect(typeof JSON.parse).deep.equal('function');
  1908 + });
  1909 +
  1910 + it('should parse a GeoJSON Point string', function() {
  1911 + var a = new Wkt.Wkt(cases.point.jsonStr);
  1912 + expect(a.write()).deep.equal(cases.point.str);
  1913 + });
  1914 +
  1915 + it('should parse a GeoJSON LineString string', function() {
  1916 + var a = new Wkt.Wkt(cases.linestring.jsonStr);
  1917 + expect(a.write()).deep.equal(cases.linestring.str);
  1918 + });
  1919 +
  1920 + it('should parse a GeoJSON Polygon string', function() {
  1921 + var a = new Wkt.Wkt(cases.polygon.jsonStr);
  1922 + expect(a.write()).deep.equal(cases.polygon.str);
  1923 + });
  1924 +
  1925 + it('should parse a GeoJSON Polygon string with a hole', function() {
  1926 + var a = new Wkt.Wkt(cases.polygon2.jsonStr);
  1927 + expect(a.write()).deep.equal(cases.polygon2.str);
  1928 + });
  1929 +
  1930 + it('should parse a GeoJSON MultiPolygon string', function() {
  1931 + var a = new Wkt.Wkt(cases.multipolygon.jsonStr);
  1932 + expect(a.write()).deep.equal(cases.multipolygon.str);
  1933 + });
  1934 +
  1935 + it('should parse a GeoJSON MultiPolygon string with a hole', function() {
  1936 + var a = new Wkt.Wkt(cases.multipolygon2.jsonStr);
  1937 + expect(a.write()).deep.equal(cases.multipolygon2.str);
  1938 + });
  1939 +
  1940 + it('should parse a GeoJSON MultiPoint string', function() {
  1941 + var a = new Wkt.Wkt(cases.multipoint.jsonStr);
  1942 + expect(a.write()).deep.equal(cases.multipoint.str);
  1943 + });
  1944 +
  1945 + it('should parse a GeoJSON MultiLineString string', function() {
  1946 + var a = new Wkt.Wkt(cases.multilinestring.jsonStr);
  1947 + expect(a.write()).deep.equal(cases.multilinestring.str);
  1948 + });
  1949 +
  1950 + });
  1951 +
  1952 +});
... ...
pacotes/wicket/wicket-arcgis.js 0 → 100644
... ... @@ -0,0 +1,392 @@
  1 +/** @license
  2 + *
  3 + * Copyright (C) 2012 K. Arthur Endsley (kaendsle@mtu.edu)
  4 + * Michigan Tech Research Institute (MTRI)
  5 + * 3600 Green Court, Suite 100, Ann Arbor, MI, 48105
  6 + *
  7 + * This program is free software: you can redistribute it and/or modify
  8 + * it under the terms of the GNU General Public License as published by
  9 + * the Free Software Foundation, either version 3 of the License, or
  10 + * (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 + *
  20 + */
  21 +
  22 +if (!Array.prototype.map) {
  23 + Array.prototype.map = function (fun /* thisArg? */) {
  24 + 'use strict';
  25 + var t, len, res, thisArg;
  26 +
  27 + if (this === void 0 || this === null) {
  28 + throw new TypeError();
  29 + }
  30 +
  31 + t = Object(this);
  32 + len = t.length >>> 0;
  33 +
  34 + if (typeof fun !== 'function') {
  35 + throw new TypeError();
  36 + }
  37 +
  38 + res = new Array(len);
  39 + thisArg = arguments.length >= 2 ? arguments[1] : void 0;
  40 +
  41 + for (var i = 0; i < len; i++) {
  42 + // NOTE: Absolute correctness would demand Object.defineProperty
  43 + // be used. But this method is fairly new, and failure is
  44 + // possible only if Object.prototype or Array.prototype
  45 + // has a property |i| (very unlikely), so use a less-correct
  46 + // but more portable alternative.
  47 + if (i in t) {
  48 + res[i] = fun.call(thisArg, t[i], i, t);
  49 + }
  50 + }
  51 +
  52 + return res;
  53 + };
  54 +}
  55 +
  56 +/**
  57 + * @augments Wkt.Wkt
  58 + * A framework-dependent flag, set for each Wkt.Wkt() instance, that indicates
  59 + * whether or not a closed polygon geometry should be interpreted as a rectangle.
  60 + */
  61 +Wkt.Wkt.prototype.isRectangle = false;
  62 +
  63 +/**
  64 + * @augments Wkt.Wkt
  65 + * An object of framework-dependent construction methods used to generate
  66 + * objects belonging to the various geometry classes of the framework.
  67 + */
  68 +Wkt.Wkt.prototype.construct = {
  69 + /**
  70 + * Creates the framework's equivalent point geometry object.
  71 + * @param config {Object} An optional properties hash the object should use
  72 + * @param component {Object} An optional component to build from
  73 + * @return {esri.geometry.Point}
  74 + */
  75 + point: function (config, component) {
  76 + var coord = component || this.components;
  77 + if (coord instanceof Array) {
  78 + coord = coord[0];
  79 + }
  80 +
  81 + if (config) {
  82 + // Allow the specification of a coordinate system
  83 + coord.spatialReference = config.spatialReference || config.srs;
  84 + }
  85 +
  86 + return new esri.geometry.Point(coord);
  87 + },
  88 +
  89 + /**
  90 + * Creates the framework's equivalent multipoint geometry object.
  91 + * @param config {Object} An optional properties hash the object should use
  92 + * @return {esri.geometry.Multipoint}
  93 + */
  94 + multipoint: function (config) {
  95 + config = config || {};
  96 + if (!config.spatialReference && config.srs) {
  97 + config.spatialReference = config.srs;
  98 + }
  99 +
  100 + return new esri.geometry.Multipoint({
  101 + // Create an Array of [x, y] coords from each point among the components
  102 + points: this.components.map(function (i) {
  103 + if (Wkt.isArray(i)) {
  104 + i = i[0]; // Unwrap coords
  105 + }
  106 + return [i.x, i.y];
  107 + }),
  108 + spatialReference: config.spatialReference
  109 + });
  110 + },
  111 +
  112 + /**
  113 + * Creates the framework's equivalent linestring geometry object.
  114 + * @param config {Object} An optional properties hash the object should use
  115 + * @return {esri.geometry.Polyline}
  116 + */
  117 + linestring: function (config) {
  118 + config = config || {};
  119 + if (!config.spatialReference && config.srs) {
  120 + config.spatialReference = config.srs;
  121 + }
  122 +
  123 + return new esri.geometry.Polyline({
  124 + // Create an Array of paths...
  125 + paths: [
  126 + this.components.map(function (i) {
  127 + return [i.x, i.y];
  128 + })
  129 + ],
  130 + spatialReference: config.spatialReference
  131 + });
  132 + },
  133 +
  134 + /**
  135 + * Creates the framework's equivalent multilinestring geometry object.
  136 + * @param config {Object} An optional properties hash the object should use
  137 + * @return {esri.geometry.Polyline}
  138 + */
  139 + multilinestring: function (config) {
  140 + config = config || {};
  141 + if (!config.spatialReference && config.srs) {
  142 + config.spatialReference = config.srs;
  143 + }
  144 +
  145 + return new esri.geometry.Polyline({
  146 + // Create an Array of paths...
  147 + paths: this.components.map(function (i) {
  148 + // ...Within which are Arrays of coordinate pairs (vertices)
  149 + return i.map(function (j) {
  150 + return [j.x, j.y];
  151 + });
  152 + }),
  153 + spatialReference: config.spatialReference
  154 + });
  155 + },
  156 +
  157 + /**
  158 + * Creates the framework's equivalent polygon geometry object.
  159 + * @param config {Object} An optional properties hash the object should use
  160 + * @return {esri.geometry.Polygon}
  161 + */
  162 + polygon: function (config) {
  163 + config = config || {};
  164 + if (!config.spatialReference && config.srs) {
  165 + config.spatialReference = config.srs;
  166 + }
  167 +
  168 + return new esri.geometry.Polygon({
  169 + // Create an Array of rings...
  170 + rings: this.components.map(function (i) {
  171 + // ...Within which are Arrays of coordinate pairs (vertices)
  172 + return i.map(function (j) {
  173 + return [j.x, j.y];
  174 + });
  175 + }),
  176 + spatialReference: config.spatialReference
  177 + });
  178 + },
  179 +
  180 + /**
  181 + * Creates the framework's equivalent multipolygon geometry object.
  182 + * @param config {Object} An optional properties hash the object should use
  183 + * @return {esri.geometry.Polygon}
  184 + */
  185 + multipolygon: function (config) {
  186 + var that = this;
  187 + config = config || {};
  188 + if (!config.spatialReference && config.srs) {
  189 + config.spatialReference = config.srs;
  190 + }
  191 +
  192 + return new esri.geometry.Polygon({
  193 + // Create an Array of rings...
  194 + rings: (function () {
  195 + var i, j, holey, newRings, rings;
  196 +
  197 + holey = false; // Assume there are no inner rings (holes)
  198 + rings = that.components.map(function (i) {
  199 + // ...Within which are Arrays of (outer) rings (polygons)
  200 + var rings = i.map(function (j) {
  201 + // ...Within which are (possibly) Arrays of (inner) rings (holes)
  202 + return j.map(function (k) {
  203 + return [k.x, k.y];
  204 + });
  205 + });
  206 +
  207 + holey = (rings.length > 1);
  208 +
  209 + return rings;
  210 + });
  211 +
  212 + if (!holey && rings[0].length > 1) { // Easy, if there are no inner rings (holes)
  213 + // But we add the second condition to check that we're not too deeply nested
  214 + return rings;
  215 + }
  216 +
  217 + newRings = [];
  218 + for (i = 0; i < rings.length; i += 1) {
  219 + if (rings[i].length > 1) {
  220 + for (j = 0; j < rings[i].length; j += 1) {
  221 + newRings.push(rings[i][j]);
  222 + }
  223 + } else {
  224 + newRings.push(rings[i][0]);
  225 + }
  226 + }
  227 +
  228 + return newRings;
  229 +
  230 + }()),
  231 + spatialReference: config.spatialReference
  232 + });
  233 + }
  234 +
  235 +};
  236 +
  237 +/**
  238 + * A test for determining whether one ring is an inner ring of another; tests
  239 + * to see whether the first argument (ring1) is an inner ring of the second
  240 + * (ring2) argument
  241 + * @param ring1 {Array} An Array of vertices that describe a ring in an esri.geometry.Polygon instance
  242 + * @param ring2 {Array} An Array of vertices that describe a ring in an esri.geometry.Polygon instance
  243 + * @param srs {esri.SpatialReference} The SRS to conduct this test within
  244 + * @return {Boolean}
  245 + */
  246 +Wkt.isInnerRingOf = function (ring1, ring2, srs) {
  247 + var contained, i, ply, pnt;
  248 +
  249 + // Though less common, we assume that the first ring is an inner ring of the
  250 + // second as this is a stricter case (all vertices must be contained);
  251 + // we'll test this against the contrary where at least one vertex of the
  252 + // first ring is not contained by the second ring (ergo, not an inner ring)
  253 + contained = true;
  254 +
  255 + ply = new esri.geometry.Polygon({ // Create single polygon from second ring
  256 + rings: ring2.map(function (i) {
  257 + // ...Within which are Arrays of coordinate pairs (vertices)
  258 + return i.map(function (j) {
  259 + return [j.x, j.y];
  260 + });
  261 + }),
  262 + spatialReference: srs
  263 + });
  264 +
  265 + for (i = 0; i < ring1.length; i += 1) {
  266 + // Sample a vertex of the first ring
  267 + pnt = new esri.geometry.Point(ring1[i].x, ring1[i].y, srs);
  268 +
  269 + // Now we have a test for inner rings: if the second ring does not
  270 + // contain every vertex of the first, then the first ring cannot be
  271 + // an inner ring of the second
  272 + if (!ply.contains(pnt)) {
  273 + contained = false;
  274 + break;
  275 + }
  276 + }
  277 +
  278 + return contained;
  279 +};
  280 +
  281 +/**
  282 + * @augments Wkt.Wkt
  283 + * A framework-dependent deconstruction method used to generate internal
  284 + * geometric representations from instances of framework geometry. This method
  285 + * uses object detection to attempt to classify members of framework geometry
  286 + * classes into the standard WKT types.
  287 + * @param obj {Object} An instance of one of the framework's geometry classes
  288 + * @return {Object} A hash of the 'type' and 'components' thus derived
  289 + */
  290 +Wkt.Wkt.prototype.deconstruct = function (obj) {
  291 + var i, j, paths, rings, verts;
  292 +
  293 + // esri.geometry.Point /////////////////////////////////////////////////////
  294 + if (obj.constructor === esri.geometry.Point) {
  295 +
  296 + return {
  297 + type: 'point',
  298 + components: [{
  299 + x: obj.getLongitude(),
  300 + y: obj.getLatitude()
  301 + }]
  302 + };
  303 +
  304 + }
  305 +
  306 + // esri.geometry.Multipoint ////////////////////////////////////////////////
  307 + if (obj.constructor === esri.geometry.Multipoint) {
  308 +
  309 + verts = [];
  310 + for (i = 0; i < obj.points.length; i += 1) {
  311 + verts.push([{
  312 + x: obj.points[i][0],
  313 + y: obj.points[i][1]
  314 + }]);
  315 + }
  316 +
  317 + return {
  318 + type: 'multipoint',
  319 + components: verts
  320 + };
  321 +
  322 + }
  323 +
  324 + // esri.geometry.Polyline //////////////////////////////////////////////////
  325 + if (obj.constructor === esri.geometry.Polyline) {
  326 +
  327 + paths = [];
  328 + for (i = 0; i < obj.paths.length; i += 1) {
  329 + verts = [];
  330 + for (j = 0; j < obj.paths[i].length; j += 1) {
  331 + verts.push({
  332 + x: obj.paths[i][j][0], // First item is longitude, second is latitude
  333 + y: obj.paths[i][j][1]
  334 + });
  335 + }
  336 + paths.push(verts);
  337 + }
  338 +
  339 + if (obj.paths.length > 1) { // More than one path means more than one linestring
  340 + return {
  341 + type: 'multilinestring',
  342 + components: paths
  343 + };
  344 + }
  345 +
  346 + return {
  347 + type: 'linestring',
  348 + components: verts
  349 + };
  350 +
  351 + }
  352 +
  353 + // esri.geometry.Polygon ///////////////////////////////////////////////////
  354 + if (obj.constructor === esri.geometry.Polygon) {
  355 +
  356 + rings = [];
  357 + for (i = 0; i < obj.rings.length; i += 1) {
  358 + verts = [];
  359 +
  360 + for (j = 0; j < obj.rings[i].length; j += 1) {
  361 + verts.push({
  362 + x: obj.rings[i][j][0], // First item is longitude, second is latitude
  363 + y: obj.rings[i][j][1]
  364 + });
  365 + }
  366 +
  367 + if (i > 0) {
  368 + if (Wkt.isInnerRingOf(verts, rings[i - 1], obj.spatialReference)) {
  369 + rings[rings.length - 1].push(verts);
  370 + } else {
  371 + rings.push([verts]);
  372 + }
  373 + } else {
  374 + rings.push([verts]);
  375 + }
  376 +
  377 + }
  378 +
  379 + if (rings.length > 1) {
  380 + return {
  381 + type: 'multipolygon',
  382 + components: rings
  383 + };
  384 + }
  385 +
  386 + return {
  387 + type: 'polygon',
  388 + components: rings[0]
  389 + };
  390 +
  391 + }
  392 +};
0 393 \ No newline at end of file
... ...
pacotes/wicket/wicket-gmap3.js
1   -google.maps.Marker.prototype.type="marker";google.maps.Polyline.prototype.type="polyline";google.maps.Polygon.prototype.type="polygon";google.maps.Rectangle.prototype.type="rectangle";google.maps.Circle.prototype.type="circle";
2   -Wkt.Wkt.prototype.construct={point:function(config,component){var c=component||this.components;config=config||{};config.position=new google.maps.LatLng(c[0].y,c[0].x);return new google.maps.Marker(config)},multipoint:function(config){var i,c,arr;c=this.components;config=config||{};arr=[];for(i=0;i<c.length;i+=1)arr.push(this.construct.point(config,c[i]));return arr},linestring:function(config,component){var i,c;c=component||this.components;config=config||{editable:false};config.path=[];for(i=0;i<
3   -c.length;i+=1)config.path.push(new google.maps.LatLng(c[i].y,c[i].x));return new google.maps.Polyline(config)},multilinestring:function(config){var i,c,arr;c=this.components;config=config||{editable:false};config.path=[];arr=[];for(i=0;i<c.length;i+=1)arr.push(this.construct.linestring(config,c[i]));return arr},polygon:function(config){var j,k,c,rings,verts;c=this.components;config=config||{editable:false};config.paths=[];rings=[];for(j=0;j<c.length;j+=1){verts=[];for(k=0;k<c[j].length;k+=1)verts.push(new google.maps.LatLng(c[j][k].y,
4   -c[j][k].x));if(j!==0)verts.reverse();rings.push(verts)}config.paths=config.paths.concat(rings);if(this.isRectangle)console.log("Rectangles are not yet supported; set the isRectangle property to false (default).");else return new google.maps.Polygon(config)},multipolygon:function(config){var i,j,k,c,rings,verts;c=this.components;config=config||{editable:false};config.paths=[];for(i=0;i<c.length;i+=1){rings=[];for(j=0;j<c[i].length;j+=1){verts=[];for(k=0;k<c[i][j].length;k+=1)verts.push(new google.maps.LatLng(c[i][j][k].y,
5   -c[i][j][k].x));rings.push(verts)}config.paths=config.paths.concat(rings)}return new google.maps.Polygon(config)}};
6   -Wkt.Wkt.prototype.deconstruct=function(obj){var i,j,verts,rings,tmp;if(obj.getPosition&&typeof obj.getPosition==="function")return{type:"point",components:[{x:obj.getPosition().lng(),y:obj.getPosition().lat()}]};else if(obj.getPath&&!obj.getPaths){verts=[];for(i=0;i<obj.getPath().length;i+=1){tmp=obj.getPath().getAt(i);verts.push({x:tmp.lng(),y:tmp.lat()})}return{type:"linestring",components:verts}}else if(obj.getPaths){rings=[];for(i=0;i<obj.getPaths().length;i+=1){tmp=obj.getPaths().getAt(i);verts=
7   -[];for(j=0;j<obj.getPaths().getAt(i).length;j+=1)verts.push({x:tmp.getAt(j).lng(),y:tmp.getAt(j).lat()});verts.push({x:tmp.getAt(0).lng(),y:tmp.getAt(0).lat()});if(obj.getPaths().length>1)verts=[verts];rings.push(verts)}return{type:"polygon",components:rings}}else if(obj.getBounds&&!obj.getRadius){tmp=obj.getBounds();return{type:"polygon",isRectangle:true,components:[[{x:tmp.getSouthWest().lng(),y:tmp.getNorthEast().lat()},{x:tmp.getNorthEast().lng(),y:tmp.getNorthEast().lat()},{x:tmp.getNorthEast().lng(),
8   -y:tmp.getSouthWest().lat()},{x:tmp.getSouthWest().lng(),y:tmp.getSouthWest().lat()},{x:tmp.getSouthWest().lng(),y:tmp.getNorthEast().lat()}]]}}else if(obj.getBounds&&obj.getRadius)console.log("Deconstruction of google.maps.Circle objects is not yet supported");else console.log("The passed object does not have any recognizable properties.")};Wkt.Wkt.prototype.isRectangle=false;
  1 +/** @license
  2 + *
  3 + * Copyright (C) 2012 K. Arthur Endsley (kaendsle@mtu.edu)
  4 + * Michigan Tech Research Institute (MTRI)
  5 + * 3600 Green Court, Suite 100, Ann Arbor, MI, 48105
  6 + *
  7 + * This program is free software: you can redistribute it and/or modify
  8 + * it under the terms of the GNU General Public License as published by
  9 + * the Free Software Foundation, either version 3 of the License, or
  10 + * (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 + *
  20 + */
  21 +(function (Wkt) {
  22 +
  23 + /**
  24 + * @augments Wkt.Wkt
  25 + * A framework-dependent flag, set for each Wkt.Wkt() instance, that indicates
  26 + * whether or not a closed polygon geometry should be interpreted as a rectangle.
  27 + */
  28 + Wkt.Wkt.prototype.isRectangle = false;
  29 +
  30 + /**
  31 + * @augments Wkt.Wkt
  32 + * An object of framework-dependent construction methods used to generate
  33 + * objects belonging to the various geometry classes of the framework.
  34 + */
  35 + Wkt.Wkt.prototype.construct = {
  36 + /**
  37 + * Creates the framework's equivalent point geometry object.
  38 + * @param config {Object} An optional properties hash the object should use
  39 + * @param component {Object} An optional component to build from
  40 + * @return {google.maps.Marker}
  41 + */
  42 + point: function (config, component) {
  43 + var c = component || this.components;
  44 +
  45 + config = config || {};
  46 +
  47 + config.position = new google.maps.LatLng(c[0].y, c[0].x);
  48 +
  49 + return new google.maps.Marker(config);
  50 + },
  51 +
  52 + /**
  53 + * Creates the framework's equivalent multipoint geometry object.
  54 + * @param config {Object} An optional properties hash the object should use
  55 + * @return {Array} Array containing multiple google.maps.Marker
  56 + */
  57 + multipoint: function (config) {
  58 + var i, c, arr;
  59 +
  60 + c = this.components;
  61 +
  62 + config = config || {};
  63 +
  64 + arr = [];
  65 +
  66 + for (i = 0; i < c.length; i += 1) {
  67 + arr.push(this.construct.point(config, c[i]));
  68 + }
  69 +
  70 + return arr;
  71 + },
  72 +
  73 + /**
  74 + * Creates the framework's equivalent linestring geometry object.
  75 + * @param config {Object} An optional properties hash the object should use
  76 + * @param component {Object} An optional component to build from
  77 + * @return {google.maps.Polyline}
  78 + */
  79 + linestring: function (config, component) {
  80 + var i, c;
  81 +
  82 + c = component || this.components;
  83 +
  84 + config = config || {
  85 + editable: false
  86 + };
  87 +
  88 + config.path = [];
  89 +
  90 + for (i = 0; i < c.length; i += 1) {
  91 + config.path.push(new google.maps.LatLng(c[i].y, c[i].x));
  92 + }
  93 +
  94 + return new google.maps.Polyline(config);
  95 + },
  96 +
  97 + /**
  98 + * Creates the framework's equivalent multilinestring geometry object.
  99 + * @param config {Object} An optional properties hash the object should use
  100 + * @return {Array} Array containing multiple google.maps.Polyline instances
  101 + */
  102 + multilinestring: function (config) {
  103 + var i, c, arr;
  104 +
  105 + c = this.components;
  106 +
  107 + config = config || {
  108 + editable: false
  109 + };
  110 +
  111 + config.path = [];
  112 +
  113 + arr = [];
  114 +
  115 + for (i = 0; i < c.length; i += 1) {
  116 + arr.push(this.construct.linestring(config, c[i]));
  117 + }
  118 +
  119 + return arr;
  120 + },
  121 +
  122 + /**
  123 + * Creates the framework's equivalent Box or Rectangle geometry object.
  124 + * @param config {Object} An optional properties hash the object should use
  125 + * @param component {Object} An optional component to build from
  126 + * @return {google.maps.Rectangle}
  127 + */
  128 + box: function (config, component) {
  129 + var c = component || this.components;
  130 +
  131 + config = config || {};
  132 +
  133 + config.bounds = new google.maps.LatLngBounds(
  134 + new google.maps.LatLng(c[0].y, c[0].x),
  135 + new google.maps.LatLng(c[1].y, c[1].x));
  136 +
  137 + return new google.maps.Rectangle(config);
  138 + },
  139 +
  140 + /**
  141 + * Creates the framework's equivalent polygon geometry object.
  142 + * @param config {Object} An optional properties hash the object should use
  143 + * @param component {Object} An optional component to build from
  144 + * @return {google.maps.Polygon}
  145 + */
  146 + polygon: function (config, component) {
  147 + var j, k, c, rings, verts;
  148 +
  149 + c = component || this.components;
  150 +
  151 + config = config || {
  152 + editable: false // Editable geometry off by default
  153 + };
  154 +
  155 + config.paths = [];
  156 +
  157 + rings = [];
  158 + for (j = 0; j < c.length; j += 1) { // For each ring...
  159 +
  160 + verts = [];
  161 + // NOTE: We iterate to one (1) less than the Array length to skip the last vertex
  162 + for (k = 0; k < c[j].length - 1; k += 1) { // For each vertex...
  163 + verts.push(new google.maps.LatLng(c[j][k].y, c[j][k].x));
  164 +
  165 + } // eo for each vertex
  166 +
  167 + if (j !== 0) { // Reverse the order of coordinates in inner rings
  168 + if (config.reverseInnerPolygons == null || config.reverseInnerPolygons) {
  169 + verts.reverse();
  170 + }
  171 + }
  172 +
  173 + rings.push(verts);
  174 + } // eo for each ring
  175 +
  176 + config.paths = config.paths.concat(rings);
  177 +
  178 + if (this.isRectangle) {
  179 + return (function () {
  180 + var bounds, v;
  181 +
  182 + bounds = new google.maps.LatLngBounds();
  183 +
  184 + for (v in rings[0]) { // Ought to be only 1 ring in a Rectangle
  185 + if (rings[0].hasOwnProperty(v)) {
  186 + bounds.extend(rings[0][v]);
  187 + }
  188 + }
  189 +
  190 + return new google.maps.Rectangle({
  191 + bounds: bounds
  192 + });
  193 + }());
  194 + } else {
  195 + return new google.maps.Polygon(config);
  196 + }
  197 + },
  198 +
  199 + /**
  200 + * Creates the framework's equivalent multipolygon geometry object.
  201 + * @param config {Object} An optional properties hash the object should use
  202 + * @return {Array} Array containing multiple google.maps.Polygon
  203 + */
  204 + multipolygon: function (config) {
  205 + var i, c, arr;
  206 +
  207 + c = this.components;
  208 +
  209 + config = config || {
  210 + editable: false
  211 + };
  212 +
  213 + config.path = [];
  214 +
  215 + arr = [];
  216 +
  217 + for (i = 0; i < c.length; i += 1) {
  218 + arr.push(this.construct.polygon(config, c[i]));
  219 + }
  220 +
  221 + return arr;
  222 + }
  223 +
  224 + };
  225 +
  226 + /**
  227 + * @augments Wkt.Wkt
  228 + * A framework-dependent deconstruction method used to generate internal
  229 + * geometric representations from instances of framework geometry. This method
  230 + * uses object detection to attempt to classify members of framework geometry
  231 + * classes into the standard WKT types.
  232 + * @param obj {Object} An instance of one of the framework's geometry classes
  233 + * @param multiFlag {Boolean} If true, then the deconstructor will be forced to return a MultiGeometry (multipoint, multilinestring or multipolygon)
  234 + * @return {Object} A hash of the 'type' and 'components' thus derived, plus the WKT string of the feature.
  235 + */
  236 + Wkt.Wkt.prototype.deconstruct = function (obj, multiFlag) {
  237 + var features, i, j, multiFlag, verts, rings, sign, tmp, response, lat, lng;
  238 +
  239 + // Shortcut to signed area function (determines clockwise vs counter-clock)
  240 + if (google.maps.geometry) {
  241 + sign = google.maps.geometry.spherical.computeSignedArea;
  242 + };
  243 +
  244 + // google.maps.LatLng //////////////////////////////////////////////////////
  245 + if (obj.constructor === google.maps.LatLng) {
  246 +
  247 + response = {
  248 + type: 'point',
  249 + components: [{
  250 + x: obj.lng(),
  251 + y: obj.lat()
  252 + }]
  253 + };
  254 + return response;
  255 + }
  256 +
  257 + // google.maps.Point //////////////////////////////////////////////////////
  258 + if (obj.constructor === google.maps.Point) {
  259 + response = {
  260 + type: 'point',
  261 + components: [{
  262 + x: obj.x,
  263 + y: obj.y
  264 + }]
  265 + };
  266 + return response;
  267 + }
  268 +
  269 + // google.maps.Marker //////////////////////////////////////////////////////
  270 + if (obj.constructor === google.maps.Marker) {
  271 + response = {
  272 + type: 'point',
  273 + components: [{
  274 + x: obj.getPosition().lng(),
  275 + y: obj.getPosition().lat()
  276 + }]
  277 + };
  278 + return response;
  279 + }
  280 +
  281 + // google.maps.Polyline ////////////////////////////////////////////////////
  282 + if (obj.constructor === google.maps.Polyline) {
  283 +
  284 + verts = [];
  285 + for (i = 0; i < obj.getPath().length; i += 1) {
  286 + tmp = obj.getPath().getAt(i);
  287 + verts.push({
  288 + x: tmp.lng(),
  289 + y: tmp.lat()
  290 + });
  291 + }
  292 + response = {
  293 + type: 'linestring',
  294 + components: verts
  295 + };
  296 + return response;
  297 +
  298 + }
  299 +
  300 + // google.maps.Polygon /////////////////////////////////////////////////////
  301 + if (obj.constructor === google.maps.Polygon) {
  302 +
  303 + rings = [];
  304 +
  305 + if (multiFlag === undefined) {
  306 + multiFlag = (function () {
  307 + var areas, i, l;
  308 +
  309 + l = obj.getPaths().length;
  310 + if (l <= 1) { // Trivial; this is a single polygon
  311 + return false;
  312 + }
  313 +
  314 + if (l === 2) {
  315 + // If clockwise*clockwise or counter*counter, i.e.
  316 + // (-1)*(-1) or (1)*(1), then result would be positive
  317 + if (sign(obj.getPaths().getAt(0)) * sign(obj.getPaths().getAt(1)) < 0) {
  318 + return false; // Most likely single polygon with 1 hole
  319 + }
  320 +
  321 + return true;
  322 + }
  323 +
  324 + // Must be longer than 3 polygons at this point...
  325 + areas = obj.getPaths().getArray().map(function (k) {
  326 + return sign(k) / Math.abs(sign(k)); // Unit normalization (outputs 1 or -1)
  327 + });
  328 +
  329 + // If two clockwise or two counter-clockwise rings are found
  330 + // (at different indices)...
  331 + if (areas.indexOf(areas[0]) !== areas.lastIndexOf(areas[0])) {
  332 + multiFlag = true; // Flag for holes in one or more polygons
  333 + return true;
  334 + }
  335 +
  336 + return false;
  337 +
  338 + }());
  339 + }
  340 +
  341 + for (i = 0; i < obj.getPaths().length; i += 1) { // For each polygon (ring)...
  342 + tmp = obj.getPaths().getAt(i);
  343 + verts = [];
  344 + for (j = 0; j < obj.getPaths().getAt(i).length; j += 1) { // For each vertex...
  345 + verts.push({
  346 + x: tmp.getAt(j).lng(),
  347 + y: tmp.getAt(j).lat()
  348 + });
  349 +
  350 + }
  351 +
  352 + if (!tmp.getAt(tmp.length - 1).equals(tmp.getAt(0))) {
  353 + if (i % 2 !== 0) { // In inner rings, coordinates are reversed...
  354 + verts.unshift({ // Add the first coordinate again for closure
  355 + x: tmp.getAt(tmp.length - 1).lng(),
  356 + y: tmp.getAt(tmp.length - 1).lat()
  357 + });
  358 +
  359 + } else {
  360 + verts.push({ // Add the first coordinate again for closure
  361 + x: tmp.getAt(0).lng(),
  362 + y: tmp.getAt(0).lat()
  363 + });
  364 +
  365 + }
  366 +
  367 + }
  368 +
  369 + if (obj.getPaths().length > 1 && i > 0) {
  370 + // If this and the last ring have the same signs...
  371 + if (sign(obj.getPaths().getAt(i)) > 0 && sign(obj.getPaths().getAt(i - 1)) > 0 ||
  372 + sign(obj.getPaths().getAt(i)) < 0 && sign(obj.getPaths().getAt(i - 1)) < 0 && !multiFlag) {
  373 + // ...They must both be inner rings (or both be outer rings, in a multipolygon)
  374 + verts = [verts]; // Wrap multipolygons once more (collection)
  375 + }
  376 +
  377 + }
  378 +
  379 + //TODO This makes mistakes when a second polygon has holes; it sees them all as individual polygons
  380 + if (i % 2 !== 0) { // In inner rings, coordinates are reversed...
  381 + verts.reverse();
  382 + }
  383 + rings.push(verts);
  384 + }
  385 +
  386 + response = {
  387 + type: (multiFlag) ? 'multipolygon' : 'polygon',
  388 + components: rings
  389 + };
  390 + return response;
  391 +
  392 + }
  393 +
  394 + // google.maps.Circle //////////////////////////////////////////////////////
  395 + if (obj.constructor === google.maps.Circle) {
  396 + var point = obj.getCenter();
  397 + var radius = obj.getRadius();
  398 + verts = [];
  399 + var d2r = Math.PI / 180; // degrees to radians
  400 + var r2d = 180 / Math.PI; // radians to degrees
  401 + radius = radius / 1609; // meters to miles
  402 + var earthsradius = 3963; // 3963 is the radius of the earth in miles
  403 + var num_seg = 32; // number of segments used to approximate a circle
  404 + var rlat = (radius / earthsradius) * r2d;
  405 + var rlng = rlat / Math.cos(point.lat() * d2r);
  406 +
  407 + for (var n = 0; n <= num_seg; n++) {
  408 + var theta = Math.PI * (n / (num_seg / 2));
  409 + lng = point.lng() + (rlng * Math.cos(theta)); // center a + radius x * cos(theta)
  410 + lat = point.lat() + (rlat * Math.sin(theta)); // center b + radius y * sin(theta)
  411 + verts.push({
  412 + x: lng,
  413 + y: lat
  414 + });
  415 + }
  416 +
  417 + response = {
  418 + type: 'polygon',
  419 + components: [verts]
  420 + };
  421 +
  422 + return response;
  423 +
  424 + }
  425 +
  426 + // google.maps.LatLngBounds ///////////////////////////////////////////////////
  427 + if (obj.constructor === google.maps.LatLngBounds) {
  428 +
  429 + tmp = obj;
  430 + verts = [];
  431 + verts.push({ // NW corner
  432 + x: tmp.getSouthWest().lng(),
  433 + y: tmp.getNorthEast().lat()
  434 + });
  435 +
  436 + verts.push({ // NE corner
  437 + x: tmp.getNorthEast().lng(),
  438 + y: tmp.getNorthEast().lat()
  439 + });
  440 +
  441 + verts.push({ // SE corner
  442 + x: tmp.getNorthEast().lng(),
  443 + y: tmp.getSouthWest().lat()
  444 + });
  445 +
  446 + verts.push({ // SW corner
  447 + x: tmp.getSouthWest().lng(),
  448 + y: tmp.getSouthWest().lat()
  449 + });
  450 +
  451 + verts.push({ // NW corner (again, for closure)
  452 + x: tmp.getSouthWest().lng(),
  453 + y: tmp.getNorthEast().lat()
  454 + });
  455 +
  456 +
  457 + response = {
  458 + type: 'polygon',
  459 + isRectangle: true,
  460 + components: [verts]
  461 + };
  462 +
  463 + return response;
  464 +
  465 + }
  466 +
  467 + // google.maps.Rectangle ///////////////////////////////////////////////////
  468 + if (obj.constructor === google.maps.Rectangle) {
  469 +
  470 + tmp = obj.getBounds();
  471 + verts = [];
  472 + verts.push({ // NW corner
  473 + x: tmp.getSouthWest().lng(),
  474 + y: tmp.getNorthEast().lat()
  475 + });
  476 +
  477 + verts.push({ // NE corner
  478 + x: tmp.getNorthEast().lng(),
  479 + y: tmp.getNorthEast().lat()
  480 + });
  481 +
  482 + verts.push({ // SE corner
  483 + x: tmp.getNorthEast().lng(),
  484 + y: tmp.getSouthWest().lat()
  485 + });
  486 +
  487 + verts.push({ // SW corner
  488 + x: tmp.getSouthWest().lng(),
  489 + y: tmp.getSouthWest().lat()
  490 + });
  491 +
  492 + verts.push({ // NW corner (again, for closure)
  493 + x: tmp.getSouthWest().lng(),
  494 + y: tmp.getNorthEast().lat()
  495 + });
  496 +
  497 +
  498 + response = {
  499 + type: 'polygon',
  500 + isRectangle: true,
  501 + components: [verts]
  502 + };
  503 +
  504 + return response;
  505 +
  506 + }
  507 +
  508 + // google.maps.Data Geometry Types /////////////////////////////////////////////////////
  509 +
  510 + // google.maps.Data.Feature /////////////////////////////////////////////////////
  511 + if (obj.constructor === google.maps.Data.Feature) {
  512 + return this.deconstruct.call(this, obj.getGeometry());
  513 + }
  514 +
  515 + // google.maps.Data.Point /////////////////////////////////////////////////////
  516 + if (obj.constructor === google.maps.Data.Point) {
  517 + //console.log('It is a google.maps.Data.Point');
  518 + response = {
  519 + type: 'point',
  520 + components: [{
  521 + x: obj.get().lng(),
  522 + y: obj.get().lat()
  523 + }]
  524 + };
  525 + return response;
  526 + }
  527 +
  528 + // google.maps.Data.LineString /////////////////////////////////////////////////////
  529 + if (obj.constructor === google.maps.Data.LineString) {
  530 + verts = [];
  531 + //console.log('It is a google.maps.Data.LineString');
  532 + for (i = 0; i < obj.getLength(); i += 1) {
  533 + vertex = obj.getAt(i);
  534 + verts.push({
  535 + x: vertex.lng(),
  536 + y: vertex.lat()
  537 + });
  538 + }
  539 + response = {
  540 + type: 'linestring',
  541 + components: verts
  542 + };
  543 + return response;
  544 + }
  545 +
  546 +
  547 +
  548 +
  549 + // google.maps.Data.Polygon /////////////////////////////////////////////////////
  550 + if (obj.constructor === google.maps.Data.Polygon) {
  551 + var rings = [];
  552 + //console.log('It is a google.maps.Data.Polygon');
  553 + for (i = 0; i < obj.getLength(); i += 1) { // For each ring...
  554 + ring = obj.getAt(i);
  555 + var verts = [];
  556 + for (j = 0; j < ring.getLength(); j += 1) { // For each vertex...
  557 + vertex = ring.getAt(j);
  558 + verts.push({
  559 + x: vertex.lng(),
  560 + y: vertex.lat()
  561 + });
  562 + }
  563 + verts.push({
  564 + x: ring.getAt(0).lng(),
  565 + y: ring.getAt(0).lat()
  566 + });
  567 +
  568 + rings.push(verts);
  569 + }
  570 + response = {
  571 + type: 'polygon',
  572 + components: rings
  573 + };
  574 +
  575 + return response;
  576 + }
  577 +
  578 +
  579 + // google.maps.Data.MultiPoint /////////////////////////////////////////////////////
  580 + if (obj.constructor === google.maps.Data.MultiPoint) {
  581 + verts = [];
  582 + for (i = 0; i < obj.getLength(); i += 1) {
  583 + vertex = obj.getAt(i);
  584 + verts.push([{
  585 + x: vertex.lng(),
  586 + y: vertex.lat()
  587 + }]);
  588 + }
  589 + response = {
  590 + type: 'multipoint',
  591 + components: verts
  592 + };
  593 + return response;
  594 + }
  595 +
  596 + // google.maps.Data.MultiLineString /////////////////////////////////////////////////////
  597 + if (obj.constructor === google.maps.Data.MultiLineString) {
  598 + linestrings = []
  599 + for (i = 0; i < obj.getLength(); i += 1) {
  600 + verts = [];
  601 + var linestring = obj.getAt(i);
  602 + for (j = 0; j < linestring.getLength(); j += 1) {
  603 + vertex = linestring.getAt(j);
  604 + verts.push({
  605 + x: vertex.lng(),
  606 + y: vertex.lat()
  607 + });
  608 + }
  609 + linestrings.push(verts);
  610 + }
  611 + response = {
  612 + type: 'multilinestring',
  613 + components: linestrings
  614 + };
  615 + return response;
  616 + }
  617 +
  618 + // google.maps.Data.MultiPolygon /////////////////////////////////////////////////////
  619 + if (obj.constructor === google.maps.Data.MultiPolygon) {
  620 +
  621 + var polygons = [];
  622 +
  623 + //console.log('It is a google.maps.Data.MultiPolygon');
  624 + for (k = 0; k < obj.getLength(); k += 1) { // For each multipolygon
  625 + var polygon = obj.getAt(k);
  626 + var rings = [];
  627 + for (i = 0; i < polygon.getLength(); i += 1) { // For each ring...
  628 + ring = polygon.getAt(i);
  629 + var verts = [];
  630 + for (j = 0; j < ring.getLength(); j += 1) { // For each vertex...
  631 + vertex = ring.getAt(j);
  632 + verts.push({
  633 + x: vertex.lng(),
  634 + y: vertex.lat()
  635 + });
  636 + }
  637 + verts.push({
  638 + x: ring.getAt(0).lng(),
  639 + y: ring.getAt(0).lat()
  640 + });
  641 +
  642 + rings.push(verts);
  643 + }
  644 + polygons.push(rings);
  645 + }
  646 +
  647 + response = {
  648 + type: 'multipolygon',
  649 + components: polygons
  650 + };
  651 + return response;
  652 + }
  653 +
  654 + // google.maps.Data.GeometryCollection /////////////////////////////////////////////////////
  655 + if (obj.constructor === google.maps.Data.GeometryCollection) {
  656 +
  657 + var objects = [];
  658 + for (k = 0; k < obj.getLength(); k += 1) { // For each multipolygon
  659 + var object = obj.getAt(k);
  660 + objects.push(this.deconstruct.call(this, object));
  661 + }
  662 + //console.log('It is a google.maps.Data.GeometryCollection', objects);
  663 + response = {
  664 + type: 'geometrycollection',
  665 + components: objects
  666 + };
  667 + return response;
  668 + }
  669 +
  670 +
  671 + // Array ///////////////////////////////////////////////////////////////////
  672 + if (Wkt.isArray(obj)) {
  673 + features = [];
  674 +
  675 + for (i = 0; i < obj.length; i += 1) {
  676 + features.push(this.deconstruct.call(this, obj[i], true));
  677 + }
  678 +
  679 + response = {
  680 +
  681 + type: (function () {
  682 + var k, type = obj[0].constructor;
  683 +
  684 + for (k = 0; k < obj.length; k += 1) {
  685 + // Check that all items have the same constructor as the first item
  686 + if (obj[k].constructor !== type) {
  687 + // If they don't, type is heterogeneous geometry collection
  688 + return 'geometrycollection';
  689 + }
  690 + }
  691 +
  692 + switch (type) {
  693 + case google.maps.Marker:
  694 + return 'multipoint';
  695 + case google.maps.Polyline:
  696 + return 'multilinestring';
  697 + case google.maps.Polygon:
  698 + return 'multipolygon';
  699 + default:
  700 + return 'geometrycollection';
  701 + }
  702 +
  703 + }()),
  704 + components: (function () {
  705 + // Pluck the components from each Wkt
  706 + var i, comps;
  707 +
  708 + comps = [];
  709 + for (i = 0; i < features.length; i += 1) {
  710 + if (features[i].components) {
  711 + comps.push(features[i].components);
  712 + }
  713 + }
  714 +
  715 + return {
  716 + comps: comps
  717 + };
  718 + }())
  719 +
  720 + };
  721 + response.components = response.components.comps;
  722 + return response;
  723 +
  724 + }
  725 +
  726 + console.log('The passed object does not have any recognizable properties.');
  727 +
  728 + };
  729 +}(Wkt || require('./wicket')));
... ...
pacotes/wicket/wicket-leaflet.js
1   -Wkt.Wkt.prototype.isRectangle=false;
2   -Wkt.Wkt.prototype.construct={point:function(config,component){var coord=component||this.components;if(coord instanceof Array)coord=coord[0];return L.marker(this.coordsToLatLng(coord),config)},multipoint:function(config){var layers=[],coords=this.components,latlng;for(var i=0,len=coords.length;i<len;i++)layers.push(this.construct.point.call(this,config,coords[i]));return L.featureGroup(layers,config)},linestring:function(config,component){var coords=component||this.components,latlngs=this.coordsToLatLngs(coords);
3   -return L.polyLine(latlngs)},multilinestring:function(config){var coords=this.components,latlngs=this.coordsToLatLngs(coords,1);return L.multiPolyline(latlngs)},polygon:function(config){var coords=this.components,latlngs=this.coordsToLatLngs(coords,1);return L.polygon(latlngs)},multipolygon:function(config){var coords=this.components,latlngs=this.coordsToLatLngs(coords,2);return L.multiPolygon(latlngs)}};
4   -L.Util.extend(Wkt.Wkt.prototype,{coordsToLatLngs:L.GeoJSON.coordsToLatLngs,coordsToLatLng:function(coords,reverse){var lat=reverse?coords.x:coords.y,lng=reverse?coords.y:coords.x;return L.latLng(lat,lng,true)}});
  1 +/** @license
  2 + *
  3 + * Copyright (C) 2012 K. Arthur Endsley (kaendsle@mtu.edu)
  4 + * Michigan Tech Research Institute (MTRI)
  5 + * 3600 Green Court, Suite 100, Ann Arbor, MI, 48105
  6 + *
  7 + * This program is free software: you can redistribute it and/or modify
  8 + * it under the terms of the GNU General Public License as published by
  9 + * the Free Software Foundation, either version 3 of the License, or
  10 + * (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 + *
  20 + */
  21 +
  22 +/**
  23 + * @augments Wkt.Wkt
  24 + * A framework-dependent flag, set for each Wkt.Wkt() instance, that indicates
  25 + * whether or not a closed polygon geometry should be interpreted as a rectangle.
  26 + */
  27 +Wkt.Wkt.prototype.isRectangle = false;
  28 +
  29 +/**
  30 + * @augments Wkt.Wkt
  31 + * Truncates an Array of coordinates by the closing coordinate when it is
  32 + * equal to the first coordinate given--this is only to be used for closed
  33 + * geometries in order to provide merely an "implied" closure to Leaflet.
  34 + * @param coords {Array} An Array of x,y coordinates (objects)
  35 + * @return {Array}
  36 + */
  37 +Wkt.Wkt.prototype.trunc = function (coords) {
  38 + var i, verts = [];
  39 +
  40 + for (i = 0; i < coords.length; i += 1) {
  41 + if (Wkt.isArray(coords[i])) {
  42 + verts.push(this.trunc(coords[i]));
  43 +
  44 + } else {
  45 +
  46 + // Add the first coord, but skip the last if it is identical
  47 + if (i === 0 || !this.sameCoords(coords[0], coords[i])) {
  48 + verts.push(coords[i]);
  49 + }
  50 + }
  51 + }
  52 +
  53 + return verts;
  54 +};
  55 +
  56 +/**
  57 + * @augments Wkt.Wkt
  58 + * An object of framework-dependent construction methods used to generate
  59 + * objects belonging to the various geometry classes of the framework.
  60 + */
  61 +Wkt.Wkt.prototype.construct = {
  62 + /**
  63 + * Creates the framework's equivalent point geometry object.
  64 + * @param config {Object} An optional properties hash the object should use
  65 + * @param component {Object} An optional component to build from
  66 + * @return {L.marker}
  67 + */
  68 + point: function (config, component) {
  69 + var coord = component || this.components;
  70 + if (coord instanceof Array) {
  71 + coord = coord[0];
  72 + }
  73 +
  74 + return L.marker(this.coordsToLatLng(coord), config);
  75 + },
  76 +
  77 + /**
  78 + * Creates the framework's equivalent multipoint geometry object.
  79 + * @param config {Object} An optional properties hash the object should use
  80 + * @return {L.featureGroup}
  81 + */
  82 + multipoint: function (config) {
  83 + var i,
  84 + layers = [],
  85 + coords = this.components;
  86 +
  87 + for (i = 0; i < coords.length; i += 1) {
  88 + layers.push(this.construct.point.call(this, config, coords[i]));
  89 + }
  90 +
  91 + return L.featureGroup(layers, config);
  92 + },
  93 +
  94 + /**
  95 + * Creates the framework's equivalent linestring geometry object.
  96 + * @param config {Object} An optional properties hash the object should use
  97 + * @param component {Object} An optional component to build from
  98 + * @return {L.polyline}
  99 + */
  100 + linestring: function (config, component) {
  101 + var coords = component || this.components,
  102 + latlngs = this.coordsToLatLngs(coords);
  103 +
  104 + return L.polyline(latlngs, config);
  105 + },
  106 +
  107 + /**
  108 + * Creates the framework's equivalent multilinestring geometry object.
  109 + * @param config {Object} An optional properties hash the object should use
  110 + * @return {L.multiPolyline}
  111 + */
  112 + multilinestring: function (config) {
  113 + var coords = this.components,
  114 + latlngs = this.coordsToLatLngs(coords, 1);
  115 +
  116 + return L.multiPolyline(latlngs, config);
  117 + },
  118 +
  119 + /**
  120 + * Creates the framework's equivalent polygon geometry object.
  121 + * @param config {Object} An optional properties hash the object should use
  122 + * @return {L.multiPolygon}
  123 + */
  124 + polygon: function (config) {
  125 + // Truncate the coordinates to remove the closing coordinate
  126 + var coords = this.trunc(this.components),
  127 + latlngs = this.coordsToLatLngs(coords, 1);
  128 + return L.polygon(latlngs, config);
  129 + },
  130 +
  131 + /**
  132 + * Creates the framework's equivalent multipolygon geometry object.
  133 + * @param config {Object} An optional properties hash the object should use
  134 + * @return {L.multiPolygon}
  135 + */
  136 + multipolygon: function (config) {
  137 + // Truncate the coordinates to remove the closing coordinate
  138 + var coords = this.trunc(this.components),
  139 + latlngs = this.coordsToLatLngs(coords, 2);
  140 +
  141 + return L.multiPolygon(latlngs, config);
  142 + },
  143 +
  144 + /**
  145 + * Creates the framework's equivalent collection of geometry objects.
  146 + * @param config {Object} An optional properties hash the object should use
  147 + * @return {L.featureGroup}
  148 + */
  149 + geometrycollection: function (config) {
  150 + var comps, i, layers;
  151 +
  152 + comps = this.trunc(this.components);
  153 + layers = [];
  154 + for (i = 0; i < this.components.length; i += 1) {
  155 + layers.push(this.construct[comps[i].type].call(this, comps[i]));
  156 + }
  157 +
  158 + return L.featureGroup(layers, config);
  159 +
  160 + }
  161 +};
  162 +
  163 +L.Util.extend(Wkt.Wkt.prototype, {
  164 + coordsToLatLngs: L.GeoJSON.coordsToLatLngs,
  165 + // TODO Why doesn't the coordsToLatLng function in L.GeoJSON already suffice?
  166 + coordsToLatLng: function (coords, reverse) {
  167 + var lat = reverse ? coords.x : coords.y,
  168 + lng = reverse ? coords.y : coords.x;
  169 +
  170 + return L.latLng(lat, lng, true);
  171 + }
  172 +});
  173 +
  174 +/**
  175 + * @augments Wkt.Wkt
  176 + * A framework-dependent deconstruction method used to generate internal
  177 + * geometric representations from instances of framework geometry. This method
  178 + * uses object detection to attempt to classify members of framework geometry
  179 + * classes into the standard WKT types.
  180 + * @param obj {Object} An instance of one of the framework's geometry classes
  181 + * @return {Object} A hash of the 'type' and 'components' thus derived
  182 + */
  183 +Wkt.Wkt.prototype.deconstruct = function (obj) {
  184 + var attr, coordsFromLatLngs, features, i, verts, rings, tmp;
  185 +
  186 + /**
  187 + * Accepts an Array (arr) of LatLngs from which it extracts each one as a
  188 + * vertex; calls itself recursively to deal with nested Arrays.
  189 + */
  190 + coordsFromLatLngs = function (arr) {
  191 + var i, coords;
  192 +
  193 + coords = [];
  194 + for (i = 0; i < arr.length; i += 1) {
  195 + if (Wkt.isArray(arr[i])) {
  196 + coords.push(coordsFromLatLngs(arr[i]));
  197 +
  198 + } else {
  199 + coords.push({
  200 + x: arr[i].lng,
  201 + y: arr[i].lat
  202 + });
  203 + }
  204 + }
  205 +
  206 + return coords;
  207 + };
  208 +
  209 + // L.Marker ////////////////////////////////////////////////////////////////
  210 + if (obj.constructor === L.Marker || obj.constructor === L.marker) {
  211 + return {
  212 + type: 'point',
  213 + components: [{
  214 + x: obj.getLatLng().lng,
  215 + y: obj.getLatLng().lat
  216 + }]
  217 + };
  218 + }
  219 +
  220 + // L.Rectangle /////////////////////////////////////////////////////////////
  221 + if (obj.constructor === L.Rectangle || obj.constructor === L.rectangle) {
  222 + tmp = obj.getBounds(); // L.LatLngBounds instance
  223 + return {
  224 + type: 'polygon',
  225 + isRectangle: true,
  226 + components: [
  227 + [
  228 + { // NW corner
  229 + x: tmp.getSouthWest().lng,
  230 + y: tmp.getNorthEast().lat
  231 + },
  232 + { // NE corner
  233 + x: tmp.getNorthEast().lng,
  234 + y: tmp.getNorthEast().lat
  235 + },
  236 + { // SE corner
  237 + x: tmp.getNorthEast().lng,
  238 + y: tmp.getSouthWest().lat
  239 + },
  240 + { // SW corner
  241 + x: tmp.getSouthWest().lng,
  242 + y: tmp.getSouthWest().lat
  243 + },
  244 + { // NW corner (again, for closure)
  245 + x: tmp.getSouthWest().lng,
  246 + y: tmp.getNorthEast().lat
  247 + }
  248 + ]
  249 + ]
  250 + };
  251 +
  252 + }
  253 +
  254 + // L.Polyline //////////////////////////////////////////////////////////////
  255 + if (obj.constructor === L.Polyline || obj.constructor === L.polyline) {
  256 + verts = [];
  257 + tmp = obj.getLatLngs();
  258 +
  259 + if (!tmp[0].equals(tmp[tmp.length - 1])) {
  260 +
  261 + for (i = 0; i < tmp.length; i += 1) {
  262 + verts.push({
  263 + x: tmp[i].lng,
  264 + y: tmp[i].lat
  265 + });
  266 + }
  267 +
  268 + return {
  269 + type: 'linestring',
  270 + components: verts
  271 + };
  272 +
  273 + }
  274 + }
  275 +
  276 + // L.Polygon ///////////////////////////////////////////////////////////////
  277 +
  278 + if (obj.constructor === L.Polygon || obj.constructor === L.polygon) {
  279 + rings = [];
  280 + verts = [];
  281 + tmp = obj.getLatLngs();
  282 +
  283 + // First, we deal with the boundary points
  284 + for (i = 0; i < obj._latlngs.length; i += 1) {
  285 + verts.push({ // Add the first coordinate again for closure
  286 + x: tmp[i].lng,
  287 + y: tmp[i].lat
  288 + });
  289 + }
  290 +
  291 + verts.push({ // Add the first coordinate again for closure
  292 + x: tmp[0].lng,
  293 + y: tmp[0].lat
  294 + });
  295 +
  296 + rings.push(verts);
  297 +
  298 + // Now, any holes
  299 + if (obj._holes && obj._holes.length > 0) {
  300 + // Reworked to support holes properly
  301 + verts = coordsFromLatLngs(obj._holes);
  302 + for (i=0; i < verts.length;i++) {
  303 + verts[i].push(verts[i][0]); // Copy the beginning coords again for closure
  304 + rings.push(verts[i]);
  305 + }
  306 + }
  307 +
  308 + return {
  309 + type: 'polygon',
  310 + components: rings
  311 + };
  312 +
  313 + }
  314 +
  315 + // L.MultiPolyline /////////////////////////////////////////////////////////
  316 + // L.MultiPolygon //////////////////////////////////////////////////////////
  317 + // L.LayerGroup ////////////////////////////////////////////////////////////
  318 + // L.FeatureGroup //////////////////////////////////////////////////////////
  319 + if (obj.constructor === L.MultiPolyline || obj.constructor === L.MultiPolygon
  320 + || obj.constructor === L.LayerGroup || obj.constructor === L.FeatureGroup) {
  321 +
  322 + features = [];
  323 + tmp = obj._layers;
  324 +
  325 + for (attr in tmp) {
  326 + if (tmp.hasOwnProperty(attr)) {
  327 + if (tmp[attr].getLatLngs || tmp[attr].getLatLng) {
  328 + // Recursively deconstruct each layer
  329 + features.push(this.deconstruct(tmp[attr]));
  330 + }
  331 + }
  332 + }
  333 +
  334 + return {
  335 +
  336 + type: (function () {
  337 + switch (obj.constructor) {
  338 + case L.MultiPolyline:
  339 + return 'multilinestring';
  340 + case L.MultiPolygon:
  341 + return 'multipolygon';
  342 + case L.FeatureGroup:
  343 + return (function () {
  344 + var i, mpgon, mpline, mpoint;
  345 +
  346 + // Assume that all layers are of one type (any one type)
  347 + mpgon = true;
  348 + mpline = true;
  349 + mpoint = true;
  350 +
  351 + for (i in obj._layers) {
  352 + if (obj._layers.hasOwnProperty(i)) {
  353 + if (obj._layers[i].constructor !== L.Marker) {
  354 + mpoint = false;
  355 + }
  356 + if (obj._layers[i].constructor !== L.Polyline) {
  357 + mpline = false;
  358 + }
  359 + if (obj._layers[i].constructor !== L.Polygon) {
  360 + mpgon = false;
  361 + }
  362 + }
  363 + }
  364 +
  365 + if (mpoint) {
  366 + return 'multipoint';
  367 + }
  368 + if (mpline) {
  369 + return 'multilinestring';
  370 + }
  371 + if (mpgon) {
  372 + return 'multipolygon';
  373 + }
  374 + return 'geometrycollection';
  375 +
  376 + }());
  377 + default:
  378 + return 'geometrycollection';
  379 + }
  380 + }()),
  381 +
  382 + components: (function () {
  383 + // Pluck the components from each Wkt
  384 + var i, comps;
  385 +
  386 + comps = [];
  387 + for (i = 0; i < features.length; i += 1) {
  388 + if (features[i].components) {
  389 + comps.push(features[i].components);
  390 + }
  391 + }
  392 +
  393 + return comps;
  394 + }())
  395 +
  396 + };
  397 +
  398 + }
  399 +
  400 + // L.Circle ////////////////////////////////////////////////////////////////
  401 + if (obj.constructor === L.Rectangle || obj.constructor === L.rectangle) {
  402 + console.log('Deconstruction of L.Circle objects is not yet supported');
  403 +
  404 + } else {
  405 + console.log('The passed object does not have any recognizable properties.');
  406 + }
  407 +
  408 +};
5 409 \ No newline at end of file
... ...
pacotes/wicket/wicket.js
1   -var Wkt=function(){return{delimiter:" ",isArray:function(obj){return!!(obj&&obj.constructor==Array)},Wkt:function(initializer){var beginsWith,endsWith,trim;beginsWith=function(str,sub){return str.substring(0,sub.length)===sub};endsWith=function(str,sub){return str.substring(str.length-sub.length)===sub};trim=function(str,sub){sub=sub||" ";while(beginsWith(str,sub))str=str.substring(1);while(endsWith(str,sub))str=str.substring(0,str.length-1);return str};this.delimiter=Wkt.delimiter;this.regExes={typeStr:/^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/,
2   -spaces:/\s+|\+/,numeric:/-*\d+\.*\d+/,comma:/\s*,\s*/,parenComma:/\)\s*,\s*\(/,doubleParenComma:/\)\s*\)\s*,\s*\(\s*\(/,trimParens:/^\s*\(?(.*?)\)?\s*$/};this.isCollection=function(){switch(this.type.slice(0,5)){case "multi":return true;case "polyg":return true;default:return false}};this.components=undefined;this.fromObject=function(obj){var result=this.deconstruct.call(this,obj);this.components=result.components;this.isRectangle=result.isRectangle||false;this.type=result.type;return this};this.toObject=
3   -function(config){return this.construct[this.type].call(this,config)};this.read=function(wkt){var matches;matches=this.regExes.typeStr.exec(wkt);if(matches){this.type=matches[1].toLowerCase();this.base=matches[2];if(this.ingest[this.type])this.components=this.ingest[this.type].apply(this,[this.base])}else{console.log("Invalid WKT string provided to read()");throw{name:"WKTError",message:"Invalid WKT string provided to read()"};}return this.components};this.write=function(components){var i,pieces,data;
4   -components=components||this.components;pieces=[];pieces.push(this.type.toUpperCase()+"(");for(i=0;i<components.length;i+=1){if(this.isCollection()&&i>0)pieces.push(",");if(!this.extract[this.type])return null;
5   -//alterado por edmar moretti
6   - if(components[i].length == 1){
7   - data = this.extract[this.type].apply(this, [components[i][0]]);
8   - }
9   - else{
10   - data = this.extract[this.type].apply(this, [components[i]]);
11   - }
12   -
13   -if(this.isCollection())pieces.push("("+data+")");else{pieces.push(data);if(i!==components.length-1)pieces.push(",")}}pieces.push(")");return pieces.join("")};this.extract={point:function(point){return point.x+this.delimiter+point.y},multipoint:function(multipoint){var i,
14   -parts=[];for(i=0;i<multipoint.length;i+=1)parts.push(this.extract.point.apply(this,[multipoint[i]]));return parts.join(",")},linestring:function(linestring){return this.extract.point.apply(this,[linestring])},multilinestring:function(multilinestring){var i,parts=[];for(i=0;i<multilinestring.length;i+=1)parts.push("("+this.extract.linestring.apply(this,[multilinestring[i]])+")");return parts.join(",")},polygon:function(polygon){return this.extract.multipoint.apply(this,[polygon])},multipolygon:function(multipolygon){var i,
15   -parts=[];for(i=0;i<multipolygon.length;i+=1)parts.push("("+this.extract.polygon.apply(this,[multipolygon[i]])+")");return parts.join(",")}};this.ingest={point:function(str){var coords=trim(str).split(this.regExes.spaces);return[{x:parseFloat(this.regExes.numeric.exec(coords[0])[0]),y:parseFloat(this.regExes.numeric.exec(coords[1])[0])}]},multipoint:function(str){var i,components,points;components=[];points=trim(str).split(this.regExes.comma);for(i=0;i<points.length;i+=1)components.push(this.ingest.point.apply(this,
16   -[points[i]]));return components},linestring:function(str){var i,multipoints,components;multipoints=this.ingest.multipoint.apply(this,[str]);components=[];for(i=0;i<multipoints.length;i+=1)components=components.concat(multipoints[i]);return components},multilinestring:function(str){var i,components,line,lines;components=[];lines=trim(str).split(this.regExes.parenComma);for(i=0;i<lines.length;i+=1){line=lines[i].replace(this.regExes.trimParens,"$1");components.push(this.ingest.linestring.apply(this,
17   -[line]))}return components},polygon:function(str){var i,j,components,subcomponents,ring,rings;rings=trim(str).split(this.regExes.parenComma);components=[];for(i=0;i<rings.length;i+=1){ring=rings[i].replace(this.regExes.trimParens,"$1").split(this.regExes.comma);subcomponents=[];for(j=0;j<ring.length;j+=1)subcomponents.push({x:parseFloat(ring[j].split(this.regExes.spaces)[0]),y:parseFloat(ring[j].split(this.regExes.spaces)[1])});components.push(subcomponents)}return components},multipolygon:function(str){var i,
18   -components,polygon,polygons;components=[];polygons=trim(str).split(this.regExes.doubleParenComma);for(i=0;i<polygons.length;i+=1){polygon=polygons[i].replace(this.regExes.trimParens,"$1");components.push(this.ingest.polygon.apply(this,[polygon]))}return components},geometrycollection:function(str){console.log("The geometrycollection WKT type is not yet supported.")}};if(initializer&&typeof initializer==="string")this.read(initializer);else if(this.fromGeometry)this.fromGeometry(initializer)}}}();
  1 +/** @license
  2 + *
  3 + * Copyright (C) 2012 K. Arthur Endsley (kaendsle@mtu.edu)
  4 + * Michigan Tech Research Institute (MTRI)
  5 + * 3600 Green Court, Suite 100, Ann Arbor, MI, 48105
  6 + *
  7 + * This program is free software: you can redistribute it and/or modify
  8 + * it under the terms of the GNU General Public License as published by
  9 + * the Free Software Foundation, either version 3 of the License, or
  10 + * (at your option) any later version.
  11 + *
  12 + * This program is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15 + * GNU General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU General Public License
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19 + *
  20 + */
  21 +
  22 +(function (global) {
  23 + var beginsWith, endsWith, root, Wkt;
  24 +
  25 + // Establish the root object, window in the browser, or exports on the server
  26 + root = this;
  27 +
  28 + /**
  29 + * @desc The Wkt namespace.
  30 + * @property {String} delimiter - The default delimiter for separating components of atomic geometry (coordinates)
  31 + * @namespace
  32 + * @global
  33 + */
  34 + Wkt = function (obj) {
  35 + if (obj instanceof Wkt) return obj;
  36 + if (!(this instanceof Wkt)) return new Wkt(obj);
  37 + this._wrapped = obj;
  38 + };
  39 +
  40 + // Following Underscore module pattern (http://underscorejs.org/docs/underscore.html)
  41 + if (typeof exports !== 'undefined') {
  42 + if (typeof module !== 'undefined' && module.exports) {
  43 + exports = module.exports = Wkt;
  44 + }
  45 + exports.Wkt = Wkt;
  46 + } else {
  47 + root.Wkt = Wkt;
  48 + }
  49 +
  50 + /**
  51 + * Returns true if the substring is found at the beginning of the string.
  52 + * @param str {String} The String to search
  53 + * @param sub {String} The substring of interest
  54 + * @return {Boolean}
  55 + * @private
  56 + */
  57 + beginsWith = function (str, sub) {
  58 + return str.substring(0, sub.length) === sub;
  59 + };
  60 +
  61 + /**
  62 + * Returns true if the substring is found at the end of the string.
  63 + * @param str {String} The String to search
  64 + * @param sub {String} The substring of interest
  65 + * @return {Boolean}
  66 + * @private
  67 + */
  68 + endsWith = function (str, sub) {
  69 + return str.substring(str.length - sub.length) === sub;
  70 + };
  71 +
  72 + /**
  73 + * The default delimiter for separating components of atomic geometry (coordinates)
  74 + * @ignore
  75 + */
  76 + Wkt.delimiter = ' ';
  77 +
  78 + /**
  79 + * Determines whether or not the passed Object is an Array.
  80 + * @param obj {Object} The Object in question
  81 + * @return {Boolean}
  82 + * @member Wkt.isArray
  83 + * @method
  84 + */
  85 + Wkt.isArray = function (obj) {
  86 + return !!(obj && obj.constructor === Array);
  87 + };
  88 +
  89 + /**
  90 + * Removes given character String(s) from a String.
  91 + * @param str {String} The String to search
  92 + * @param sub {String} The String character(s) to trim
  93 + * @return {String} The trimmed string
  94 + * @member Wkt.trim
  95 + * @method
  96 + */
  97 + Wkt.trim = function (str, sub) {
  98 + sub = sub || ' '; // Defaults to trimming spaces
  99 + // Trim beginning spaces
  100 + while (beginsWith(str, sub)) {
  101 + str = str.substring(1);
  102 + }
  103 + // Trim ending spaces
  104 + while (endsWith(str, sub)) {
  105 + str = str.substring(0, str.length - 1);
  106 + }
  107 + return str;
  108 + };
  109 +
  110 + /**
  111 + * An object for reading WKT strings and writing geographic features
  112 + * @constructor this.Wkt.Wkt
  113 + * @param initializer {String} An optional WKT string for immediate read
  114 + * @property {Array} components - Holder for atomic geometry objects (internal representation of geometric components)
  115 + * @property {String} delimiter - The default delimiter for separating components of atomic geometry (coordinates)
  116 + * @property {Object} regExes - Some regular expressions copied from OpenLayers.Format.WKT.js
  117 + * @property {String} type - The Well-Known Text name (e.g. 'point') of the geometry
  118 + * @property {Boolean} wrapVerticies - True to wrap vertices in MULTIPOINT geometries; If true: MULTIPOINT((30 10),(10 30),(40 40)); If false: MULTIPOINT(30 10,10 30,40 40)
  119 + * @return {this.Wkt.Wkt}
  120 + * @memberof Wkt
  121 + */
  122 + Wkt.Wkt = function (initializer) {
  123 +
  124 + /**
  125 + * The default delimiter between X and Y coordinates.
  126 + * @ignore
  127 + */
  128 + this.delimiter = Wkt.delimiter || ' ';
  129 +
  130 + /**
  131 + * Configuration parameter for controlling how Wicket seralizes
  132 + * MULTIPOINT strings. Examples; both are valid WKT:
  133 + * If true: MULTIPOINT((30 10),(10 30),(40 40))
  134 + * If false: MULTIPOINT(30 10,10 30,40 40)
  135 + * @ignore
  136 + */
  137 + this.wrapVertices = true;
  138 +
  139 + /**
  140 + * Some regular expressions copied from OpenLayers.Format.WKT.js
  141 + * @ignore
  142 + */
  143 + this.regExes = {
  144 + 'typeStr': /^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/,
  145 + 'spaces': /\s+|\+/, // Matches the '+' or the empty space
  146 + 'numeric': /-*\d+(\.*\d+)?/,
  147 + 'comma': /\s*,\s*/,
  148 + 'parenComma': /\)\s*,\s*\(/,
  149 + 'coord': /-*\d+\.*\d+ -*\d+\.*\d+/, // e.g. "24 -14"
  150 + 'doubleParenComma': /\)\s*\)\s*,\s*\(\s*\(/,
  151 + 'trimParens': /^\s*\(?(.*?)\)?\s*$/,
  152 + 'ogcTypes': /^(multi)?(point|line|polygon|box)?(string)?$/i, // Captures e.g. "Multi","Line","String"
  153 + 'crudeJson': /^{.*"(type|coordinates|geometries|features)":.*}$/ // Attempts to recognize JSON strings
  154 + };
  155 +
  156 + /**
  157 + * The internal representation of geometry--the "components" of geometry.
  158 + * @ignore
  159 + */
  160 + this.components = undefined;
  161 +
  162 + // An initial WKT string may be provided
  163 + if (initializer && typeof initializer === 'string') {
  164 + this.read(initializer);
  165 + } else if (initializer && typeof initializer !== undefined) {
  166 + this.fromObject(initializer);
  167 + }
  168 +
  169 + };
  170 +
  171 + global.Wkt = Wkt;
  172 +
  173 + /**
  174 + * Returns true if the internal geometry is a collection of geometries.
  175 + * @return {Boolean} Returns true when it is a collection
  176 + * @memberof this.Wkt.Wkt
  177 + * @method
  178 + */
  179 + Wkt.Wkt.prototype.isCollection = function () {
  180 + switch (this.type.slice(0, 5)) {
  181 + case 'multi':
  182 + // Trivial; any multi-geometry is a collection
  183 + return true;
  184 + case 'polyg':
  185 + // Polygons with holes are "collections" of rings
  186 + return true;
  187 + default:
  188 + // Any other geometry is not a collection
  189 + return false;
  190 + }
  191 + };
  192 +
  193 + /**
  194 + * Compares two x,y coordinates for equality.
  195 + * @param a {Object} An object with x and y properties
  196 + * @param b {Object} An object with x and y properties
  197 + * @return {Boolean}
  198 + * @memberof this.Wkt.Wkt
  199 + * @method
  200 + */
  201 + Wkt.Wkt.prototype.sameCoords = function (a, b) {
  202 + return (a.x === b.x && a.y === b.y);
  203 + };
  204 +
  205 + /**
  206 + * Sets internal geometry (components) from framework geometry (e.g.
  207 + * Google Polygon objects or google.maps.Polygon).
  208 + * @param obj {Object} The framework-dependent geometry representation
  209 + * @return {this.Wkt.Wkt} The object itself
  210 + * @memberof this.Wkt.Wkt
  211 + * @method
  212 + */
  213 + Wkt.Wkt.prototype.fromObject = function (obj) {
  214 + var result;
  215 +
  216 + if (obj.hasOwnProperty('type') && obj.hasOwnProperty('coordinates')) {
  217 + result = this.fromJson(obj);
  218 + } else {
  219 + result = this.deconstruct.call(this, obj);
  220 + }
  221 +
  222 + this.components = result.components;
  223 + this.isRectangle = result.isRectangle || false;
  224 + this.type = result.type;
  225 + return this;
  226 + };
  227 +
  228 + /**
  229 + * Creates external geometry objects based on a plug-in framework's
  230 + * construction methods and available geometry classes.
  231 + * @param config {Object} An optional framework-dependent properties specification
  232 + * @return {Object} The framework-dependent geometry representation
  233 + * @memberof this.Wkt.Wkt
  234 + * @method
  235 + */
  236 + Wkt.Wkt.prototype.toObject = function (config) {
  237 + var obj = this.construct[this.type].call(this, config);
  238 + // Don't assign the "properties" property to an Array
  239 + if (typeof obj === 'object' && !Wkt.isArray(obj)) {
  240 + obj.properties = this.properties;
  241 + }
  242 + return obj;
  243 + };
  244 +
  245 + /**
  246 + * Returns the WKT string representation; the same as the write() method.
  247 + * @memberof this.Wkt.Wkt
  248 + * @method
  249 + */
  250 + Wkt.Wkt.prototype.toString = function (config) {
  251 + return this.write();
  252 + };
  253 +
  254 + /**
  255 + * Parses a JSON representation as an Object.
  256 + * @param obj {Object} An Object with the GeoJSON schema
  257 + * @return {this.Wkt.Wkt} The object itself
  258 + * @memberof this.Wkt.Wkt
  259 + * @method
  260 + */
  261 + Wkt.Wkt.prototype.fromJson = function (obj) {
  262 + var i, j, k, coords, iring, oring;
  263 +
  264 + this.type = obj.type.toLowerCase();
  265 + this.components = [];
  266 + if (obj.hasOwnProperty('geometry')) { //Feature
  267 + this.fromJson(obj.geometry);
  268 + this.properties = obj.properties;
  269 + return this;
  270 + }
  271 + coords = obj.coordinates;
  272 +
  273 + if (!Wkt.isArray(coords[0])) { // Point
  274 + this.components.push({
  275 + x: coords[0],
  276 + y: coords[1]
  277 + });
  278 +
  279 + } else {
  280 +
  281 + for (i in coords) {
  282 + if (coords.hasOwnProperty(i)) {
  283 +
  284 + if (!Wkt.isArray(coords[i][0])) { // LineString
  285 +
  286 + if (this.type === 'multipoint') { // MultiPoint
  287 + this.components.push([{
  288 + x: coords[i][0],
  289 + y: coords[i][1]
  290 + }]);
  291 +
  292 + } else {
  293 + this.components.push({
  294 + x: coords[i][0],
  295 + y: coords[i][1]
  296 + });
  297 +
  298 + }
  299 +
  300 + } else {
  301 +
  302 + oring = [];
  303 + for (j in coords[i]) {
  304 + if (coords[i].hasOwnProperty(j)) {
  305 +
  306 + if (!Wkt.isArray(coords[i][j][0])) {
  307 + oring.push({
  308 + x: coords[i][j][0],
  309 + y: coords[i][j][1]
  310 + });
  311 +
  312 + } else {
  313 +
  314 + iring = [];
  315 + for (k in coords[i][j]) {
  316 + if (coords[i][j].hasOwnProperty(k)) {
  317 +
  318 + iring.push({
  319 + x: coords[i][j][k][0],
  320 + y: coords[i][j][k][1]
  321 + });
  322 +
  323 + }
  324 + }
  325 +
  326 + oring.push(iring);
  327 +
  328 + }
  329 +
  330 + }
  331 + }
  332 +
  333 + this.components.push(oring);
  334 + }
  335 + }
  336 + }
  337 +
  338 + }
  339 +
  340 + return this;
  341 + };
  342 +
  343 + /**
  344 + * Creates a JSON representation, with the GeoJSON schema, of the geometry.
  345 + * @return {Object} The corresponding GeoJSON representation
  346 + * @memberof this.Wkt.Wkt
  347 + * @method
  348 + */
  349 + Wkt.Wkt.prototype.toJson = function () {
  350 + var cs, json, i, j, k, ring, rings;
  351 +
  352 + cs = this.components;
  353 + json = {
  354 + coordinates: [],
  355 + type: (function () {
  356 + var i, type, s;
  357 +
  358 + type = this.regExes.ogcTypes.exec(this.type).slice(1);
  359 + s = [];
  360 +
  361 + for (i in type) {
  362 + if (type.hasOwnProperty(i)) {
  363 + if (type[i] !== undefined) {
  364 + s.push(type[i].toLowerCase().slice(0, 1).toUpperCase() + type[i].toLowerCase().slice(1));
  365 + }
  366 + }
  367 + }
  368 +
  369 + return s;
  370 + }.call(this)).join('')
  371 + }
  372 +
  373 + // Wkt BOX type gets a special bbox property in GeoJSON
  374 + if (this.type.toLowerCase() === 'box') {
  375 + json.type = 'Polygon';
  376 + json.bbox = [];
  377 +
  378 + for (i in cs) {
  379 + if (cs.hasOwnProperty(i)) {
  380 + json.bbox = json.bbox.concat([cs[i].x, cs[i].y]);
  381 + }
  382 + }
  383 +
  384 + json.coordinates = [
  385 + [
  386 + [cs[0].x, cs[0].y],
  387 + [cs[0].x, cs[1].y],
  388 + [cs[1].x, cs[1].y],
  389 + [cs[1].x, cs[0].y],
  390 + [cs[0].x, cs[0].y]
  391 + ]
  392 + ];
  393 +
  394 + return json;
  395 + }
  396 +
  397 + // For the coordinates of most simple features
  398 + for (i in cs) {
  399 + if (cs.hasOwnProperty(i)) {
  400 +
  401 + // For those nested structures
  402 + if (Wkt.isArray(cs[i])) {
  403 + rings = [];
  404 +
  405 + for (j in cs[i]) {
  406 + if (cs[i].hasOwnProperty(j)) {
  407 +
  408 + if (Wkt.isArray(cs[i][j])) { // MULTIPOLYGONS
  409 + ring = [];
  410 +
  411 + for (k in cs[i][j]) {
  412 + if (cs[i][j].hasOwnProperty(k)) {
  413 + ring.push([cs[i][j][k].x, cs[i][j][k].y]);
  414 + }
  415 + }
  416 +
  417 + rings.push(ring);
  418 +
  419 + } else { // POLYGONS and MULTILINESTRINGS
  420 +
  421 + if (cs[i].length > 1) {
  422 + rings.push([cs[i][j].x, cs[i][j].y]);
  423 +
  424 + } else { // MULTIPOINTS
  425 + rings = rings.concat([cs[i][j].x, cs[i][j].y]);
  426 + }
  427 + }
  428 + }
  429 + }
  430 +
  431 + json.coordinates.push(rings);
  432 +
  433 + } else {
  434 + if (cs.length > 1) { // For LINESTRING type
  435 + json.coordinates.push([cs[i].x, cs[i].y]);
  436 +
  437 + } else { // For POINT type
  438 + json.coordinates = json.coordinates.concat([cs[i].x, cs[i].y]);
  439 + }
  440 + }
  441 +
  442 + }
  443 + }
  444 +
  445 + return json;
  446 + };
  447 +
  448 + /**
  449 + * Absorbs the geometry of another this.Wkt.Wkt instance, merging it with its own,
  450 + * creating a collection (MULTI-geometry) based on their types, which must agree.
  451 + * For example, creates a MULTIPOLYGON from a POLYGON type merged with another
  452 + * POLYGON type, or adds a POLYGON instance to a MULTIPOLYGON instance.
  453 + * @param wkt {String} A Wkt.Wkt object
  454 + * @return {this.Wkt.Wkt} The object itself
  455 + * @memberof this.Wkt.Wkt
  456 + * @method
  457 + */
  458 + Wkt.Wkt.prototype.merge = function (wkt) {
  459 + var prefix = this.type.slice(0, 5);
  460 +
  461 + if (this.type !== wkt.type) {
  462 + if (this.type.slice(5, this.type.length) !== wkt.type) {
  463 + throw TypeError('The input geometry types must agree or the calling this.Wkt.Wkt instance must be a multigeometry of the other');
  464 + }
  465 + }
  466 +
  467 + switch (prefix) {
  468 +
  469 + case 'point':
  470 + this.components = [this.components.concat(wkt.components)];
  471 + break;
  472 +
  473 + case 'multi':
  474 + this.components = this.components.concat((wkt.type.slice(0, 5) === 'multi') ? wkt.components : [wkt.components]);
  475 + break;
  476 +
  477 + default:
  478 + this.components = [
  479 + this.components,
  480 + wkt.components
  481 + ];
  482 + break;
  483 +
  484 + }
  485 +
  486 + if (prefix !== 'multi') {
  487 + this.type = 'multi' + this.type;
  488 + }
  489 + return this;
  490 + };
  491 +
  492 + /**
  493 + * Reads a WKT string, validating and incorporating it.
  494 + * @param str {String} A WKT or GeoJSON string
  495 + * @return {this.Wkt.Wkt} The object itself
  496 + * @memberof this.Wkt.Wkt
  497 + * @method
  498 + */
  499 + Wkt.Wkt.prototype.read = function (str) {
  500 + var matches;
  501 + matches = this.regExes.typeStr.exec(str);
  502 + if (matches) {
  503 + this.type = matches[1].toLowerCase();
  504 + this.base = matches[2];
  505 + if (this.ingest[this.type]) {
  506 + this.components = this.ingest[this.type].apply(this, [this.base]);
  507 + }
  508 +
  509 + } else {
  510 + if (this.regExes.crudeJson.test(str)) {
  511 + if (typeof JSON === 'object' && typeof JSON.parse === 'function') {
  512 + this.fromJson(JSON.parse(str));
  513 +
  514 + } else {
  515 + console.log('JSON.parse() is not available; cannot parse GeoJSON strings');
  516 + throw {
  517 + name: 'JSONError',
  518 + message: 'JSON.parse() is not available; cannot parse GeoJSON strings'
  519 + };
  520 + }
  521 +
  522 + } else {
  523 + console.log('Invalid WKT string provided to read()');
  524 + throw {
  525 + name: 'WKTError',
  526 + message: 'Invalid WKT string provided to read()'
  527 + };
  528 + }
  529 + }
  530 +
  531 + return this;
  532 + }; // eo readWkt
  533 +
  534 + /**
  535 + * Writes a WKT string.
  536 + * @param components {Array} An Array of internal geometry objects
  537 + * @return {String} The corresponding WKT representation
  538 + * @memberof this.Wkt.Wkt
  539 + * @method
  540 + */
  541 + Wkt.Wkt.prototype.write = function (components) {
  542 + var i, pieces, data;
  543 +
  544 + components = components || this.components;
  545 +
  546 + pieces = [];
  547 +
  548 + pieces.push(this.type.toUpperCase() + '(');
  549 +
  550 + for (i = 0; i < components.length; i += 1) {
  551 + if (this.isCollection() && i > 0) {
  552 + pieces.push(',');
  553 + }
  554 +
  555 + // There should be an extract function for the named type
  556 + if (!this.extract[this.type]) {
  557 + return null;
  558 + }
  559 +
  560 + data = this.extract[this.type].apply(this, [components[i]]);
  561 + if (this.isCollection() && this.type !== 'multipoint') {
  562 + pieces.push('(' + data + ')');
  563 +
  564 + } else {
  565 + pieces.push(data);
  566 +
  567 + // If not at the end of the components, add a comma
  568 + if (i !== (components.length - 1) && this.type !== 'multipoint') {
  569 + pieces.push(',');
  570 + }
  571 +
  572 + }
  573 + }
  574 +
  575 + pieces.push(')');
  576 +
  577 + return pieces.join('');
  578 + };
  579 +
  580 + /**
  581 + * This object contains functions as property names that extract WKT
  582 + * strings from the internal representation.
  583 + * @memberof this.Wkt.Wkt
  584 + * @namespace this.Wkt.Wkt.extract
  585 + * @instance
  586 + */
  587 + Wkt.Wkt.prototype.extract = {
  588 + /**
  589 + * Return a WKT string representing atomic (point) geometry
  590 + * @param point {Object} An object with x and y properties
  591 + * @return {String} The WKT representation
  592 + * @memberof this.Wkt.Wkt.extract
  593 + * @instance
  594 + */
  595 + point: function (point) {
  596 + return String(point.x) + this.delimiter + String(point.y);
  597 + },
  598 +
  599 + /**
  600 + * Return a WKT string representing multiple atoms (points)
  601 + * @param multipoint {Array} Multiple x-and-y objects
  602 + * @return {String} The WKT representation
  603 + * @memberof this.Wkt.Wkt.extract
  604 + * @instance
  605 + */
  606 + multipoint: function (multipoint) {
  607 + var i, parts = [],
  608 + s;
  609 +
  610 + for (i = 0; i < multipoint.length; i += 1) {
  611 + s = this.extract.point.apply(this, [multipoint[i]]);
  612 +
  613 + if (this.wrapVertices) {
  614 + s = '(' + s + ')';
  615 + }
  616 +
  617 + parts.push(s);
  618 + }
  619 +
  620 + return parts.join(',');
  621 + },
  622 +
  623 + /**
  624 + * Return a WKT string representing a chain (linestring) of atoms
  625 + * @param linestring {Array} Multiple x-and-y objects
  626 + * @return {String} The WKT representation
  627 + * @memberof this.Wkt.Wkt.extract
  628 + * @instance
  629 + */
  630 + linestring: function (linestring) {
  631 + // Extraction of linestrings is the same as for points
  632 + return this.extract.point.apply(this, [linestring]);
  633 + },
  634 +
  635 + /**
  636 + * Return a WKT string representing multiple chains (multilinestring) of atoms
  637 + * @param multilinestring {Array} Multiple of multiple x-and-y objects
  638 + * @return {String} The WKT representation
  639 + * @memberof this.Wkt.Wkt.extract
  640 + * @instance
  641 + */
  642 + multilinestring: function (multilinestring) {
  643 + var i, parts = [];
  644 +
  645 + for (i = 0; i < multilinestring.length; i += 1) {
  646 + parts.push(this.extract.linestring.apply(this, [multilinestring[i]]));
  647 + }
  648 +
  649 + return parts.join(',');
  650 + },
  651 +
  652 + /**
  653 + * Return a WKT string representing multiple atoms in closed series (polygon)
  654 + * @param polygon {Array} Collection of ordered x-and-y objects
  655 + * @return {String} The WKT representation
  656 + * @memberof this.Wkt.Wkt.extract
  657 + * @instance
  658 + */
  659 + polygon: function (polygon) {
  660 + // Extraction of polygons is the same as for multilinestrings
  661 + return this.extract.multilinestring.apply(this, [polygon]);
  662 + },
  663 +
  664 + /**
  665 + * Return a WKT string representing multiple closed series (multipolygons) of multiple atoms
  666 + * @param multipolygon {Array} Collection of ordered x-and-y objects
  667 + * @return {String} The WKT representation
  668 + * @memberof this.Wkt.Wkt.extract
  669 + * @instance
  670 + */
  671 + multipolygon: function (multipolygon) {
  672 + var i, parts = [];
  673 + for (i = 0; i < multipolygon.length; i += 1) {
  674 + parts.push('(' + this.extract.polygon.apply(this, [multipolygon[i]]) + ')');
  675 + }
  676 + return parts.join(',');
  677 + },
  678 +
  679 + /**
  680 + * Return a WKT string representing a 2DBox
  681 + * @param multipolygon {Array} Collection of ordered x-and-y objects
  682 + * @return {String} The WKT representation
  683 + * @memberof this.Wkt.Wkt.extract
  684 + * @instance
  685 + */
  686 + box: function (box) {
  687 + return this.extract.linestring.apply(this, [box]);
  688 + },
  689 +
  690 + geometrycollection: function (str) {
  691 + console.log('The geometrycollection WKT type is not yet supported.');
  692 + }
  693 + };
  694 +
  695 + /**
  696 + * This object contains functions as property names that ingest WKT
  697 + * strings into the internal representation.
  698 + * @memberof this.Wkt.Wkt
  699 + * @namespace this.Wkt.Wkt.ingest
  700 + * @instance
  701 + */
  702 + Wkt.Wkt.prototype.ingest = {
  703 +
  704 + /**
  705 + * Return point feature given a point WKT fragment.
  706 + * @param str {String} A WKT fragment representing the point
  707 + * @memberof this.Wkt.Wkt.ingest
  708 + * @instance
  709 + */
  710 + point: function (str) {
  711 + var coords = Wkt.trim(str).split(this.regExes.spaces);
  712 + // In case a parenthetical group of coordinates is passed...
  713 + return [{ // ...Search for numeric substrings
  714 + x: parseFloat(this.regExes.numeric.exec(coords[0])[0]),
  715 + y: parseFloat(this.regExes.numeric.exec(coords[1])[0])
  716 + }];
  717 + },
  718 +
  719 + /**
  720 + * Return a multipoint feature given a multipoint WKT fragment.
  721 + * @param str {String} A WKT fragment representing the multipoint
  722 + * @memberof this.Wkt.Wkt.ingest
  723 + * @instance
  724 + */
  725 + multipoint: function (str) {
  726 + var i, components, points;
  727 + components = [];
  728 + points = Wkt.trim(str).split(this.regExes.comma);
  729 + for (i = 0; i < points.length; i += 1) {
  730 + components.push(this.ingest.point.apply(this, [points[i]]));
  731 + }
  732 + return components;
  733 + },
  734 +
  735 + /**
  736 + * Return a linestring feature given a linestring WKT fragment.
  737 + * @param str {String} A WKT fragment representing the linestring
  738 + * @memberof this.Wkt.Wkt.ingest
  739 + * @instance
  740 + */
  741 + linestring: function (str) {
  742 + var i, multipoints, components;
  743 +
  744 + // In our x-and-y representation of components, parsing
  745 + // multipoints is the same as parsing linestrings
  746 + multipoints = this.ingest.multipoint.apply(this, [str]);
  747 +
  748 + // However, the points need to be joined
  749 + components = [];
  750 + for (i = 0; i < multipoints.length; i += 1) {
  751 + components = components.concat(multipoints[i]);
  752 + }
  753 + return components;
  754 + },
  755 +
  756 + /**
  757 + * Return a multilinestring feature given a multilinestring WKT fragment.
  758 + * @param str {String} A WKT fragment representing the multilinestring
  759 + * @memberof this.Wkt.Wkt.ingest
  760 + * @instance
  761 + */
  762 + multilinestring: function (str) {
  763 + var i, components, line, lines;
  764 + components = [];
  765 +
  766 + lines = Wkt.trim(str).split(this.regExes.doubleParenComma);
  767 + if (lines.length === 1) { // If that didn't work...
  768 + lines = Wkt.trim(str).split(this.regExes.parenComma);
  769 + }
  770 +
  771 + for (i = 0; i < lines.length; i += 1) {
  772 + line = lines[i].replace(this.regExes.trimParens, '$1');
  773 + components.push(this.ingest.linestring.apply(this, [line]));
  774 + }
  775 +
  776 + return components;
  777 + },
  778 +
  779 + /**
  780 + * Return a polygon feature given a polygon WKT fragment.
  781 + * @param str {String} A WKT fragment representing the polygon
  782 + * @memberof this.Wkt.Wkt.ingest
  783 + * @instance
  784 + */
  785 + polygon: function (str) {
  786 + var i, j, components, subcomponents, ring, rings;
  787 + rings = Wkt.trim(str).split(this.regExes.parenComma);
  788 + components = []; // Holds one or more rings
  789 + for (i = 0; i < rings.length; i += 1) {
  790 + ring = rings[i].replace(this.regExes.trimParens, '$1').split(this.regExes.comma);
  791 + subcomponents = []; // Holds the outer ring and any inner rings (holes)
  792 + for (j = 0; j < ring.length; j += 1) {
  793 + // Split on the empty space or '+' character (between coordinates)
  794 + var split=ring[j].split(this.regExes.spaces);
  795 + if(split.length>2){
  796 + //remove the elements which are blanks
  797 + split = split.filter(function(n){ return n != "" });
  798 + }
  799 + if(split.length===2){
  800 + var x_cord=split[0];
  801 + var y_cord=split[1];
  802 +
  803 + //now push
  804 + subcomponents.push({
  805 + x: parseFloat(x_cord),
  806 + y: parseFloat(y_cord)
  807 + });
  808 + }
  809 + }
  810 + components.push(subcomponents);
  811 + }
  812 + return components;
  813 + },
  814 +
  815 + /**
  816 + * Return box vertices (which would become the Rectangle bounds) given a Box WKT fragment.
  817 + * @param str {String} A WKT fragment representing the box
  818 + * @memberof this.Wkt.Wkt.ingest
  819 + * @instance
  820 + */
  821 + box: function (str) {
  822 + var i, multipoints, components;
  823 +
  824 + // In our x-and-y representation of components, parsing
  825 + // multipoints is the same as parsing linestrings
  826 + multipoints = this.ingest.multipoint.apply(this, [str]);
  827 +
  828 + // However, the points need to be joined
  829 + components = [];
  830 + for (i = 0; i < multipoints.length; i += 1) {
  831 + components = components.concat(multipoints[i]);
  832 + }
  833 +
  834 + return components;
  835 + },
  836 +
  837 + /**
  838 + * Return a multipolygon feature given a multipolygon WKT fragment.
  839 + * @param str {String} A WKT fragment representing the multipolygon
  840 + * @memberof this.Wkt.Wkt.ingest
  841 + * @instance
  842 + */
  843 + multipolygon: function (str) {
  844 + var i, components, polygon, polygons;
  845 + components = [];
  846 + polygons = Wkt.trim(str).split(this.regExes.doubleParenComma);
  847 + for (i = 0; i < polygons.length; i += 1) {
  848 + polygon = polygons[i].replace(this.regExes.trimParens, '$1');
  849 + components.push(this.ingest.polygon.apply(this, [polygon]));
  850 + }
  851 + return components;
  852 + },
  853 +
  854 + /**
  855 + * Return an array of features given a geometrycollection WKT fragment.
  856 + * @param str {String} A WKT fragment representing the geometry collection
  857 + * @memberof this.Wkt.Wkt.ingest
  858 + * @instance
  859 + */
  860 + geometrycollection: function (str) {
  861 + console.log('The geometrycollection WKT type is not yet supported.');
  862 + }
  863 +
  864 + }; // eo ingest
  865 +
  866 + return this;
  867 +}(this));
  868 +
... ...