Added interactive option to ol.control.OverviewMap

This commit is contained in:
Félix VEYSSEYRE
2016-09-15 15:10:01 +02:00
parent bdced57162
commit 2b7ed7381f
3 changed files with 55 additions and 0 deletions

View File

@@ -42,12 +42,20 @@ ol.control.OverviewMap = function(opt_options) {
this.collapsible_ = options.collapsible !== undefined ?
options.collapsible : true;
/**
* @type {boolean}
* @private
*/
this.interactive_ = options.interactive !== undefined ? options.interactive : false;
if (!this.collapsible_) {
this.collapsed_ = false;
}
var className = options.className !== undefined ? options.className : 'ol-overviewmap';
if (this.interactive_) className += ' ol-overviewmap-interactive';
var tipLabel = options.tipLabel !== undefined ? options.tipLabel : 'Overview map';
var collapseLabel = options.collapseLabel !== undefined ? options.collapseLabel : '\u00AB';
@@ -378,6 +386,42 @@ 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);