wfs-scribble.html
3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
#map {
width: 100%;
height: 80%;
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);
$('serialize').value = xmls.serializeToString(data);
$('serialize').style.display='block';
}
</script>
</head>
<body onload="init()">
<h2>Draw Lines, Save to GeoServer</h2>
<p>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!<br />
Hold shift to turn on freehand mode while drawing.</p>
<div style="float:right; 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 />
<div id="map"></div>
<textarea style="display:none" id="serialize" cols="100" rows="10">
</textarea>
</body>
</html>