Changeset 8582
- Timestamp:
- 01/05/09 14:23:01 (1 year ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Feature/Vector.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Format/GeoJSON.js (modified) (2 diffs)
- trunk/openlayers/tests/Format/GeoJSON.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Feature/Vector.js
r8559 r8582 47 47 */ 48 48 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, 49 58 50 59 /** trunk/openlayers/lib/OpenLayers/Format/GeoJSON.js
r7689 r8582 179 179 */ 180 180 parseFeature: function(obj) { 181 var feature, geometry, attributes ;181 var feature, geometry, attributes, bbox; 182 182 attributes = (obj.properties) ? obj.properties : {}; 183 bbox = (obj.geometry && obj.geometry.bbox) || obj.bbox; 183 184 try { 184 geometry = this.parseGeometry(obj.geometry); 185 geometry = this.parseGeometry(obj.geometry); 185 186 } catch(err) { 186 187 // deal with bad geometries … … 188 189 } 189 190 feature = new OpenLayers.Feature.Vector(geometry, attributes); 191 if(bbox) { 192 feature.bounds = OpenLayers.Bounds.fromArray(bbox); 193 } 190 194 if(obj.id) { 191 195 feature.fid = obj.id; trunk/openlayers/tests/Format/GeoJSON.html
r8520 r8582 387 387 } 388 388 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 389 412 </script> 390 413 </head>
