Merge pull request #519 from ahocevar/zoom-click

New zoomOnClick option for ZoomBox control. r=@bartvde
This commit is contained in:
ahocevar
2012-06-11 10:24:06 -07:00
3 changed files with 63 additions and 2 deletions

View File

@@ -41,10 +41,18 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
/**
* 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,
/**
* APIProperty: zoomOnClick
* {Boolean} Should we zoom when no box was dragged, i.e. the user only
* clicked? Default is true.
*/
zoomOnClick: true,
/**
* Method: draw
*/
@@ -93,7 +101,7 @@ OpenLayers.Control.ZoomBox = OpenLayers.Class(OpenLayers.Control, {
if (lastZoom == this.map.getZoom() && this.alwaysZoom == true){
this.map.zoomTo(lastZoom + (this.out ? -1 : 1));
}
} else { // it's a pixel
} else if (this.zoomOnClick) { // it's a pixel
if (!this.out) {
this.map.setCenter(this.map.getLonLatFromPixel(position),
this.map.getZoom() + 1);

View File

@@ -0,0 +1,52 @@
<!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");
map.destroy();
}
</script>
</head>
<body>
<div id="map" style="width: 512px; height: 256px;"/>
</body>
</html>

View File

@@ -49,6 +49,7 @@
<li>Control/PanPanel.html</li>
<li>Control/SLDSelect.html</li>
<li>Control/Zoom.html</li>
<li>Control/ZoomBox.html</li>
<li>Events.html</li>
<li>Events/buttonclick.html</li>
<li>Extras.html</li>