@@ -447,7 +447,7 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
447
447
if ( geojson . type == null ) {
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" ) {
453
453
OpenLayers . Console . error ( "FeatureCollection only supports collections of features: " + element ) ;
@@ -469,7 +469,7 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
469
469
} else if ( obj instanceof OpenLayers . Feature . Vector ) {
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
}
475
475
return OpenLayers . Format . JSON . prototype . write . apply ( this ,
@@ -479,27 +479,36 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
479
479
/**
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 ( / e p s g : / 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" : {
491
499
"urn" : "urn:ogc:def:crs:OGC:1.3:CRS84"
492
500
}
493
501
} ;
494
502
} else {
495
- geojson . crs = {
503
+ crs = {
496
504
"type" : "EPSG" ,
497
505
"properties" : {
498
506
"code" : code
499
507
}
500
508
} ;
501
509
}
502
510
}
511
+ return crs ;
503
512
} ,
504
513
505
514
/**
0 commit comments