git-svn-id: http://svn.openlayers.org/trunk/openlayers@572 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
117 lines
4.3 KiB
JavaScript
117 lines
4.3 KiB
JavaScript
// @require: OpenLayers/Control.js
|
|
//
|
|
// default zoom/pan controls
|
|
//
|
|
OpenLayers.Control.PanZoom = Class.create();
|
|
OpenLayers.Control.PanZoom.X = 4;
|
|
OpenLayers.Control.PanZoom.Y = 4;
|
|
OpenLayers.Control.PanZoom.prototype =
|
|
Object.extend( new OpenLayers.Control(), {
|
|
|
|
/** @type Array(...) */
|
|
buttons: null,
|
|
|
|
initialize: function() {
|
|
OpenLayers.Control.prototype.initialize.apply(this, arguments);
|
|
this.position = new OpenLayers.Pixel(OpenLayers.Control.PanZoom.X,
|
|
OpenLayers.Control.PanZoom.Y);
|
|
},
|
|
|
|
/**
|
|
* @param {OpenLayers.Pixel} px
|
|
*/
|
|
draw: function(px) {
|
|
// initialize our internal div
|
|
OpenLayers.Control.prototype.draw.apply(this, arguments);
|
|
px = this.position;
|
|
|
|
// place the controls
|
|
this.buttons = new Array();
|
|
|
|
var sz = new OpenLayers.Size(18,18);
|
|
var centered = new OpenLayers.Pixel(px.x+sz.w/2, px.y);
|
|
|
|
this._addButton("panup", "north-mini.png", centered, sz);
|
|
px.y = centered.y+sz.h;
|
|
this._addButton("panleft", "west-mini.png", px, sz);
|
|
this._addButton("panright", "east-mini.png", px.add(sz.w, 0), sz);
|
|
this._addButton("pandown", "south-mini.png", centered.add(0, sz.h*2), sz);
|
|
this._addButton("zoomin", "zoom-plus-mini.png", centered.add(0, sz.h*3+5), sz);
|
|
this._addButton("zoomworld", "zoom-world-mini.png", centered.add(0, sz.h*4+5), sz);
|
|
this._addButton("zoomout", "zoom-minus-mini.png", centered.add(0, sz.h*5+5), sz);
|
|
return this.div;
|
|
},
|
|
_addButton:function(id, img, xy, sz) {
|
|
var imgLocation = OpenLayers.Util.getImagesLocation() + img;
|
|
// var btn = new ol.AlphaImage("_"+id, imgLocation, xy, sz);
|
|
var btn = OpenLayers.Util.createAlphaImageDiv(
|
|
"OpenLayers_Control_PanZoom_" + id,
|
|
xy, sz, imgLocation, "absolute");
|
|
|
|
//we want to add the outer div
|
|
this.div.appendChild(btn);
|
|
|
|
btn.onmousedown = this.buttonDown.bindAsEventListener(btn);
|
|
btn.ondblclick = this.doubleClick.bindAsEventListener(btn);
|
|
btn.onclick = this.doubleClick.bindAsEventListener(btn);
|
|
btn.action = id;
|
|
btn.map = this.map;
|
|
|
|
//we want to remember/reference the outer div
|
|
this.buttons.push(btn);
|
|
return btn;
|
|
},
|
|
|
|
doubleClick: function (evt) {
|
|
Event.stop(evt);
|
|
return false;
|
|
},
|
|
|
|
buttonDown: function (evt) {
|
|
switch (this.action) {
|
|
case "panup":
|
|
var resolution = this.map.getResolution();
|
|
var center = this.map.getCenter();
|
|
this.map.setCenter(
|
|
new OpenLayers.LonLat(center.lon,
|
|
center.lat + (resolution * 50))
|
|
);
|
|
break;
|
|
case "pandown":
|
|
var resolution = this.map.getResolution();
|
|
var center = this.map.getCenter();
|
|
this.map.setCenter(
|
|
new OpenLayers.LonLat(center.lon,
|
|
center.lat - (resolution * 50))
|
|
);
|
|
break;
|
|
case "panleft":
|
|
var resolution = this.map.getResolution();
|
|
var center = this.map.getCenter();
|
|
this.map.setCenter(
|
|
new OpenLayers.LonLat(center.lon - (resolution * 50),
|
|
center.lat)
|
|
);
|
|
break;
|
|
case "panright":
|
|
var resolution = this.map.getResolution();
|
|
var center = this.map.getCenter();
|
|
this.map.setCenter(
|
|
new OpenLayers.LonLat(center.lon + (resolution * 50),
|
|
center.lat)
|
|
);
|
|
break;
|
|
case "zoomin": this.map.zoomIn(); break;
|
|
case "zoomout": this.map.zoomOut(); break;
|
|
case "zoomworld": this.map.zoomExtent(); break;
|
|
}
|
|
Event.stop(evt);
|
|
},
|
|
destroy: function() {
|
|
OpenLayers.Control.prototype.destroy.apply(this, arguments);
|
|
for(i=0; i<this.buttons.length; i++) {
|
|
this.buttons[i].map = null;
|
|
}
|
|
}
|
|
});
|