Moved logic into the constructor

This commit is contained in:
Félix VEYSSEYRE
2016-09-16 15:28:07 +02:00
parent ac99b5011a
commit 328862172d

View File

@@ -151,6 +151,46 @@ ol.control.OverviewMap = function(opt_options) {
render: render,
target: options.target
});
/* Interactive map */
if (this.interactive_) {
var scope = this;
var overlay = this.boxOverlay_;
var overlayBox = this.boxOverlay_.getElement();
/* Functions definition */
var computeDesiredMousePosition = function(mousePosition) {
return {
clientX: mousePosition.clientX - (overlayBox.offsetWidth / 2),
clientY: mousePosition.clientY + (overlayBox.offsetHeight / 2)
};
};
var move = function(event) {
var coordinates = ovmap.getEventCoordinate(computeDesiredMousePosition(event));
overlay.setPosition(coordinates);
};
var endMoving = function(event) {
var coordinates = ovmap.getEventCoordinate(event);
scope.getMap().getView().setCenter(coordinates);
window.removeEventListener('mousemove', move);
window.removeEventListener('mouseup', endMoving);
};
/* Binding */
overlayBox.addEventListener('mousedown', function() {
window.addEventListener('mousemove', move);
window.addEventListener('mouseup', endMoving);
});
}
};
ol.inherits(ol.control.OverviewMap, ol.control.Control);
@@ -386,42 +426,6 @@ ol.control.OverviewMap.prototype.updateBox_ = function() {
var bottomLeft = ol.extent.getBottomLeft(extent);
var topRight = ol.extent.getTopRight(extent);
/* Interactive map */
if (this.interactive_) {
/* Functions definition */
var computeDesiredMousePosition = function(mousePosition) {
return {
clientX: mousePosition.clientX - (box.offsetWidth / 2),
clientY: mousePosition.clientY + (box.offsetHeight / 2)
};
};
var move = function(event) {
var coordinates = ovmap.getEventCoordinate(computeDesiredMousePosition(event));
overlay.setPosition(coordinates);
};
var endMoving = function(event) {
var coordinates = ovmap.getEventCoordinate(event);
map.getView().setCenter(coordinates);
window.removeEventListener('mousemove', move);
window.removeEventListener('mouseup', endMoving);
};
/* Binding */
box.addEventListener('mousedown', function() {
window.addEventListener('mousemove', move);
window.addEventListener('mouseup', endMoving);
});
}
// set position using bottom left coordinates
var rotateBottomLeft = this.calculateCoordinateRotate_(rotation, bottomLeft);
overlay.setPosition(rotateBottomLeft);