OpenLayers OpenLayers

Changeset 8582

Show
Ignore:
Timestamp:
01/05/09 14:23:01 (1 year ago)
Author:
elemoine
Message:

Add support for GeoJSON Bounding Box/Envelope, r=crschmidt (closes #1878)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Feature/Vector.js

    r8559 r8582  
    4747     */ 
    4848    attributes: null, 
     49 
     50    /** 
     51     * Property: bounds 
     52     * {<OpenLayers.Bounds>} The box bounding that feature's geometry, that 
     53     *     property can be set by an <OpenLayers.Format> object when 
     54     *     deserializing the feature, so in most cases it represents an 
     55     *     information set by the server.  
     56     */ 
     57    bounds: null, 
    4958 
    5059    /**  
  • trunk/openlayers/lib/OpenLayers/Format/GeoJSON.js

    r7689 r8582  
    179179     */ 
    180180    parseFeature: function(obj) { 
    181         var feature, geometry, attributes
     181        var feature, geometry, attributes, bbox
    182182        attributes = (obj.properties) ? obj.properties : {}; 
     183        bbox = (obj.geometry && obj.geometry.bbox) || obj.bbox; 
    183184        try { 
    184             geometry = this.parseGeometry(obj.geometry);             
     185            geometry = this.parseGeometry(obj.geometry); 
    185186        } catch(err) { 
    186187            // deal with bad geometries 
     
    188189        } 
    189190        feature = new OpenLayers.Feature.Vector(geometry, attributes); 
     191        if(bbox) { 
     192            feature.bounds = OpenLayers.Bounds.fromArray(bbox); 
     193        } 
    190194        if(obj.id) { 
    191195            feature.fid = obj.id; 
  • trunk/openlayers/tests/Format/GeoJSON.html

    r8520 r8582  
    387387    } 
    388388 
     389    function test_read_bbox(t) { 
     390        t.plan(8); 
     391 
     392        var f; 
     393        parser = new OpenLayers.Format.GeoJSON(); 
     394 
     395        // 4 tests 
     396        f = '{"geometry": {"type": "Point", "coordinates": [94.21875, 72.94921875], "bbox": [94.21875, 72.94921875, 94.21875, 72.94921875]}, "type": "Feature", "id": 573, "properties": {}, "bbox": [95.0, 73.0]}'; 
     397        data = parser.read(f); 
     398        t.eq(data[0].bounds.left, 94.21875, "read left bound is correct"); 
     399        t.eq(data[0].bounds.bottom, 72.94921875, "read bottom left bound is correct"); 
     400        t.eq(data[0].bounds.right, 94.21875, "read right bound is correct"); 
     401        t.eq(data[0].bounds.top, 72.94921875, "read top left bound is correct"); 
     402 
     403        // 4 tests 
     404        f = '{"geometry": {"type": "Point", "coordinates": [94.21875, 72.94921875]}, "type": "Feature", "id": 573, "properties": {}, "bbox": [95.0, 73.0, 96.0, 74.0]}'; 
     405        data = parser.read(f); 
     406        t.eq(data[0].bounds.left, 95.0, "read left bound is correct"); 
     407        t.eq(data[0].bounds.bottom, 73.0, "read bottom left bound is correct"); 
     408        t.eq(data[0].bounds.right, 96.0, "read right bound is correct"); 
     409        t.eq(data[0].bounds.top, 74.0, "read top left bound is correct"); 
     410    } 
     411 
    389412    </script>  
    390413</head>