Commit b9a99284f31ff92dfa7f24366b7401b3edf8207c
1 parent
17aeead2
Exists in
master
and in
7 other branches
Atualização do pacote wiket
Showing
3 changed files
with
0 additions
and
759 deletions
Show diff stats
pacotes/wicket/wicket-gmap3.src.js
... | ... | @@ -1,313 +0,0 @@ |
1 | -/*global Wkt, google, document, window, console*/ | |
2 | -google.maps.Marker.prototype.type = 'marker'; | |
3 | -google.maps.Polyline.prototype.type = 'polyline'; | |
4 | -google.maps.Polygon.prototype.type = 'polygon'; | |
5 | -google.maps.Rectangle.prototype.type = 'rectangle'; | |
6 | -google.maps.Circle.prototype.type = 'circle'; | |
7 | - | |
8 | -/** | |
9 | - * An object of framework-dependent construction methods used to generate | |
10 | - * objects belonging to the various geometry classes of the framework. | |
11 | - */ | |
12 | -Wkt.Wkt.prototype.construct = { | |
13 | - /** | |
14 | - * Creates the framework's equivalent point geometry object. | |
15 | - * @param config {Object} An optional properties hash the object should use | |
16 | - * @param component {Object} An optional component to build from | |
17 | - * @return {google.maps.Marker} | |
18 | - */ | |
19 | - 'point': function (config, component) { | |
20 | - var c = component || this.components; | |
21 | - | |
22 | - config = config || {}; | |
23 | - | |
24 | - config.position = new google.maps.LatLng(c[0].y, c[0].x); | |
25 | - | |
26 | - return new google.maps.Marker(config); | |
27 | - }, | |
28 | - | |
29 | - /** | |
30 | - * Creates the framework's equivalent multipoint geometry object. | |
31 | - * @param config {Object} An optional properties hash the object should use | |
32 | - * @return {Array} Array containing multiple google.maps.Marker | |
33 | - */ | |
34 | - 'multipoint': function (config) { | |
35 | - var i, c, arr; | |
36 | - | |
37 | - c = this.components; | |
38 | - | |
39 | - config = config || {}; | |
40 | - | |
41 | - arr = []; | |
42 | - | |
43 | - for (i = 0; i < c.length; i += 1) { | |
44 | - arr.push(this.construct.point(config, c[i])); | |
45 | - } | |
46 | - | |
47 | - return arr; | |
48 | - }, | |
49 | - | |
50 | - /** | |
51 | - * Creates the framework's equivalent multipoint geometry object. | |
52 | - * @param config {Object} An optional properties hash the object should use | |
53 | - * @param component {Object} An optional component to build from | |
54 | - * @return {google.maps.Polyline} | |
55 | - */ | |
56 | - 'linestring': function (config, component) { | |
57 | - var i, c; | |
58 | - | |
59 | - c = component || this.components; | |
60 | - | |
61 | - config = config || { | |
62 | - editable: false | |
63 | - }; | |
64 | - | |
65 | - config.path = []; | |
66 | - | |
67 | - for (i = 0; i < c.length; i += 1) { | |
68 | - config.path.push(new google.maps.LatLng(c[i].y, c[i].x)); | |
69 | - } | |
70 | - | |
71 | - return new google.maps.Polyline(config); | |
72 | - }, | |
73 | - | |
74 | - /** | |
75 | - * Creates the framework's equivalent multilinestring geometry object. | |
76 | - * @param config {Object} An optional properties hash the object should use | |
77 | - * @return {Array} Array containing multiple google.maps.Polyline instances | |
78 | - */ | |
79 | - 'multilinestring': function (config) { | |
80 | - var i, c, arr; | |
81 | - | |
82 | - c = this.components; | |
83 | - | |
84 | - config = config || { | |
85 | - editable: false | |
86 | - }; | |
87 | - | |
88 | - config.path = []; | |
89 | - | |
90 | - arr = []; | |
91 | - | |
92 | - for (i = 0; i < c.length; i += 1) { | |
93 | - arr.push(this.construct.linestring(config, c[i])); | |
94 | - } | |
95 | - | |
96 | - return arr; | |
97 | - }, | |
98 | - | |
99 | - /** | |
100 | - * Creates the framework's equivalent polygon geometry object. | |
101 | - * @param config {Object} An optional properties hash the object should use | |
102 | - * @return {google.maps.Polygon} | |
103 | - */ | |
104 | - 'polygon': function (config) { | |
105 | - var j, k, c, rings, verts; | |
106 | - | |
107 | - c = this.components; | |
108 | - | |
109 | - config = config || { | |
110 | - editable: false // Editable geometry off by default | |
111 | - }; | |
112 | - | |
113 | - config.paths = []; | |
114 | - | |
115 | - rings = []; | |
116 | - for (j = 0; j < c.length; j += 1) { // For each ring... | |
117 | - | |
118 | - verts = []; | |
119 | - for (k = 0; k < c[j].length; k += 1) { // For each vertex... | |
120 | - verts.push(new google.maps.LatLng(c[j][k].y, c[j][k].x)); | |
121 | - | |
122 | - } // eo for each vertex | |
123 | - | |
124 | - if (j !== 0) { // Reverse the order of coordinates in inner rings | |
125 | - if (config.reverseInnerPolygons == null || config.reverseInnerPolygons) { | |
126 | - verts.reverse(); | |
127 | - } | |
128 | - } | |
129 | - | |
130 | - rings.push(verts); | |
131 | - } // eo for each ring | |
132 | - | |
133 | - config.paths = config.paths.concat(rings); | |
134 | - | |
135 | - if (this.isRectangle) { | |
136 | - console.log('Rectangles are not yet supported; set the isRectangle property to false (default).'); | |
137 | - } else { | |
138 | - return new google.maps.Polygon(config); | |
139 | - } | |
140 | - }, | |
141 | - | |
142 | - /** | |
143 | - * Creates the framework's equivalent multipolygon geometry object. | |
144 | - * @param config {Object} An optional properties hash the object should use | |
145 | - * @return {Array} Array containing multiple google.maps.Polygon | |
146 | - */ | |
147 | - 'multipolygon': function (config) { | |
148 | - var i, j, k, c, rings, verts; | |
149 | - | |
150 | - c = this.components; | |
151 | - | |
152 | - config = config || { | |
153 | - editable: false // Editable geometry off by default | |
154 | - }; | |
155 | - | |
156 | - config.paths = []; // Must ensure this property is available | |
157 | - | |
158 | - for (i = 0; i < c.length; i += 1) { // For each polygon... | |
159 | - | |
160 | - rings = []; | |
161 | - for (j = 0; j < c[i].length; j += 1) { // For each ring... | |
162 | - | |
163 | - verts = []; | |
164 | - for (k = 0; k < c[i][j].length; k += 1) { // For each vertex... | |
165 | - verts.push(new google.maps.LatLng(c[i][j][k].y, c[i][j][k].x)); | |
166 | - | |
167 | - } // eo for each vertex | |
168 | - | |
169 | -/* // This is apparently not needed in multipolygon cases | |
170 | - if (j !== 0) { // Reverse the order of coordinates in inner rings | |
171 | - verts.reverse(); | |
172 | - } | |
173 | -*/ | |
174 | - rings.push(verts); | |
175 | - } // eo for each ring | |
176 | - | |
177 | - config.paths = config.paths.concat(rings); | |
178 | - | |
179 | - } // eo for each polygon | |
180 | - | |
181 | - return new google.maps.Polygon(config); | |
182 | - } | |
183 | - | |
184 | -}; | |
185 | - | |
186 | -/** | |
187 | - * A framework-dependent deconstruction method used to generate internal | |
188 | - * geometric representations from instances of framework geometry. This method | |
189 | - * uses object detection to attempt to classify members of framework geometry | |
190 | - * classes into the standard WKT types. | |
191 | - * @param obj {Object} An instance of one of the framework's geometry classes | |
192 | - * @return {Object} A hash of the 'type' and 'components' thus derived | |
193 | - */ | |
194 | -Wkt.Wkt.prototype.deconstruct = function (obj) { | |
195 | - var i, j, verts, rings, tmp; | |
196 | - | |
197 | - // google.maps.Marker ////////////////////////////////////////////////////// | |
198 | - if (obj.getPosition && typeof obj.getPosition === 'function') { | |
199 | - // Only Markers, among all overlays, have the getPosition property | |
200 | - | |
201 | - return { | |
202 | - type: 'point', | |
203 | - components: [{ | |
204 | - x: obj.getPosition().lng(), | |
205 | - y: obj.getPosition().lat() | |
206 | - }] | |
207 | - }; | |
208 | - | |
209 | - // google.maps.Polyline //////////////////////////////////////////////////// | |
210 | - } else if (obj.getPath && !obj.getPaths) { | |
211 | - // Polylines have a single path (getPath) not paths (getPaths) | |
212 | - | |
213 | - verts = []; | |
214 | - for (i = 0; i < obj.getPath().length; i += 1) { | |
215 | - tmp = obj.getPath().getAt(i); | |
216 | - verts.push({ | |
217 | - x: tmp.lng(), | |
218 | - y: tmp.lat() | |
219 | - }); | |
220 | - } | |
221 | - | |
222 | - return { | |
223 | - type: 'linestring', | |
224 | - components: verts | |
225 | - }; | |
226 | - | |
227 | - // google.maps.Polygon ///////////////////////////////////////////////////// | |
228 | - } else if (obj.getPaths) { | |
229 | - // Polygon is the only class with the getPaths property | |
230 | - | |
231 | - // TODO Polygons with holes cannot be distinguished from multipolygons | |
232 | - rings = []; | |
233 | - for (i = 0; i < obj.getPaths().length; i += 1) { // For each polygon (ring)... | |
234 | - tmp = obj.getPaths().getAt(i); | |
235 | - | |
236 | - verts = []; | |
237 | - for (j = 0; j < obj.getPaths().getAt(i).length; j += 1) { // For each vertex... | |
238 | - verts.push({ | |
239 | - x: tmp.getAt(j).lng(), | |
240 | - y: tmp.getAt(j).lat() | |
241 | - }); | |
242 | - } | |
243 | - | |
244 | - verts.push({ // Add the first coordinate again for closure | |
245 | - x: tmp.getAt(0).lng(), | |
246 | - y: tmp.getAt(0).lat() | |
247 | - }); | |
248 | - | |
249 | - // Since we can't distinguish between single polygons with holes | |
250 | - // and multipolygons, we always create multipolygons | |
251 | - if (obj.getPaths().length > 1) { | |
252 | - verts = [verts]; // Wrap multipolygons once more (collection) | |
253 | - } | |
254 | - | |
255 | - rings.push(verts); | |
256 | - } | |
257 | - | |
258 | - return { | |
259 | - type: 'polygon', | |
260 | - components: rings | |
261 | - }; | |
262 | - | |
263 | - // google.maps.Rectangle /////////////////////////////////////////////////// | |
264 | - } else if (obj.getBounds && !obj.getRadius) { | |
265 | - // Rectangle is only overlay class with getBounds property and not getRadius property | |
266 | - | |
267 | - tmp = obj.getBounds(); | |
268 | - return { | |
269 | - type: 'polygon', | |
270 | - isRectangle: true, | |
271 | - components: [ | |
272 | - [ | |
273 | - { // NW corner | |
274 | - x: tmp.getSouthWest().lng(), | |
275 | - y: tmp.getNorthEast().lat() | |
276 | - }, | |
277 | - { // NE corner | |
278 | - x: tmp.getNorthEast().lng(), | |
279 | - y: tmp.getNorthEast().lat() | |
280 | - }, | |
281 | - { // SE corner | |
282 | - x: tmp.getNorthEast().lng(), | |
283 | - y: tmp.getSouthWest().lat() | |
284 | - }, | |
285 | - { // SW corner | |
286 | - x: tmp.getSouthWest().lng(), | |
287 | - y: tmp.getSouthWest().lat() | |
288 | - }, | |
289 | - { // NW corner (again, for closure) | |
290 | - x: tmp.getSouthWest().lng(), | |
291 | - y: tmp.getNorthEast().lat() | |
292 | - } | |
293 | - ] | |
294 | - ] | |
295 | - }; | |
296 | - | |
297 | - // google.maps.Circle ////////////////////////////////////////////////////// | |
298 | - } else if (obj.getBounds && obj.getRadius) { | |
299 | - // Circle is the only overlay class with both the getBounds and getRadius properties | |
300 | - | |
301 | - console.log('Deconstruction of google.maps.Circle objects is not yet supported'); | |
302 | - | |
303 | - } else { | |
304 | - console.log('The passed object does not have any recognizable properties.'); | |
305 | - } | |
306 | - | |
307 | -}; | |
308 | - | |
309 | -/** | |
310 | - * A framework-dependent flag, set for each Wkt.Wkt() instance, that indicates | |
311 | - * whether or not a closed polygon geometry should be interpreted as a rectangle. | |
312 | - */ | |
313 | -Wkt.Wkt.prototype.isRectangle = false; |
pacotes/wicket/wicket-leaflet.src.js
... | ... | @@ -1,61 +0,0 @@ |
1 | -Wkt.Wkt.prototype.isRectangle = false; | |
2 | - | |
3 | -Wkt.Wkt.prototype.construct = { | |
4 | - point: function (config, component) { | |
5 | - var coord = component || this.components; | |
6 | - if (coord instanceof Array) { | |
7 | - coord = coord[0]; | |
8 | - } | |
9 | - | |
10 | - return L.marker(this.coordsToLatLng(coord), config); | |
11 | - }, | |
12 | - | |
13 | - multipoint: function (config) { | |
14 | - var layers = [], | |
15 | - coords = this.components, | |
16 | - latlng; | |
17 | - | |
18 | - for (var i = 0, len = coords.length; i < len; i++) { | |
19 | - layers.push(this.construct.point.call(this, config, coords[i])); | |
20 | - } | |
21 | - | |
22 | - return L.featureGroup(layers, config); | |
23 | - }, | |
24 | - | |
25 | - linestring: function (config, component) { | |
26 | - var coords = component || this.components, | |
27 | - latlngs = this.coordsToLatLngs(coords); | |
28 | - | |
29 | - return L.polyLine(latlngs); | |
30 | - }, | |
31 | - | |
32 | - multilinestring: function (config) { | |
33 | - var coords = this.components, | |
34 | - latlngs = this.coordsToLatLngs(coords, 1); | |
35 | - | |
36 | - return L.multiPolyline(latlngs); | |
37 | - }, | |
38 | - | |
39 | - polygon: function (config) { | |
40 | - var coords = this.components, | |
41 | - latlngs = this.coordsToLatLngs(coords, 1); | |
42 | - return L.polygon(latlngs); | |
43 | - }, | |
44 | - | |
45 | - multipolygon: function (config) { | |
46 | - var coords = this.components, | |
47 | - latlngs = this.coordsToLatLngs(coords, 2); | |
48 | - | |
49 | - return L.multiPolygon(latlngs); | |
50 | - } | |
51 | -}; | |
52 | - | |
53 | -L.Util.extend(Wkt.Wkt.prototype, { | |
54 | - coordsToLatLngs: L.GeoJSON.coordsToLatLngs, | |
55 | - coordsToLatLng: function (coords, reverse) { | |
56 | - var lat = reverse ? coords.x : coords.y, | |
57 | - lng = reverse ? coords.y : coords.x; | |
58 | - | |
59 | - return L.latLng(lat, lng, true); | |
60 | - } | |
61 | -}); |
pacotes/wicket/wicket.src.js
... | ... | @@ -1,385 +0,0 @@ |
1 | -/*global console, document, window*/ | |
2 | -/** | |
3 | - * @author K. Arthur Endsley <arthur.endsley@gmail.com> | |
4 | - */ | |
5 | -var Wkt = (function () { // Execute function immediately | |
6 | - | |
7 | - return { | |
8 | - // The default delimiter for separating components of atomic geometry (coordinates) | |
9 | - delimiter: ' ', | |
10 | - | |
11 | - isArray: function (obj) { | |
12 | - return !!(obj && obj.constructor == Array); | |
13 | - }, | |
14 | - | |
15 | - /** | |
16 | - * An object for reading WKT strings and writing geographic features | |
17 | - * @param {String} An optional WKT string for immediate read | |
18 | - * @param {Wkt.Wkt} A WKT object | |
19 | - */ | |
20 | - Wkt: function (initializer) { | |
21 | - var beginsWith, endsWith, trim; | |
22 | - | |
23 | - /** | |
24 | - * @private | |
25 | - */ | |
26 | - beginsWith = function (str, sub) { | |
27 | - return str.substring(0, sub.length) === sub; | |
28 | - }; | |
29 | - | |
30 | - /** | |
31 | - * @private | |
32 | - */ | |
33 | - endsWith = function (str, sub) { | |
34 | - return str.substring(str.length - sub.length) === sub; | |
35 | - }; | |
36 | - | |
37 | - /** | |
38 | - * @private | |
39 | - */ | |
40 | - trim = function (str, sub) { | |
41 | - sub = sub || ' '; // Defaults to trimming spaces | |
42 | - // Trim beginning spaces | |
43 | - while (beginsWith(str, sub)) { | |
44 | - str = str.substring(1); | |
45 | - } | |
46 | - // Trim ending spaces | |
47 | - while (endsWith(str, sub)) { | |
48 | - str = str.substring(0, str.length - 1); | |
49 | - } | |
50 | - return str; | |
51 | - }; | |
52 | - | |
53 | - /** | |
54 | - * The default delimiter between X and Y coordinates. | |
55 | - */ | |
56 | - this.delimiter = Wkt.delimiter; | |
57 | - | |
58 | - /** | |
59 | - * Some regular expressions copied from OpenLayers.Format.WKT.js | |
60 | - */ | |
61 | - this.regExes = { | |
62 | - 'typeStr': /^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/, | |
63 | - 'spaces': /\s+|\+/, // Matches the '+' or the empty space | |
64 | - 'numeric': /-*\d+\.*\d+/, | |
65 | - 'comma': /\s*,\s*/, | |
66 | - 'parenComma': /\)\s*,\s*\(/, | |
67 | - 'doubleParenComma': /\)\s*\)\s*,\s*\(\s*\(/, | |
68 | - 'trimParens': /^\s*\(?(.*?)\)?\s*$/ | |
69 | - }; | |
70 | - | |
71 | - /** | |
72 | - * Returns true if the internal geometry is a collection of geometries. | |
73 | - * @return {Boolean} Returns true when it is a collection | |
74 | - */ | |
75 | - this.isCollection = function () { | |
76 | - switch (this.type.slice(0, 5)) { | |
77 | - case 'multi': | |
78 | - // Trivial; any multi-geometry is a collection | |
79 | - return true; | |
80 | - case 'polyg': | |
81 | - // Polygons with holes are "collections" of rings | |
82 | - return true; | |
83 | - default: | |
84 | - // Any other geometry is not a collection | |
85 | - return false; | |
86 | - } | |
87 | - }; | |
88 | - | |
89 | - /** | |
90 | - * The internal representation of geometry--the "components" of geometry. | |
91 | - */ | |
92 | - this.components = undefined; | |
93 | - | |
94 | - /** | |
95 | - * Sets internal geometry (components) from framework geometry (e.g. | |
96 | - * Google Polygon objects or google.maps.Polygon). | |
97 | - * @param obj {Object} The framework-dependent geometry representation | |
98 | - * @return {Wkt.Wkt} The object itself | |
99 | - */ | |
100 | - this.fromObject = function (obj) { | |
101 | - var result = this.deconstruct.call(this, obj); | |
102 | - this.components = result.components; | |
103 | - this.isRectangle = result.isRectangle || false; | |
104 | - this.type = result.type; | |
105 | - return this; | |
106 | - }; | |
107 | - | |
108 | - /** | |
109 | - * Creates external geometry objects based on a plug-in framework's | |
110 | - * construction methods and available geometry classes. | |
111 | - * @param config {Object} An optional framework-dependent properties specification | |
112 | - * @return {Object} The framework-dependent geometry representation | |
113 | - */ | |
114 | - this.toObject = function (config) { | |
115 | - return this.construct[this.type].call(this, config); | |
116 | - }; | |
117 | - | |
118 | - /** | |
119 | - * Reads a WKT string, validating and incorporating it. | |
120 | - * @param wkt {String} A WKT string | |
121 | - * @return {Array} An Array of internal geometry objects | |
122 | - */ | |
123 | - this.read = function (wkt) { | |
124 | - var matches; | |
125 | - matches = this.regExes.typeStr.exec(wkt); | |
126 | - if (matches) { | |
127 | - this.type = matches[1].toLowerCase(); | |
128 | - this.base = matches[2]; | |
129 | - if (this.ingest[this.type]) { | |
130 | - this.components = this.ingest[this.type].apply(this, [this.base]); | |
131 | - } | |
132 | - } else { | |
133 | - console.log("Invalid WKT string provided to read()"); | |
134 | - throw { | |
135 | - name: "WKTError", | |
136 | - message: "Invalid WKT string provided to read()" | |
137 | - } | |
138 | - } | |
139 | - return this.components; | |
140 | - }; // eo readWkt | |
141 | - | |
142 | - /** | |
143 | - * Writes a WKT string. | |
144 | - * @param components {Array} An Array of internal geometry objects | |
145 | - * @return {String} The corresponding WKT representation | |
146 | - */ | |
147 | - this.write = function (components) { | |
148 | - var i, pieces, data; | |
149 | - | |
150 | - components = components || this.components; | |
151 | - | |
152 | - pieces = []; | |
153 | - | |
154 | - pieces.push(this.type.toUpperCase() + '('); | |
155 | - | |
156 | - for (i = 0; i < components.length; i += 1) { | |
157 | - if (this.isCollection() && i > 0) { | |
158 | - pieces.push(','); | |
159 | - } | |
160 | - | |
161 | - // There should be an extract function for the named type | |
162 | - if (!this.extract[this.type]) { | |
163 | - return null; | |
164 | - } | |
165 | -//original | |
166 | -//data = this.extract[this.type].apply(this, [components[i]]); | |
167 | -//alterado por edmar | |
168 | - if(components[i].length == 1){ | |
169 | - data = this.extract[this.type].apply(this, [components[i][0]]); | |
170 | - } | |
171 | - else{ | |
172 | - data = this.extract[this.type].apply(this, [components[i]]); | |
173 | - } | |
174 | - if (this.isCollection()) { | |
175 | - pieces.push('(' + data + ')'); | |
176 | - } else { | |
177 | - pieces.push(data); | |
178 | - // If not at the end of the components, add a comma | |
179 | - if (i !== components.length - 1) { | |
180 | - pieces.push(','); | |
181 | - } | |
182 | - } | |
183 | - } | |
184 | - | |
185 | - pieces.push(')'); | |
186 | - | |
187 | - return pieces.join(''); | |
188 | - }; | |
189 | - | |
190 | - /** | |
191 | - * This object contains functions as property names that extract WKT | |
192 | - * strings from the internal representation. | |
193 | - */ | |
194 | - this.extract = { | |
195 | - /** | |
196 | - * Return a WKT string representing atomic (point) geometry | |
197 | - * @param point {Object} An object with x and y properties | |
198 | - * @return {String} The WKT representation | |
199 | - */ | |
200 | - 'point': function (point) { | |
201 | - return point.x + this.delimiter + point.y; | |
202 | - }, | |
203 | - /** | |
204 | - * Return a WKT string representing multiple atoms (points) | |
205 | - * @param point {Array} Multiple x-and-y objects | |
206 | - * @return {String} The WKT representation | |
207 | - */ | |
208 | - 'multipoint': function (multipoint) { | |
209 | - var i, parts = []; | |
210 | - for (i = 0; i < multipoint.length; i += 1) { | |
211 | - parts.push(this.extract.point.apply(this, [multipoint[i]])); | |
212 | - } | |
213 | - return parts.join(','); | |
214 | - }, | |
215 | - /** | |
216 | - * Return a WKT string representing a chain (linestring) of atoms | |
217 | - * @param point {Array} Multiple x-and-y objects | |
218 | - * @return {String} The WKT representation | |
219 | - */ | |
220 | - 'linestring': function (linestring) { | |
221 | - // Extraction of linestrings is the same as for points | |
222 | - return this.extract.point.apply(this, [linestring]); | |
223 | - }, | |
224 | - /** | |
225 | - * Return a WKT string representing multiple chains (multilinestring) of atoms | |
226 | - * @param point {Array} Multiple of multiple x-and-y objects | |
227 | - * @return {String} The WKT representation | |
228 | - */ | |
229 | - 'multilinestring': function (multilinestring) { | |
230 | - var i, parts = []; | |
231 | - for (i = 0; i < multilinestring.length; i += 1) { | |
232 | - parts.push('(' + this.extract.linestring.apply(this, [multilinestring[i]]) + ')'); | |
233 | - } | |
234 | - return parts.join(','); | |
235 | - }, | |
236 | - /** | |
237 | - * Return a WKT string representing multiple atoms in closed series (polygon) | |
238 | - * @param point {Array} Collection of ordered x-and-y objects | |
239 | - * @return {String} The WKT representation | |
240 | - */ | |
241 | - 'polygon': function (polygon) { | |
242 | - // Extraction of polygons is the same as for multipoints | |
243 | - return this.extract.multipoint.apply(this, [polygon]); | |
244 | - }, | |
245 | - /** | |
246 | - * Return a WKT string representing multiple closed series (multipolygons) of multiple atoms | |
247 | - * @param point {Array} Collection of ordered x-and-y objects | |
248 | - * @return {String} The WKT representation | |
249 | - */ | |
250 | - 'multipolygon': function (multipolygon) { | |
251 | - var i, parts = []; | |
252 | - for (i = 0; i < multipolygon.length; i += 1) { | |
253 | - parts.push('(' + this.extract.polygon.apply(this, [multipolygon[i]]) + ')'); | |
254 | - } | |
255 | - return parts.join(','); | |
256 | - } | |
257 | - }; | |
258 | - | |
259 | - /** | |
260 | - * This object contains functions as property names that ingest WKT | |
261 | - * strings into the internal representation. | |
262 | - */ | |
263 | - this.ingest = { | |
264 | - | |
265 | - /** | |
266 | - * Return point feature given a point WKT fragment. | |
267 | - * @param str {String} A WKT fragment representing the point | |
268 | - */ | |
269 | - 'point': function (str) { | |
270 | - var coords = trim(str).split(this.regExes.spaces); | |
271 | - // In case a parenthetical group of coordinates is passed... | |
272 | - return [{ // ...Search for numeric substrings | |
273 | - x: parseFloat(this.regExes.numeric.exec(coords[0])[0]), | |
274 | - y: parseFloat(this.regExes.numeric.exec(coords[1])[0]) | |
275 | - }]; | |
276 | - }, | |
277 | - | |
278 | - /** | |
279 | - * Return a multipoint feature given a multipoint WKT fragment. | |
280 | - * @param str {String} A WKT fragment representing the multipoint | |
281 | - */ | |
282 | - 'multipoint': function (str) { | |
283 | - var i, components, points; | |
284 | - components = []; | |
285 | - points = trim(str).split(this.regExes.comma); | |
286 | - for (i = 0; i < points.length; i += 1) { | |
287 | - components.push(this.ingest.point.apply(this, [points[i]])); | |
288 | - } | |
289 | - return components; | |
290 | - }, | |
291 | - | |
292 | - /** | |
293 | - * Return a linestring feature given a linestring WKT fragment. | |
294 | - * @param str {String} A WKT fragment representing the linestring | |
295 | - */ | |
296 | - 'linestring': function (str) { | |
297 | - var i, multipoints, components; | |
298 | - | |
299 | - // In our x-and-y representation of components, parsing | |
300 | - // multipoints is the same as parsing linestrings | |
301 | - multipoints = this.ingest.multipoint.apply(this, [str]); | |
302 | - | |
303 | - // However, the points need to be joined | |
304 | - components = []; | |
305 | - for (i = 0; i < multipoints.length; i += 1) { | |
306 | - components = components.concat(multipoints[i]); | |
307 | - } | |
308 | - return components; | |
309 | - }, | |
310 | - | |
311 | - /** | |
312 | - * Return a multilinestring feature given a multilinestring WKT fragment. | |
313 | - * @param str {String} A WKT fragment representing the multilinestring | |
314 | - */ | |
315 | - 'multilinestring': function (str) { | |
316 | - var i, components, line, lines; | |
317 | - components = []; | |
318 | - lines = trim(str).split(this.regExes.parenComma); | |
319 | - for (i = 0; i < lines.length; i += 1) { | |
320 | - line = lines[i].replace(this.regExes.trimParens, '$1'); | |
321 | - components.push(this.ingest.linestring.apply(this, [line])); | |
322 | - } | |
323 | - return components; | |
324 | - }, | |
325 | - | |
326 | - /** | |
327 | - * Return a polygon feature given a polygon WKT fragment. | |
328 | - * @param str {String} A WKT fragment representing the polygon | |
329 | - */ | |
330 | - 'polygon': function (str) { | |
331 | - var i, j, components, subcomponents, ring, rings; | |
332 | - rings = trim(str).split(this.regExes.parenComma); | |
333 | - components = []; // Holds one or more rings | |
334 | - for (i = 0; i < rings.length; i += 1) { | |
335 | - ring = rings[i].replace(this.regExes.trimParens, '$1').split(this.regExes.comma); | |
336 | - subcomponents = []; // Holds the outer ring and any inner rings (holes) | |
337 | - for (j = 0; j < ring.length; j += 1) { | |
338 | - // Split on the empty space or '+' character (between coordinates) | |
339 | - subcomponents.push({ | |
340 | - x: parseFloat(ring[j].split(this.regExes.spaces)[0]), | |
341 | - y: parseFloat(ring[j].split(this.regExes.spaces)[1]) | |
342 | - }); | |
343 | - } | |
344 | - components.push(subcomponents); | |
345 | - } | |
346 | - return components; | |
347 | - }, | |
348 | - | |
349 | - /** | |
350 | - * Return a multipolygon feature given a multipolygon WKT fragment. | |
351 | - * @param str {String} A WKT fragment representing the multipolygon | |
352 | - */ | |
353 | - 'multipolygon': function (str) { | |
354 | - var i, components, polygon, polygons; | |
355 | - components = []; | |
356 | - polygons = trim(str).split(this.regExes.doubleParenComma); | |
357 | - for (i = 0; i < polygons.length; i += 1) { | |
358 | - polygon = polygons[i].replace(this.regExes.trimParens, '$1'); | |
359 | - components.push(this.ingest.polygon.apply(this, [polygon])); | |
360 | - } | |
361 | - return components; | |
362 | - }, | |
363 | - | |
364 | - /** | |
365 | - * Return an array of features given a geometrycollection WKT fragment. | |
366 | - * @param str {String} A WKT fragment representing the geometry collection | |
367 | - */ | |
368 | - 'geometrycollection': function (str) { | |
369 | - console.log('The geometrycollection WKT type is not yet supported.'); | |
370 | - } | |
371 | - | |
372 | - }; // eo ingest | |
373 | - | |
374 | - // An initial WKT string may be provided | |
375 | - if (initializer && typeof initializer === 'string') { | |
376 | - this.read(initializer); | |
377 | - } else if (this.fromGeometry) { // Or, an initial geometry object to be read | |
378 | - this.fromGeometry(initializer); | |
379 | - } | |
380 | - | |
381 | - } // eo WKt.Wkt | |
382 | - | |
383 | - }; // eo return | |
384 | - | |
385 | -}()); // eo Wkt |