Symbolizers with method for creating literals

This commit is contained in:
Tim Schaub
2013-02-19 22:24:21 -07:00
parent 1faa6214f1
commit 7141721bb1
8 changed files with 500 additions and 6 deletions
+126 -2
View File
@@ -1,7 +1,11 @@
goog.provide('ol.style.LiteralShape');
goog.provide('ol.style.Shape');
goog.provide('ol.style.ShapeType');
goog.require('ol.Expression');
goog.require('ol.ExpressionLiteral');
goog.require('ol.style.LiteralPoint');
goog.require('ol.style.Point');
/**
@@ -20,14 +24,14 @@ ol.style.ShapeType = {
* strokeWidth: (number),
* opacity: (number)}}
*/
ol.style.LiteralShapeConfig;
ol.style.LiteralShapeOptions;
/**
* @constructor
* @extends {ol.style.LiteralPoint}
* @param {ol.style.LiteralShapeConfig} config Symbolizer properties.
* @param {ol.style.LiteralShapeOptions} config Symbolizer properties.
*/
ol.style.LiteralShape = function(config) {
@@ -51,3 +55,123 @@ ol.style.LiteralShape = function(config) {
};
goog.inherits(ol.style.LiteralShape, ol.style.LiteralPoint);
/**
* @typedef {{type: (ol.style.ShapeType),
* size: (number|ol.Expression),
* fillStyle: (string|ol.Expression),
* strokeStyle: (string|ol.Expression),
* strokeWidth: (number|ol.Expression),
* opacity: (number|ol.Expression)}}
*/
ol.style.ShapeOptions;
/**
* @constructor
* @extends {ol.style.Point}
* @param {ol.style.ShapeOptions} options Symbolizer properties.
*/
ol.style.Shape = function(options) {
/**
* @type {ol.style.ShapeType}
* @private
*/
this.type_ = /** @type {ol.style.ShapeType} */ goog.isDef(options.type) ?
options.type : ol.style.ShapeDefaults.type;
/**
* @type {ol.Expression}
* @private
*/
this.size_ = !goog.isDef(options.size) ?
new ol.ExpressionLiteral(ol.style.ShapeDefaults.size) :
(options.size instanceof ol.Expression) ?
options.size : new ol.ExpressionLiteral(options.size);
/**
* @type {ol.Expression}
* @private
*/
this.fillStyle_ = !goog.isDef(options.fillStyle) ?
new ol.ExpressionLiteral(ol.style.ShapeDefaults.fillStyle) :
(options.fillStyle instanceof ol.Expression) ?
options.fillStyle : new ol.ExpressionLiteral(options.fillStyle);
/**
* @type {ol.Expression}
* @private
*/
this.strokeStyle_ = !goog.isDef(options.strokeStyle) ?
new ol.ExpressionLiteral(ol.style.ShapeDefaults.strokeStyle) :
(options.strokeStyle instanceof ol.Expression) ?
options.strokeStyle : new ol.ExpressionLiteral(options.strokeStyle);
/**
* @type {ol.Expression}
* @private
*/
this.strokeWidth_ = !goog.isDef(options.strokeWidth) ?
new ol.ExpressionLiteral(ol.style.ShapeDefaults.strokeWidth) :
(options.strokeWidth instanceof ol.Expression) ?
options.strokeWidth : new ol.ExpressionLiteral(options.strokeWidth);
/**
* @type {ol.Expression}
* @private
*/
this.opacity_ = !goog.isDef(options.opacity) ?
new ol.ExpressionLiteral(ol.style.ShapeDefaults.opacity) :
(options.opacity instanceof ol.Expression) ?
options.opacity : new ol.ExpressionLiteral(options.opacity);
};
/**
* @inheritDoc
* @return {ol.style.LiteralShape} Literal shape symbolizer.
*/
ol.style.Shape.prototype.createLiteral = function(feature) {
var attrs = feature.getAttributes();
var size = this.size_.evaluate(feature, attrs);
goog.asserts.assertNumber(size, 'size must be a number');
var fillStyle = this.fillStyle_.evaluate(feature, attrs);
goog.asserts.assertString(fillStyle, 'fillStyle must be a string');
var strokeStyle = this.strokeStyle_.evaluate(feature, attrs);
goog.asserts.assertString(strokeStyle, 'strokeStyle must be a string');
var strokeWidth = this.strokeWidth_.evaluate(feature, attrs);
goog.asserts.assertNumber(strokeWidth, 'strokeWidth must be a number');
var opacity = this.opacity_.evaluate(feature, attrs);
goog.asserts.assertNumber(opacity, 'opacity must be a number');
return new ol.style.LiteralShape({
type: this.type_,
size: size,
fillStyle: fillStyle,
strokeStyle: strokeStyle,
strokeWidth: strokeWidth,
opacity: opacity
});
};
/**
* @type {ol.style.LiteralShape}
*/
ol.style.ShapeDefaults = new ol.style.LiteralShape({
type: ol.style.ShapeType.CIRCLE,
size: 5,
fillStyle: '#ffffff',
strokeStyle: '#696969',
strokeWidth: 1.5,
opacity: 0.75
});