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
+4 -4
View File
@@ -6845,14 +6845,14 @@ olx.style.FillOptions.prototype.color;
/** /**
* @typedef {{anchor: (Array.<number>|undefined), * @typedef {{anchor: (Array.<number>|undefined),
* anchorOrigin: (ol.style.Icon.Origin|undefined), * anchorOrigin: (ol.style.IconOrigin|undefined),
* anchorXUnits: (ol.style.Icon.AnchorUnits|undefined), * anchorXUnits: (ol.style.Icon.AnchorUnits|undefined),
* anchorYUnits: (ol.style.Icon.AnchorUnits|undefined), * anchorYUnits: (ol.style.Icon.AnchorUnits|undefined),
* color: (ol.Color|string|undefined), * color: (ol.Color|string|undefined),
* crossOrigin: (null|string|undefined), * crossOrigin: (null|string|undefined),
* img: (Image|HTMLCanvasElement|undefined), * img: (Image|HTMLCanvasElement|undefined),
* offset: (Array.<number>|undefined), * offset: (Array.<number>|undefined),
* offsetOrigin: (ol.style.Icon.Origin|undefined), * offsetOrigin: (ol.style.IconOrigin|undefined),
* opacity: (number|undefined), * opacity: (number|undefined),
* scale: (number|undefined), * scale: (number|undefined),
* snapToPixel: (boolean|undefined), * snapToPixel: (boolean|undefined),
@@ -6876,7 +6876,7 @@ olx.style.IconOptions.prototype.anchor;
/** /**
* Origin of the anchor: `bottom-left`, `bottom-right`, `top-left` or * Origin of the anchor: `bottom-left`, `bottom-right`, `top-left` or
* `top-right`. Default is `top-left`. * `top-right`. Default is `top-left`.
* @type {ol.style.Icon.Origin|undefined} * @type {ol.style.IconOrigin|undefined}
* @api * @api
*/ */
olx.style.IconOptions.prototype.anchorOrigin; 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 * Origin of the offset: `bottom-left`, `bottom-right`, `top-left` or
* `top-right`. Default is `top-left`. * `top-right`. Default is `top-left`.
* @type {ol.style.Icon.Origin|undefined} * @type {ol.style.IconOrigin|undefined}
* @api * @api
*/ */
olx.style.IconOptions.prototype.offsetOrigin; olx.style.IconOptions.prototype.offsetOrigin;
+4 -3
View File
@@ -27,6 +27,7 @@ goog.require('ol.math');
goog.require('ol.proj'); goog.require('ol.proj');
goog.require('ol.style.Fill'); goog.require('ol.style.Fill');
goog.require('ol.style.Icon'); goog.require('ol.style.Icon');
goog.require('ol.style.IconOrigin');
goog.require('ol.style.Stroke'); goog.require('ol.style.Stroke');
goog.require('ol.style.Style'); goog.require('ol.style.Style');
goog.require('ol.style.Text'); goog.require('ol.style.Text');
@@ -212,7 +213,7 @@ ol.format.KML.createStyleDefaults_ = function() {
*/ */
ol.format.KML.DEFAULT_IMAGE_STYLE_ = new ol.style.Icon({ ol.format.KML.DEFAULT_IMAGE_STYLE_ = new ol.style.Icon({
anchor: ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_, 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_, anchorXUnits: ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS_,
anchorYUnits: ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_, anchorYUnits: ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_,
crossOrigin: 'anonymous', crossOrigin: 'anonymous',
@@ -627,12 +628,12 @@ ol.format.KML.IconStyleParser_ = function(node, objectStack) {
var imageStyle = new ol.style.Icon({ var imageStyle = new ol.style.Icon({
anchor: anchor, anchor: anchor,
anchorOrigin: ol.style.Icon.Origin.BOTTOM_LEFT, anchorOrigin: ol.style.IconOrigin.BOTTOM_LEFT,
anchorXUnits: anchorXUnits, anchorXUnits: anchorXUnits,
anchorYUnits: anchorYUnits, anchorYUnits: anchorYUnits,
crossOrigin: 'anonymous', // FIXME should this be configurable? crossOrigin: 'anonymous', // FIXME should this be configurable?
offset: offset, offset: offset,
offsetOrigin: ol.style.Icon.Origin.BOTTOM_LEFT, offsetOrigin: ol.style.IconOrigin.BOTTOM_LEFT,
rotation: rotation, rotation: rotation,
scale: scale, scale: scale,
size: size, size: size,
+15 -26
View File
@@ -7,6 +7,7 @@ goog.require('ol.color');
goog.require('ol.events'); goog.require('ol.events');
goog.require('ol.events.EventType'); goog.require('ol.events.EventType');
goog.require('ol.style.IconImage'); goog.require('ol.style.IconImage');
goog.require('ol.style.IconOrigin');
goog.require('ol.style.Image'); goog.require('ol.style.Image');
@@ -37,10 +38,10 @@ ol.style.Icon = function(opt_options) {
/** /**
* @private * @private
* @type {ol.style.Icon.Origin} * @type {ol.style.IconOrigin}
*/ */
this.anchorOrigin_ = options.anchorOrigin !== undefined ? this.anchorOrigin_ = options.anchorOrigin !== undefined ?
options.anchorOrigin : ol.style.Icon.Origin.TOP_LEFT; options.anchorOrigin : ol.style.IconOrigin.TOP_LEFT;
/** /**
* @private * @private
@@ -117,10 +118,10 @@ ol.style.Icon = function(opt_options) {
/** /**
* @private * @private
* @type {ol.style.Icon.Origin} * @type {ol.style.IconOrigin}
*/ */
this.offsetOrigin_ = options.offsetOrigin !== undefined ? this.offsetOrigin_ = options.offsetOrigin !== undefined ?
options.offsetOrigin : ol.style.Icon.Origin.TOP_LEFT; options.offsetOrigin : ol.style.IconOrigin.TOP_LEFT;
/** /**
* @private * @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) { if (!size) {
return null; return null;
} }
if (anchor === this.anchor_) { if (anchor === this.anchor_) {
anchor = this.anchor_.slice(); anchor = this.anchor_.slice();
} }
if (this.anchorOrigin_ == ol.style.Icon.Origin.TOP_RIGHT || if (this.anchorOrigin_ == ol.style.IconOrigin.TOP_RIGHT ||
this.anchorOrigin_ == ol.style.Icon.Origin.BOTTOM_RIGHT) { this.anchorOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
anchor[0] = -anchor[0] + size[0]; anchor[0] = -anchor[0] + size[0];
} }
if (this.anchorOrigin_ == ol.style.Icon.Origin.BOTTOM_LEFT || if (this.anchorOrigin_ == ol.style.IconOrigin.BOTTOM_LEFT ||
this.anchorOrigin_ == ol.style.Icon.Origin.BOTTOM_RIGHT) { this.anchorOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
anchor[1] = -anchor[1] + size[1]; anchor[1] = -anchor[1] + size[1];
} }
} }
@@ -323,19 +324,19 @@ ol.style.Icon.prototype.getOrigin = function() {
} }
var offset = this.offset_; 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 size = this.getSize();
var iconImageSize = this.iconImage_.getSize(); var iconImageSize = this.iconImage_.getSize();
if (!size || !iconImageSize) { if (!size || !iconImageSize) {
return null; return null;
} }
offset = offset.slice(); offset = offset.slice();
if (this.offsetOrigin_ == ol.style.Icon.Origin.TOP_RIGHT || if (this.offsetOrigin_ == ol.style.IconOrigin.TOP_RIGHT ||
this.offsetOrigin_ == ol.style.Icon.Origin.BOTTOM_RIGHT) { this.offsetOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
offset[0] = iconImageSize[0] - size[0] - offset[0]; offset[0] = iconImageSize[0] - size[0] - offset[0];
} }
if (this.offsetOrigin_ == ol.style.Icon.Origin.BOTTOM_LEFT || if (this.offsetOrigin_ == ol.style.IconOrigin.BOTTOM_LEFT ||
this.offsetOrigin_ == ol.style.Icon.Origin.BOTTOM_RIGHT) { this.offsetOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
offset[1] = iconImageSize[1] - size[1] - offset[1]; offset[1] = iconImageSize[1] - size[1] - offset[1];
} }
} }
@@ -401,15 +402,3 @@ ol.style.Icon.AnchorUnits = {
FRACTION: 'fraction', FRACTION: 'fraction',
PIXELS: 'pixels' 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'
};
+12
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'
};