Take css borders into account when drawing the box. This has to be done for every browser, except IE in quirks mode. r=crschmidt (closes 1593)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@7649 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -29,6 +29,13 @@ OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
* olHandlerBoxZoomBox
|
* olHandlerBoxZoomBox
|
||||||
*/
|
*/
|
||||||
boxDivClassName: 'olHandlerBoxZoomBox',
|
boxDivClassName: 'olHandlerBoxZoomBox',
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: boxCharacteristics
|
||||||
|
* {Object} Caches some box characteristics from css. This is used
|
||||||
|
* by the getBoxCharacteristics method.
|
||||||
|
*/
|
||||||
|
boxCharacteristics: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor: OpenLayers.Handler.Box
|
* Constructor: OpenLayers.Handler.Box
|
||||||
@@ -92,6 +99,20 @@ OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
this.zoomBox.style.height = Math.max(1, deltaY) + "px";
|
this.zoomBox.style.height = Math.max(1, deltaY) + "px";
|
||||||
this.zoomBox.style.left = xy.x < startX ? xy.x+"px" : startX+"px";
|
this.zoomBox.style.left = xy.x < startX ? xy.x+"px" : startX+"px";
|
||||||
this.zoomBox.style.top = xy.y < startY ? xy.y+"px" : startY+"px";
|
this.zoomBox.style.top = xy.y < startY ? xy.y+"px" : startY+"px";
|
||||||
|
|
||||||
|
// depending on the box model, modify width and height to take borders
|
||||||
|
// of the box into account
|
||||||
|
var box = this.getBoxCharacteristics(deltaX, deltaY);
|
||||||
|
if (box.newBoxModel) {
|
||||||
|
if (xy.x > startX) {
|
||||||
|
this.zoomBox.style.width =
|
||||||
|
Math.max(1, deltaX - box.xOffset) + "px";
|
||||||
|
}
|
||||||
|
if (xy.y > startY) {
|
||||||
|
this.zoomBox.style.height =
|
||||||
|
Math.max(1, deltaY - box.yOffset) + "px";
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,6 +146,7 @@ OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
removeBox: function() {
|
removeBox: function() {
|
||||||
this.map.viewPortDiv.removeChild(this.zoomBox);
|
this.map.viewPortDiv.removeChild(this.zoomBox);
|
||||||
this.zoomBox = null;
|
this.zoomBox = null;
|
||||||
|
this.boxCharacteristics = null;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,6 +172,26 @@ OpenLayers.Handler.Box = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getBoxCharacteristics: function(dx, dy) {
|
||||||
|
if (!this.boxCharacteristics) {
|
||||||
|
var xOffset = parseInt(OpenLayers.Element.getStyle(this.zoomBox,
|
||||||
|
"border-left-width")) + parseInt(OpenLayers.Element.getStyle(
|
||||||
|
this.zoomBox, "border-right-width")) + 1;
|
||||||
|
var yOffset = parseInt(OpenLayers.Element.getStyle(this.zoomBox,
|
||||||
|
"border-top-width")) + parseInt(OpenLayers.Element.getStyle(
|
||||||
|
this.zoomBox, "border-bottom-width")) + 1;
|
||||||
|
// all browsers use the new box model, except IE in quirks mode
|
||||||
|
var newBoxModel = OpenLayers.Util.getBrowserName() == "msie" ?
|
||||||
|
document.compatMode != "BackCompat" : true;
|
||||||
|
this.boxCharacteristics = {
|
||||||
|
xOffset: xOffset,
|
||||||
|
yOffset: yOffset,
|
||||||
|
newBoxModel: newBoxModel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.boxCharacteristics;
|
||||||
|
},
|
||||||
|
|
||||||
CLASS_NAME: "OpenLayers.Handler.Box"
|
CLASS_NAME: "OpenLayers.Handler.Box"
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user