Changeset 4830
- Timestamp:
- 10/04/07 18:51:23 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/openlayers/2.5/lib/OpenLayers/Format/GeoJSON.js
r4794 r4830 448 448 geojson.type = "FeatureCollection"; 449 449 if(element.layer && element.layer.projection) { 450 this.createCRSObject(element);450 geojson.crs = this.createCRSObject(element); 451 451 } 452 452 } else if(geojson.type != "FeatureCollection") { … … 470 470 geojson = this.extract.feature.apply(this, [obj]); 471 471 if(obj.layer && obj.layer.projection) { 472 this.createCRSObject(obj);472 geojson.crs = this.createCRSObject(obj); 473 473 } 474 474 } … … 480 480 * Method: createCRSObject 481 481 * Create the CRS object for an object. 482 * 483 * Parameters: 484 * object - {<OpenLayers.Feature.Vector>} 485 * 486 * Returns: 487 * {Object} An object which can be assigned to the crs property 488 * of a GeoJSON object. 482 489 */ 483 490 createCRSObject: function(object) { 484 491 var proj = object.layer.projection; 492 var crs = {} 485 493 if (proj.match(/epsg:/i)) { 486 494 var code = parseInt(proj.substring(proj.indexOf(":") + 1)); 487 495 if (code == 4326) { 488 geojson.crs = {496 crs = { 489 497 "type": "OGC", 490 498 "properties": { … … 493 501 }; 494 502 } else { 495 geojson.crs = {503 crs = { 496 504 "type": "EPSG", 497 505 "properties": { … … 501 509 } 502 510 } 511 return crs; 503 512 }, 504 513 branches/openlayers/2.5/tests/Format/test_GeoJSON.html
r4794 r4830 185 185 } 186 186 187 function test_Format_GeoJSON_writeWithCRS(t) { 188 t.plan(2) 189 var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1,2)); 190 feature.fid = 0; 191 var output = '{"type":"Feature","id":0,"properties":{},"geometry":{"type":"Point","coordinates":[1,2]},"crs":{"type":"OGC","properties":{"urn":"urn:ogc:def:crs:OGC:1.3:CRS84"}}}'; 192 layer = new OpenLayers.Layer.Vector(); 193 layer.projection = "EPSG:4326"; 194 feature.layer = layer; 195 var parser = new OpenLayers.Format.GeoJSON(); 196 test_out = parser.write(feature); 197 t.eq(test_out, output, "Output is equal for vector with layer in EPSG:4326 "); 198 feature.layer.projection = "EPSG:2805"; 199 var output = '{"type":"Feature","id":0,"properties":{},"geometry":{"type":"Point","coordinates":[1,2]},"crs":{"type":"EPSG","properties":{"code":2805}}}'; 200 test_out = parser.write(feature); 201 t.eq(test_out, output, "Output is equal for vector with point"); 202 } 203 187 204 function test_Format_GeoJSON_write(t) { 188 205 t.plan(10);
