| | 1097 | function test_Map_zoomToScale(t) { |
|---|
| | 1098 | t.plan(4); |
|---|
| | 1099 | |
|---|
| | 1100 | var m = { |
|---|
| | 1101 | 'baseLayer': { 'units': {} }, |
|---|
| | 1102 | 'getSize': function() { return {'w': 10, 'h': 15}; }, |
|---|
| | 1103 | 'getCenter': function() { return {'lon': -5, 'lat': -25}; }, |
|---|
| | 1104 | 'zoomToExtent': function(extent, closest) { |
|---|
| | 1105 | t.ok(extent.equals(g_ExpectedExtent), "extent correctly calculated for zoomToExtent()"); |
|---|
| | 1106 | t.ok(closest == g_Closest, "closest correctly passed on to zoomToExtent()"); |
|---|
| | 1107 | } |
|---|
| | 1108 | } |
|---|
| | 1109 | |
|---|
| | 1110 | var temp = OpenLayers.Util.getResolutionFromScale; |
|---|
| | 1111 | OpenLayers.Util.getResolutionFromScale = function(scale, units) { |
|---|
| | 1112 | t.ok(scale == g_Scale, "scale parameter correctly passed to getResolutionFromScale"); |
|---|
| | 1113 | t.ok(units == m.baseLayer.units, "map's baselayer's units parameter correctly passed to getResolutionFromScale"); |
|---|
| | 1114 | return 1000; |
|---|
| | 1115 | }; |
|---|
| | 1116 | |
|---|
| | 1117 | g_ExpectedExtent = new OpenLayers.Bounds(-5005,-7525,4995,7475); |
|---|
| | 1118 | g_Scale = {}; |
|---|
| | 1119 | g_Closest = {}; |
|---|
| | 1120 | var args = [g_Scale, g_Closest]; |
|---|
| | 1121 | OpenLayers.Map.prototype.zoomToScale.apply(m, args); |
|---|
| | 1122 | |
|---|
| | 1123 | OpenLayers.Util.getResolutionFromScale = temp; |
|---|
| | 1124 | } |
|---|
| | 1126 | function test_Map_zoomToExtent(t) { |
|---|
| | 1127 | t.plan(8); |
|---|
| | 1128 | |
|---|
| | 1129 | |
|---|
| | 1130 | var m = { |
|---|
| | 1131 | 'baseLayer': { |
|---|
| | 1132 | 'wrapDateLine': false |
|---|
| | 1133 | }, |
|---|
| | 1134 | 'setCenter': function(center, zoomLevel) { |
|---|
| | 1135 | g_Center = center; |
|---|
| | 1136 | g_ZoomLevel = zoomLevel; |
|---|
| | 1137 | }, |
|---|
| | 1138 | 'getZoomForExtent': function(bounds, closest) { |
|---|
| | 1139 | t.ok(bounds.equals(g_ToCenterBounds), "bounds correctly passed into getZoomForExtent()"); |
|---|
| | 1140 | t.ok(closest == g_Closest, "closest correctly passed along to getZoomForExtent()"); |
|---|
| | 1141 | return g_ZoomLevelReturn; |
|---|
| | 1142 | } |
|---|
| | 1143 | }; |
|---|
| | 1144 | |
|---|
| | 1145 | //no wrapDateLine |
|---|
| | 1146 | g_ZoomLevelReturn = {}; |
|---|
| | 1147 | g_Bounds = new OpenLayers.Bounds(-20,-15,0,5); |
|---|
| | 1148 | g_ExpectedCenter = new OpenLayers.LonLat(-10,-5); |
|---|
| | 1149 | g_Closest = {}; |
|---|
| | 1150 | g_ToCenterBounds = g_Bounds; |
|---|
| | 1151 | var args = [g_Bounds, g_Closest]; |
|---|
| | 1152 | OpenLayers.Map.prototype.zoomToExtent.apply(m, args); |
|---|
| | 1153 | |
|---|
| | 1154 | t.ok(g_Center.equals(g_ExpectedCenter), "setCenter called on correct center"); |
|---|
| | 1155 | t.ok(g_ZoomLevel == g_ZoomLevelReturn, "correctly passes along zoom level as returned from getZoomForExtent()"); |
|---|
| | 1156 | |
|---|
| | 1157 | |
|---|
| | 1158 | //wrapDateLine |
|---|
| | 1159 | m.baseLayer.wrapDateLine = true; |
|---|
| | 1160 | m.getMaxExtent = function() { return new OpenLayers.Bounds(-200,-200,200,200); }; |
|---|
| | 1161 | |
|---|
| | 1162 | g_ZoomLevelReturn = {}; |
|---|
| | 1163 | g_BoundsCenter = {}; |
|---|
| | 1164 | g_Bounds = new OpenLayers.Bounds(160,-60,-60,60); |
|---|
| | 1165 | g_ExpectedCenter = new OpenLayers.LonLat(-150,0); |
|---|
| | 1166 | g_Closest = {}; |
|---|
| | 1167 | g_ToCenterBounds = new OpenLayers.Bounds(160,-60,340,60); |
|---|
| | 1168 | var args = [g_Bounds, g_Closest]; |
|---|
| | 1169 | OpenLayers.Map.prototype.zoomToExtent.apply(m, args); |
|---|
| | 1170 | t.ok(g_Center.equals(g_ExpectedCenter), "setCenter called on correct center"); |
|---|
| | 1171 | t.ok(g_ZoomLevel == g_ZoomLevelReturn, "correctly passes along zoom level as returned from getZoomForExtent()"); |
|---|
| | 1172 | |
|---|
| | 1173 | |
|---|
| | 1174 | } |
|---|