Ticket #750: getDataExtent.patch
| File getDataExtent.patch, 3.0 kB (added by euzuro, 1 year ago) |
|---|
-
tests/Layer/test_Markers.html
old new 49 49 layer.destroy(); 50 50 t.eq( layer.map, null, "layer.map is null after destroy" ); 51 51 } 52 53 function test_03_Layer_Markers_getDataExtent(t) { 54 t.plan( 4 ); 55 56 var layer = {}; 57 var ret = OpenLayers.Layer.Markers.prototype.getDataExtent.apply(layer, []); 58 t.eq(ret, null, "does not crash, returns null on layer with null 'this.markers'"); 59 60 layer.markers = []; 61 ret = OpenLayers.Layer.Markers.prototype.getDataExtent.apply(layer, []); 62 t.eq(ret, null, "returns null on layer with empty 'this.markers'"); 63 64 layer.markers.push({ 65 'lonlat': new OpenLayers.LonLat(4,5) 66 }); 67 var expectedBounds = new OpenLayers.Bounds(4,5,4,5); 68 ret = OpenLayers.Layer.Markers.prototype.getDataExtent.apply(layer, []); 69 t.ok(ret.equals(expectedBounds), "returns expected bounds with only one marker"); 70 71 layer.markers.push({ 72 'lonlat': new OpenLayers.LonLat(1,2) 73 }); 74 var expectedBounds = new OpenLayers.Bounds(1,2,4,5); 75 ret = OpenLayers.Layer.Markers.prototype.getDataExtent.apply(layer, []); 76 t.ok(ret.equals(expectedBounds), "returns expected bounds with multiple markers"); 77 78 } 79 52 80 // --> 53 81 </script> 54 82 </head> -
lib/OpenLayers/Layer.js
old new 723 723 return this.getZoomForResolution(idealResolution); 724 724 }, 725 725 726 /** 727 * Method: getDataExtent 728 * Calculates the max extent which includes all of the data for the layer. 729 * This function is to be implemented by subclasses. 730 * 731 * Returns: 732 * {<OpenLayers.Bounds>} 733 */ 734 getDataExtent: function () { 735 //to be implemented by subclasses 736 }, 737 726 738 /** 727 739 * APIMethod: getZoomForResolution 728 740 * -
lib/OpenLayers/Layer/Markers.js
old new 139 139 } 140 140 } 141 141 }, 142 143 /** 144 * Method: getDataExtent 145 * Calculates the max extent which includes all of the markers. 146 * 147 * Returns: 148 * {<OpenLayers.Bounds>} 149 */ 150 getDataExtent: function () { 151 var maxExtent = null; 152 153 if ( this.markers && (this.markers.length > 0)) { 154 var maxExtent = new OpenLayers.Bounds(); 155 for(var i=0; i < this.markers.length; i++) { 156 var marker = this.markers[i]; 157 maxExtent.extend(marker.lonlat); 158 } 159 } 142 160 161 return maxExtent; 162 }, 163 143 164 CLASS_NAME: "OpenLayers.Layer.Markers" 144 165 });
