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