Dedicated module for icon origin enum

This commit is contained in:
Tim Schaub
2016-12-27 10:22:57 -07:00
parent 895a506025
commit cbe82913b4
4 changed files with 35 additions and 33 deletions

View File

@@ -6845,14 +6845,14 @@ olx.style.FillOptions.prototype.color;
/**
* @typedef {{anchor: (Array.<number>|undefined),
* anchorOrigin: (ol.style.Icon.Origin|undefined),
* anchorOrigin: (ol.style.IconOrigin|undefined),
* anchorXUnits: (ol.style.Icon.AnchorUnits|undefined),
* anchorYUnits: (ol.style.Icon.AnchorUnits|undefined),
* color: (ol.Color|string|undefined),
* crossOrigin: (null|string|undefined),
* img: (Image|HTMLCanvasElement|undefined),
* offset: (Array.<number>|undefined),
* offsetOrigin: (ol.style.Icon.Origin|undefined),
* offsetOrigin: (ol.style.IconOrigin|undefined),
* opacity: (number|undefined),
* scale: (number|undefined),
* snapToPixel: (boolean|undefined),
@@ -6876,7 +6876,7 @@ olx.style.IconOptions.prototype.anchor;
/**
* Origin of the anchor: `bottom-left`, `bottom-right`, `top-left` or
* `top-right`. Default is `top-left`.
* @type {ol.style.Icon.Origin|undefined}
* @type {ol.style.IconOrigin|undefined}
* @api
*/
olx.style.IconOptions.prototype.anchorOrigin;
@@ -6945,7 +6945,7 @@ olx.style.IconOptions.prototype.offset;
/**
* Origin of the offset: `bottom-left`, `bottom-right`, `top-left` or
* `top-right`. Default is `top-left`.
* @type {ol.style.Icon.Origin|undefined}
* @type {ol.style.IconOrigin|undefined}
* @api
*/
olx.style.IconOptions.prototype.offsetOrigin;

View File

@@ -27,6 +27,7 @@ goog.require('ol.math');
goog.require('ol.proj');
goog.require('ol.style.Fill');
goog.require('ol.style.Icon');
goog.require('ol.style.IconOrigin');
goog.require('ol.style.Stroke');
goog.require('ol.style.Style');
goog.require('ol.style.Text');
@@ -212,7 +213,7 @@ ol.format.KML.createStyleDefaults_ = function() {
*/
ol.format.KML.DEFAULT_IMAGE_STYLE_ = new ol.style.Icon({
anchor: ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_,
anchorOrigin: ol.style.Icon.Origin.BOTTOM_LEFT,
anchorOrigin: ol.style.IconOrigin.BOTTOM_LEFT,
anchorXUnits: ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS_,
anchorYUnits: ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_,
crossOrigin: 'anonymous',
@@ -627,12 +628,12 @@ ol.format.KML.IconStyleParser_ = function(node, objectStack) {
var imageStyle = new ol.style.Icon({
anchor: anchor,
anchorOrigin: ol.style.Icon.Origin.BOTTOM_LEFT,
anchorOrigin: ol.style.IconOrigin.BOTTOM_LEFT,
anchorXUnits: anchorXUnits,
anchorYUnits: anchorYUnits,
crossOrigin: 'anonymous', // FIXME should this be configurable?
offset: offset,
offsetOrigin: ol.style.Icon.Origin.BOTTOM_LEFT,
offsetOrigin: ol.style.IconOrigin.BOTTOM_LEFT,
rotation: rotation,
scale: scale,
size: size,

View File

@@ -7,6 +7,7 @@ goog.require('ol.color');
goog.require('ol.events');
goog.require('ol.events.EventType');
goog.require('ol.style.IconImage');
goog.require('ol.style.IconOrigin');
goog.require('ol.style.Image');
@@ -37,10 +38,10 @@ ol.style.Icon = function(opt_options) {
/**
* @private
* @type {ol.style.Icon.Origin}
* @type {ol.style.IconOrigin}
*/
this.anchorOrigin_ = options.anchorOrigin !== undefined ?
options.anchorOrigin : ol.style.Icon.Origin.TOP_LEFT;
options.anchorOrigin : ol.style.IconOrigin.TOP_LEFT;
/**
* @private
@@ -117,10 +118,10 @@ ol.style.Icon = function(opt_options) {
/**
* @private
* @type {ol.style.Icon.Origin}
* @type {ol.style.IconOrigin}
*/
this.offsetOrigin_ = options.offsetOrigin !== undefined ?
options.offsetOrigin : ol.style.Icon.Origin.TOP_LEFT;
options.offsetOrigin : ol.style.IconOrigin.TOP_LEFT;
/**
* @private
@@ -238,19 +239,19 @@ ol.style.Icon.prototype.getAnchor = function() {
}
}
if (this.anchorOrigin_ != ol.style.Icon.Origin.TOP_LEFT) {
if (this.anchorOrigin_ != ol.style.IconOrigin.TOP_LEFT) {
if (!size) {
return null;
}
if (anchor === this.anchor_) {
anchor = this.anchor_.slice();
}
if (this.anchorOrigin_ == ol.style.Icon.Origin.TOP_RIGHT ||
this.anchorOrigin_ == ol.style.Icon.Origin.BOTTOM_RIGHT) {
if (this.anchorOrigin_ == ol.style.IconOrigin.TOP_RIGHT ||
this.anchorOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
anchor[0] = -anchor[0] + size[0];
}
if (this.anchorOrigin_ == ol.style.Icon.Origin.BOTTOM_LEFT ||
this.anchorOrigin_ == ol.style.Icon.Origin.BOTTOM_RIGHT) {
if (this.anchorOrigin_ == ol.style.IconOrigin.BOTTOM_LEFT ||
this.anchorOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
anchor[1] = -anchor[1] + size[1];
}
}
@@ -323,19 +324,19 @@ ol.style.Icon.prototype.getOrigin = function() {
}
var offset = this.offset_;
if (this.offsetOrigin_ != ol.style.Icon.Origin.TOP_LEFT) {
if (this.offsetOrigin_ != ol.style.IconOrigin.TOP_LEFT) {
var size = this.getSize();
var iconImageSize = this.iconImage_.getSize();
if (!size || !iconImageSize) {
return null;
}
offset = offset.slice();
if (this.offsetOrigin_ == ol.style.Icon.Origin.TOP_RIGHT ||
this.offsetOrigin_ == ol.style.Icon.Origin.BOTTOM_RIGHT) {
if (this.offsetOrigin_ == ol.style.IconOrigin.TOP_RIGHT ||
this.offsetOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
offset[0] = iconImageSize[0] - size[0] - offset[0];
}
if (this.offsetOrigin_ == ol.style.Icon.Origin.BOTTOM_LEFT ||
this.offsetOrigin_ == ol.style.Icon.Origin.BOTTOM_RIGHT) {
if (this.offsetOrigin_ == ol.style.IconOrigin.BOTTOM_LEFT ||
this.offsetOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
offset[1] = iconImageSize[1] - size[1] - offset[1];
}
}
@@ -401,15 +402,3 @@ ol.style.Icon.AnchorUnits = {
FRACTION: 'fraction',
PIXELS: 'pixels'
};
/**
* Icon origin. One of 'bottom-left', 'bottom-right', 'top-left', 'top-right'.
* @enum {string}
*/
ol.style.Icon.Origin = {
BOTTOM_LEFT: 'bottom-left',
BOTTOM_RIGHT: 'bottom-right',
TOP_LEFT: 'top-left',
TOP_RIGHT: 'top-right'
};

View File

@@ -0,0 +1,12 @@
goog.provide('ol.style.IconOrigin');
/**
* Icon origin. One of 'bottom-left', 'bottom-right', 'top-left', 'top-right'.
* @enum {string}
*/
ol.style.IconOrigin = {
BOTTOM_LEFT: 'bottom-left',
BOTTOM_RIGHT: 'bottom-right',
TOP_LEFT: 'top-left',
TOP_RIGHT: 'top-right'
};