Compare commits
2 Commits
release-2.
...
release-2.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ac845503f | ||
|
|
4f62fdcfc8 |
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
OpenLayers.js -- OpenLayers Map Viewer Library
|
OpenLayers.js -- OpenLayers Map Viewer Library
|
||||||
|
|
||||||
Copyright 2005-2007 MetaCarta, Inc., released under the BSD license.
|
Copyright 2005-2007 MetaCarta, Inc., released under theBSD license.
|
||||||
Please see http://svn.openlayers.org/trunk/openlayers/release-license.txt
|
Please see http://svn.openlayers.org/trunk/openlayers/release-license.txt
|
||||||
for the full text of the license.
|
for the full text of the license.
|
||||||
|
|
||||||
|
|||||||
@@ -447,7 +447,7 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
|
|||||||
if(geojson.type == null) {
|
if(geojson.type == null) {
|
||||||
geojson.type = "FeatureCollection";
|
geojson.type = "FeatureCollection";
|
||||||
if(element.layer && element.layer.projection) {
|
if(element.layer && element.layer.projection) {
|
||||||
this.createCRSObject(element);
|
geojson.crs = this.createCRSObject(element);
|
||||||
}
|
}
|
||||||
} else if(geojson.type != "FeatureCollection") {
|
} else if(geojson.type != "FeatureCollection") {
|
||||||
OpenLayers.Console.error("FeatureCollection only supports collections of features: " + element);
|
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) {
|
} else if (obj instanceof OpenLayers.Feature.Vector) {
|
||||||
geojson = this.extract.feature.apply(this, [obj]);
|
geojson = this.extract.feature.apply(this, [obj]);
|
||||||
if(obj.layer && obj.layer.projection) {
|
if(obj.layer && obj.layer.projection) {
|
||||||
this.createCRSObject(obj);
|
geojson.crs = this.createCRSObject(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return OpenLayers.Format.JSON.prototype.write.apply(this,
|
return OpenLayers.Format.JSON.prototype.write.apply(this,
|
||||||
@@ -479,20 +479,28 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
|
|||||||
/**
|
/**
|
||||||
* Method: createCRSObject
|
* Method: createCRSObject
|
||||||
* Create the CRS object for an object.
|
* 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) {
|
createCRSObject: function(object) {
|
||||||
var proj = object.layer.projection;
|
var proj = object.layer.projection;
|
||||||
|
var crs = {}
|
||||||
if (proj.match(/epsg:/i)) {
|
if (proj.match(/epsg:/i)) {
|
||||||
var code = parseInt(proj.substring(proj.indexOf(":") + 1));
|
var code = parseInt(proj.substring(proj.indexOf(":") + 1));
|
||||||
if (code == 4326) {
|
if (code == 4326) {
|
||||||
geojson.crs = {
|
crs = {
|
||||||
"type": "OGC",
|
"type": "OGC",
|
||||||
"properties": {
|
"properties": {
|
||||||
"urn": "urn:ogc:def:crs:OGC:1.3:CRS84"
|
"urn": "urn:ogc:def:crs:OGC:1.3:CRS84"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
geojson.crs = {
|
crs = {
|
||||||
"type": "EPSG",
|
"type": "EPSG",
|
||||||
"properties": {
|
"properties": {
|
||||||
"code": code
|
"code": code
|
||||||
@@ -500,6 +508,7 @@ OpenLayers.Format.GeoJSON = OpenLayers.Class(OpenLayers.Format.JSON, {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return crs;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -184,6 +184,23 @@
|
|||||||
t.eq(types, {'Point':15, 'Polygon': 2, 'LineString':2}, "Correct number of each type");
|
t.eq(types, {'Point':15, 'Polygon': 2, 'LineString':2}, "Correct number of each type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_Format_GeoJSON_writeWithCRS(t) {
|
||||||
|
t.plan(2)
|
||||||
|
var feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(1,2));
|
||||||
|
feature.fid = 0;
|
||||||
|
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"}}}';
|
||||||
|
layer = new OpenLayers.Layer.Vector();
|
||||||
|
layer.projection = "EPSG:4326";
|
||||||
|
feature.layer = layer;
|
||||||
|
var parser = new OpenLayers.Format.GeoJSON();
|
||||||
|
test_out = parser.write(feature);
|
||||||
|
t.eq(test_out, output, "Output is equal for vector with layer in EPSG:4326 ");
|
||||||
|
feature.layer.projection = "EPSG:2805";
|
||||||
|
var output = '{"type":"Feature","id":0,"properties":{},"geometry":{"type":"Point","coordinates":[1,2]},"crs":{"type":"EPSG","properties":{"code":2805}}}';
|
||||||
|
test_out = parser.write(feature);
|
||||||
|
t.eq(test_out, output, "Output is equal for vector with point");
|
||||||
|
}
|
||||||
|
|
||||||
function test_Format_GeoJSON_write(t) {
|
function test_Format_GeoJSON_write(t) {
|
||||||
t.plan(10);
|
t.plan(10);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user