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

@@ -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_;