3 <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
4 <link rel="stylesheet" href="style.css" type="text/css" />
5 <script src="../lib/OpenLayers.js"></script>
7 .customEditingToolbar {
13 .customEditingToolbar div {
19 .olControlNavigationItemActive {
20 background-image: url("../theme/default/img/editing_tool_bar.png");
21 background-repeat: no-repeat;
22 background-position: -103px -23px;
24 .olControlNavigationItemInactive {
25 background-image: url("../theme/default/img/editing_tool_bar.png");
26 background-repeat: no-repeat;
27 background-position: -103px -0px;
29 .olControlDrawFeaturePointItemInactive {
30 background-image: url("../theme/default/img/editing_tool_bar.png");
31 background-repeat: no-repeat;
32 background-position: -77px 0px;
34 .olControlDrawFeaturePointItemActive {
35 background-image: url("../theme/default/img/editing_tool_bar.png");
36 background-repeat: no-repeat;
37 background-position: -77px -23px ;
39 .olControlModifyFeatureItemActive {
40 background-image: url(../theme/default/img/move_feature_on.png);
41 background-repeat: no-repeat;
42 background-position: 0px 1px;
44 .olControlModifyFeatureItemInactive {
45 background-image: url(../theme/default/img/move_feature_off.png);
46 background-repeat: no-repeat;
47 background-position: 0px 1px;
49 .olControlDeleteFeatureItemActive {
50 background-image: url(../theme/default/img/remove_point_on.png);
51 background-repeat: no-repeat;
52 background-position: 0px 1px;
54 .olControlDeleteFeatureItemInactive {
55 background-image: url(../theme/default/img/remove_point_off.png);
56 background-repeat: no-repeat;
57 background-position: 0px 1px;
60 <script type="text/javascript">
63 var DeleteFeature = OpenLayers.Class(OpenLayers.Control, {
64 initialize: function(layer, options) {
65 OpenLayers.Control.prototype.initialize.apply(this, [options]);
67 this.handler = new OpenLayers.Handler.Feature(
68 this, layer, {click: this.clickFeature}
71 clickFeature: function(feature) {
72 // if feature doesn't have a fid, destroy it
73 if(feature.fid == undefined) {
74 this.layer.destroyFeatures([feature]);
76 feature.state = OpenLayers.State.DELETE;
77 this.layer.events.triggerEvent("afterfeaturemodified",
79 feature.renderIntent = "select";
80 this.layer.drawFeature(feature);
83 setMap: function(map) {
84 this.handler.setMap(map);
85 OpenLayers.Control.prototype.setMap.apply(this, arguments);
87 CLASS_NAME: "OpenLayers.Control.DeleteFeature"
91 OpenLayers.ProxyHost= "proxy.cgi?url=";
92 map = new OpenLayers.Map('map', {
93 maxResolution: 156543.03390625,
94 restrictedExtent: new OpenLayers.Bounds(
95 -11560239, 5541115, -11560239, 5542338
97 maxExtent: new OpenLayers.Bounds(
98 -2.003750834E7,-2.003750834E7,
99 2.003750834E7,2.003750834E7
101 projection: new OpenLayers.Projection("EPSG:900913"),
103 new OpenLayers.Control.PanZoom()
107 var wms = new OpenLayers.Layer.WMS(
108 "Base Layer", "http://demo.opengeo.org/geoserver_openstreetmap/gwc/service/wms",
110 layers: 'openstreetmap',
114 var styles = new OpenLayers.StyleMap({
115 "default": new OpenLayers.Style(null, {
117 new OpenLayers.Rule({
121 graphicName: "square",
126 strokeColor: "#333333"
131 strokeColor: "#666666"
137 "select": new OpenLayers.Style({
138 strokeColor: "#00ccff",
141 "temporary": new OpenLayers.Style(null, {
143 new OpenLayers.Rule({
147 graphicName: "square",
152 strokeColor: "#333333"
157 strokeColor: "#00ccff"
165 var saveStrategy = new OpenLayers.Strategy.Save();
166 wfs = new OpenLayers.Layer.Vector("Editable Features", {
167 strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
168 projection: new OpenLayers.Projection("EPSG:4326"),
170 protocol: new OpenLayers.Protocol.WFS({
172 srsName: "EPSG:4326",
173 url: "http://demo.opengeo.org/geoserver/wfs",
174 featureNS : "http://opengeo.org",
175 featureType: "roads",
176 geometryName: "the_geom",
177 schema: "http://demo.opengeo.org/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=og:roads"
181 map.addLayers([wms, wfs]);
183 // configure the snapping agent
184 var snap = new OpenLayers.Control.Snapping({layer: wfs});
185 map.addControl(snap);
188 // configure split agent
189 var split = new OpenLayers.Control.Split({
195 aftersplit: function(event) {
196 var msg = "Split resulted in " + event.features.length + " features.";
197 flashFeatures(event.features);
201 map.addControl(split);
204 // add some editing tools to a panel
205 var panel = new OpenLayers.Control.Panel(
206 {displayClass: 'customEditingToolbar'}
208 var draw = new OpenLayers.Control.DrawFeature(
209 wfs, OpenLayers.Handler.Path,
211 title: "Draw Feature",
212 displayClass: "olControlDrawFeaturePoint",
213 handlerOptions: {multi: true}
216 modify = new OpenLayers.Control.ModifyFeature(
217 wfs, {displayClass: "olControlModifyFeature"}
219 var del = new DeleteFeature(wfs, {title: "Delete Feature"});
221 var save = new OpenLayers.Control.Button({
222 title: "Save Changes",
223 trigger: function() {
225 modify.selectControl.unselectAll();
229 displayClass: "olControlSaveFeatures"
235 new OpenLayers.Control.Navigation(),
236 save, del, modify, draw
239 panel.defaultControl = panel.controls[0];
240 map.addControl(panel);
244 function flashFeatures(features, index) {
248 var current = features[index];
249 if(current && current.layer === wfs) {
250 wfs.drawFeature(features[index], "select");
252 var prev = features[index-1];
253 if(prev && prev.layer === wfs) {
254 wfs.drawFeature(prev, "default");
257 if(index <= features.length) {
258 window.setTimeout(function() {flashFeatures(features, index)}, 100);
264 <body onload="init()">
266 <h1 id="title">Snap/Split and Persist via WFS</h1>
271 Shows snapping, splitting, and use of the WFS Transactions (WFS-T).
274 <div id="map" class="smallmap"></div>
277 <p>The WFS protocol allows for creation of new features and reading,
278 updating, or deleting of existing features.</p>
279 <p>Use the tools to create, modify, and delete (in order from left
280 to right) features. Use the save tool (picture of a disk) to
281 save your changes. Use the navigation tool (hand) to stop editing
282 and use the mouse for map navigation.</p>