Dedicated module for icon anchor units enum

This commit is contained in:
Tim Schaub
2016-12-27 10:26:11 -07:00
parent cbe82913b4
commit 02edf0ab24
5 changed files with 37 additions and 35 deletions
+4 -4
View File
@@ -6846,8 +6846,8 @@ olx.style.FillOptions.prototype.color;
/** /**
* @typedef {{anchor: (Array.<number>|undefined), * @typedef {{anchor: (Array.<number>|undefined),
* anchorOrigin: (ol.style.IconOrigin|undefined), * anchorOrigin: (ol.style.IconOrigin|undefined),
* anchorXUnits: (ol.style.Icon.AnchorUnits|undefined), * anchorXUnits: (ol.style.IconAnchorUnits|undefined),
* anchorYUnits: (ol.style.Icon.AnchorUnits|undefined), * anchorYUnits: (ol.style.IconAnchorUnits|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),
@@ -6886,7 +6886,7 @@ olx.style.IconOptions.prototype.anchorOrigin;
* Units in which the anchor x value is specified. A value of `'fraction'` * Units in which the anchor x value is specified. A value of `'fraction'`
* indicates the x value is a fraction of the icon. A value of `'pixels'` * indicates the x value is a fraction of the icon. A value of `'pixels'`
* indicates the x value in pixels. Default is `'fraction'`. * indicates the x value in pixels. Default is `'fraction'`.
* @type {ol.style.Icon.AnchorUnits|undefined} * @type {ol.style.IconAnchorUnits|undefined}
* @api * @api
*/ */
olx.style.IconOptions.prototype.anchorXUnits; olx.style.IconOptions.prototype.anchorXUnits;
@@ -6896,7 +6896,7 @@ olx.style.IconOptions.prototype.anchorXUnits;
* Units in which the anchor y value is specified. A value of `'fraction'` * Units in which the anchor y value is specified. A value of `'fraction'`
* indicates the y value is a fraction of the icon. A value of `'pixels'` * indicates the y value is a fraction of the icon. A value of `'pixels'`
* indicates the y value in pixels. Default is `'fraction'`. * indicates the y value in pixels. Default is `'fraction'`.
* @type {ol.style.Icon.AnchorUnits|undefined} * @type {ol.style.IconAnchorUnits|undefined}
* @api * @api
*/ */
olx.style.IconOptions.prototype.anchorYUnits; olx.style.IconOptions.prototype.anchorYUnits;
+12 -11
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.IconAnchorUnits');
goog.require('ol.style.IconOrigin'); 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');
@@ -170,19 +171,19 @@ ol.format.KML.createStyleDefaults_ = function() {
/** /**
* @const * @const
* @type {ol.style.Icon.AnchorUnits} * @type {ol.style.IconAnchorUnits}
* @private * @private
*/ */
ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS_ = ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS_ =
ol.style.Icon.AnchorUnits.PIXELS; ol.style.IconAnchorUnits.PIXELS;
/** /**
* @const * @const
* @type {ol.style.Icon.AnchorUnits} * @type {ol.style.IconAnchorUnits}
* @private * @private
*/ */
ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_ = ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_ =
ol.style.Icon.AnchorUnits.PIXELS; ol.style.IconAnchorUnits.PIXELS;
/** /**
* @const * @const
@@ -288,12 +289,12 @@ ol.format.KML.createStyleDefaults_ = function() {
/** /**
* @const * @const
* @type {Object.<string, ol.style.Icon.AnchorUnits>} * @type {Object.<string, ol.style.IconAnchorUnits>}
* @private * @private
*/ */
ol.format.KML.ICON_ANCHOR_UNITS_MAP_ = { ol.format.KML.ICON_ANCHOR_UNITS_MAP_ = {
'fraction': ol.style.Icon.AnchorUnits.FRACTION, 'fraction': ol.style.IconAnchorUnits.FRACTION,
'pixels': ol.style.Icon.AnchorUnits.PIXELS 'pixels': ol.style.IconAnchorUnits.PIXELS
}; };
@@ -586,8 +587,8 @@ ol.format.KML.IconStyleParser_ = function(node, objectStack) {
anchorYUnits = ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_; anchorYUnits = ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_;
} else if (/^http:\/\/maps\.(?:google|gstatic)\.com\//.test(src)) { } else if (/^http:\/\/maps\.(?:google|gstatic)\.com\//.test(src)) {
anchor = [0.5, 0]; anchor = [0.5, 0];
anchorXUnits = ol.style.Icon.AnchorUnits.FRACTION; anchorXUnits = ol.style.IconAnchorUnits.FRACTION;
anchorYUnits = ol.style.Icon.AnchorUnits.FRACTION; anchorYUnits = ol.style.IconAnchorUnits.FRACTION;
} }
var offset; var offset;
@@ -2412,9 +2413,9 @@ ol.format.KML.writeIconStyle_ = function(node, style, objectStack) {
if (anchor && anchor[0] !== 0 && anchor[1] !== size[1]) { if (anchor && anchor[0] !== 0 && anchor[1] !== size[1]) {
var /** @type {ol.KMLVec2_} */ hotSpot = { var /** @type {ol.KMLVec2_} */ hotSpot = {
x: anchor[0], x: anchor[0],
xunits: ol.style.Icon.AnchorUnits.PIXELS, xunits: ol.style.IconAnchorUnits.PIXELS,
y: size[1] - anchor[1], y: size[1] - anchor[1],
yunits: ol.style.Icon.AnchorUnits.PIXELS yunits: ol.style.IconAnchorUnits.PIXELS
}; };
properties['hotSpot'] = hotSpot; properties['hotSpot'] = hotSpot;
} }
+9 -18
View File
@@ -6,6 +6,7 @@ goog.require('ol.asserts');
goog.require('ol.color'); 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.IconAnchorUnits');
goog.require('ol.style.IconImage'); goog.require('ol.style.IconImage');
goog.require('ol.style.IconOrigin'); goog.require('ol.style.IconOrigin');
goog.require('ol.style.Image'); goog.require('ol.style.Image');
@@ -45,17 +46,17 @@ ol.style.Icon = function(opt_options) {
/** /**
* @private * @private
* @type {ol.style.Icon.AnchorUnits} * @type {ol.style.IconAnchorUnits}
*/ */
this.anchorXUnits_ = options.anchorXUnits !== undefined ? this.anchorXUnits_ = options.anchorXUnits !== undefined ?
options.anchorXUnits : ol.style.Icon.AnchorUnits.FRACTION; options.anchorXUnits : ol.style.IconAnchorUnits.FRACTION;
/** /**
* @private * @private
* @type {ol.style.Icon.AnchorUnits} * @type {ol.style.IconAnchorUnits}
*/ */
this.anchorYUnits_ = options.anchorYUnits !== undefined ? this.anchorYUnits_ = options.anchorYUnits !== undefined ?
options.anchorYUnits : ol.style.Icon.AnchorUnits.FRACTION; options.anchorYUnits : ol.style.IconAnchorUnits.FRACTION;
/** /**
* @private * @private
@@ -225,16 +226,16 @@ ol.style.Icon.prototype.getAnchor = function() {
} }
var anchor = this.anchor_; var anchor = this.anchor_;
var size = this.getSize(); var size = this.getSize();
if (this.anchorXUnits_ == ol.style.Icon.AnchorUnits.FRACTION || if (this.anchorXUnits_ == ol.style.IconAnchorUnits.FRACTION ||
this.anchorYUnits_ == ol.style.Icon.AnchorUnits.FRACTION) { this.anchorYUnits_ == ol.style.IconAnchorUnits.FRACTION) {
if (!size) { if (!size) {
return null; return null;
} }
anchor = this.anchor_.slice(); anchor = this.anchor_.slice();
if (this.anchorXUnits_ == ol.style.Icon.AnchorUnits.FRACTION) { if (this.anchorXUnits_ == ol.style.IconAnchorUnits.FRACTION) {
anchor[0] *= size[0]; anchor[0] *= size[0];
} }
if (this.anchorYUnits_ == ol.style.Icon.AnchorUnits.FRACTION) { if (this.anchorYUnits_ == ol.style.IconAnchorUnits.FRACTION) {
anchor[1] *= size[1]; anchor[1] *= size[1];
} }
} }
@@ -392,13 +393,3 @@ ol.style.Icon.prototype.unlistenImageChange = function(listener, thisArg) {
ol.events.unlisten(this.iconImage_, ol.events.EventType.CHANGE, ol.events.unlisten(this.iconImage_, ol.events.EventType.CHANGE,
listener, thisArg); listener, thisArg);
}; };
/**
* Icon anchor units. One of 'fraction', 'pixels'.
* @enum {string}
*/
ol.style.Icon.AnchorUnits = {
FRACTION: 'fraction',
PIXELS: 'pixels'
};
+10
View File
@@ -0,0 +1,10 @@
goog.provide('ol.style.IconAnchorUnits');
/**
* Icon anchor units. One of 'fraction', 'pixels'.
* @enum {string}
*/
ol.style.IconAnchorUnits = {
FRACTION: 'fraction',
PIXELS: 'pixels'
};
+2 -2
View File
@@ -284,8 +284,8 @@ ol.ImageLoadFunctionType;
/** /**
* @typedef {{x: number, xunits: (ol.style.Icon.AnchorUnits|undefined), * @typedef {{x: number, xunits: (ol.style.IconAnchorUnits|undefined),
* y: number, yunits: (ol.style.Icon.AnchorUnits|undefined)}} * y: number, yunits: (ol.style.IconAnchorUnits|undefined)}}
*/ */
ol.KMLVec2_; ol.KMLVec2_;