diff options
author | Chris Schlaeger <chris@linux.com> | 2014-08-12 21:56:44 +0200 |
---|---|---|
committer | Chris Schlaeger <chris@linux.com> | 2014-08-12 21:56:44 +0200 |
commit | ea346a785dc1b3f7c156f6fc33da634e1f1a627b (patch) | |
tree | af67530553d20b6e82ad60fd79593e9c4abf5565 /misc/openlayers/examples/style-rules.js | |
parent | 59741cd535c47f25971bf8c32b25da25ceadc6d5 (diff) | |
download | postrunner-ea346a785dc1b3f7c156f6fc33da634e1f1a627b.zip |
Adding jquery, flot and openlayers to be included with the GEM.v0.0.4
Diffstat (limited to 'misc/openlayers/examples/style-rules.js')
-rw-r--r-- | misc/openlayers/examples/style-rules.js | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/misc/openlayers/examples/style-rules.js b/misc/openlayers/examples/style-rules.js new file mode 100644 index 0000000..42d3f00 --- /dev/null +++ b/misc/openlayers/examples/style-rules.js @@ -0,0 +1,99 @@ +var map; + +function init() { + map = new OpenLayers.Map("map"); + + var wms = new OpenLayers.Layer.WMS( + "OpenLayers WMS", + "http://vmap0.tiles.osgeo.org/wms/vmap0", + {layers: "basic"} + ); + + /** + * Create 50 vector features. Your features would typically be fetched + * from the server. These are created here to demonstrate a rule based + * style. The features are given an attribute named "foo". The value + * of this attribute is an integer that ranges from 0 to 100. + */ + var features = new Array(25); + for (var i=0; i<features.length; i++) { + features[i] = new OpenLayers.Feature.Vector( + new OpenLayers.Geometry.Point( + (340 * Math.random()) - 170, + (160 * Math.random()) - 80 + ), { + foo: 100 * Math.random() | 0 + } + ); + } + + /** + * Here we create a new style object with rules that determine + * which symbolizer will be used to render each feature. + */ + var style = new OpenLayers.Style( + // the first argument is a base symbolizer + // all other symbolizers in rules will extend this one + { + graphicWidth: 21, + graphicHeight: 25, + graphicYOffset: -28, // shift graphic up 28 pixels + label: "${foo}" // label will be foo attribute value + }, + // the second argument will include all rules + { + rules: [ + new OpenLayers.Rule({ + // a rule contains an optional filter + filter: new OpenLayers.Filter.Comparison({ + type: OpenLayers.Filter.Comparison.LESS_THAN, + property: "foo", // the "foo" feature attribute + value: 25 + }), + // if a feature matches the above filter, use this symbolizer + symbolizer: { + externalGraphic: "../img/marker-blue.png" + } + }), + new OpenLayers.Rule({ + filter: new OpenLayers.Filter.Comparison({ + type: OpenLayers.Filter.Comparison.BETWEEN, + property: "foo", + lowerBoundary: 25, + upperBoundary: 50 + }), + symbolizer: { + externalGraphic: "../img/marker-green.png" + } + }), + new OpenLayers.Rule({ + filter: new OpenLayers.Filter.Comparison({ + type: OpenLayers.Filter.Comparison.BETWEEN, + property: "foo", + lowerBoundary: 50, + upperBoundary: 75 + }), + symbolizer: { + externalGraphic: "../img/marker-gold.png" + } + }), + new OpenLayers.Rule({ + // apply this rule if no others apply + elseFilter: true, + symbolizer: { + externalGraphic: "../img/marker.png" + } + }) + ] + } + ); + + // create the layer styleMap that uses the above style for all render intents + var vector = new OpenLayers.Layer.Vector("Points", { + styleMap: new OpenLayers.StyleMap(style) + }); + vector.addFeatures(features); + + map.addLayers([wms, vector]); + map.setCenter(new OpenLayers.LonLat(0, 0), 1); +} |