Files
openlayers/examples/wfs-scribble.html
crschmidt 10907f2880 In order to make it more clear that users are required to have the theme/
directory to deploy when depending on features which use CSS, and make it clear
how to override the CSS in OpenLayers, include <link rel> ags in all examples.
(Closes #884)  


git-svn-id: http://svn.openlayers.org/trunk/openlayers@6145 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2008-02-08 22:19:28 +00:00

92 lines
3.5 KiB
HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
<style type="text/css">
#map {
width: 512px;
height: 512px;
border: 1px solid black;
}
</style>
<title>Scribble on a WFS</title>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, layer;
function init(){
map = new OpenLayers.Map('map', {controls: [ new OpenLayers.Control.PanZoom(), new OpenLayers.Control.Permalink() ]} );
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms-c/Basic.py",
{layers: 'basic'} );
map.addLayer(layer);
layer = new OpenLayers.Layer.WFS( "Scribble WFS",
"/geoserver/wfs",
{ typename: 'topp:line' },
{
typename: 'line',
featureNS: 'http://www.openplans.org/topp',
extractAttributes: false
} );
map.addLayer(layer);
var p = new OpenLayers.Control.Panel({'displayClass': 'olControlEditingToolbar'});
df = new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path, {handlerOptions: {'freehand': false}, 'displayClass': 'olControlDrawFeaturePath'});
df.featureAdded = function(feature) {
feature.state = OpenLayers.State.INSERT;
feature.style['strokeColor'] = "#ff0000";
feature.layer.drawFeature(feature);
}
p.addControls([ new OpenLayers.Control.Navigation(), df ]);
map.addControl(p);
p.activateControl(p.controls[0])
map.setCenter(new OpenLayers.LonLat(0,0), 3);
}
function save() {
for(var i = 0; i < map.layers[1].features.length; i++) {
var f = map.layers[1].features[i];
f.style['strokeColor'] = '#ee9900';
map.layers[1].drawFeature(f);
}
map.layers[1].commit();
return false;
}
function serialize(type) {
var xmls = new XMLSerializer();
var serialize = new OpenLayers.Format[type]({},map.layers[1]);
var data = serialize.write(map.layers[1].features);
OpenLayers.Util.getElement('serialize').value = xmls.serializeToString(data);
OpenLayers.Util.getElement('serialize').style.display='block';
}
</script>
</head>
<body onload="init()">
<h1 id="title">Scribble on a WFS Example</h1>
<div id="tags">
</div>
<p id="shortdesc">
Shows how you can draw features and save to GeoServer.
</p>
<div id="map"></div>
<div id="docs">
Using GeoServer and the WFS-T support in OpenLayers, draw on a map, save the results, reload the page and see the results still there!
Hold shift to turn on freehand mode while drawing. </div>
<div style="float:left; text-align:right;">
<a href="#serialize" onclick="serialize('WFS')">Show WFS Transaction</a> |
<a href="#serialize" onclick="serialize('GML')">Export GML</a> |
<a href="#serialize" onclick="serialize('GeoRSS')">Export GeoRSS</a> |
<a href="#" onclick="return save()">Save</a> |
<a href="#" onclick="map.layers[1].refresh(); return false">Refresh</a> (removes all newly added lines)</div><br />
<textarea style="display:none" id="serialize" cols="100" rows="10">
</textarea>
</div>
</body>
</html>