OpenLayers OpenLayers

Changeset 7689

Show
Ignore:
Timestamp:
08/04/08 06:38:01 (4 months ago)
Author:
crschmidt
Message:

"Format.GeoJSON does not parse features with null geometries", r=elemoine
(Closes #1145)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Format/GeoJSON.js

    r7627 r7689  
    205205     */ 
    206206    parseGeometry: function(obj) { 
     207        if (obj == null) { 
     208            return null; 
     209        } 
    207210        var geometry; 
    208211        if(obj.type == "GeometryCollection") { 
     
    533536         */ 
    534537        'geometry': function(geometry) { 
     538            if (geometry == null) { 
     539                return null; 
     540            } 
    535541            if (this.internalProjection && this.externalProjection) { 
    536542                geometry = geometry.clone(); 
  • trunk/openlayers/tests/Format/GeoJSON.html

    r6719 r7689  
    55 
    66    var poly_content = '{"type": "FeatureCollection", "features": [{"geometry": {"type": "Polygon", "coordinates": [[[-131.484375, -5.9765625], [-112.5, -58.0078125], [-32.34375, -50.2734375], [-114.609375, 52.3828125], [-167.34375, -35.5078125], [-146.953125, -57.3046875], [-139.921875, -34.1015625], [-131.484375, -5.9765625]]]}, "type": "Feature", "id": 562, "properties": {"strokeColor": "red", "title": "Feature 2", "author": "Your Name Here"}}]}';  
     7    var null_geom_feature = '{"type":"Feature","id":573,"properties":{"strokeColor":"blue","title":"Feature 5","author":"Your Name Here"},"geometry":null}'; 
    78    var point_feature = '{"geometry": {"type": "Point", "coordinates": [94.21875, 72.94921875]}, "type": "Feature", "id": 573, "properties": {"strokeColor": "blue", "title": "Feature 5", "author": "Your Name Here"}}' 
    89    var line_feature = '{"type": "FeatureCollection", "features": [{"geometry": {"type": "LineString", "coordinates": [[-27.0703125, 59.4140625], [-77.6953125, 20.7421875], [30.5859375, -36.2109375], [67.1484375, 34.8046875]]}, "type": "Feature", "id": 559, "properties": {"strokeColor": "red", "title": "Feature 1", "author": "Your Name Here"}}]}'; 
     
    2223    } 
    2324 
     25    function test_Format_GeoJSON_null_geom(t) { 
     26        t.plan(2); 
     27        var f = new OpenLayers.Format.GeoJSON(); 
     28        var fs = f.read(null_geom_feature); 
     29        t.ok(fs[0].geometry == null, "Reading feature with null geom works okay"); 
     30        t.eq(f.write(fs[0]), null_geom_feature, "round trip null okay");  
     31 
     32    }    
    2433    function test_Format_GeoJSON_valid_type(t) {  
    2534        t.plan(14);