Changeset 3156
- Timestamp:
- 05/17/07 14:01:17 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/tschaub/geojson/lib/OpenLayers/Format/GeoJSON.js
r3140 r3156 73 73 throw "Geometry must have coordinates array: " + obj; 74 74 } 75 if(!this.parseCoords[obj.type ]) {75 if(!this.parseCoords[obj.type.toLowerCase()]) { 76 76 throw "Unsupported geometry type: " + obj.type; 77 77 } 78 78 try { 79 geometry = this.parseCoords[obj.type ].apply(this, [obj.coordinates]);79 geometry = this.parseCoords[obj.type.toLowerCase()].apply(this, [obj.coordinates]); 80 80 } catch(err) { 81 81 // deal with bad coordinates … … 97 97 * @private 98 98 */ 99 " Point": function(array) {99 "point": function(array) { 100 100 if(array.length != 1) { 101 101 throw "Bad point coordinates: " + array; … … 104 104 throw "Only 2D points are supported: " + array[0]; 105 105 } 106 // let this [[x, y]] be gone please 106 107 return new OpenLayers.Geometry.Point(array[0][0], array[0][1]); 107 108 }, … … 113 114 * @private 114 115 */ 115 " Line": function(array) {116 "multipoint": function(array) { 116 117 var points = []; 117 118 var p = null; 118 119 for(var i=0; i<array.length; ++i) { 119 p = this.parseCoords[" Point"].apply(this, [[array[i]]]);120 p = this.parseCoords["point"].apply(this, [[array[i]]]); 120 121 points.push(p); 121 122 } 123 return new OpenLayers.Geometry.MultiPoint(points); 124 }, 125 126 /** 127 * Convert a coordinate array from GeoJSON into an OpenLayers.Geometry. 128 * @param {Object} array The coordinates array from the GeoJSON fragment 129 * @returns {OpenLayers.Geometry} A geometry 130 * @private 131 */ 132 "linestring": function(array) { 133 var points = []; 134 var p = null; 135 for(var i=0; i<array.length; ++i) { 136 p = this.parseCoords["point"].apply(this, [[array[i]]]); 137 points.push(p); 138 } 122 139 return new OpenLayers.Geometry.LineString(points); 123 140 }, … … 129 146 * @private 130 147 */ 131 "Polygon": function(array) { 148 "multilinestring": function(array) { 149 var lines = []; 150 var l = null; 151 for(var i=0; i<array.length; ++i) { 152 l = this.parseCoords["linestring"].apply(this, [array[i]]); 153 lines.push(l); 154 } 155 return new OpenLayers.Geometry.MultiLineString(lines); 156 }, 157 158 /** 159 * Convert a coordinate array from GeoJSON into an OpenLayers.Geometry. 160 * @param {Object} array The coordinates array from the GeoJSON fragment 161 * @returns {OpenLayers.Geometry} A geometry 162 * @private 163 */ 164 "polygon": function(array) { 132 165 var rings = []; 133 166 var r, l; 134 167 for(var i=0; i<array.length; ++i) { 135 l = this.parseCoords[" Line"].apply(this, [array[i]]);168 l = this.parseCoords["linestring"].apply(this, [array[i]]); 136 169 r = new OpenLayers.Geometry.LinearRing(l.components); 137 170 rings.push(r); 138 171 } 139 172 return new OpenLayers.Geometry.Polygon(rings); 140 } 173 }, 174 175 /** 176 * Convert a coordinate array from GeoJSON into an OpenLayers.Geometry. 177 * @param {Object} array The coordinates array from the GeoJSON fragment 178 * @returns {OpenLayers.Geometry} A geometry 179 * @private 180 */ 181 "multipolygon": function(array) { 182 var polys = []; 183 var p = null; 184 for(var i=0; i<array.length; ++i) { 185 p = this.parseCoords["polygon"].apply(this, [array[i]]); 186 polys.push(p); 187 } 188 return new OpenLayers.Geometry.MultiPolygon(polys); 189 } 190 141 191 }, 142 192 … … 159 209 type = geometry.CLASS_NAME.split('.')[2]; 160 210 data = this.extract[type.toLowerCase()].apply(this, [geometry]); 161 if (type == "LineString") { 162 type = "Line"; 163 } 164 if (type == "Point") { 211 // please let this go away 212 if(type == "Point") { 165 213 data = [data]; 166 214 } … … 209 257 210 258 /** 211 * Return an array of coordinate arrays from a line .259 * Return an array of coordinate arrays from a linestring. 212 260 * @param {OpenLayers.Geometry.LineString} linestring 213 261 * @returns {Array} An array of coordinate arrays representing … … 223 271 224 272 /** 225 * Return an array of linestring arrays from a line .226 * @param {OpenLayers.Geometry.MultiLineString} line 273 * Return an array of linestring arrays from a linestring. 274 * @param {OpenLayers.Geometry.MultiLineString} linestring 227 275 * @returns {Array} An array of linestring arrays representing 228 276 * the multilinestring
