/**
* Zoom Control buttons. Buttons: Zoom In and Zoom Out
* @class
* @constructor
* @param {cercaliax.Control.ZoomOptions|undefined} options
* @extends {ol.control.Control}
*/
cercalia.Control.Zoom = function(options) {
/**
* @private
* @type {string}
*/
this.name_ = cercalia.MapControls.Zoom;
/**
* Class name
* @private
* @type {string}
*/
this.CLASS_NAME_ = "cercalia.Control.Zoom";
/**
* @private
* @type {number}
*/
this.top_ = options.top ? options.top : 0;
/**
* @private
* @type {string}
*/
this.position_ = options.position_ ? options.position_ : 'left';
var zoomIn = document.createElement('a');
zoomIn.href = '#ZoomIn';
//zoomIn.innerHTML = '+';
var zoomOut = document.createElement('a');
zoomOut.href = '#ZoomOut';
//zoomOut.innerHTML = '-';
var self = this;
var funcZoom = function(e,inc){
var view = self.getMap().getView();
var currentResolution = view.getResolution();
self.getMap().beforeRender(ol.animation.zoom({
resolution: currentResolution,
duration: 250,
easing: ol.easing.easeOut
}));
var newResolution = view.constrainResolution(currentResolution, inc);
view.setResolution(newResolution);
e.preventDefault();
};
var doZoomIn = function(e) {funcZoom(e,1);};
var doZoomOut = function(e) {funcZoom(e,-1);};
zoomIn.addEventListener('click', doZoomIn, false);
zoomIn.addEventListener('touchstart', doZoomIn, false);
zoomOut.addEventListener('click', doZoomOut, false);
zoomOut.addEventListener('touchstart', doZoomOut, false);
this.element_ = document.createElement('div');
this.element_.className = cercalia.isMobile ? 'cercalia-control-zoom-mobile ol-unselectable' : 'cercalia-control-zoom ol-unselectable';
this.element_.appendChild(zoomIn);
this.element_.appendChild(zoomOut);
cercalia.jQuery(this.element_).css("top", this.top_ + "px");
this.setPosition(this.position_);
cercalia.jQuery(zoomIn).button({ icons: { primary: "cercalia-icon-zoomin" }, text: false });
cercalia.jQuery(zoomOut).button({ icons: { primary: "cercalia-icon-zoomout" }, text: false });
ol.control.Control.call(this, {
element: this.element_,
target: options.target
});
};
ol.inherits(cercalia.Control.Zoom, ol.control.Control);
/**
* Change the Zoom control position.
* @param {string} position ZoomSlider position, 'left' or 'right'.
*/
cercalia.Control.Zoom.prototype.setPosition = function(position){
this.position_ = position;
if(this.position_ == 'left'){
cercalia.jQuery(this.element_).css({
left: cercalia.isMobile ? '5px' : '24px',
right : ''
});
} else {
cercalia.jQuery(this.element_).css({
right: cercalia.isMobile ? '5px' : '20px',
left : ''
});
}
};