diff --git a/examples/georss-flickr.html b/examples/georss-flickr.html new file mode 100644 index 0000000000..e2991466bd --- /dev/null +++ b/examples/georss-flickr.html @@ -0,0 +1,105 @@ + + + + + + + +

GeoRSS from Flickr in OpenLayers

+

The displayed GeoRSS feed has a <media:thumbnail/> property for each item. An extended createFeatureFromItem() function is used to add this attribute to the attributes hash of each feature read in by OpenLayers.Format.GeoRSS. The example is configured with a style to render each item with its thumbnail image. Also, to show how rules work, we defined a rule that if the title of an rss item contains "powder", it will be rendered larger than the others.

+
+ + diff --git a/examples/xml/georss-flickr.xml b/examples/xml/georss-flickr.xml new file mode 100644 index 0000000000..23ec199bfe --- /dev/null +++ b/examples/xml/georss-flickr.xml @@ -0,0 +1,730 @@ + + + + Photos from everyone tagged snowboard and powder, with geodata + http://www.flickr.com/photos/ + + Sat, 24 Nov 2007 16:25:03 -0800 + Sat, 24 Nov 2007 16:25:03 -0800 + + http://www.flickr.com/ + + http://www.flickr.com/images/buddyicon.jpg + Photos from everyone tagged snowboard and powder, with geodata + http://www.flickr.com/photos/ + + + + hofü07_5259 + http://www.flickr.com/photos/-mo-/2061136492/ + I - mo - I posted a photo:

+ +

hofü07_5259

+ + ]]>
+ Sat, 24 Nov 2007 16:25:03 -0800 + 2007-11-17T12:01:18-08:00 + nobody@flickr.com (I - mo - I) + tag:flickr.com,2004:/photo/2061136492 + 47.25162 11.754426 + + + 47.25162 + 11.754426 + + + hofü07_5259 + I - mo - I posted a photo:

+ +

hofü07_5259

+ + ]]>
+ + I - mo - I + sun snow fall fun austria yeah powder snowboard tyrol 2007 hochfügen powderahyeahturn + +
+ + First tracks + + http://www.flickr.com/photos/ruthanddave/2046899659/ + Ruth and Dave posted a photo:

+ +

First tracks

+ +

Not mine, alas.

+ ]]>
+ Mon, 19 Nov 2007 08:20:11 -0800 + 2007-11-18T11:19:50-08:00 + nobody@flickr.com (Ruth and Dave) + tag:flickr.com,2004:/photo/2046899659 + + 50.107423 -122.899847 + + 50.107423 + -122.899847 + + + First tracks + Ruth and Dave posted a photo:

+ +

First tracks

+ +

Not mine, alas.

+ ]]>
+ + Ruth and Dave + november lines whistler snowboarding tracks peak powder snowboard turns freshies + +
+ + + Powder turns + http://www.flickr.com/photos/ruthanddave/2047707124/ + Ruth and Dave posted a photo:

+ +

Powder turns

+ + ]]>
+ Mon, 19 Nov 2007 08:26:04 -0800 + 2007-11-18T11:19:57-08:00 + nobody@flickr.com (Ruth and Dave) + tag:flickr.com,2004:/photo/2047707124 + 50.107423 -122.899847 + + + 50.107423 + -122.899847 + + + Powder turns + Ruth and Dave posted a photo:

+ +

Powder turns

+ + ]]>
+ + Ruth and Dave + november face lines whistler snowboarding tracks first peak powder fresh snowboard turns + +
+ + Splitboard + + http://www.flickr.com/photos/hamsgod/1330385819/ + @nt!x posted a photo:

+ +

Splitboard

+ + ]]>
+ Wed, 5 Sep 2007 09:00:56 -0800 + 2007-03-04T04:40:12-08:00 + nobody@flickr.com (@nt!x) + tag:flickr.com,2004:/photo/1330385819 + 41.931831 -111.646049 + + + 41.931831 + -111.646049 + + + Splitboard + @nt!x posted a photo:

+ +

Splitboard

+ + ]]>
+ + @nt!x + snow mountains snowboarding utah powder yurt snowboard splitboard supershot + +
+ + Fresh powder + + http://www.flickr.com/photos/oliver80/1266854486/ + Oliver Astrologo posted a photo:

+ +

Fresh powder

+ + ]]>
+ Wed, 29 Aug 2007 05:19:36 -0800 + 2007-08-24T10:05:48-08:00 + nobody@flickr.com (Oliver Astrologo) + tag:flickr.com,2004:/photo/1266854486 + 46.528236 10.449789 + + + 46.528236 + 10.449789 + + + Fresh powder + Oliver Astrologo posted a photo:

+ +

Fresh powder

+ + ]]>
+ + Oliver Astrologo + sky people italy panorama mountain snow alps landscape powder snowboard rider snowboarder passo ghiacciaio stelvio + +
+ + Sawatch Range From Vail Pano + + http://www.flickr.com/photos/dman861/498747983/ + dman861 posted a photo:

+ +

Sawatch Range From Vail Pano

+ +

View near the Eagle's Nest at the top of Eagle Bahn Gondola. Mount of the Holy Cross mountain is visible in this picture but you can't make out the cross shape. I have no idea who the lady is. Handheld panorama, stitch of 5 + photos.

+ ]]>
+ Mon, 14 May 2007 17:05:11 -0800 + 2007-05-14T15:00:27-08:00 + nobody@flickr.com (dman861) + tag:flickr.com,2004:/photo/498747983 + + 39.617598 -106.386773 + + 39.617598 + -106.386773 + + + Sawatch Range From Vail Pano + dman861 posted a photo:

+ +

Sawatch Range From Vail Pano

+ +

View near the Eagle's Nest at the top of Eagle Bahn Gondola. Mount of the Holy Cross mountain is visible in this picture but you can't make out the cross shape. I have no idea who the lady is. Handheld panorama, stitch of 5 + photos.

+ ]]>
+ + dman861 + + trees sky panorama mountain snow ski mountains sport pinetree person photo colorado peak wideangle panoramic powder resort panasonic trail vail snowboard gondola beavercreek range avon mountainrange mountoftheholycross sawatch dmctz3 tz3 + + +
+ + + Flash Powder + http://www.flickr.com/photos/eckan/488776800/ + Erik Eckerström posted a photo:

+ +

Flash Powder

+ +

Some late night powder in Åre

+ ]]>
+ Mon, 7 May 2007 13:17:48 -0800 + 2007-01-18T15:37:17-08:00 + nobody@flickr.com (Erik Eckerström) + tag:flickr.com,2004:/photo/488776800 + + 63.409238 13.079953 + + 63.409238 + 13.079953 + + + Flash Powder + Erik Eckerström posted a photo:

+ +

Flash Powder

+ +

Some late night powder in Åre

+ ]]>
+ + Erik Eckerström + snow forest canon eos board flash powder snowboard portfolio Åre 30d canon30d canoneos30d are + +
+ + + Hannes and Reini + http://www.flickr.com/photos/moschitz/483974969/ + martinom posted a photo:

+ +

Hannes and Reini

+ + ]]>
+ Fri, 4 May 2007 08:56:02 -0800 + 2007-03-26T12:17:53-08:00 + nobody@flickr.com (martinom) + tag:flickr.com,2004:/photo/483974969 + 47.252086 14.365139 + + + 47.252086 + 14.365139 + + + Hannes and Reini + martinom posted a photo:

+ +

Hannes and Reini

+ + ]]>
+ + martinom + powder snowboard autoupload obertauern lachtal + +
+ + Zehnerkar, Obertauern + + http://www.flickr.com/photos/moschitz/483975805/ + martinom posted a photo:

+ +

Zehnerkar, Obertauern

+ + ]]>
+ Fri, 4 May 2007 08:56:46 -0800 + 2007-03-21T15:56:56-08:00 + nobody@flickr.com (martinom) + tag:flickr.com,2004:/photo/483975805 + 47.249698 13.557643 + + + 47.249698 + 13.557643 + + + Zehnerkar, Obertauern + martinom posted a photo:

+ +

Zehnerkar, Obertauern

+ + ]]>
+ + martinom + powder snowboard autoupload obertauern lachtal + +
+ + Uhh, thats high + + http://www.flickr.com/photos/moschitz/483941044/ + martinom posted a photo:

+ +

Uhh, thats high

+ + ]]>
+ Fri, 4 May 2007 08:55:25 -0800 + 2007-03-23T11:38:54-08:00 + nobody@flickr.com (martinom) + tag:flickr.com,2004:/photo/483941044 + 47.258669 14.359989 + + + 47.258669 + 14.359989 + + + Uhh, thats high + martinom posted a photo:

+ +

Uhh, thats high

+ + ]]>
+ + martinom + powder snowboard autoupload obertauern lachtal + +
+ + Powder days + + http://www.flickr.com/photos/moschitz/483973863/ + martinom posted a photo:

+ +

Powder days

+ + ]]>
+ Fri, 4 May 2007 08:55:02 -0800 + 2007-03-26T11:25:01-08:00 + nobody@flickr.com (martinom) + tag:flickr.com,2004:/photo/483973863 + 47.258669 14.359989 + + + 47.258669 + 14.359989 + + + Powder days + martinom posted a photo:

+ +

Powder days

+ + ]]>
+ + martinom + powder snowboard autoupload obertauern lachtal + +
+ + Getting ready + + http://www.flickr.com/photos/moschitz/483940792/ + martinom posted a photo:

+ +

Getting ready

+ + ]]>
+ Fri, 4 May 2007 08:55:14 -0800 + 2007-03-23T11:38:53-08:00 + nobody@flickr.com (martinom) + tag:flickr.com,2004:/photo/483940792 + 47.258669 14.359989 + + + 47.258669 + 14.359989 + + + Getting ready + martinom posted a photo:

+ +

Getting ready

+ + ]]>
+ + martinom + powder snowboard autoupload obertauern lachtal + +
+ + Going up and getting ready for the descent + + http://www.flickr.com/photos/moschitz/483941528/ + martinom posted a photo:

+ +

Going up and getting ready for the descent

+ + ]]>
+ Fri, 4 May 2007 08:55:50 -0800 + 2007-03-26T12:17:17-08:00 + nobody@flickr.com (martinom) + tag:flickr.com,2004:/photo/483941528 + 47.258669 14.359989 + + + 47.258669 + 14.359989 + + + Going up and getting ready for the descent + martinom posted a photo:

+ +

Going up and getting ready for the descent

+ + ]]>
+ + martinom + powder snowboard autoupload obertauern lachtal + +
+ + I made it! + + http://www.flickr.com/photos/moschitz/483941314/ + martinom posted a photo:

+ +

I made it!

+ + ]]>
+ Fri, 4 May 2007 08:55:39 -0800 + 2007-03-23T11:38:54-08:00 + nobody@flickr.com (martinom) + tag:flickr.com,2004:/photo/483941314 + 47.258669 14.359989 + + + 47.258669 + 14.359989 + + + I made it! + martinom posted a photo:

+ +

I made it!

+ + ]]>
+ + martinom + powder snowboard autoupload obertauern lachtal + +
+ + Reini and me + + http://www.flickr.com/photos/moschitz/483942166/ + martinom posted a photo:

+ +

Reini and me

+ + ]]>
+ Fri, 4 May 2007 08:56:24 -0800 + 2007-03-21T15:45:38-08:00 + nobody@flickr.com (martinom) + tag:flickr.com,2004:/photo/483942166 + 47.249698 13.557643 + + + 47.249698 + 13.557643 + + + Reini and me + martinom posted a photo:

+ +

Reini and me

+ + ]]>
+ + martinom + powder snowboard autoupload obertauern lachtal + +
+ + Obertauern + + http://www.flickr.com/photos/moschitz/483976145/ + martinom posted a photo:

+ +

Obertauern

+ + ]]>
+ Fri, 4 May 2007 08:57:04 -0800 + 2007-03-21T15:48:01-08:00 + nobody@flickr.com (martinom) + tag:flickr.com,2004:/photo/483976145 + 47.249698 13.557643 + + + 47.249698 + 13.557643 + + + Obertauern + martinom posted a photo:

+ +

Obertauern

+ + ]]>
+ + martinom + powder snowboard autoupload obertauern lachtal + +
+ + Ross Fall Line 2 + + http://www.flickr.com/photos/pwadsworth/480290173/ + phwadsworth posted a photo:

+ +

Ross Fall Line 2

+ + ]]>
+ Tue, 1 May 2007 12:02:23 -0800 + 2007-05-01T15:02:23-08:00 + nobody@flickr.com (phwadsworth) + tag:flickr.com,2004:/photo/480290173 + 44.196728 -72.926688 + + + 44.196728 + -72.926688 + + + Ross Fall Line 2 + phwadsworth posted a photo:

+ +

Ross Fall Line 2

+ + ]]>
+ + phwadsworth + ski river geotagged powder glen snowboard mad vt mrg vemont + +
+ + Ross Fall Line 1 + + http://www.flickr.com/photos/pwadsworth/480290169/ + phwadsworth posted a photo:

+ +

Ross Fall Line 1

+ + ]]>
+ Tue, 1 May 2007 12:02:23 -0800 + 2007-05-01T15:02:23-08:00 + nobody@flickr.com (phwadsworth) + tag:flickr.com,2004:/photo/480290169 + 44.196728 -72.926688 + + + 44.196728 + -72.926688 + + + Ross Fall Line 1 + phwadsworth posted a photo:

+ +

Ross Fall Line 1

+ + ]]>
+ + phwadsworth + ski river geotagged powder glen snowboard mad vt mrg vemont + +
+ + IMGP0575 + + http://www.flickr.com/photos/beppoegeppa/471446918/ + beppovox posted a photo:

+ +

IMGP0575

+ + ]]>
+ Tue, 24 Apr 2007 10:32:41 -0800 + 2003-12-29T11:07:29-08:00 + nobody@flickr.com (beppovox) + tag:flickr.com,2004:/photo/471446918 + 45.082308 6.761913 + + + 45.082308 + 6.761913 + + + IMGP0575 + beppovox posted a photo:

+ +

IMGP0575

+ + ]]>
+ + beppovox + geotagged free powder snowboard freeride jafferau + +
+ + Slopes + + http://www.flickr.com/photos/blupic/469735045/ + blupic.com posted a photo:

+ +

Slopes

+ +

One day...

+ ]]>
+ Mon, 23 Apr 2007 02:48:17 -0800 + 2007-03-31T17:31:13-08:00 + nobody@flickr.com (blupic.com) + tag:flickr.com,2004:/photo/469735045 + + 50.111882 -122.939436 + + 50.111882 + -122.939436 + + + Slopes + blupic.com posted a photo:

+ +

Slopes

+ +

One day...

+ ]]>
+ + blupic.com + blue winter sky mountain snow canada ski nature vancouver whistler nikon skiing d70 peak columbia powder 1870mmf3545g snowboard british blackcomb mogul + +
+ +
+
\ No newline at end of file diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index 877455a4b1..1719e68f5d 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -164,6 +164,11 @@ "OpenLayers/Renderer/VML.js", "OpenLayers/Layer/Vector.js", "OpenLayers/Layer/GML.js", + "OpenLayers/Style.js", + "OpenLayers/Rule.js", + "OpenLayers/Rule/FeatureId.js", + "OpenLayers/Rule/Logical.js", + "OpenLayers/Rule/Comparison.js", "OpenLayers/Format.js", "OpenLayers/Format/XML.js", "OpenLayers/Format/GML.js", diff --git a/lib/OpenLayers/Layer/Vector.js b/lib/OpenLayers/Layer/Vector.js index 332206113f..2af80dad28 100644 --- a/lib/OpenLayers/Layer/Vector.js +++ b/lib/OpenLayers/Layer/Vector.js @@ -350,6 +350,12 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { style = this.style; } } + + if (style && style.CLASS_NAME && + style.CLASS_NAME == "OpenLayers.Style") { + style = style.createStyle(feature); + } + this.renderer.drawFeature(feature, style); }, diff --git a/lib/OpenLayers/Rule.js b/lib/OpenLayers/Rule.js new file mode 100644 index 0000000000..f7b0c66bfa --- /dev/null +++ b/lib/OpenLayers/Rule.js @@ -0,0 +1,90 @@ +/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license. + * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt + * for the full text of the license. */ + + +/** + * @requires OpenLayers/Util.js + * @requires OpenLayers/Style.js + * + * Class: OpenLayers.Rule + * + * This class represents a OGC Rule, as being used for rule-based SLD styling + */ +OpenLayers.Rule = OpenLayers.Class({ + + /** + * APIProperty: name + * {String} name of this rule + */ + name: 'default', + + /** + * Property: symbolizer + * {Object} Hash of styles for this rule. Contains hashes of feature + * styles. Keys are one or more of ["Point", "Line", "Polygon"] + */ + symbolizer: null, + + /** + * APIProperty: minScale + * {Number} or {String} minimum scale at which to draw the feature. + * In the case of a String, this can be a combination of text and + * propertyNames in the form "literal ${propertyName}" + */ + minScale: null, + + /** + * APIProperty: maxScale + * {Number} or {String} maximum scale at which to draw the feature. + * In the case of a String, this can be a combination of text and + * propertyNames in the form "literal ${propertyName}" + */ + maxScale: null, + + /** + * Constructor: OpenLayers.Rule + * Creates a Rule. + * + * Parameters: + * options - {Object} An optional object with properties to set on the + * rule + * + * Returns: + * {} + */ + initialize: function(options) { + this.symbolizer = {}; + + OpenLayers.Util.extend(this, options); + }, + + /** + * APIMethod: destroy + * nullify references to prevent circular references and memory leaks + */ + destroy: function() { + for (var i in this.symbolizer) { + this.symbolizer[i] = null; + } + this.symbolizer = null; + }, + + /** + * APIMethod: evaluate + * evaluates this rule for a specific feature + * + * Parameters: + * feature - {} feature to apply the rule to. + * + * Returns: + * {boolean} true if the rule applies, false if it does not. + * This rule is the default rule and always returns true. + */ + evaluate: function(feature) { + // Default rule always applies. Subclasses will want to override this. + return true; + }, + + CLASS_NAME: "OpenLayers.Rule" +}); \ No newline at end of file diff --git a/lib/OpenLayers/Rule/Comparison.js b/lib/OpenLayers/Rule/Comparison.js new file mode 100644 index 0000000000..4eaea6e312 --- /dev/null +++ b/lib/OpenLayers/Rule/Comparison.js @@ -0,0 +1,204 @@ +/* Copyright (c) 2006-2007 MetaCarta, Inc., published under the Clear BSD + * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the + * full text of the license. */ + +/** + * @requires: OpenLayers/Rule.js + * + * Class: OpenLayers.Rule.Comparison + * + * This class represents the comparison rules, as being used for rule-based + * SLD styling + * + * Inherits from + * - + */ +OpenLayers.Rule.Comparison = OpenLayers.Class(OpenLayers.Rule, { + + /** + * APIProperty: type + * {String} type: type of the comparison. This is one of + * - OpenLayers.Rule.Comparison.EQUAL_TO = "=="; + * - OpenLayers.Rule.Comparison.NOT_EQUAL_TO = "!="; + * - OpenLayers.Rule.Comparison.LESS_THAN = "<"; + * - OpenLayers.Rule.Comparison.GREATER_THAN = ">"; + * - OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO = "<="; + * - OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO = ">="; + * - OpenLayers.Rule.Comparison.BETWEEN = ".."; + * - OpenLayers.Rule.Comparison.LIKE = "~"; + */ + type: null, + + /** + * APIProperty: property + * {String} + * name of the feature attribute to compare + */ + property: null, + + /** + * APIProperty: value + * {Number} or {String} + * comparison value for binary comparisons. In the case of a String, this + * can be a combination of text and propertyNames in the form + * "literal ${propertyName}" + */ + value: null, + + /** + * APIProperty: lowerBoundary + * {Number} or {String} + * lower boundary for between comparisons. In the case of a String, this + * can be a combination of text and propertyNames in the form + * "literal ${propertyName}" + */ + lowerBoundary: null, + + /** + * APIProperty: upperBoundary + * {Number} or {String} + * upper boundary for between comparisons. In the case of a String, this + * can be a combination of text and propertyNames in the form + * "literal ${propertyName}" + */ + upperBoundary: null, + + /** + * Constructor: OpenLayers.Rule.Logical + * Creates a logical rule (And, Or, Not). + * + * Parameters: + * params - {Object} Hash of parameters for this rule: + * - + * - value: + * options - {Object} An optional object with properties to set on the + * rule + * + * Returns: + * {} + */ + initialize: function(options) { + OpenLayers.Rule.prototype.initialize.apply( + this, [options]); + }, + + /** + * APIMethod: evaluate + * evaluates this rule for a specific feature + * + * Parameters: + * feature - {} feature to apply the rule to. + * + * Returns: + * {boolean} true if the rule applies, false if it does not + */ + evaluate: function(feature) { + var attributes = feature.attributes || feature.data; + switch(this.type) { + case OpenLayers.Rule.Comparison.EQUAL_TO: + case OpenLayers.Rule.Comparison.LESS_THAN: + case OpenLayers.Rule.Comparison.GREATER_THAN: + case OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO: + case OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO: + return this.binaryCompare(feature, this.property, this.value); + + case OpenLayers.Rule.Comparison.BETWEEN: + var result = + attributes[this.property] > this.lowerBoundary; + result = result && + attributes[this.property] < this.upperBoundary; + return result; + case OpenLayers.Rule.Comparison.LIKE: + var regexp = new RegExp(this.value, + "gi"); + return regexp.test(attributes[this.property]); + } + }, + + /** + * APIMethod: value2regex + * Converts the value of this rule into a regular expression string, + * according to the wildcard characters specified. This method has to + * be called after instantiation of this class, if the value is not a + * regular expression already. + * + * Parameters: + * wildCard - {} wildcard character in the above value, default + * is "*" + * singleChar - {) single-character wildcard in the above value + * default is "." + * escape - {) escape character in the above value, default is + * "!" + * + * Returns: + * {String} regular expression string + */ + value2regex: function(wildCard, singleChar, escapeChar) { + if (wildCard == ".") { + var msg = "'.' is an unsupported wildCard character for "+ + "OpenLayers.Rule.Comparison"; + OpenLayers.Console.error(msg); + return null; + } + + // set UMN MapServer defaults for unspecified parameters + wildCard = wildCard ? wildCard : "*"; + singleChar = singleChar ? singleChar : "."; + escapeChar = escapeChar ? escapeChar : "!"; + + this.value = this.value.replace( + new RegExp("\\"+escapeChar, "g"), "\\"); + this.value = this.value.replace( + new RegExp("\\"+singleChar, "g"), "."); + this.value = this.value.replace( + new RegExp("\\"+wildCard, "g"), ".*"); + this.value = this.value.replace( + new RegExp("\\\\.\\*", "g"), "\\"+wildCard); + this.value = this.value.replace( + new RegExp("\\\\\\.", "g"), "\\"+singleChar); + + return this.value; + }, + + /** + * Function: binaryCompare + * Compares a feature property to a rule value + * + * Parameters: + * feature - {} + * property - {String} or {Number} + * value - {String} or {Number}, same as property + * + * Returns: + * {boolean} + */ + binaryCompare: function(feature, property, value) { + var attributes = feature.attributes || feature.data; + switch (this.type) { + case OpenLayers.Rule.Comparison.EQUAL_TO: + return attributes[property] == value; + case OpenLayers.Rule.Comparison.NOT_EQUAL_TO: + return attributes[property] != value; + case OpenLayers.Rule.Comparison.LESS_THAN: + return attributes[property] < value; + case OpenLayers.Rule.Comparison.GREATER_THAN: + return attributes[property] > value; + case OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO: + return attributes[property] <= value; + case OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO: + return attributes[property] >= value; + } + }, + + CLASS_NAME: "OpenLayers.Rule.Comparison" +}); + + +OpenLayers.Rule.Comparison.EQUAL_TO = "=="; +OpenLayers.Rule.Comparison.NOT_EQUAL_TO = "!="; +OpenLayers.Rule.Comparison.LESS_THAN = "<"; +OpenLayers.Rule.Comparison.GREATER_THAN = ">"; +OpenLayers.Rule.Comparison.LESS_THAN_OR_EQUAL_TO = "<="; +OpenLayers.Rule.Comparison.GREATER_THAN_OR_EQUAL_TO = ">="; +OpenLayers.Rule.Comparison.BETWEEN = ".."; +OpenLayers.Rule.Comparison.LIKE = "~"; diff --git a/lib/OpenLayers/Rule/FeatureId.js b/lib/OpenLayers/Rule/FeatureId.js new file mode 100644 index 0000000000..8f4007aa29 --- /dev/null +++ b/lib/OpenLayers/Rule/FeatureId.js @@ -0,0 +1,69 @@ +/* Copyright (c) 2006-2007 MetaCarta, Inc., published under the Clear BSD + * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the + * full text of the license. */ + + +/** + * @requires: OpenLayers/Rule.js + * + * Class: OpenLayers.Rule + * + * This class represents a ogc:FeatureId Rule, as being used for rule-based SLD + * styling + * + * Inherits from + * - + */ +OpenLayers.Rule.FeatureId = OpenLayers.Class(OpenLayers.Rule, { + + /** + * APIProperty: fid + * {Array()} Feature Ids to evaluate this rule against. To be passed + * To be passed inside the params object. + */ + fids: null, + + /** + * Constructor: OpenLayers.Rule.FeatureId + * Creates an ogc:FeatureId rule. + * + * Parameters: + * options - {Object} An optional object with properties to set on the + * rule + * + * Returns: + * {} + * + * Inherits from: + * - + */ + initialize: function(options) { + this.fids = []; + OpenLayers.Rule.prototype.initialize.apply( + this, [options]); + }, + + /** + * APIMethod: evaluate + * evaluates this rule for a specific feature + * + * Parameters: + * feature - {} feature to apply the rule to. + * For vector features, the check is run against the fid, + * for plain features against the id. + * + * Returns: + * {boolean} true if the rule applies, false if it does not + */ + evaluate: function(feature) { + for (var i=0; i + */ +OpenLayers.Rule.Logical = OpenLayers.Class(OpenLayers.Rule, { + + /** + * APIProperty: children + * {Array()} child rules for this rule + */ + children: null, + + /** + * APIProperty: type + * {String} type of logical operator. Available types are: + * - OpenLayers.Rule.Locical.AND = "&&"; + * - OpenLayers.Rule.Logical.OR = "||"; + * - OpenLayers.Rule.Logical.NOT = "!"; + */ + type: null, + + /** + * Constructor: OpenLayers.Rule.Logical + * Creates a logical rule (And, Or, Not). + * + * Parameters: + * options - {Object} An optional object with properties to set on the + * rule + * + * Returns: + * {} + */ + initialize: function(options) { + this.children = []; + OpenLayers.Rule.prototype.initialize.apply( + this, [options]); + }, + + /** + * APIMethod: destroy + * nullify references to prevent circular references and memory leaks + */ + destroy: function() { + for (var i=0; i} feature to apply the rule to. + * + * Returns: + * {boolean} true if the rule applies, false if it does not + */ + evaluate: function(feature) { + switch(this.type) { + case OpenLayers.Rule.Logical.AND: + for (var i=0; i} name of the layer that this style belongs to, usually + * according to the NamedLayer attribute of an SLD document. + */ + layerName: null, + + /** + * APIProperty: isDefault + * {Boolean} + */ + isDefault: false, + + /** + * Property: rules + * Array({}) + */ + rules: null, + + /** + * Property: defaultStyle + * {Object} hash of style properties to use as default for merging + * rule-based style symbolizers onto. If no rules are defined, createStyle + * will return this style. + */ + defaultStyle: null, + + /** + * Property: propertyStyles + * {Hash of Boolean} cache of style properties that need to be parsed for + * propertyNames. Property names are keys, values won't be used. + */ + propertyStyles: null, + + + /** + * Constructor: OpenLayers.Style + * Creates a UserStyle. + * + * Parameters: + * style - {Object} Optional hash of style properties that will be + * used as default style for this style object. This style + * applies if no rules are specified. Symbolizers defined in + * rules will extend this default style. + * options - {Object} An optional object with properties to set on the + * userStyle + * + * Return: + * {} + */ + initialize: function(style, options) { + this.rules = []; + + // use the default style from OpenLayers.Feature.Vector if no style + // was given in the constructor + this.setDefaultStyle(style || + OpenLayers.Feature.Vector.style["default"]); + + OpenLayers.Util.extend(this, options); + }, + + /** + * APIMethod: destroy + * nullify references to prevent circular references and memory leaks + */ + destroy: function() { + for (var i=0; i} feature to evaluate rules for + * baseStyle - {Object} hash of styles feature styles to extend + * + * Returns: + * {} hash of feature styles + */ + createStyle: function(feature, baseStyle) { + if (!baseStyle) { + baseStyle = this.defaultStyle; + } + var style = OpenLayers.Util.extend({}, baseStyle); + + var draw = true; + + for (var i=0; i OpenLayers.Style.createLiteral( + this.rules[i].minScale, feature); + } + if (draw && this.rules[i].maxScale) { + draw = scale < OpenLayers.Style.createLiteral( + this.rules[i].maxScale, feature); + } + + // determine which symbolizer (Point, Line, Polygon) to use + var symbolizerPrefix = feature.geometry ? + this.getSymbolizerPrefix(feature.geometry) : + OpenLayers.Style.SYMBOLIZER_PREFIXES[0]; + + // now merge the style with the current style + var symbolizer = this.rules[i].symbolizer[symbolizerPrefix]; + OpenLayers.Util.extend(style, symbolizer); + } + } + + style.display = draw ? "" : "none"; + + // calculate literals for all styles in the propertyStyles cache + for (var i in this.propertyStyles) { + style[i] = OpenLayers.Style.createLiteral(style[i], feature); + } + + return style; + }, + + /** + * Method: findPropertyStyles + * Looks into all rules for this style and the defaultStyle to collect + * all the style hash property names containing ${...} strings that have + * to be replaced using the createLiteral method before returning them. + * + * Returns: + * {Object} hash of property names that need createLiteral parsing. The + * name of the property is the key, and the value is true; + */ + findPropertyStyles: function() { + var propertyStyles = {}; + + // check the default style + var style = this.defaultStyle; + for (var i in style) { + if (typeof style[i] == "string" && style[i].match(/\$\{\w+\}/)) { + propertyStyles[i] = true; + } + } + + // walk through all rules to check for properties in their symbolizer + var rules = this.rules; + var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES; + for (var i in rules) { + for (var s=0; s)} + */ + addRules: function(rules) { + this.rules = this.rules.concat(rules); + this.propertyStyles = this.findPropertyStyles(); + }, + + /** + * APIMethod: setDefaultStyle + * Sets the default style for this style object. + * + * Parameters: + * style - {Object} Hash of style properties + */ + setDefaultStyle: function(style) { + this.defaultStyle = style; + this.propertyStyles = this.findPropertyStyles(); + }, + + /** + * Method: getSymbolizerPrefix + * Returns the correct symbolizer prefix according to the + * geometry type of the passed geometry + * + * Parameters: + * geometry {} + * + * Returns: + * {String} key of the according symbolizer + */ + getSymbolizerPrefix: function(geometry) { + var prefixes = OpenLayers.Style.SYMBOLIZER_PREFIXES; + for (var i=0; i} feature to take attribute values from + * + * Returns: + * {String} the parsed value. In the example of the value parameter above, the + * result would be "foo valueOfBar", assuming that the passed feature has an + * attribute named "bar" with the value "valueOfBar". + */ +OpenLayers.Style.createLiteral = function(value, feature) { + if (typeof value == "string" && value.indexOf("${") != -1) { + var attributes = feature.attributes || feature.data; + value = OpenLayers.String.format(value, attributes) + value = isNaN(value) ? value : parseFloat(value); + } + return value; +} + +/** + * Constant: OpenLayers.Style.SYMBOLIZER_PREFIXES + * {Array} prefixes of the sld symbolizers. These are the + * same as the main geometry types + */ +OpenLayers.Style.SYMBOLIZER_PREFIXES = ['Point', 'Line', 'Polygon']; diff --git a/tests/Rule/test_Comparison.html b/tests/Rule/test_Comparison.html new file mode 100644 index 0000000000..2793fc39e2 --- /dev/null +++ b/tests/Rule/test_Comparison.html @@ -0,0 +1,70 @@ + + + + + + + + diff --git a/tests/Rule/test_FeatureId.html b/tests/Rule/test_FeatureId.html new file mode 100644 index 0000000000..b5f554c8a7 --- /dev/null +++ b/tests/Rule/test_FeatureId.html @@ -0,0 +1,47 @@ + + + + + + + + diff --git a/tests/Rule/test_Logical.html b/tests/Rule/test_Logical.html new file mode 100644 index 0000000000..b6398fb874 --- /dev/null +++ b/tests/Rule/test_Logical.html @@ -0,0 +1,41 @@ + + + + + + + + diff --git a/tests/list-tests.html b/tests/list-tests.html index 34d2fcb08f..5abbc687b7 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -35,6 +35,11 @@
  • Popup/test_AnchoredBubble.html
  • test_Feature.html
  • Feature/test_Vector.html
  • +
  • test_Style.html
  • +
  • test_Rule.html
  • +
  • Rule/test_FeatureId.html
  • +
  • Rule/test_Logical.html
  • +
  • Rule/test_Comparison.html
  • test_Events.html
  • test_Util.html
  • test_Layer.html
  • diff --git a/tests/test_Rule.html b/tests/test_Rule.html new file mode 100644 index 0000000000..1ed77c9a85 --- /dev/null +++ b/tests/test_Rule.html @@ -0,0 +1,29 @@ + + + + + + + + diff --git a/tests/test_Style.html b/tests/test_Style.html new file mode 100644 index 0000000000..ef9aefa8fb --- /dev/null +++ b/tests/test_Style.html @@ -0,0 +1,79 @@ + + + + + + +
    + +