Add placement, maxAngle and exceedLength options to ol.style.Text
This commit is contained in:
@@ -2,6 +2,7 @@ goog.provide('ol.style.Text');
|
||||
|
||||
|
||||
goog.require('ol.style.Fill');
|
||||
goog.require('ol.style.TextPlacement');
|
||||
|
||||
|
||||
/**
|
||||
@@ -65,6 +66,24 @@ ol.style.Text = function(opt_options) {
|
||||
this.fill_ = options.fill !== undefined ? options.fill :
|
||||
new ol.style.Fill({color: ol.style.Text.DEFAULT_FILL_COLOR_});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxAngle_ = options.maxAngle !== undefined ? options.maxAngle : Math.PI / 4;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.style.TextPlacement|string}
|
||||
*/
|
||||
this.placement_ = options.placement !== undefined ? options.placement : ol.style.TextPlacement.POINT;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.exceedLength_ = options.exceedLength !== undefined ? options.exceedLength : false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.style.Stroke}
|
||||
@@ -103,6 +122,9 @@ ol.style.Text.DEFAULT_FILL_COLOR_ = '#333';
|
||||
ol.style.Text.prototype.clone = function() {
|
||||
return new ol.style.Text({
|
||||
font: this.getFont(),
|
||||
placement: this.getPlacement(),
|
||||
maxAngle: this.getMaxAngle(),
|
||||
exceedLength: this.getExceedLength(),
|
||||
rotation: this.getRotation(),
|
||||
rotateWithView: this.getRotateWithView(),
|
||||
scale: this.getScale(),
|
||||
@@ -117,6 +139,16 @@ ol.style.Text.prototype.clone = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the `exceedLength` configuration.
|
||||
* @return {boolean} Let text exceed the length of the path they follow.
|
||||
* @api
|
||||
*/
|
||||
ol.style.Text.prototype.getExceedLength = function() {
|
||||
return this.exceedLength_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the font name.
|
||||
* @return {string|undefined} Font.
|
||||
@@ -127,6 +159,26 @@ ol.style.Text.prototype.getFont = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the maximum angle between adjacent characters.
|
||||
* @return {number} Angle in radians.
|
||||
* @api
|
||||
*/
|
||||
ol.style.Text.prototype.getMaxAngle = function() {
|
||||
return this.maxAngle_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the label placement.
|
||||
* @return {ol.style.TextPlacement|string} Text placement.
|
||||
* @api
|
||||
*/
|
||||
ol.style.Text.prototype.getPlacement = function() {
|
||||
return this.placement_;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get the x-offset for the text.
|
||||
* @return {number} Horizontal text offset.
|
||||
@@ -227,6 +279,17 @@ ol.style.Text.prototype.getTextBaseline = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the `exceedLength` property.
|
||||
*
|
||||
* @param {boolean} exceedLength Let text exceed the path that it follows.
|
||||
* @api
|
||||
*/
|
||||
ol.style.Text.prototype.setExceedLength = function(exceedLength) {
|
||||
this.exceedLength_ = exceedLength;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the font.
|
||||
*
|
||||
@@ -238,6 +301,17 @@ ol.style.Text.prototype.setFont = function(font) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the maximum angle between adjacent characters.
|
||||
*
|
||||
* @param {number} maxAngle Angle in radians.
|
||||
* @api
|
||||
*/
|
||||
ol.style.Text.prototype.setMaxAngle = function(maxAngle) {
|
||||
this.maxAngle_ = maxAngle;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the x offset.
|
||||
*
|
||||
@@ -260,6 +334,17 @@ ol.style.Text.prototype.setOffsetY = function(offsetY) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the text placement.
|
||||
*
|
||||
* @param {ol.style.TextPlacement|string} placement Placement.
|
||||
* @api
|
||||
*/
|
||||
ol.style.Text.prototype.setPlacement = function(placement) {
|
||||
this.placement_ = placement;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Set the fill.
|
||||
*
|
||||
|
||||
14
src/ol/style/textplacement.js
Normal file
14
src/ol/style/textplacement.js
Normal file
@@ -0,0 +1,14 @@
|
||||
goog.provide('ol.style.TextPlacement');
|
||||
|
||||
|
||||
/**
|
||||
* Text placement. One of `'point'`, `'line'`. Default is `'point'`. Note that
|
||||
* `'line'` requires the underlying geometry to be a {@link ol.geom.LineString},
|
||||
* {@link ol.geom.Polygon}, {@link ol.geom.MultiLineString} or
|
||||
* {@link ol.geom.MultiPolygon}.
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.style.TextPlacement = {
|
||||
POINT: 'point',
|
||||
LINE: 'line'
|
||||
};
|
||||
Reference in New Issue
Block a user