Dedicated module for icon anchor units enum
This commit is contained in:
@@ -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.IconAnchorUnits');
|
||||
goog.require('ol.style.IconOrigin');
|
||||
goog.require('ol.style.Stroke');
|
||||
goog.require('ol.style.Style');
|
||||
@@ -170,19 +171,19 @@ ol.format.KML.createStyleDefaults_ = function() {
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.style.Icon.AnchorUnits}
|
||||
* @type {ol.style.IconAnchorUnits}
|
||||
* @private
|
||||
*/
|
||||
ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_X_UNITS_ =
|
||||
ol.style.Icon.AnchorUnits.PIXELS;
|
||||
ol.style.IconAnchorUnits.PIXELS;
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {ol.style.Icon.AnchorUnits}
|
||||
* @type {ol.style.IconAnchorUnits}
|
||||
* @private
|
||||
*/
|
||||
ol.format.KML.DEFAULT_IMAGE_STYLE_ANCHOR_Y_UNITS_ =
|
||||
ol.style.Icon.AnchorUnits.PIXELS;
|
||||
ol.style.IconAnchorUnits.PIXELS;
|
||||
|
||||
/**
|
||||
* @const
|
||||
@@ -288,12 +289,12 @@ ol.format.KML.createStyleDefaults_ = function() {
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @type {Object.<string, ol.style.Icon.AnchorUnits>}
|
||||
* @type {Object.<string, ol.style.IconAnchorUnits>}
|
||||
* @private
|
||||
*/
|
||||
ol.format.KML.ICON_ANCHOR_UNITS_MAP_ = {
|
||||
'fraction': ol.style.Icon.AnchorUnits.FRACTION,
|
||||
'pixels': ol.style.Icon.AnchorUnits.PIXELS
|
||||
'fraction': ol.style.IconAnchorUnits.FRACTION,
|
||||
'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_;
|
||||
} else if (/^http:\/\/maps\.(?:google|gstatic)\.com\//.test(src)) {
|
||||
anchor = [0.5, 0];
|
||||
anchorXUnits = ol.style.Icon.AnchorUnits.FRACTION;
|
||||
anchorYUnits = ol.style.Icon.AnchorUnits.FRACTION;
|
||||
anchorXUnits = ol.style.IconAnchorUnits.FRACTION;
|
||||
anchorYUnits = ol.style.IconAnchorUnits.FRACTION;
|
||||
}
|
||||
|
||||
var offset;
|
||||
@@ -2412,9 +2413,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.Icon.AnchorUnits.PIXELS,
|
||||
xunits: ol.style.IconAnchorUnits.PIXELS,
|
||||
y: size[1] - anchor[1],
|
||||
yunits: ol.style.Icon.AnchorUnits.PIXELS
|
||||
yunits: ol.style.IconAnchorUnits.PIXELS
|
||||
};
|
||||
properties['hotSpot'] = hotSpot;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ goog.require('ol.asserts');
|
||||
goog.require('ol.color');
|
||||
goog.require('ol.events');
|
||||
goog.require('ol.events.EventType');
|
||||
goog.require('ol.style.IconAnchorUnits');
|
||||
goog.require('ol.style.IconImage');
|
||||
goog.require('ol.style.IconOrigin');
|
||||
goog.require('ol.style.Image');
|
||||
@@ -45,17 +46,17 @@ ol.style.Icon = function(opt_options) {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.style.Icon.AnchorUnits}
|
||||
* @type {ol.style.IconAnchorUnits}
|
||||
*/
|
||||
this.anchorXUnits_ = options.anchorXUnits !== undefined ?
|
||||
options.anchorXUnits : ol.style.Icon.AnchorUnits.FRACTION;
|
||||
options.anchorXUnits : ol.style.IconAnchorUnits.FRACTION;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.style.Icon.AnchorUnits}
|
||||
* @type {ol.style.IconAnchorUnits}
|
||||
*/
|
||||
this.anchorYUnits_ = options.anchorYUnits !== undefined ?
|
||||
options.anchorYUnits : ol.style.Icon.AnchorUnits.FRACTION;
|
||||
options.anchorYUnits : ol.style.IconAnchorUnits.FRACTION;
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -225,16 +226,16 @@ ol.style.Icon.prototype.getAnchor = function() {
|
||||
}
|
||||
var anchor = this.anchor_;
|
||||
var size = this.getSize();
|
||||
if (this.anchorXUnits_ == ol.style.Icon.AnchorUnits.FRACTION ||
|
||||
this.anchorYUnits_ == ol.style.Icon.AnchorUnits.FRACTION) {
|
||||
if (this.anchorXUnits_ == ol.style.IconAnchorUnits.FRACTION ||
|
||||
this.anchorYUnits_ == ol.style.IconAnchorUnits.FRACTION) {
|
||||
if (!size) {
|
||||
return null;
|
||||
}
|
||||
anchor = this.anchor_.slice();
|
||||
if (this.anchorXUnits_ == ol.style.Icon.AnchorUnits.FRACTION) {
|
||||
if (this.anchorXUnits_ == ol.style.IconAnchorUnits.FRACTION) {
|
||||
anchor[0] *= size[0];
|
||||
}
|
||||
if (this.anchorYUnits_ == ol.style.Icon.AnchorUnits.FRACTION) {
|
||||
if (this.anchorYUnits_ == ol.style.IconAnchorUnits.FRACTION) {
|
||||
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,
|
||||
listener, thisArg);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Icon anchor units. One of 'fraction', 'pixels'.
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.style.Icon.AnchorUnits = {
|
||||
FRACTION: 'fraction',
|
||||
PIXELS: 'pixels'
|
||||
};
|
||||
|
||||
10
src/ol/style/iconanchorunits.js
Normal file
10
src/ol/style/iconanchorunits.js
Normal 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'
|
||||
};
|
||||
@@ -284,8 +284,8 @@ ol.ImageLoadFunctionType;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{x: number, xunits: (ol.style.Icon.AnchorUnits|undefined),
|
||||
* y: number, yunits: (ol.style.Icon.AnchorUnits|undefined)}}
|
||||
* @typedef {{x: number, xunits: (ol.style.IconAnchorUnits|undefined),
|
||||
* y: number, yunits: (ol.style.IconAnchorUnits|undefined)}}
|
||||
*/
|
||||
ol.KMLVec2_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user