Proper handling of defaults
This commit is contained in:
+15
-17
@@ -9,8 +9,8 @@ goog.require('ol.style.SymbolizerLiteral');
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{color: (string|undefined),
|
* @typedef {{color: string,
|
||||||
* fontFamily: (string|undefined),
|
* fontFamily: string,
|
||||||
* fontSize: number,
|
* fontSize: number,
|
||||||
* text: string,
|
* text: string,
|
||||||
* opacity: number}}
|
* opacity: number}}
|
||||||
@@ -26,13 +26,13 @@ ol.style.TextLiteralOptions;
|
|||||||
*/
|
*/
|
||||||
ol.style.TextLiteral = function(options) {
|
ol.style.TextLiteral = function(options) {
|
||||||
|
|
||||||
/** @type {string|undefined} */
|
/** @type {string} */
|
||||||
this.color = options.color;
|
this.color = options.color;
|
||||||
if (goog.isDef(options.color)) {
|
if (goog.isDef(options.color)) {
|
||||||
goog.asserts.assertString(options.color, 'color must be a string');
|
goog.asserts.assertString(options.color, 'color must be a string');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {string|undefined} */
|
/** @type {string} */
|
||||||
this.fontFamily = options.fontFamily;
|
this.fontFamily = options.fontFamily;
|
||||||
if (goog.isDef(options.fontFamily)) {
|
if (goog.isDef(options.fontFamily)) {
|
||||||
goog.asserts.assertString(options.fontFamily,
|
goog.asserts.assertString(options.fontFamily,
|
||||||
@@ -79,7 +79,7 @@ ol.style.Text = function(options) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.color_ = !goog.isDef(options.color) ?
|
this.color_ = !goog.isDef(options.color) ?
|
||||||
null :
|
new ol.ExpressionLiteral(ol.style.TextDefaults.color) :
|
||||||
(options.color instanceof ol.Expression) ?
|
(options.color instanceof ol.Expression) ?
|
||||||
options.color : new ol.ExpressionLiteral(options.color);
|
options.color : new ol.ExpressionLiteral(options.color);
|
||||||
|
|
||||||
@@ -87,8 +87,8 @@ ol.style.Text = function(options) {
|
|||||||
* @type {ol.Expression}
|
* @type {ol.Expression}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.fontFamily_ = !goog.isDefAndNotNull(options.fontFamily) ?
|
this.fontFamily_ = !goog.isDef(options.fontFamily) ?
|
||||||
null :
|
new ol.ExpressionLiteral(ol.style.TextDefaults.fontFamily) :
|
||||||
(options.fontFamily instanceof ol.Expression) ?
|
(options.fontFamily instanceof ol.Expression) ?
|
||||||
options.fontFamily : new ol.ExpressionLiteral(options.fontFamily);
|
options.fontFamily : new ol.ExpressionLiteral(options.fontFamily);
|
||||||
|
|
||||||
@@ -96,8 +96,8 @@ ol.style.Text = function(options) {
|
|||||||
* @type {ol.Expression}
|
* @type {ol.Expression}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.fontSize_ = !goog.isDefAndNotNull(options.fontSize) ?
|
this.fontSize_ = !goog.isDef(options.fontSize) ?
|
||||||
null :
|
new ol.ExpressionLiteral(ol.style.TextDefaults.fontSize) :
|
||||||
(options.fontSize instanceof ol.Expression) ?
|
(options.fontSize instanceof ol.Expression) ?
|
||||||
options.fontSize : new ol.ExpressionLiteral(options.fontSize);
|
options.fontSize : new ol.ExpressionLiteral(options.fontSize);
|
||||||
|
|
||||||
@@ -132,15 +132,11 @@ ol.style.Text.prototype.createLiteral = function(opt_feature) {
|
|||||||
attrs = feature.getAttributes();
|
attrs = feature.getAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
var color = goog.isNull(this.color_) ?
|
var color = this.color_.evaluate(feature, attrs);
|
||||||
undefined :
|
goog.asserts.assertString(color, 'color must be a string');
|
||||||
/** @type {string} */ (this.color_.evaluate(feature, attrs));
|
|
||||||
goog.asserts.assert(!goog.isDef(color) || goog.isString(color));
|
|
||||||
|
|
||||||
var fontFamily = goog.isNull(this.fontFamily_) ?
|
var fontFamily = this.fontFamily_.evaluate(feature, attrs);
|
||||||
undefined :
|
goog.asserts.assertString(fontFamily, 'fontFamily must be a string');
|
||||||
/** @type {string} */ (this.fontFamily_.evaluate(feature, attrs));
|
|
||||||
goog.asserts.assert(!goog.isDef(fontFamily) || goog.isString(fontFamily));
|
|
||||||
|
|
||||||
var fontSize = this.fontSize_.evaluate(feature, attrs);
|
var fontSize = this.fontSize_.evaluate(feature, attrs);
|
||||||
goog.asserts.assertNumber(fontSize, 'fontSize must be a number');
|
goog.asserts.assertNumber(fontSize, 'fontSize must be a number');
|
||||||
@@ -165,6 +161,8 @@ ol.style.Text.prototype.createLiteral = function(opt_feature) {
|
|||||||
* @type {ol.style.TextLiteral}
|
* @type {ol.style.TextLiteral}
|
||||||
*/
|
*/
|
||||||
ol.style.TextDefaults = new ol.style.TextLiteral({
|
ol.style.TextDefaults = new ol.style.TextLiteral({
|
||||||
|
color: '#000',
|
||||||
|
fontFamily: 'sans-serif',
|
||||||
fontSize: 10,
|
fontSize: 10,
|
||||||
text: '',
|
text: '',
|
||||||
opacity: 1
|
opacity: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user