3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
6 function test_initialize (t) {
9 control = new OpenLayers.Control.MousePosition();
10 t.ok( control instanceof OpenLayers.Control.MousePosition, "new OpenLayers.Control returns object" );
11 t.eq( control.displayClass, "olControlMousePosition", "displayClass is correct" );
13 function test_redraw_noLayer_displayProjection(t) {
15 control = new OpenLayers.Control.MousePosition({'displayProjection': new OpenLayers.Projection("WGS84")});
16 map = new OpenLayers.Map('map');
17 map.addControl(control);
18 control.redraw({'xy': new OpenLayers.Pixel(10,10)});
19 control.redraw({'xy': new OpenLayers.Pixel(12,12)});
20 t.eq(control.div.innerHTML, "", "innerHTML set correctly");
21 l = new OpenLayers.Layer('name', {'isBaseLayer': true});
23 map.zoomToMaxExtent();
24 control.redraw({'xy': new OpenLayers.Pixel(10,10)});
25 control.redraw({'xy': new OpenLayers.Pixel(12,12)});
26 t.eq(control.div.innerHTML, "-175.78125, 85.78125", "innerHTML set correctly when triggered.");
28 function test_destroy(t) {
31 var map = new OpenLayers.Map('map');
32 var control = new OpenLayers.Control.MousePosition();
33 map.addControl(control);
35 var listeners = map.events.listeners.mousemove.length;
38 t.eq(map.events.listeners.mousemove.length, listeners - 1, "mousemove event is unregistered");
41 function test_addControl(t) {
44 var map = new OpenLayers.Map('map');
45 var control = new OpenLayers.Control.MousePosition();
46 map.addControl(control);
48 t.ok(control.map === map, "Control.map is set to the map object");
49 t.ok(map.controls[map.controls.length - 1] === control, "map.controls contains control");
50 t.eq(parseInt(control.div.style.zIndex), map.Z_INDEX_BASE['Control'] + 5, "Control div zIndexed properly" );
51 t.eq(parseInt(map.viewPortDiv.lastChild.style.zIndex), map.Z_INDEX_BASE['Control'] + 5, "Viewport div contains control div");
54 function test_redraw_noLayer_displayProjection(t) {
56 var control = new OpenLayers.Control.MousePosition();
57 var map = new OpenLayers.Map('map');
58 map.addControl(control);
59 t.eq(control.div.innerHTML, "0.00000, 0.00000", "innerHTML set correctly");
60 control.redraw({'xy': new OpenLayers.Pixel(10,10)});
61 control.redraw({'xy': new OpenLayers.Pixel(12,12)});
62 t.eq(control.div.innerHTML, "0.00000, 0.00000", "innerHTML set correctly");
63 var l = new OpenLayers.Layer('name', {'isBaseLayer': true});
65 map.zoomToMaxExtent();
66 control.redraw({'xy': new OpenLayers.Pixel(10,10)});
67 control.redraw({'xy': new OpenLayers.Pixel(12,12)});
68 t.eq(control.div.innerHTML, "-175.78125, 85.78125", "innerHTML set correctly when triggered.");
71 function test_formatOutput(t) {
73 var control = new OpenLayers.Control.MousePosition({
76 separator: 'separator',
79 var lonlat = new OpenLayers.LonLat(0.75699, 0.37365);
80 var val = control.formatOutput(lonlat);
81 t.eq(val, 'prefix0.757separator0.374suffix', 'formatOutput correctly formats the mouse position output');
86 <div id="map" style="width: 1024px; height: 512px;"/>