The second argument to map.setCenter is a zoom.
var map = new OpenLayers.Map("mapdiv");
// add layers here
map.setCenter(new OpenLayers.LonLat(yourlon, yourlat), 5);
If you want something more complex than that, you're probably going to need to share more details about what your map and setup currently look like. (Projection, base layer, etc.)
In order to do this without modifying the actual source code for openlayers (which you won't be doing if you're using a minified version, which by default you probably are), look at this answer.
However, I had to change it slightly for my code, which is using OpenLayers 2.11
OpenLayers.Control.PanZoom.prototype.buttonDown = function(evt) {
var btn = evt.currentTarget ? evt.currentTarget : this;
switch (btn.action) {
case "panup":
this.map.pan(0, -this.getSlideFactor("h"));
break;
case "pandown":
this.map.pan(0, this.getSlideFactor("h"));
break;
case "panleft":
this.map.pan(-this.getSlideFactor("w"), 0);
break;
case "panright":
this.map.pan(this.getSlideFactor("w"), 0);
break;
case "zoomin":
this.map.zoomIn();
break;
case "zoomout":
this.map.zoomOut();
break;
case "zoomworld":
alert("Hello world!");
break;
}
};
The only difference between this code and the one in the answer linked is that instead of onButtonClick
, we're using buttonDown
, and rather than evt.buttonElement
, we're using evt.currentTarget
EDIT: Internet Explorer has no currentTarget
property in their event handling. Luckily, we can use this
instead. I have modified the code above accordingly. For an explanation of this, please see this article. A relevant stackoverflow question is here.
Best Answer
I think a good way to minimize unneccessary traffic is to use a BBOX-Strategy:
Otherwise you can use "maxFeatures=xxxx" to limit the number of features delivered but with this solution you can't decide with features will be sent back.