Rename ol.style.IconAnchorUnits and ol.style.IconOrigin

This commit is contained in:
Andreas Hocevar
2016-08-28 19:24:29 +02:00
committed by Tim Schaub
parent 1beddcd99a
commit a8d8942fba
5 changed files with 78 additions and 75 deletions

View File

@@ -4,6 +4,13 @@
As last step in the removal of the dependency on Google Closure Library, the `goog.DEBUG` compiler define was renamed to `ol.DEBUG`. Please change accordingly in your custom build configuration json files.
#### Changes only relevant to those who compile their applications together with the Closure Compiler
A number of internal types have been renamed. This will not affect those who use the API provided by the library, but if you are compiling your application together with OpenLayers and using type names, you'll need to do the following:
* rename `ol.style.IconAnchorUnits` to `ol.style.Icon.AnchorUnits`
* rename `ol.style.IconOrigin` to `ol.style.Icon.Origin`
### v3.18.0
#### Changes in the way assertions are handled

View File

@@ -2722,7 +2722,7 @@ olx.interaction.ExtentOptions;
olx.interaction.ExtentOptions.prototype.extent;
/**
* Style for the drawn extent box.
* Style for the drawn extent box.
* Defaults to ol.style.Style.createDefaultEditing()[ol.geom.GeometryType.POLYGON]
* @type {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction|undefined}
* @api
@@ -2730,7 +2730,7 @@ olx.interaction.ExtentOptions.prototype.extent;
olx.interaction.ExtentOptions.prototype.boxStyle;
/**
* Style for the cursor used to draw the extent.
* Style for the cursor used to draw the extent.
* Defaults to ol.style.Style.createDefaultEditing()[ol.geom.GeometryType.POINT]
* @type {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction|undefined}
* @api
@@ -2738,7 +2738,7 @@ olx.interaction.ExtentOptions.prototype.boxStyle;
olx.interaction.ExtentOptions.prototype.pointerStyle;
/**
* Wrap the drawn extent across multiple maps in the X direction?
* Wrap the drawn extent across multiple maps in the X direction?
* Only affects visuals, not functionality. Defaults to false.
* @type {boolean|undefined}
* @api
@@ -6636,14 +6636,14 @@ olx.style.FillOptions.prototype.color;
/**
* @typedef {{anchor: (Array.<number>|undefined),
* anchorOrigin: (ol.style.IconOrigin|undefined),
* anchorXUnits: (ol.style.IconAnchorUnits|undefined),
* anchorYUnits: (ol.style.IconAnchorUnits|undefined),
* anchorOrigin: (ol.style.Icon.Origin|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.IconOrigin|undefined),
* offsetOrigin: (ol.style.Icon.Origin|undefined),
* opacity: (number|undefined),
* scale: (number|undefined),
* snapToPixel: (boolean|undefined),
@@ -6667,7 +6667,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.IconOrigin|undefined}
* @type {ol.style.Icon.Origin|undefined}
* @api
*/
olx.style.IconOptions.prototype.anchorOrigin;
@@ -6677,7 +6677,7 @@ olx.style.IconOptions.prototype.anchorOrigin;
* 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 in pixels. Default is `'fraction'`.
* @type {ol.style.IconAnchorUnits|undefined}
* @type {ol.style.Icon.AnchorUnits|undefined}
* @api
*/
olx.style.IconOptions.prototype.anchorXUnits;
@@ -6687,7 +6687,7 @@ olx.style.IconOptions.prototype.anchorXUnits;
* 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 in pixels. Default is `'fraction'`.
* @type {ol.style.IconAnchorUnits|undefined}
* @type {ol.style.Icon.AnchorUnits|undefined}
* @api
*/
olx.style.IconOptions.prototype.anchorYUnits;
@@ -6736,7 +6736,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.IconOrigin|undefined}
* @type {ol.style.Icon.Origin|undefined}
* @api
*/
olx.style.IconOptions.prototype.offsetOrigin;

View File

@@ -27,8 +27,6 @@ goog.require('ol.math');
goog.require('ol.proj');
goog.require('ol.style.Fill');
goog.require('ol.style.Icon');
goog.require('ol.style.IconAnchorUnits');
goog.require('ol.style.IconOrigin');
goog.require('ol.style.Stroke');
goog.require('ol.style.Style');
goog.require('ol.style.Text');
@@ -168,19 +166,19 @@ ol.format.KML.createStyleDefaults_ = function() {
/**
* @const
* @type {ol.style.IconAnchorUnits}
* @type {ol.style.Icon.AnchorUnits}
* @private
*/
ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS_ =
ol.style.IconAnchorUnits.PIXELS;
ol.style.Icon.AnchorUnits.PIXELS;
/**
* @const
* @type {ol.style.IconAnchorUnits}
* @type {ol.style.Icon.AnchorUnits}
* @private
*/
ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_ =
ol.style.IconAnchorUnits.PIXELS;
ol.style.Icon.AnchorUnits.PIXELS;
/**
* @const
@@ -211,7 +209,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.IconOrigin.BOTTOM_LEFT,
anchorOrigin: ol.style.Icon.Origin.BOTTOM_LEFT,
anchorXUnits: ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS_,
anchorYUnits: ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_,
crossOrigin: 'anonymous',
@@ -286,12 +284,12 @@ ol.format.KML.createStyleDefaults_ = function() {
/**
* @const
* @type {Object.<string, ol.style.IconAnchorUnits>}
* @type {Object.<string, ol.style.Icon.AnchorUnits>}
* @private
*/
ol.format.KML.ICON_ANCHOR_UNITS_MAP_ = {
'fraction': ol.style.IconAnchorUnits.FRACTION,
'pixels': ol.style.IconAnchorUnits.PIXELS
'fraction': ol.style.Icon.AnchorUnits.FRACTION,
'pixels': ol.style.Icon.AnchorUnits.PIXELS
};
@@ -598,8 +596,8 @@ ol.format.KML.IconStyleParser_ = function(node, objectStack) {
anchorYUnits = ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_;
} else if (/^http:\/\/maps\.(?:google|gstatic)\.com\//.test(src)) {
anchor = [0.5, 0];
anchorXUnits = ol.style.IconAnchorUnits.FRACTION;
anchorYUnits = ol.style.IconAnchorUnits.FRACTION;
anchorXUnits = ol.style.Icon.AnchorUnits.FRACTION;
anchorYUnits = ol.style.Icon.AnchorUnits.FRACTION;
}
var offset;
@@ -645,12 +643,12 @@ ol.format.KML.IconStyleParser_ = function(node, objectStack) {
var imageStyle = new ol.style.Icon({
anchor: anchor,
anchorOrigin: ol.style.IconOrigin.BOTTOM_LEFT,
anchorOrigin: ol.style.Icon.Origin.BOTTOM_LEFT,
anchorXUnits: anchorXUnits,
anchorYUnits: anchorYUnits,
crossOrigin: 'anonymous', // FIXME should this be configurable?
offset: offset,
offsetOrigin: ol.style.IconOrigin.BOTTOM_LEFT,
offsetOrigin: ol.style.Icon.Origin.BOTTOM_LEFT,
rotation: rotation,
scale: scale,
size: size,
@@ -2190,9 +2188,9 @@ ol.format.KML.writeIconStyle_ = function(node, style, objectStack) {
if (anchor && anchor[0] !== 0 && anchor[1] !== size[1]) {
var /** @type {ol.KMLVec2_} */ hotSpot = {
x: anchor[0],
xunits: ol.style.IconAnchorUnits.PIXELS,
xunits: ol.style.Icon.AnchorUnits.PIXELS,
y: size[1] - anchor[1],
yunits: ol.style.IconAnchorUnits.PIXELS
yunits: ol.style.Icon.AnchorUnits.PIXELS
};
properties['hotSpot'] = hotSpot;
}

View File

@@ -1,6 +1,4 @@
goog.provide('ol.style.Icon');
goog.provide('ol.style.IconAnchorUnits');
goog.provide('ol.style.IconOrigin');
goog.require('ol');
goog.require('ol.asserts');
@@ -12,28 +10,6 @@ goog.require('ol.style.IconImage');
goog.require('ol.style.Image');
/**
* Icon anchor units. One of 'fraction', 'pixels'.
* @enum {string}
*/
ol.style.IconAnchorUnits = {
FRACTION: 'fraction',
PIXELS: 'pixels'
};
/**
* 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'
};
/**
* @classdesc
* Set icon style for vector features.
@@ -61,24 +37,24 @@ ol.style.Icon = function(opt_options) {
/**
* @private
* @type {ol.style.IconOrigin}
* @type {ol.style.Icon.Origin}
*/
this.anchorOrigin_ = options.anchorOrigin !== undefined ?
options.anchorOrigin : ol.style.IconOrigin.TOP_LEFT;
options.anchorOrigin : ol.style.Icon.Origin.TOP_LEFT;
/**
* @private
* @type {ol.style.IconAnchorUnits}
* @type {ol.style.Icon.AnchorUnits}
*/
this.anchorXUnits_ = options.anchorXUnits !== undefined ?
options.anchorXUnits : ol.style.IconAnchorUnits.FRACTION;
options.anchorXUnits : ol.style.Icon.AnchorUnits.FRACTION;
/**
* @private
* @type {ol.style.IconAnchorUnits}
* @type {ol.style.Icon.AnchorUnits}
*/
this.anchorYUnits_ = options.anchorYUnits !== undefined ?
options.anchorYUnits : ol.style.IconAnchorUnits.FRACTION;
options.anchorYUnits : ol.style.Icon.AnchorUnits.FRACTION;
/**
* @type {?string}
@@ -139,10 +115,10 @@ ol.style.Icon = function(opt_options) {
/**
* @private
* @type {ol.style.IconOrigin}
* @type {ol.style.Icon.Origin}
*/
this.offsetOrigin_ = options.offsetOrigin !== undefined ?
options.offsetOrigin : ol.style.IconOrigin.TOP_LEFT;
options.offsetOrigin : ol.style.Icon.Origin.TOP_LEFT;
/**
* @private
@@ -205,33 +181,33 @@ ol.style.Icon.prototype.getAnchor = function() {
}
var anchor = this.anchor_;
var size = this.getSize();
if (this.anchorXUnits_ == ol.style.IconAnchorUnits.FRACTION ||
this.anchorYUnits_ == ol.style.IconAnchorUnits.FRACTION) {
if (this.anchorXUnits_ == ol.style.Icon.AnchorUnits.FRACTION ||
this.anchorYUnits_ == ol.style.Icon.AnchorUnits.FRACTION) {
if (!size) {
return null;
}
anchor = this.anchor_.slice();
if (this.anchorXUnits_ == ol.style.IconAnchorUnits.FRACTION) {
if (this.anchorXUnits_ == ol.style.Icon.AnchorUnits.FRACTION) {
anchor[0] *= size[0];
}
if (this.anchorYUnits_ == ol.style.IconAnchorUnits.FRACTION) {
if (this.anchorYUnits_ == ol.style.Icon.AnchorUnits.FRACTION) {
anchor[1] *= size[1];
}
}
if (this.anchorOrigin_ != ol.style.IconOrigin.TOP_LEFT) {
if (this.anchorOrigin_ != ol.style.Icon.Origin.TOP_LEFT) {
if (!size) {
return null;
}
if (anchor === this.anchor_) {
anchor = this.anchor_.slice();
}
if (this.anchorOrigin_ == ol.style.IconOrigin.TOP_RIGHT ||
this.anchorOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
if (this.anchorOrigin_ == ol.style.Icon.Origin.TOP_RIGHT ||
this.anchorOrigin_ == ol.style.Icon.Origin.BOTTOM_RIGHT) {
anchor[0] = -anchor[0] + size[0];
}
if (this.anchorOrigin_ == ol.style.IconOrigin.BOTTOM_LEFT ||
this.anchorOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
if (this.anchorOrigin_ == ol.style.Icon.Origin.BOTTOM_LEFT ||
this.anchorOrigin_ == ol.style.Icon.Origin.BOTTOM_RIGHT) {
anchor[1] = -anchor[1] + size[1];
}
}
@@ -294,19 +270,19 @@ ol.style.Icon.prototype.getOrigin = function() {
}
var offset = this.offset_;
if (this.offsetOrigin_ != ol.style.IconOrigin.TOP_LEFT) {
if (this.offsetOrigin_ != ol.style.Icon.Origin.TOP_LEFT) {
var size = this.getSize();
var iconImageSize = this.iconImage_.getSize();
if (!size || !iconImageSize) {
return null;
}
offset = offset.slice();
if (this.offsetOrigin_ == ol.style.IconOrigin.TOP_RIGHT ||
this.offsetOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
if (this.offsetOrigin_ == ol.style.Icon.Origin.TOP_RIGHT ||
this.offsetOrigin_ == ol.style.Icon.Origin.BOTTOM_RIGHT) {
offset[0] = iconImageSize[0] - size[0] - offset[0];
}
if (this.offsetOrigin_ == ol.style.IconOrigin.BOTTOM_LEFT ||
this.offsetOrigin_ == ol.style.IconOrigin.BOTTOM_RIGHT) {
if (this.offsetOrigin_ == ol.style.Icon.Origin.BOTTOM_LEFT ||
this.offsetOrigin_ == ol.style.Icon.Origin.BOTTOM_RIGHT) {
offset[1] = iconImageSize[1] - size[1] - offset[1];
}
}
@@ -362,3 +338,25 @@ ol.style.Icon.prototype.unlistenImageChange = function(listener, thisArg) {
ol.events.unlisten(this.iconImage_, ol.events.EventType.CHANGE,
listener, thisArg);
};
/**
* Icon anchor units. One of 'fraction', 'pixels'.
* @enum {string}
*/
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

@@ -274,8 +274,8 @@ ol.ImageLoadFunctionType;
/**
* @typedef {{x: number, xunits: (ol.style.IconAnchorUnits|undefined),
* y: number, yunits: (ol.style.IconAnchorUnits|undefined)}}
* @typedef {{x: number, xunits: (ol.style.Icon.AnchorUnits|undefined),
* y: number, yunits: (ol.style.Icon.AnchorUnits|undefined)}}
*/
ol.KMLVec2_;