From 4caaebf5bc42d109fef25e4e15cdc217b7ab14ef Mon Sep 17 00:00:00 2001 From: ahocevar Date: Tue, 19 Jul 2011 10:09:58 +0000 Subject: [PATCH] Simplified the sld example git-svn-id: http://svn.openlayers.org/trunk/openlayers@12173 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/sld.html | 104 ++--------------------------- examples/sld.js | 99 +++++++++++++++++++++++++++ examples/tasmania/sld-tasmania.xml | 2 +- 3 files changed, 106 insertions(+), 99 deletions(-) create mode 100644 examples/sld.js diff --git a/examples/sld.html b/examples/sld.html index f64f54b97b..4667ba34b5 100644 --- a/examples/sld.html +++ b/examples/sld.html @@ -6,92 +6,9 @@ - + - +

Styled Layer Descriptor (SLD) Example

@@ -105,19 +22,10 @@

Styled Layer Descriptor (SLD) Example

This example uses a SLD file to style the vector features. To construct layers that use styles from SLD, create a StyleMap for the layer that uses one of the userStyles in the - namedLayers object of the return from format.read().

+ namedLayers object of the return from format.read(). Look at the sld.js source + to see how this is done.

Select a new style for the WaterBodies layer below:

-
- Default Styler (zoom in to see more features)
- Styler Test PropertyIsEqualTo
- Styler Test WATER_TYPE
- Styler Test PropertyIsGreaterThanOrEqualTo
- Styler Test PropertyIsLessThanOrEqualTo
- Styler Test PropertyIsGreaterThan
- Styler Test PropertyIsLessThan
- Styler Test PropertyIsLike
- Styler Test PropertyIsBetween
- Styler Test FeatureId
-
+ diff --git a/examples/sld.js b/examples/sld.js new file mode 100644 index 0000000000..21cb295a5d --- /dev/null +++ b/examples/sld.js @@ -0,0 +1,99 @@ +var map, sld, waterBodies; +var format = new OpenLayers.Format.SLD(); +function init() { + + map = new OpenLayers.Map('map', {allOverlays: true}); + var layers = createLayers(); + map.addLayers(layers); + + waterBodies = layers[2]; + map.addControl(new OpenLayers.Control.SelectFeature( + waterBodies, {hover: true, autoActivate: true} + )); + map.addControl(new OpenLayers.Control.LayerSwitcher()); + + OpenLayers.loadURL("tasmania/sld-tasmania.xml", null, null, complete); +} + +// handler for the loadURL function in the init method +function complete(req) { + sld = format.read(req.responseXML || req.responseText); + buildStyleChooser(); + setLayerStyles(); + + map.zoomToExtent(new OpenLayers.Bounds(143,-39,150,-45)); +} + +function createLayers() { + // the name of each layer matches a NamedLayer name in the SLD document + var layerData = [{ + name: "Land", + url: "tasmania/TasmaniaStateBoundaries.xml" + }, { + name: "Roads", + url: "tasmania/TasmaniaRoads.xml" + }, { + name: "WaterBodies", + url: "tasmania/TasmaniaWaterBodies.xml" + }, { + name: "Cities", + url: "tasmania/TasmaniaCities.xml" + }]; + + var layers = []; + for (var i=0,ii=layerData.length; iWaterBodies Default Styler - Default Styler + Default Styler (zoom in to see more objects) 1