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/cql-format.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/cql-format.js')
-rw-r--r-- | misc/openlayers/examples/cql-format.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/misc/openlayers/examples/cql-format.js b/misc/openlayers/examples/cql-format.js new file mode 100644 index 0000000..9b4a210 --- /dev/null +++ b/misc/openlayers/examples/cql-format.js @@ -0,0 +1,61 @@ + +// use a CQL parser for easy filter creation +var format = new OpenLayers.Format.CQL(); + +// this rule will get a filter from the CQL text in the form +var rule = new OpenLayers.Rule({ + // We could also set a filter here. E.g. + // filter: format.read("STATE_ABBR >= 'B' AND STATE_ABBR <= 'O'"), + symbolizer: { + fillColor: "#ff0000", + strokeColor: "#ffcccc", + fillOpacity: "0.5" + } +}); + +var states = new OpenLayers.Layer.Vector("States", { + styleMap: new OpenLayers.StyleMap({ + "default": new OpenLayers.Style(null, {rules: [rule]}) + }) +}); + +var map = new OpenLayers.Map({ + div: "map", + layers: [ + new OpenLayers.Layer.WMS( + "OpenLayers WMS", + "http://maps.opengeo.org/geowebcache/service/wms", + {layers: "openstreetmap", format: "image/png"} + ), + states + ], + center: new OpenLayers.LonLat(-101, 39), + zoom: 3 +}); + +// called when features are fetched +function loadFeatures(data) { + var features = new OpenLayers.Format.GeoJSON().read(data); + states.addFeatures(features); +} + +// update filter and redraw when form is submitted +var cql = document.getElementById("cql"); +var output = document.getElementById("output"); +function updateFilter() { + var filter; + try { + filter = format.read(cql.value); + } catch (err) { + output.value = err.message; + } + if (filter) { + output.value = ""; + rule.filter = filter; + states.redraw(); + } + return false; +} +updateFilter(); +var form = document.getElementById("cql_form"); +form.onsubmit = updateFilter; |