diff --git a/externs/olx.js b/externs/olx.js index 22dcd4c472..cf0e8c1add 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -7658,8 +7658,11 @@ olx.style.StrokeOptions.prototype.width; /** * @typedef {{font: (string|undefined), + * exceedLength: (boolean|undefined), + * maxAngle: (number|undefined), * offsetX: (number|undefined), * offsetY: (number|undefined), + * placement: (ol.style.TextPlacement|string|undefined), * scale: (number|undefined), * rotateWithView: (boolean|undefined), * rotation: (number|undefined), @@ -7672,6 +7675,15 @@ olx.style.StrokeOptions.prototype.width; olx.style.TextOptions; +/** + * When `placement` is set to `'line'`, allow text to exceed the length of the + * path that it follows. Default is `false`. + * @type {boolean|undefined} + * @api + */ +olx.style.TextOptions.prototype.exceedLength; + + /** * Font style as CSS 'font' value, see: * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/font}. @@ -7682,6 +7694,16 @@ olx.style.TextOptions; olx.style.TextOptions.prototype.font; +/** + * When `placement` is set to `'line'`, allow a maximum angle between adjacent + * characters. The expected value is in radians, and the default is 45° + * (`Math.PI / 4`). + * @type {number|undefined} + * @api + */ +olx.style.TextOptions.prototype.maxAngle; + + /** * Horizontal text offset in pixels. A positive will shift the text right. * Default is `0`. @@ -7700,6 +7722,14 @@ olx.style.TextOptions.prototype.offsetX; olx.style.TextOptions.prototype.offsetY; +/** + * Text placement. + * @type {ol.style.TextPlacement|undefined} + * @api + */ +olx.style.TextOptions.prototype.placement; + + /** * Scale. * @type {number|undefined} diff --git a/src/ol/style/text.js b/src/ol/style/text.js index c4ba6327f3..ddb484f42b 100644 --- a/src/ol/style/text.js +++ b/src/ol/style/text.js @@ -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. * diff --git a/src/ol/style/textplacement.js b/src/ol/style/textplacement.js new file mode 100644 index 0000000000..39c45e06b4 --- /dev/null +++ b/src/ol/style/textplacement.js @@ -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' +};