Source: temp/jsdocinputdirs/cercalia.icon.js

/**
 *
 * @private
 * @enum {string}
 */
cercalia.IconDefaults = {
  IMAGE: cercaliaGlobals.img + '/marker.png',
  SIZE: [26, 33],
  ANCHOR: [13, 33],
  ROTATION: 0,
  OPACITY: 1,
  SCALE: 1,
  ANCHOR_X_UNITS: 'pixels',
  ANCHOR_Y_UNITS: 'pixels'
};


/**
 * @classdesc
 *
 * The {@link cercalia.Marker} can contain icons. This icons can be created using this class.
 * This icon can include rotation, transparency.<br/>
 * If `icon` option is not included in the {@link cercalia.Marker} constructor, by default cercalia
 * API use the <a href='http://api.cercalia.com/api/img/marker.png'>icon</a>.
 *
 *
 * @constructor
 * @param {cercaliax.IconOptions} options
 */
cercalia.Icon = function(options) {

  /**
   * @private
   * @type {Object.<string, ?>}
   */
  this.iconOptions_ = {};

  if (!options) {
    this.iconOptions_ = {
      src: cercalia.IconDefaults.IMAGE,
      size: cercalia.IconDefaults.SIZE,
      anchor: cercalia.IconDefaults.ANCHOR,
      rotation: cercalia.IconDefaults.ROTATION,
      opacity: cercalia.IconDefaults.OPACITY,
      scale: cercalia.IconDefaults.SCALE,
      anchorXUnits: cercalia.IconDefaults.ANCHOR_X_UNITS,
      anchorYUnits: cercalia.IconDefaults.ANCHOR_Y_UNITS,
      crossOrigin: 'anonymous'
    };
  } else {
    this.iconOptions_ = {
      src: options.src ? options.src : cercalia.IconDefaults.IMAGE,
      size: options.src ? (options.size ? options.size : null) : cercalia.IconDefaults.SIZE,
      opacity: options.opacity ? options.opacity : cercalia.IconDefaults.OPACITY,
      scale: options.scale ? options.scale : cercalia.IconDefaults.SCALE,
      crossOrigin: options.crossOrigin !== undefined ? options.crossOrigin : 'anonymous'
    };

    if (options.anchor) { //Si se pasa por parametro pixeles
      this.iconOptions_.anchor = options.anchor;
      this.iconOptions_.anchorXUnits = cercalia.IconDefaults.ANCHOR_X_UNITS;
      this.iconOptions_.anchorYUnits = cercalia.IconDefaults.ANCHOR_Y_UNITS;
    } else { //Por defecto el anchor si no se especifica utiliza el de OL3 [0.5 0.5] (fraction)
      this.iconOptions_.anchor = [0.5, 0.5];
      this.iconOptions_.anchorXUnits = 'fraction';
      this.iconOptions_.anchorYUnits = 'fraction';
    }

    this.iconOptions_.rotation = options.rotation ? (Math.PI * options.rotation / 180) : 0;
  }

  /**
   * @private
   * @type {string}
   */
  this.anchorUnits_ = this.iconOptions_.anchorXUnits;

  /**
   * @private
   * @type {cercalia.Marker}
   */
  this.marker_ = null;

  /**
   * @private
   * @type {ol.style.Icon}
   */
  this.iconStyle_ = null;

  /**
   * @private
   * @type {string}
   */
  this.CLASS_NAME_ = 'cercalia.Icon';


  this.setIconStyle_();
};

/**
 * @private
 * @param {string}
 */
cercalia.Icon.prototype.getAnchorUnits = function() {
  return this.anchorUnits_;
};

/**
 * @private
 * @param {cercalia.Marker} marker
 */
cercalia.Icon.prototype.setMarker = function(marker) {
  this.marker_ = marker;
};

/**
 * @private
 */
cercalia.Icon.prototype.setIconStyle_ = function() {
  this.iconStyle_ = new ol.style.Icon(this.iconOptions_);
  if (this.marker_) {
    this.marker_.setIcon(this);
  }
};

/**
 * Returns <a href="http://openlayers.org/en/v3.0.0/apidoc/ol.style.Icon.html">`{ol.style.Icon}` OpenLayers3 style icon</a>
 * @return {ol.style.Icon}
 */
cercalia.Icon.prototype.getIconStyle = function() {
  return this.iconStyle_;
};

/**
 * Apply a rotation, degrees.
 * @param {string} rotation degrees rotation.
 */
cercalia.Icon.prototype.setRotation = function(rotation) {
  this.rotation_ = Math.PI * rotation / 180;
  this.iconStyle_.setRotation(this.rotation_)
  if (this.marker_) {
    this.marker_.redraw();
  }
};

/**
 * @return {number} Icon rotation (degrees).
 */
cercalia.Icon.prototype.getRotation = function() {
  var rotation = this.iconStyle_.getRotation();
  return rotation;
};

/**
 * Assign the icon image source
 * @param {string} src Image URL.
 */
cercalia.Icon.prototype.setSrc = function(src) {
  this.iconOptions_.src = src;
  this.setIconStyle_();
};

/**
 * @return {string} Image URL
 */
cercalia.Icon.prototype.getSrc = function() {
  return this.iconStyle_.getSrc();
};

/**
 * @return {Array.<number>} size
 */
cercalia.Icon.prototype.getSize = function(size) {
  return this.iconStyle_.getSize();
};

/**
 * @param {Array.<number>} size Size image source.
 * @deprecated
 */
cercalia.Icon.prototype.setSize = function(size) {
  this.iconOptions_.size = size;
  this.setIconStyle_();
};

/**
 * Returns the icon image source
 * @param {number} opacity Opacity.
 */
cercalia.Icon.prototype.setOpacity = function(opacity) {
  this.iconStyle_.setOpacity(opacity);
  if (this.marker_) {
    this.marker_.redraw();
  }
};

/**
 * @return {number} opacity Image opacity.
 */
cercalia.Icon.prototype.getOpacity = function() {
  return this.iconStyle_.getOpacity();
};

/**
 * Set icon anchor
 * @param {number} opacity Opacity.
 */
cercalia.Icon.prototype.setAnchor = function(anchor) {
  this.iconOptions_.anchor = anchor;
  this.setIconStyle_();
};

/**
 * @return {number} opacity Return icon anchor
 */
cercalia.Icon.prototype.getAnchor = function() {
  return this.iconStyle_.getAnchor();
};

/**
 * Default icon
 * @static
 * @type {cercalia.Icon}
 */
cercalia.Icon.createDefault = function() {
  return new cercalia.Icon({
    src: cercalia.IconDefaults.IMAGE,
    size: cercalia.IconDefaults.SIZE,
    anchor: cercalia.IconDefaults.ANCHOR
  });
};

/**
 * @return {string} object ClassName
 */
cercalia.Icon.prototype.getClass = function() {
  return this.CLASS_NAME_;
};