comparison gnv/src/main/webapp/scripts/olutils.js @ 975:5779220ebb80

Added functionality to read WMS-Capabilities-Documents gnv/trunk@1145 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 01 Jun 2010 17:40:54 +0000
parents
children 96db238fc5ab
comparison
equal deleted inserted replaced
974:a8e044224b16 975:5779220ebb80
1 function handleMeasurements(event) {
2 var geometry = event.geometry;
3 var units = event.units;
4 var order = event.order;
5 var measure = event.measure;
6 var element = document.getElementById('measurements');
7
8 var out = "";
9 if(order == 1) {
10 out += "L\u00e4nge: " + measure.toFixed(3) + " " + units;
11 } else {
12 out += "Fl\u00e4che: " + measure.toFixed(3) + " " + units + "<sup>2</sup>";
13 }
14
15 element.innerHTML=out;
16 };
17
18
19
20 function readWMC(merge) {
21 var layers = mapPanel.layers;
22 map = mapPanel.map;
23
24 var format = new OpenLayers.Format.WMC({'layerOptions': {buffer: 0}});
25 var text = document.getElementById("wmc").value;
26
27 merge = true;
28 if(merge) {
29 try {
30 map = format.read(text, {map: map});
31 } catch(err) {
32 document.getElementById("wmc").value = err;
33 }
34 } else {
35 map.destroy();
36 try {
37 var jsonFormat = new OpenLayers.Format.JSON();
38 var mapOptions = jsonFormat.read();
39 map = format.read(text, {map: mapOptions});
40 } catch(err) {
41 document.getElementById("wmc").value = err;
42 }
43 }
44
45 // create MapPanel
46 mapPanel = new GeoExt.MapPanel({
47 border: true,
48 title: "Karte",
49 region: "center",
50 map: map,
51 zoom: 1,
52 layers: map.layers
53 });
54 }
55
56
57 function writeWMC(merge) {
58 var format = new OpenLayers.Format.WMC({'layerOptions': {buffer: 0}});
59
60 try {
61 var text = format.write(map);
62 document.getElementById("wmc").value = text;
63 } catch(err) {
64 document.getElementById("wmc").value = err;
65 }
66 }
67
68
69
70 function toggleGetFeatureInfo(evt) {
71 if (infoActive) {
72 infoControls.click.deactivate();
73 infoActive = false;
74 }
75 else {
76 infoControls.click.activate();
77 infoActive = true;
78 }
79 }
80
81
82 function showInfo(evt) {
83 }
84
85
86 function addLayer() {
87 var record = grid.getSelectionModel().getSelected();
88
89 if (record) {
90 var copy = record.copy();
91 copy.set("layer", record.get("layer"));
92 copy.get("layer").mergeNewParams({
93 format: "image/png",
94 transparent: true
95 });
96
97 mapPanel.layers.add(copy);
98 mapPanel.map.zoomToExtent(OpenLayers.Bounds.fromArray(copy.get("llbbox")));
99 }
100 }
101
102
103 // this is just copied from OpenLayers.Util
104 function urlAppend(url, paramStr) {
105 var newUrl = url;
106 if(paramStr) {
107 var parts = (url + " ").split(/[?&]/);
108 newUrl += (parts.pop() === " " ?
109 paramStr :
110 parts.length ? "&" + paramStr : "?" + paramStr);
111 }
112 return newUrl;
113 }
114
115
116 function updateCapabilities() {
117 var ele = Ext.Element.get('capfield');
118
119 var url = ele.getValue();
120 var service = "SERVICE=WMS";
121 var request = "REQUEST=GetCapabilities";
122 url = urlAppend(url, service);
123 url = urlAppend(url, request);
124
125 store = new GeoExt.data.WMSCapabilitiesStore({
126 url: url
127 });
128 store.load();
129
130 grid.destroy();
131 grid = new Ext.grid.GridPanel({
132 id: 'wmsgrid',
133 collapsible: false,
134 split: false,
135 border: true,
136 height: 440,
137 //autoHeight: true, don't use autoHeight, because the component doesn't
138 //take care on the 'addLayer' button at the bottom
139 store: store,
140 cm: new Ext.grid.ColumnModel([
141 {
142 header: 'Name',
143 dataIndex: 'name',
144 sortable: true
145 },
146 {
147 id: 'title',
148 header: 'Title',
149 dataIndex: 'title',
150 sortable: true
151 }]),
152 renderTo: 'capgrid',
153 bbar: [{
154 text: 'Add Layer',
155 handler: addLayer
156 }]
157 });
158 }
159
160
161 function editFeature(e) {
162 var feature = e.feature;
163
164 // TODO SET FEATURE ATTRIBUTES
165 //feature.attributes['lawa'] = 999;
166 //feature.attributes['lawa_id'] = 999;
167 //feature.attributes['w_gwk_lawa'] = 999;
168 //feature.attributes['w_wrrl'] = 999;
169 //feature.attributes['length_fee'] = 999;
170 }
171
172 function updateControls() {
173 var controls = panel.controls;
174
175 controls.remove(drawPointControl);
176 controls.remove(drawPathControl);
177 controls.remove(drawPolygonControl);
178
179 panel.destroy();
180 panel = new OpenLayers.Control.Panel();
181 panel.addControls(controls);
182
183 if (points.getVisibility())
184 panel.addControls(drawPointControl);
185 if (lines.getVisibility())
186 panel.addControls(drawPathControl);
187 if (polygons.getVisibility())
188 panel.addControls(drawPolygonControl);
189
190 map.addControl(panel);
191 }

http://dive4elements.wald.intevation.org