New zoomOnClick option for ZoomBox control.
This change also finally adds tests for the ZoomBox control.
This commit is contained in:
@@ -41,10 +41,18 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* APIProperty: alwaysZoom
|
* APIProperty: alwaysZoom
|
||||||
* {Boolean} Always zoom in/out, when box drawed
|
* {Boolean} Always zoom in/out when box drawn, even if the zoom level does
|
||||||
|
* not change.
|
||||||
*/
|
*/
|
||||||
alwaysZoom: false,
|
alwaysZoom: false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIProperty: zoomOnClick
|
||||||
|
* {Boolean} Should we zoom when no box was dragged, i.e. the user only
|
||||||
|
* clicked? Default is true.
|
||||||
|
*/
|
||||||
|
zoomOnClick: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: draw
|
* Method: draw
|
||||||
*/
|
*/
|
||||||
@@ -93,7 +101,7 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
if (lastZoom == this.map.getZoom() && this.alwaysZoom == true){
|
if (lastZoom == this.map.getZoom() && this.alwaysZoom == true){
|
||||||
this.map.zoomTo(lastZoom + (this.out ? -1 : 1));
|
this.map.zoomTo(lastZoom + (this.out ? -1 : 1));
|
||||||
}
|
}
|
||||||
} else { // it's a pixel
|
} else if (this.zoomOnClick) { // it's a pixel
|
||||||
if (!this.out) {
|
if (!this.out) {
|
||||||
this.map.setCenter(this.map.getLonLatFromPixel(position),
|
this.map.setCenter(this.map.getLonLatFromPixel(position),
|
||||||
this.map.getZoom() + 1);
|
this.map.getZoom() + 1);
|
||||||
|
|||||||
51
tests/Control/ZoomBox.html
Normal file
51
tests/Control/ZoomBox.html
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="../OLLoader.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
function test_constructor(t) {
|
||||||
|
t.plan(4);
|
||||||
|
|
||||||
|
var control = new OpenLayers.Control.ZoomBox();
|
||||||
|
t.ok(control instanceof OpenLayers.Control, "instance of Control");
|
||||||
|
t.ok(control instanceof OpenLayers.Control.ZoomBox, "instance of ZoomBox");
|
||||||
|
t.eq(control.displayClass, "olControlZoomBox", "displayClass");
|
||||||
|
control.destroy();
|
||||||
|
|
||||||
|
control = new OpenLayers.Control.ZoomBox({
|
||||||
|
zoomOnClick: false
|
||||||
|
});
|
||||||
|
t.eq(control.zoomOnClick, false, "zoomOnClick");
|
||||||
|
control.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_zoomBox(t) {
|
||||||
|
t.plan(4);
|
||||||
|
var map = new OpenLayers.Map("map", {
|
||||||
|
layers: [new OpenLayers.Layer("", {isBaseLayer: true})],
|
||||||
|
center: [0, 0],
|
||||||
|
zoom: 1
|
||||||
|
});
|
||||||
|
var control = new OpenLayers.Control.ZoomBox();
|
||||||
|
map.addControl(control);
|
||||||
|
control.zoomBox(new OpenLayers.Pixel(50, 60));
|
||||||
|
t.eq(map.getZoom(), 2, "zoomed on click");
|
||||||
|
|
||||||
|
control.zoomOnClick = false;
|
||||||
|
control.zoomBox(new OpenLayers.Pixel(-50, -60));
|
||||||
|
t.eq(map.getZoom(), 2, "not zoomed with zoomOnClick set to false");
|
||||||
|
|
||||||
|
map.zoomToMaxExtent();
|
||||||
|
control.zoomBox(new OpenLayers.Bounds(128, 64, 256, 128));
|
||||||
|
t.eq(map.getCenter().toShortString(), "-45, 22.5", "centered to box center");
|
||||||
|
t.eq(map.getZoom(), 3, "zoomed to box extent");
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="map" style="width: 512px; height: 256px;"/>
|
||||||
|
<div id="in">in</div><div id="out">out</out>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -49,6 +49,7 @@
|
|||||||
<li>Control/PanPanel.html</li>
|
<li>Control/PanPanel.html</li>
|
||||||
<li>Control/SLDSelect.html</li>
|
<li>Control/SLDSelect.html</li>
|
||||||
<li>Control/Zoom.html</li>
|
<li>Control/Zoom.html</li>
|
||||||
|
<li>Control/ZoomBox.html</li>
|
||||||
<li>Events.html</li>
|
<li>Events.html</li>
|
||||||
<li>Events/buttonclick.html</li>
|
<li>Events/buttonclick.html</li>
|
||||||
<li>Extras.html</li>
|
<li>Extras.html</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user