GeoServer WFS-T EPSG:27700

A sample page demonstrating the GeoServer WFS-T capabilities using data in British National Grid (EPSG:27700) in an OpenLayers application.  Customised from the template in the GeoServer installation.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link rel="stylesheet" href="/openlayers/theme/default/style.css" type="text/css" />
    <style type="text/css">
        body {
            margin: 1em;
        }
        #map {
            width: 600px;
            height: 600px;
            border: 1px solid black;
        }
    </style>
    <script src="openlayers/OpenLayers.js"></script>
    <script type="text/javascript">
        OpenLayers.IMAGE_RELOAD_ATTEMPTS = 3;

        var map;
        var bounds = new OpenLayers.Bounds (300000, 700000, 400000, 800000);

        function init(){
            map = new OpenLayers.Map('map', {
            projection: new OpenLayers.Projection("EPSG:27700"), 
            units: "m", 
            maxExtent: bounds, 
            resolutions: [2800,1400,700,350,175,84,42,21,11.5,5.6,2.8,1.4,0.7]} );

            var basemap = new OpenLayers.Layer.WMS(
                "Basemap", 
                "/geoserver/wms",
                {layers: 'GISLIVE:OSVMD',
                 format: 'image/png'}
            );

            var political = new OpenLayers.Layer.WMS(
                "Admin Bounds", 
                "/geoserver/wms",
                {layers: 'GISLIVE:vmd_adminbnd',
                 format: 'image/png'}
            );

            var roads = new OpenLayers.Layer.WFS(
                "Roads", 
                "/geoserver/wfs",
                {typename: 'GISLIVE:vmd_roadline'},
                {
                    typename: 'vmd_roadline', 
                    extractAttributes: false
                }
            );
            roads.style = OpenLayers.Util.applyDefaults({strokeColor: "#ff0000"}, 
                    OpenLayers.Feature.Vector.style["default"]);

            var heritage = new OpenLayers.Layer.WFS(
                "Heritage",
                "/geoserver/wfs",
                {typename: 'GISLIVE:vmd_heritage'},
                {
                    typename: 'vmd_heritage',
                    extractAttributes: false
                }
            );
            heritage.style = OpenLayers.Util.applyDefaults({strokeColor: "#0000ff"}, 
                    OpenLayers.Feature.Vector.style["default"]);

            map.addLayers([basemap, political, roads, heritage]);

            var panel = new OpenLayers.Control.Panel(
                {displayClass: 'olControlEditingToolbar'}
            );

            var drawLine = new OpenLayers.Control.DrawFeature(
                roads, OpenLayers.Handler.Path,
                {displayClass: 'olControlDrawFeaturePath'}
            );
            drawLine.featureAdded = function(feature) {
                feature.layer.eraseFeatures([feature]);
                // cast to multilinestring
                feature.geometry = new OpenLayers.Geometry.MultiLineString(
                    feature.geometry
                );
                feature.style.strokeColor = "#ff0000";
                feature.state = OpenLayers.State.INSERT;
                feature.layer.drawFeature(feature);
            }

            var drawPoint = new OpenLayers.Control.DrawFeature(
                heritage, OpenLayers.Handler.Point,
                {displayClass: 'olControlDrawFeaturePoint'}
            );
            drawPoint.featureAdded = function(feature) {
                feature.layer.eraseFeatures([feature]);
                // cast to multipoint
                feature.geometry = new OpenLayers.Geometry.MultiPoint(
                    feature.geometry
                );
                feature.style.strokeColor = "#0000ff";
                feature.state = OpenLayers.State.INSERT;
                feature.layer.drawFeature(feature);
            }

            panel.addControls(
                [new OpenLayers.Control.Navigation(), drawLine, drawPoint]
            );

            map.addControl(panel);
            map.addControl(new OpenLayers.Control.LayerSwitcher());

            map.zoomToExtent(
                bounds
            );
        }
    </script>
  </head>
  <body onload="init()">
    <h3>OpenLayers WFS-T demo: Angus heritage sites and roads</h3>
    <a href="#" onclick="map.layers[2].commit();return false">Save Roads</a><br />
    <a href="#" onclick="map.layers[3].commit();return false">Save Heritage sites</a>
    <div id="map"></div>
  </body>
</html>

This file is located in the www folder in the GeoServer data_dir.  The layers used in this example are OS OpenData: VectorMap District.

openlayers_wfs-t

Leave a Reply

Your email address will not be published. Required fields are marked *