1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
|
<html>
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
var map, control;
function test_initialize(t) {
t.plan( 2 );
control = new OpenLayers.Control.OverviewMap();
t.ok( control instanceof OpenLayers.Control.OverviewMap,
"new OpenLayers.Control.OverviewMap returns object" );
t.eq( control.displayClass,
"olControlOverviewMap", "displayClass is correct" );
}
function test_divs_title(t) {
t.plan(2);
control = new OpenLayers.Control.OverviewMap({
maximizeTitle: "maximize title",
minimizeTitle: "minimize title"
});
map = new OpenLayers.Map('map', {
layers: [new OpenLayers.Layer("layer", {isBaseLayer: true})],
controls: [control]
});
map.zoomToMaxExtent();
t.eq(control.maximizeDiv.title, "maximize title", "maximizeDiv.title is correct");
t.eq(control.minimizeDiv.title, "minimize title", "minimizeDiv.title is correct");
map.destroy();
}
function test_setMap(t) {
t.plan(4);
var setMapTest = function(map) {
t.ok(true,
"Handler.setMap called for " + this.CLASS_NAME);
this.map = map;
};
var drag_setMap = OpenLayers.Handler.Drag.prototype.setMap;
OpenLayers.Handler.Drag.prototype.setMap = setMapTest;
var click_setMap = OpenLayers.Handler.Click.prototype.setMap;
OpenLayers.Handler.Click.prototype.setMap = setMapTest;
map = new OpenLayers.Map('map', {
layers : [new OpenLayers.Layer("layer", {isBaseLayer: true})],
controls: []
});
control = new OpenLayers.Control.OverviewMap();
map.addControl(control);
map.zoomToMaxExtent();
t.eq(control.handlers.drag.map.id, control.ovmap.id,
"drag.map is correct");
t.eq(control.handlers.click.map.id, control.ovmap.id,
"click.map is correct");
map.destroy();
OpenLayers.Handler.Drag.prototype.setMap = drag_setMap;
OpenLayers.Handler.Click.prototype.setMap = click_setMap;
}
function test_destroy(t) {
t.plan(6);
// set up
var log_drag = [], log_click = [], control;
map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer("layer", {isBaseLayer: true}));
control = new OpenLayers.Control.OverviewMap();
map.addControl(control);
map.zoomToMaxExtent();
control.handlers.drag.destroy = function() {
log_drag.push({"map": !!this.map.events});
};
control.handlers.click.destroy = function() {
log_click.push({"map": !!this.map.events});
};
// test
control.destroy();
t.eq(log_drag.length, 2,
"destroy() destroys drag handler twice, expected");
if (log_drag.length == 2) {
t.eq(log_drag[0].map, true,
"destroy() destroys drag handler before ovmap is destroyed (0)");
t.eq(log_drag[1].map, false,
"destroy() destroys drag handler after ovmap is destroyed (1)");
}
t.eq(log_click.length, 2,
"destroy() destroys click handler twice, expected");
if (log_click.length == 2) {
t.eq(log_click[0].map, true,
"destroy() destroys click handler before ovmap is destroyed (0)");
t.eq(log_click[1].map, false,
"destroy() destroys click handler after ovmap is destroyed (1)");
}
// tear down
map.destroy();
}
function test_addControl (t) {
t.plan( 6 );
map = new OpenLayers.Map('map');
control = new OpenLayers.Control.OverviewMap();
t.ok( control instanceof OpenLayers.Control.OverviewMap,
"new OpenLayers.Control.OverviewMap returns object" );
t.ok( map instanceof OpenLayers.Map,
"new OpenLayers.Map creates map" );
map.addControl(control);
t.ok( control.map === map,
"Control.map is set to the map object" );
t.ok( map.controls[4] === control,
"map.controls contains control" );
t.eq( parseInt(control.div.style.zIndex), map.Z_INDEX_BASE['Control'] + 5,
"Control div zIndexed properly" );
t.eq( parseInt(map.viewPortDiv.lastChild.style.zIndex), map.Z_INDEX_BASE['Control'] + 5,
"Viewport div contains control div" );
map.destroy();
}
function test_control_events (t) {
t.plan( 10 );
map = new OpenLayers.Map('map', {
// when we recenter, don't waste time animating the panning
// without this, the test fails in Firefox 10.0.1 on Linux
panMethod: null,
layers: [ new OpenLayers.Layer('Test Layer', {isBaseLayer: true}) ]
});
control = new OpenLayers.Control.OverviewMap();
map.addControl(control, new OpenLayers.Pixel(20,20));
var centerLL = new OpenLayers.LonLat(-71,42);
map.setCenter(centerLL, 11);
t.delay_call(
0.1,
function() {
var overviewCenter = control.ovmap.getCenter();
var overviewZoom = control.ovmap.getZoom();
t.eq(overviewCenter.lon, -71,
"OverviewMap center lon correct");
t.eq(overviewCenter.lat, 42,
"OverviewMap center lat correct");
t.eq(overviewZoom, 8,
"OverviewMap zoom correct");
control.mapDivClick({'xy':new OpenLayers.Pixel(5,5)});
},
0.1,
function() {
var cent = map.getCenter();
t.eq(cent.lon, -71.3515625,
"Clicking on OverviewMap has correct effect on map lon");
t.eq(cent.lat, 42.17578125,
"Clicking on OverviewMap has correct effect on map lat");
control.handlers.drag = {
last: new OpenLayers.Pixel(5,5),
destroy: function() {}
};
control.rectDrag(new OpenLayers.Pixel(15, 15));
control.updateMapToRect();
},
0.1,
function() {
var cent = map.getCenter();
t.eq(cent.lon, -71.2734375,
"Dragging on OverviewMap has correct effect on map lon");
t.eq(cent.lat, 42.09765625,
"Dragging on OverviewMap has correct effect on map lat");
map.setCenter(new OpenLayers.LonLat(0,0), 0);
var overviewCenter = control.ovmap.getCenter();
var overviewZoom = control.ovmap.getZoom();
t.eq(overviewCenter.lon, 0,
"OverviewMap center lon correct -- second zoom");
t.eq(overviewCenter.lat, 0,
"OverviewMap center lat correct -- second zoom");
t.eq(overviewZoom, 0,
"OverviewMap zoomcorrect -- second zoom");
map.destroy();
}
);
}
function test_initialize_maximized(t) {
t.plan(4);
control = new OpenLayers.Control.OverviewMap()
map = new OpenLayers.Map('map', {
layers : [new OpenLayers.Layer("layer", {isBaseLayer: true})],
controls: [control]
});
t.eq(control.maximized, false,
"OverviewMap is not maximized by default");
t.eq(control.element.style.display, 'none',
"OverviewMap.element is not visible");
map.destroy();
control = new OpenLayers.Control.OverviewMap({
maximized: true
})
map = new OpenLayers.Map('map', {
layers : [new OpenLayers.Layer("layer", {isBaseLayer: true})],
controls: [control]
});
t.eq(control.maximized, true,
"OverviewMap.maximized is set");
t.eq(control.element.style.display, '',
"OverviewMap.element is visible");
map.destroy();
}
function test_custom_div(t) {
t.plan(3);
var div = document.createElement('div');
control = new OpenLayers.Control.OverviewMap({
div: div
});
map = new OpenLayers.Map('map', {
layers : [new OpenLayers.Layer("layer", {isBaseLayer: true})],
controls: [control]
});
t.eq(control.maximizeDiv, null,
"OverviewMap does not create maximize div");
t.eq(control.minimizeDiv, null,
"OverviewMap does not create minimize div");
var exc;
try {
control.maximizeControl();
control.minimizeControl();
} catch(e) {
exc = e;
}
t.eq(exc, undefined, 'maximize and minimize do not trigger an exception');
map.destroy();
}
</script>
</head>
<body>
<div id="map" style="width: 1024px; height: 512px;"></div>
</body>
</html>
|