/**
* @classdesc
* @constructor
* @param {cercaliax.Control.CustomControlOptions} option
*
* This class let you create a custom control in the tools topbar.
* You can add several controls. It's necessary specify a `name`
* for obtaining the control reference using the `getControlsByName`
* function of the {@link cercalia.Map} class.
*
* @extends {ol.control.Control}
*/
cercalia.Control.CustomControl = function(option) {
/**
* @private
* @type {string}
*/
this.name_ = option.name ? option.name : cercalia.MapControls.CustomControl;
/**
* Class name
* @private
* @type {string}
*/
this.CLASS_NAME_ = "cercalia.Control.CustomControl";
/**
* Button icon.
* @private
* @type {string}
*/
this.icon_ = option.icon ? option.icon : "cercalia-big-icon-custom";
/**
* On click function
* @private
* @type {Function}
*/
this.click_ = option.click ? option.click : function () { cercalia.Exception(cercalia.i18n._("Click function not defined'")); };
/**
* Tooltip
* @private
* @type {string}
*/
this.tooltipText_ = option.tooltipText ? option.tooltipText : "";
/**
* Button
* @private
* @type {Object}
*/
this.element_ = document.createElement('div');
this.element_.className = "cercalia-control cercalia-control-customControl " + this.name_;
cercalia.jQuery(this.element_).button({icons: {primary:"cercalia-big-icon " + this.icon_, secondary: "" }, text: false }).attr("title", this.tooltipText_);
cercalia.jQuery(this.element_).addClass("cercalia-tool-button");
var self = this;
this.element_.addEventListener('click', function(e) {
self.click_();
});
};
ol.inherits(cercalia.Control.CustomControl, ol.control.Control);
/**
* Create the button in the tools topbar
* @private
* @param {string} idTopBar Div element ID where the control will be embedded
*/
cercalia.Control.CustomControl.prototype.setTopBar = function (idTopBar) {
var self = this;
ol.control.Control.call(this, {
element: self.element_,
target: document.getElementById(idTopBar)
});
};