Files
openlayers/tests/Control/Geolocate.html
2011-02-22 16:48:05 +00:00

106 lines
3.6 KiB
HTML

<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, control, centerLL
watch = null,
geolocation= {
getCurrentPosition: function(f) {
f({
coords: { latitude: 10, longitude: 10 }
});
},
watchPosition: function(f) {
watch = true;
},
clearWatch: function() {
watch = null;
}
};
function test_initialize(t) {
t.plan(3);
control = new OpenLayers.Control.Geolocate({geolocationOptions: {foo: 'bar'}});
t.ok(control instanceof OpenLayers.Control.Geolocate,
"new OpenLayers.Control returns object" );
t.eq(control.displayClass, "olControlGeolocate", "displayClass is correct" );
t.eq(control.geolocationOptions.foo, 'bar',
'provided geolocation options are set in the geolocationOptions prop');
}
function test_bind(t) {
t.plan(3);
var control = new OpenLayers.Control.Geolocate({
geolocation: geolocation
});
control.events.register('locationupdated', null, function() {
t.ok(true, 'locationupdated event is fired when bound');
});
map.addControl(control);
control.activate();
var center = map.getCenter();
t.eq(center.lon, 10, 'bound control sets the map lon');
t.eq(center.lat, 10, 'bound control sets the map lat');
control.deactivate();
map.removeControl(control);
map.setCenter(centerLL);
}
function test_unbind(t) {
t.plan(3);
var control = new OpenLayers.Control.Geolocate({
geolocation: geolocation,
bind: false
});
control.events.register('locationupdated', null, function() {
t.ok(true, 'locationupdated event is fired when unbound');
});
map.addControl(control);
control.activate();
var center = map.getCenter();
t.eq(center.lon, 0, 'unbound control doesnt sets the map lon');
t.eq(center.lat, 0, 'unbound control doesnt sets the map lat');
control.deactivate();
map.removeControl(control);
map.setCenter(centerLL);
}
function test_watch(t) {
t.plan(2);
var control = new OpenLayers.Control.Geolocate({
geolocation: geolocation,
watch: true
});
map.addControl(control);
control.activate();
t.eq(watch, true, 'watch option makes calls to watchPosition');
control.deactivate();
t.eq(watch, null, 'deactivate control calls the clearwatch');
map.removeControl(control);
map.setCenter(centerLL);
}
function test_uncapable(t) {
t.plan(1);
var control = new OpenLayers.Control.Geolocate({
geolocation: null,
bind: false
});
control.events.register('locationuncapable', null, function() {
t.ok(true,'uncapable browser fired locationuncapable event');
});
map.addControl(control);
control.activate();
}
function loader() {
map = new OpenLayers.Map('map');
var layer = new OpenLayers.Layer.WMS("Test Layer",
"http://labs.metacarta.com/wms-c/Basic.py?",
{layers: "basic"});
map.addLayer(layer);
centerLL = new OpenLayers.LonLat(0,0);
map.setCenter(centerLL, 5);
}
</script>
</head>
<body onload="loader()">
<div id="map" style="width: 256px; height: 256px;"/>
</body>
</html>