[OpenLayers-Users] Format.geojson.write - missing crs with
featurecollection
Frank Broniewski
brfr at metrico.lu
Tue May 25 07:37:42 EDT 2010
Hi,
I'm using Format.GeoJSON for talking with my server. When creating new
Features and sending them to my server I saw that OL sends the new
features as a featurecollection object. But there is no crs attached.
Looking at the code, the crs is only attached to instances of
OL.Features.Vector. Featurecollections are typeof array and there's no
crs attachment done in the code. I prepared a small snipped to fix this:
write: function(obj, pretty) {
console.info(obj)
var geojson = {
"type": null
};
if(obj instanceof Array) {
geojson.type = "FeatureCollection";
var numFeatures = obj.length;
geojson.features = new Array(numFeatures);
++ if(obj[0].layer && obj[0].layer.projection) {
++ geojson.crs = this.createCRSObject(obj[0]);
++ }
for(var i=0; i<numFeatures; ++i) {
var element = obj[i];
console.log(element)
if(!element instanceof OpenLayers.Feature.Vector) {
var msg = "FeatureCollection only supports
collections " +
"of features: " + element;
throw msg;
}
geojson.features[i] = this.extract.feature.apply(
this, [element]
);
}
} else if (obj.CLASS_NAME.indexOf("OpenLayers.Geometry") == 0) {
geojson = this.extract.geometry.apply(this, [obj]);
} else if (obj instanceof OpenLayers.Feature.Vector) {
geojson = this.extract.feature.apply(this, [obj]);
if(obj.layer && obj.layer.projection) {
geojson.crs = this.createCRSObject(obj);
}
}
return OpenLayers.Format.JSON.prototype.write.apply(this,
[geojson,
pretty]);
}
I don't know if it is intentionally left out, but I thougth I let
someone know ...
Frank
--
Frank BRONIEWSKI
METRICO s.à r.l.
géomètres
technologies d'information géographique
rue des Romains 36
L-5433 NIEDERDONVEN
tél.: +352 26 74 94 - 28
fax.: +352 26 74 94 99
http://www.metrico.lu
More information about the Users
mailing list