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/wfs-protocol-transactions.js | |
parent | 59741cd535c47f25971bf8c32b25da25ceadc6d5 (diff) | |
download | postrunner-0.0.4.zip |
Adding jquery, flot and openlayers to be included with the GEM.v0.0.4
Diffstat (limited to 'misc/openlayers/examples/wfs-protocol-transactions.js')
-rw-r--r-- | misc/openlayers/examples/wfs-protocol-transactions.js | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/misc/openlayers/examples/wfs-protocol-transactions.js b/misc/openlayers/examples/wfs-protocol-transactions.js new file mode 100644 index 0000000..6b1044e --- /dev/null +++ b/misc/openlayers/examples/wfs-protocol-transactions.js @@ -0,0 +1,106 @@ +var map, wfs; +OpenLayers.ProxyHost = "proxy.cgi?url="; + +var DeleteFeature = OpenLayers.Class(OpenLayers.Control, { + initialize: function(layer, options) { + OpenLayers.Control.prototype.initialize.apply(this, [options]); + this.layer = layer; + this.handler = new OpenLayers.Handler.Feature( + this, layer, {click: this.clickFeature} + ); + }, + clickFeature: function(feature) { + // if feature doesn't have a fid, destroy it + if(feature.fid == undefined) { + this.layer.destroyFeatures([feature]); + } else { + feature.state = OpenLayers.State.DELETE; + this.layer.events.triggerEvent("afterfeaturemodified", + {feature: feature}); + feature.renderIntent = "select"; + this.layer.drawFeature(feature); + } + }, + setMap: function(map) { + this.handler.setMap(map); + OpenLayers.Control.prototype.setMap.apply(this, arguments); + }, + CLASS_NAME: "OpenLayers.Control.DeleteFeature" +}); + +function init() { + + var extent = new OpenLayers.Bounds( + -11593508, 5509847, -11505759, 5557774 + ); + + + map = new OpenLayers.Map('map', { + projection: new OpenLayers.Projection("EPSG:900913"), + displayProjection: new OpenLayers.Projection("EPSG:4326"), + restrictedExtent: extent, + controls: [ + new OpenLayers.Control.PanZoom(), + new OpenLayers.Control.Navigation() + ] + }); + var gphy = new OpenLayers.Layer.Google( + "Google Physical", + {type: G_PHYSICAL_MAP, sphericalMercator: true} + ); + + var saveStrategy = new OpenLayers.Strategy.Save(); + + wfs = new OpenLayers.Layer.Vector("Editable Features", { + strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy], + projection: new OpenLayers.Projection("EPSG:4326"), + protocol: new OpenLayers.Protocol.WFS({ + version: "1.1.0", + srsName: "EPSG:4326", + url: "http://demo.opengeo.org/geoserver/wfs", + featureNS : "http://opengeo.org", + featureType: "restricted", + geometryName: "the_geom", + schema: "http://demo.opengeo.org/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=og:restricted" + }) + }); + + map.addLayers([gphy, wfs]); + + var panel = new OpenLayers.Control.Panel({ + displayClass: 'customEditingToolbar', + allowDepress: true + }); + + var draw = new OpenLayers.Control.DrawFeature( + wfs, OpenLayers.Handler.Polygon, + { + title: "Draw Feature", + displayClass: "olControlDrawFeaturePolygon", + multi: true + } + ); + + var edit = new OpenLayers.Control.ModifyFeature(wfs, { + title: "Modify Feature", + displayClass: "olControlModifyFeature" + }); + + var del = new DeleteFeature(wfs, {title: "Delete Feature"}); + + var save = new OpenLayers.Control.Button({ + title: "Save Changes", + trigger: function() { + if(edit.feature) { + edit.selectControl.unselectAll(); + } + saveStrategy.save(); + }, + displayClass: "olControlSaveFeatures" + }); + + panel.addControls([save, del, edit, draw]); + map.addControl(panel); + map.zoomToExtent(extent, true); +} + |