Pullup r4819 from trunk: fixing GeoJSON serializer breakage caused by draft4
update. (Closes #1062) git-svn-id: http://svn.openlayers.org/branches/openlayers/2.5@4830 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -447,7 +447,7 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
|
||||
if(geojson.type == null) {
|
||||
geojson.type = "FeatureCollection";
|
||||
if(element.layer && element.layer.projection) {
|
||||
this.createCRSObject(element);
|
||||
geojson.crs = this.createCRSObject(element);
|
||||
}
|
||||
} else if(geojson.type != "FeatureCollection") {
|
||||
OpenLayers.Console.error("FeatureCollection only supports collections of features: " + element);
|
||||
@@ -469,7 +469,7 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
|
||||
} else if (obj instanceof OpenLayers.Feature.Vector) {
|
||||
geojson = this.extract.feature.apply(this, [obj]);
|
||||
if(obj.layer && obj.layer.projection) {
|
||||
this.createCRSObject(obj);
|
||||
geojson.crs = this.createCRSObject(obj);
|
||||
}
|
||||
}
|
||||
return OpenLayers.Format.JSON.prototype.write.apply(this,
|
||||
@@ -479,20 +479,28 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
|
||||
/**
|
||||
* Method: createCRSObject
|
||||
* Create the CRS object for an object.
|
||||
*
|
||||
* Parameters:
|
||||
* object - {<OpenLayers.Feature.Vector>}
|
||||
*
|
||||
* Returns:
|
||||
* {Object} An object which can be assigned to the crs property
|
||||
* of a GeoJSON object.
|
||||
*/
|
||||
createCRSObject: function(object) {
|
||||
var proj = object.layer.projection;
|
||||
var crs = {}
|
||||
if (proj.match(/epsg:/i)) {
|
||||
var code = parseInt(proj.substring(proj.indexOf(":") + 1));
|
||||
if (code == 4326) {
|
||||
geojson.crs = {
|
||||
crs = {
|
||||
"type": "OGC",
|
||||
"properties": {
|
||||
"urn": "urn:ogc:def:crs:OGC:1.3:CRS84"
|
||||
}
|
||||
};
|
||||
} else {
|
||||
geojson.crs = {
|
||||
crs = {
|
||||
"type": "EPSG",
|
||||
"properties": {
|
||||
"code": code
|
||||
@@ -500,6 +508,7 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
|
||||
};
|
||||
}
|
||||
}
|
||||
return crs;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user