Ticket #1062: geojson.2.patch
| File geojson.2.patch, 3.4 kB (added by crschmidt, 1 year ago) |
|---|
-
tests/Format/test_GeoJSON.html
old new 184 184 t.eq(types, {'Point':15, 'Polygon': 2, 'LineString':2}, "Correct number of each type"); 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 var output = '{"type":"Feature","id":"OpenLayers.Feature.Vector_44","properties":{},"geometry":{"type":"Point","coordinates":[1,2]},"crs":{"type":"OGC","properties":{"urn":"urn:ogc:def:crs:OGC:1.3:CRS84"}}}'; 191 layer = new OpenLayers.Layer.Vector(); 192 layer.projection = "EPSG:4326"; 193 feature.layer = layer; 194 var parser = new OpenLayers.Format.GeoJSON(); 195 test_out = parser.write(feature); 196 t.eq(test_out, output, "Output is equal for vector with layer in EPSG:4326 "); 197 feature.layer.projection = "EPSG:2805"; 198 var output = '{"type":"Feature","id":"OpenLayers.Feature.Vector_44","properties":{},"geometry":{"type":"Point","coordinates":[1,2]},"crs":{"type":"EPSG","properties":{"code":2805}}}'; 199 test_out = parser.write(feature); 200 t.eq(test_out, output, "Output is equal for vector with point"); 201 } 202 187 203 function test_Format_GeoJSON_write(t) { 188 204 t.plan(10); 189 205 -
lib/OpenLayers/Format/GeoJSON.js
old new 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 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, … … 482 482 */ 483 483 createCRSObject: function(object) { 484 484 var proj = object.layer.projection; 485 var crs = {} 485 486 if (proj.match(/epsg:/i)) { 486 487 var code = parseInt(proj.substring(proj.indexOf(":") + 1)); 487 488 if (code == 4326) { 488 geojson.crs = {489 crs = { 489 490 "type": "OGC", 490 491 "properties": { 491 492 "urn": "urn:ogc:def:crs:OGC:1.3:CRS84" 492 493 } 493 494 }; 494 495 } else { 495 geojson.crs = {496 crs = { 496 497 "type": "EPSG", 497 498 "properties": { 498 499 "code": code … … 500 501 }; 501 502 } 502 503 } 504 return crs; 503 505 }, 504 506 505 507 /**
