superedit-OPEN_LAYERS_WPS.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  1. <?php
  2. /**
  3. * http://openlayers.org/dev/examples/wps.html
  4. * http://geoinformatyka.com.pl/usluga-wfs-jak-to-dziala/
  5. *
  6. * TODO: brak ModifyFeature - html btn: olControlModifyFeatureItemInactive
  7. */
  8. function OPEN_LAYERS_WPS() {
  9. $task = V::get('task', '', $_GET);
  10. switch ($task) {
  11. case 'proxy':
  12. $url = V::get('url', '', $_GET);
  13. // 1. http%3A%2F%2Fbiuro.biall-net.pl%2Fwps%3FSERVICE%3DWPS%26REQUEST%3DGetCapabilities
  14. // 2. http%3A%2F%2Fbiuro.biall-net.pl%2Fwps%3FSERVICE%3DWPS%26REQUEST%3DDescribeProcess%26VERSION%3D1.0.0%26IDENTIFIER%3Dpozdrawiam
  15. header('Content-Type: application/xml; charset=utf-8');
  16. $urlParts = parse_url($url);
  17. $urlQuery = array();
  18. $urlQueryTmp = V::get('query', '', $urlParts);
  19. $urlQueryTmp = explode('&', $urlQueryTmp);
  20. foreach ($urlQueryTmp as $vQuery) {
  21. $parts = explode('=', $vQuery, 2);
  22. $urlQuery[$parts[0]] = $parts[1];
  23. }
  24. if ('WPS' == V::get('SERVICE', '', $urlQuery)) {
  25. $req = V::get('REQUEST', '', $urlQuery);
  26. $wps = new WpsServer();
  27. $methodName = "{$req}Action";
  28. if (method_exists($wps, $methodName)) {
  29. $wps->$methodName($urlQuery);
  30. }
  31. }
  32. else {
  33. $wps = new WpsServer();
  34. $wps->parseXMLRequest();
  35. }
  36. exit;
  37. break;
  38. default:
  39. }
  40. //$_POST['url'] = 'http://demo.opengeo.org/geoserver/wfs';
  41. //$entityBody = file_get_contents('php://input');
  42. $url = V::get('_url', '', $_GET);
  43. if ($url) {// @see OpenLayers/examples/proxy.cgi
  44. $allowedHosts = array('www.openlayers.org', 'openlayers.org',
  45. 'labs.metacarta.com', 'world.freemap.in',
  46. 'prototype.openmnnd.org', 'geo.openplans.org',
  47. 'sigma.openplans.org', 'demo.opengeo.org',
  48. 'www.openstreetmap.org', 'sample.azavea.com',
  49. 'v2.suite.opengeo.org', 'v-swe.uni-muenster.de:8080',
  50. 'vmap0.tiles.osgeo.org', 'www.openrouteservice.org',
  51. 'maps.wien.gv.at');
  52. if (!empty($_POST)) {
  53. // qs = os.environ["QUERY_STRING"]
  54. // d = cgi.parse_qs(qs)
  55. // if d.has_key("url"):
  56. // url = d["url"][0]
  57. // else:
  58. // url = "http://www.openlayers.org"
  59. }
  60. else {
  61. // fs = cgi.FieldStorage()
  62. // url = fs.getvalue('url', "http://www.openlayers.org")
  63. }
  64. $host = explode('/', $url);
  65. $host = $host[2];
  66. if (!in_array($host, $allowedHosts)) {
  67. header("Status: 502 Bad Gateway");
  68. header("Content-Type: text/plain");
  69. echo "\nThis proxy does not allow you to access that location ({$host}).";
  70. exit;
  71. }
  72. else if (substr($url, 0, 7) == 'http://' || substr($url, 0, 8) == 'https://') {
  73. $ch = curl_init();
  74. if (!empty($_POST)) {
  75. /*
  76. length = int(os.environ["CONTENT_LENGTH"])
  77. headers = {"Content-Type": os.environ["CONTENT_TYPE"]}
  78. body = sys.stdin.read(length)
  79. r = urllib2.Request(url, body, headers)
  80. y = urllib2.urlopen(r)
  81. */
  82. }
  83. else {
  84. curl_setopt($ch, CURLOPT_URL, $url);
  85. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);// return the transfer as a string
  86. //curl_setopt($ch, CURLOPT_VERBOSE, 1);
  87. curl_setopt($ch, CURLOPT_HEADER, 1);
  88. $response = curl_exec($ch);
  89. // Then, after your curl_exec call:
  90. $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
  91. $header = substr($response, 0, $header_size);
  92. $body = substr($response, $header_size);
  93. curl_close($ch);
  94. $contentType = 'text/plain';
  95. $headers = explode("\n", $header);
  96. foreach ($headers as $vHeader) {
  97. if (substr($vHeader, 0, 13) == 'Content-Type:') {
  98. $contentType = trim(substr($vHeader, 14));
  99. }
  100. }
  101. header("Content-Type: {$contentType}");
  102. echo $body . "\n";
  103. }
  104. }
  105. else {
  106. header("Content-Type: text/plain");
  107. echo "\nIllegal request.";
  108. exit;
  109. }
  110. exit;
  111. }
  112. ?>
  113. <link rel="stylesheet" href="stuff/open-layers/theme/default/style.css" type="text/css">
  114. <link rel="stylesheet" href="stuff/open-layers/style.css" type="text/css">
  115. <style type="text/css">
  116. .olControlEditingToolbar .olControlModifyFeatureItemInactive {
  117. background-image: url(stuff/open-layers/theme/default/img/draw_point_off.png);
  118. }
  119. .olControlEditingToolbar .olControlModifyFeatureItemActive {
  120. background-image: url(stuff/open-layers/theme/default/img/draw_point_on.png);
  121. }
  122. .olControlRefresh {
  123. background-image: url(stuff/open-layers/theme/default/img/save_features_off.png.png);
  124. }
  125. .olControlZoomToPoly {
  126. background-image: url(stuff/open-layers/theme/default/img/ruler.png);
  127. }
  128. .olControlLayerSwitcher .layersDiv {
  129. border-radius: 10px 0 0 10px;
  130. opacity: 0.75;
  131. filter: alpha(opacity=75);
  132. }
  133. textarea {
  134. display: block;
  135. width: 100%;
  136. height: 3em;
  137. }
  138. label {
  139. display: block;
  140. }
  141. .notsupported {
  142. color: red;
  143. }
  144. button {
  145. display: block;
  146. margin-top: 10px;
  147. }
  148. </style>
  149. <div id="TreeTableMap"></div>
  150. <a href="http://openlayers.org/dev/examples/wps.html">http://openlayers.org/dev/examples/wps.html</a>
  151. <a href="http://openlayers.org/dev/examples/wfs-protocol-transactions.html">transaction</a>
  152. <a href="http://openlayers.org/dev/examples/select-feature-multilayer.html">on click event</a>
  153. <script src="stuff/open-layers/OpenLayers.js"></script>
  154. <!-- <script src="stuff/open-layers/wps.js"></script> -->
  155. <script>
  156. (function ( $ ) {
  157. var TableAjaxMap = function() {
  158. var priv = {}; //private api
  159. var publ = {}; //public api
  160. priv.options = {};
  161. var defaults = {
  162. wpsUrl: '',
  163. wfsUrl: '',
  164. domProcessId: '',
  165. urlInit: true, // try to load services on init
  166. preloadData: null,
  167. menuid: '',
  168. debug: false
  169. };
  170. var _nodeMapId;
  171. var _nodeMap;
  172. var _nodeProcesses;
  173. var _nodeAbstract;
  174. var _nodeInput;
  175. var _nodeOutput;
  176. var _capabilities;
  177. var _process;
  178. var _layer;
  179. /*
  180. initialize the plugin.
  181. */
  182. priv.init = function() {
  183. console.log('test jQuery plugin init...', priv);
  184. // create dom:
  185. /*
  186. <div id="map" class="smallmap"></div>
  187. <div>
  188. <select id="processes"><option>Select a process</option></select>
  189. <p id="abstract"></p>
  190. <div id="input"></div>
  191. <div id="output"></div>
  192. </div>
  193. */
  194. _nodeMapId = 'Map-' + Math.random(1).toString().substr(2);
  195. _nodeMap = $('<div id="' + _nodeMapId + '" class="smallmap"></div>');
  196. _nodeProcesses = $('<select></select>');
  197. _nodeProcesses.append('<option>Wybierz funkcję</option>');
  198. _nodeAbstract = $('<p></p>');
  199. _nodeInput = $('<div></div>');
  200. _nodeOutput = $('<div></div>');
  201. var div = $('<div></div>');
  202. div.append(_nodeProcesses);
  203. div.append(_nodeAbstract);
  204. div.append(_nodeInput);
  205. div.append(_nodeOutput);
  206. $(priv.options.id).append(_nodeMap);
  207. $(priv.options.id).append(div);
  208. _nodeProcesses.on('change', function() {
  209. console.log("onchange this:", this, this.selectedIndex, this.options);
  210. var selection = this.options[this.selectedIndex].value;
  211. if (this.selectedIndex > 0) {
  212. OpenLayers.Request.GET({
  213. url: priv.options.wpsUrl,
  214. params: {
  215. "SERVICE": "WPS",
  216. "REQUEST": "DescribeProcess",
  217. "VERSION": _capabilities.version,
  218. "IDENTIFIER": selection
  219. },
  220. success: function(response) {
  221. _process = new OpenLayers.Format.WPSDescribeProcess().read(
  222. response.responseText
  223. ).processDescriptions[selection];
  224. console.log("Process:", _process);
  225. priv.buildForm();
  226. }
  227. });
  228. }
  229. });
  230. priv.getCapabilities();
  231. _layer = new OpenLayers.Layer.Vector("Warstwa rysowania", {
  232. strategies: [new OpenLayers.Strategy.BBOX()],
  233. projection: new OpenLayers.Projection("EPSG:900913"),
  234. protocol: new OpenLayers.Protocol.WFS({
  235. version: "1.1.0",
  236. srsName: "EPSG:900913",
  237. url: priv.options.wfsUrl,
  238. featureNS : "http://opengeo.org",
  239. featureType: "restricted",
  240. geometryName: "the_geom",
  241. schema: "http://demo.opengeo.org/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=og:restricted"
  242. })
  243. });
  244. var toolbar = new OpenLayers.Control.EditingToolbar(_layer);
  245. toolbar.addControls([new OpenLayers.Control.ModifyFeature(_layer, {
  246. title: "Wybierz",
  247. deferDelete: true
  248. })]);
  249. var extent = new OpenLayers.Bounds(
  250. 2035059.4410645328, 7200979.560689885, 2113330.958028555, 7279251.0776539035
  251. );
  252. var gphy = new OpenLayers.Layer.OSM("Mapa", null, {
  253. resolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
  254. 19567.87923828125, 9783.939619140625, 4891.9698095703125,
  255. 2445.9849047851562, 1222.9924523925781, 611.4962261962891,
  256. 305.74811309814453, 152.87405654907226, 76.43702827453613,
  257. 38.218514137268066, 19.109257068634033, 9.554628534317017,
  258. 4.777314267158508, 2.388657133579254, 1.194328566789627,
  259. 0.5971642833948135, 0.25, 0.1, 0.05],
  260. serverResolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
  261. 19567.87923828125, 9783.939619140625,
  262. 4891.9698095703125, 2445.9849047851562,
  263. 1222.9924523925781, 611.4962261962891,
  264. 305.74811309814453, 152.87405654907226,
  265. 76.43702827453613, 38.218514137268066,
  266. 19.109257068634033, 9.554628534317017,
  267. 4.777314267158508, 2.388657133579254,
  268. 1.194328566789627, 0.5971642833948135],
  269. transitionEffect: 'resize'
  270. });
  271. var selectFeature = new OpenLayers.Control.SelectFeature(_layer);
  272. var dragFeature = new OpenLayers.Control.DragFeature(_layer);
  273. dragFeature.handlers['drag'].stopDown = false;
  274. dragFeature.handlers['drag'].stopUp = false;
  275. dragFeature.handlers['drag'].stopClick = false;
  276. dragFeature.handlers['feature'].stopDown = false;
  277. dragFeature.handlers['feature'].stopUp = false;
  278. dragFeature.handlers['feature'].stopClick = false;
  279. var btnZoomToPoly = new OpenLayers.Control.Button({
  280. displayClass: "olControlZoomToPoly", trigger:
  281. function() {
  282. var multiPolygon = OpenLayers.Geometry.fromWKT(
  283. "MULTIPOLYGON(((2072016.74395199 7234076.79293037,2072016.74395199 7234115.01144451,2072131.3994944 7234115.01144451,2072131.3994944 7234076.79293037,2072016.74395199 7234076.79293037)))"
  284. ).getBounds();
  285. map.zoomToExtent(multiPolygon);
  286. }
  287. });
  288. toolbar.addControls([btnZoomToPoly]);
  289. var btnRefresh = new OpenLayers.Control.Button({
  290. displayClass: "olControlRefresh", trigger:
  291. function() {
  292. _layer.refresh({force:true});
  293. }
  294. });
  295. toolbar.addControls([btnRefresh]);
  296. var map = new OpenLayers.Map(_nodeMapId, {
  297. projection: new OpenLayers.Projection("EPSG:900913"),
  298. displayProjection: new OpenLayers.Projection("EPSG:4326"),
  299. restrictedExtent: extent,
  300. controls: [
  301. toolbar,
  302. dragFeature,
  303. selectFeature,
  304. // removeFeature,
  305. new OpenLayers.Control.ZoomPanel(),
  306. new OpenLayers.Control.PanPanel(),
  307. new OpenLayers.Control.LayerSwitcher(),
  308. new OpenLayers.Control.ScaleLine(),
  309. new OpenLayers.Control.KeyboardDefaults()
  310. // new OpenLayers.Control.MousePosition()
  311. ], layers: [gphy,_layer]
  312. });
  313. map.zoomToMaxExtent();
  314. selectFeature.activate();
  315. dragFeature.activate();
  316. //var removeFeature = new OpenLayers.Control.RemoveFeature(_layer//,
  317. // {onDone: function(feature) {console.log(feature)}
  318. // }
  319. // );
  320. // _layer.removeFeatures(_layer.getSelectedFuture());
  321. // removeFuture.activate();
  322. // var draw = new OpenLayers.Control.DrawFeature(
  323. // _layer, OpenLayers.Handler.Path
  324. // );
  325. // map.addControl(_draw);
  326. // draw.activate();
  327. // OpenLayers.Event.observe(document, "keydown", function(evt) {
  328. // var handled = false;
  329. // switch (evt.keyCode) {
  330. // case 90: // z
  331. // if (evt.metaKey || evt.ctrlKey) {
  332. // draw.undo();
  333. // handled = true;
  334. // }
  335. // break;
  336. // case 89: // y
  337. // if (evt.metaKey || evt.ctrlKey) {
  338. // draw.redo();
  339. // handled = true;
  340. // }
  341. // break;
  342. // case 27: // esc
  343. // draw.cancel();
  344. // handled = true;
  345. // break;
  346. // }
  347. // if (handled) {
  348. // OpenLayers.Event.stop(evt);
  349. // }
  350. // });
  351. };
  352. // using OpenLayers.Format.WPSCapabilities to read the capabilities
  353. priv.getCapabilities = function() {
  354. OpenLayers.Request.GET({
  355. url: priv.options.wpsUrl,
  356. params: {
  357. "SERVICE": "WPS",
  358. "REQUEST": "GetCapabilities"
  359. },
  360. success: function(response){
  361. _capabilities = new OpenLayers.Format.WPSCapabilities().read(
  362. response.responseText
  363. );
  364. var dropdown = _nodeProcesses;
  365. var offerings = _capabilities.processOfferings, option;
  366. // populate the dropdown
  367. for (var p in offerings) {
  368. option = document.createElement("option");
  369. option.innerHTML = offerings[p].identifier;
  370. option.value = p;
  371. dropdown.append(option);
  372. }
  373. }
  374. });
  375. };
  376. priv.buildForm = function() {
  377. _nodeAbstract.html(_process["abstract"]);
  378. _nodeInput.html("<h3>Input:</h3>");
  379. _nodeOutput.html('');
  380. var inputs = _process.dataInputs, supported = true,
  381. sld = "text/xml; subtype=sld/1.0.0",
  382. input;
  383. for (var i = 0, ii = inputs.length; i < ii; ++i) {
  384. input = inputs[i];
  385. if (input.complexData) {
  386. var formats = input.complexData.supported.formats;
  387. if (formats["application/wkt"]) {
  388. priv.addWKTInput(input);
  389. } else if (formats["text/xml; subtype=wfs-collection/1.0"]) {
  390. priv.addWFSCollectionInput(input);
  391. } else if (formats["image/tiff"]) {
  392. //priv.addRasterInput(input);
  393. } else if (formats[sld]) {
  394. priv.addXMLInput(input, sld);
  395. } else {
  396. supported = false;
  397. }
  398. } else if (input.boundingBoxData) {
  399. priv.addBoundingBoxInput(input);
  400. } else if (input.literalData) {
  401. priv.addLiteralInput(input);
  402. } else {
  403. supported = false;
  404. }
  405. if (input.minOccurs > 0) {
  406. _nodeInput.append(document.createTextNode("* "));
  407. }
  408. }
  409. if (supported) {
  410. var executeButton = document.createElement("button");
  411. executeButton.innerHTML = "Execute";
  412. _nodeInput.append(executeButton);
  413. executeButton.onclick = priv.execute;
  414. } else {
  415. _nodeInput.html('<span class="notsupported">' +
  416. "Sorry, the WPS builder does not support the selected process." +
  417. "</span>");
  418. }
  419. };
  420. // helper function to dynamically create a textarea for geometry (WKT) data
  421. // input
  422. priv.addWKTInput = function(input, previousSibling) {
  423. var name = input.identifier;
  424. var container = _nodeInput.get(0);
  425. var label = document.createElement("label");
  426. label["for"] = name;
  427. label.title = input["abstract"];
  428. label.innerHTML = name + " (select feature, then click field):";
  429. previousSibling && previousSibling.nextSibling ?
  430. container.insertBefore(label, previousSibling.nextSibling) :
  431. container.appendChild(label);
  432. var field = document.createElement("textarea");
  433. field.onclick = function () {
  434. if (_layer.selectedFeatures.length) {
  435. this.innerHTML = new OpenLayers.Format.WKT().write(
  436. _layer.selectedFeatures[0]
  437. );
  438. console.log('_layer.selectedFeatures[0]: ', _layer.selectedFeatures[0]);
  439. }
  440. priv.createCopy(input, this, priv.addWKTInput);
  441. };
  442. field.onblur = function() {
  443. input.data = field.value ? {
  444. complexData: {
  445. mimeType: "application/wkt",
  446. value: this.value
  447. }
  448. } : undefined;
  449. };
  450. field.title = input["abstract"];
  451. field.id = name;
  452. previousSibling && previousSibling.nextSibling ?
  453. container.insertBefore(field, previousSibling.nextSibling.nextSibling) :
  454. container.appendChild(field);
  455. };
  456. // helper function for xml input
  457. priv.addXMLInput = function(input, type) {
  458. var name = input.identifier;
  459. var field = document.createElement("input");
  460. field.title = input["abstract"];
  461. field.value = name + " (" + type + ")";
  462. field.onblur = function() {
  463. input.data = field.value ? {
  464. complexData: {
  465. mimeType: type,
  466. value: this.value
  467. }
  468. } : undefined;
  469. };
  470. _nodeInput.append(field);
  471. };
  472. // helper function to dynamically create a WFS collection reference input
  473. priv.addWFSCollectionInput = function(input) {
  474. var name = input.identifier;
  475. var field = document.createElement("input");
  476. field.title = input["abstract"];
  477. field.value = name + " (layer on demo server)";
  478. priv.addValueHandlers(field, function() {
  479. input.reference = field.value ? {
  480. mimeType: "text/xml; subtype=wfs-collection/1.0",
  481. href: "http://geoserver/wfs",
  482. method: "POST",
  483. body: {
  484. wfs: {
  485. version: "1.0.0",
  486. outputFormat: "GML2",
  487. featureType: field.value
  488. }
  489. }
  490. } : undefined;
  491. });
  492. _nodeInput.append(field);
  493. };
  494. // helper function to dynamically create a raster (GeoTIFF) url input
  495. priv.addRasterInput = function(input) {
  496. var name = input.identifier;
  497. var field = document.createElement("input");
  498. field.title = input["abstract"];
  499. var url = window.location.href.split("?")[0];
  500. field.value = url.substr(0, url.lastIndexOf("/")+1) + "data/tazdem.tiff";// TODO: file path to options
  501. document.getElementById("input").appendChild(field);
  502. (field.onblur = function() {
  503. input.reference = {
  504. mimeType: "image/tiff",
  505. href: field.value,
  506. method: "GET"
  507. };
  508. })();
  509. };
  510. // helper function to dynamically create a bounding box input
  511. priv.addBoundingBoxInput = function(input) {
  512. var name = input.identifier;
  513. var field = document.createElement("input");
  514. field.title = input["abstract"];
  515. field.value = "left,bottom,right,top (EPSG:4326)";
  516. _nodeInput.append(field);
  517. priv.addValueHandlers(field, function() {
  518. input.boundingBoxData = {
  519. projection: "EPSG:4326",
  520. bounds: OpenLayers.Bounds.fromString(field.value)
  521. };
  522. });
  523. };
  524. // helper function to create a literal input textfield or dropdown
  525. priv.addLiteralInput = function(input, previousSibling) {
  526. var name = input.identifier;
  527. var container = _nodeInput.get(0);
  528. var anyValue = input.literalData.anyValue;
  529. // anyValue means textfield, otherwise we create a dropdown
  530. var field = document.createElement(anyValue ? "input" : "select");
  531. field.id = name;
  532. field.title = input["abstract"];
  533. previousSibling && previousSibling.nextSibling ?
  534. container.insertBefore(field, previousSibling.nextSibling) :
  535. container.appendChild(field);
  536. if (anyValue) {
  537. var dataType = input.literalData.dataType;
  538. field.value = name + (dataType ? " (" + dataType + ")" : "");
  539. priv.addValueHandlers(field, function() {
  540. input.data = field.value ? {
  541. literalData: {
  542. value: field.value
  543. }
  544. } : undefined;
  545. priv.createCopy(input, field, priv.addLiteralInput);
  546. });
  547. } else {
  548. var option;
  549. option = document.createElement("option");
  550. option.innerHTML = name;
  551. field.appendChild(option);
  552. for (var v in input.literalData.allowedValues) {
  553. option = document.createElement("option");
  554. option.value = v;
  555. option.innerHTML = v;
  556. field.appendChild(option);
  557. }
  558. field.onchange = function() {
  559. priv.createCopy(input, field, priv.addLiteralInput);
  560. input.data = this.selectedIndex ? {
  561. literalData: {
  562. value: this.options[this.selectedIndex].value
  563. }
  564. } : undefined;
  565. };
  566. }
  567. };
  568. // if maxOccurs is > 1, this will add a copy of the field
  569. priv.createCopy = function(input, field, fn) {
  570. if (input.maxOccurs && input.maxOccurs > 1 && !field.userSelected) {
  571. // add another copy of the field - we don't check maxOccurs
  572. field.userSelected = true;
  573. var newInput = OpenLayers.Util.extend({}, input);
  574. // we recognize copies by the occurrence property
  575. newInput.occurrence = (input.occurrence || 0) + 1;
  576. _process.dataInputs.push(newInput);
  577. fn(newInput, field);
  578. }
  579. };
  580. // helper function for adding events to form fields
  581. priv.addValueHandlers = function(field, onblur) {
  582. field.onclick = function() {
  583. if (!this.initialValue) {
  584. this.initialValue = this.value;
  585. this.value = "";
  586. }
  587. };
  588. field.onblur = function() {
  589. if (!this.value) {
  590. this.value = this.initialValue;
  591. delete this.initialValue;
  592. }
  593. onblur.apply(this, arguments);
  594. };
  595. };
  596. // execute the process
  597. priv.execute = function() {
  598. var output = _process.processOutputs[0];
  599. var input;
  600. // remove occurrences that the user has not filled out
  601. for (var i = _process.dataInputs.length - 1; i >= 0; --i) {
  602. input = _process.dataInputs[i];
  603. if ((input.minOccurs === 0 || input.occurrence) && !input.data && !input.reference) {
  604. OpenLayers.Util.removeItem(_process.dataInputs, input);
  605. }
  606. }
  607. _process.responseForm = {
  608. rawDataOutput: {
  609. identifier: output.identifier
  610. }
  611. };
  612. if (output.complexOutput && output.complexOutput.supported.formats["application/wkt"]) {
  613. _process.responseForm.rawDataOutput.mimeType = "application/wkt";
  614. }
  615. OpenLayers.Request.POST({
  616. url: priv.options.wpsUrl,
  617. data: new OpenLayers.Format.WPSExecute().write(_process),
  618. success: priv.showOutput
  619. });
  620. }
  621. // add the process's output to the page
  622. priv.showOutput = function(response) {
  623. var result = _nodeOutput.get(0);
  624. result.innerHTML = "<h3>Output:</h3>";
  625. var features;
  626. var contentType = response.getResponseHeader("Content-Type");
  627. if (contentType == "application/wkt") {
  628. features = new OpenLayers.Format.WKT().read(response.responseText);
  629. } else if (contentType == "text/xml; subtype=wfs-collection/1.0") {
  630. features = new OpenLayers.Format.WFST.v1_0_0().read(response.responseText);
  631. }
  632. if (features && (features instanceof OpenLayers.Feature.Vector || features.length)) {
  633. _layer.addFeatures(features);
  634. result.innerHTML += "The result should also be visible on the map.";
  635. }
  636. result.innerHTML += "<textarea>" + response.responseText + "</textarea>";
  637. }
  638. publ.init = function(options) {
  639. if (priv.options.debug) console.log('TableAjaxMap initialization...');
  640. //merge supplied options with defaults
  641. $.extend(priv.options, defaults, options);
  642. priv.init();
  643. return publ;
  644. };
  645. return publ;
  646. };
  647. $.fn.TableAjaxMap = function(options) {
  648. options = options || {};
  649. return this.each(function() {
  650. options.id = this;
  651. $(this).data('TableAjaxMap', new TableAjaxMap().init(options));
  652. });
  653. return this;
  654. };
  655. }(jQuery));
  656. </script>
  657. <script>
  658. OpenLayers.ProxyHost = "index.php?FUNCTION_INIT=<?php echo __FUNCTION__; ?>&HEADER_NOT_INIT=YES&task=proxy&url=";
  659. jQuery('#TreeTableMap').TableAjaxMap({
  660. wpsUrl: 'http://biuro.biall-net.pl/wps',
  661. wfsUrl: 'http://biuro.biall-net.pl/wps'
  662. });
  663. </script>
  664. <?php
  665. }
  666. class WpsActionBase {
  667. public $title = '';
  668. public $description = '';
  669. public $dataInputs = array();
  670. public function execute($args) {
  671. var_dump($args);
  672. }
  673. }
  674. class WpsActionPrzypiszDoRekordu extends WpsActionBase {
  675. public function __construct() {
  676. $this->title = 'Przypisz';
  677. $this->description = 'Przypisuje położenie do wybranego rekordu w tabeli.';
  678. $this->dataInputs['geom'] = new stdClass();
  679. $this->dataInputs['geom']->title = 'geom';
  680. $this->dataInputs['geom']->description = 'Input geometry';
  681. $this->dataInputs['geom']->type = 'geom';// CoomplexData
  682. $this->dataInputs['idTable'] = new stdClass();
  683. $this->dataInputs['idTable']->title = 'geom';
  684. $this->dataInputs['idTable']->description = 'Table ID';
  685. $this->dataInputs['idTable']->type = 'integer';// LiteralData: xs:integer
  686. $this->dataInputs['idRecord'] = new stdClass();
  687. $this->dataInputs['idRecord']->title = 'idRecord';
  688. $this->dataInputs['idRecord']->description = 'Record ID';
  689. $this->dataInputs['idRecord']->type = 'integer';// LiteralData: xs:integer
  690. }
  691. }
  692. class WfsAction {
  693. /**
  694. * example: MULTIPOLYGON(((2072016.74395199 7234076.79293037,2072016.74395199 7234115.01144451,2072131.3994944 7234115.01144451,2072131.3994944 7234076.79293037,2072016.74395199 7234076.79293037)))
  695. */
  696. public function generateGmlFromWKT($wkt) {
  697. $gml = '';
  698. $wktParts = explode('(', $wkt, 2);
  699. ob_start();
  700. switch ($wktParts[0]) {
  701. case 'MULTIPOLYGON':
  702. case 'POLYGON': {
  703. $points = trim($wktParts[1], '() ');
  704. $points = str_replace(',', "\n", $points);
  705. ?>
  706. <gml:boundedBy>
  707. <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
  708. <gml:lowerCorner>-180 -90</gml:lowerCorner>
  709. <gml:upperCorner>180 90</gml:upperCorner>
  710. </gml:Envelope>
  711. </gml:boundedBy>
  712. <og:the_geom>
  713. <gml:MultiSurface srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#900913">
  714. <gml:surfaceMember>
  715. <gml:Polygon srsDimension="2">
  716. <gml:exterior>
  717. <gml:LinearRing srsDimension="2">
  718. <gml:posList>
  719. <?php echo $points; ?>
  720. </gml:posList>
  721. </gml:LinearRing>
  722. </gml:exterior>
  723. </gml:Polygon>
  724. </gml:surfaceMember>
  725. </gml:MultiSurface>
  726. </og:the_geom>
  727. <?php
  728. }
  729. break;
  730. default:
  731. }
  732. $gml = ob_get_contents();
  733. ob_clean();
  734. return $gml;
  735. }
  736. public function execute($args) {
  737. /*
  738. * Mapa odczytywanie punktów: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
  739. *
  740. * CI50:
  741. 18.613243103027344 54.33614429135817
  742. 18.613243103027344 54.33634445792519
  743. 18.614273071289062 54.33634445792519
  744. 18.614273071289062 54.33614429135817
  745. */
  746. $tblId = 16;// `BUILDINGS`
  747. $buildingsGml = array();
  748. $db = DB::getDB();
  749. $sql = "select b.`ID`, AsWKT(b.`the_geom`) as the_geom
  750. from `BUILDINGS` as b
  751. where b.`the_geom` is not null and b.`the_geom`!=''
  752. limit 10;
  753. ";
  754. $res = $db->query($sql);
  755. while ($r = $db->fetch($res)) {
  756. $buildingsGml[$r->ID] = $this->generateGmlFromWKT($r->the_geom);
  757. }
  758. /**
  759. * <og:recordId><?php echo $kId; ?></og:recordId>
  760. * <og:tblId><?php echo $tblId; ?></og:tblId>
  761. *
  762. * goes to js: @see priv.addWKTInput _layer.selectedFeatures[0]
  763. *
  764. * attributes: Object
  765. recordId: "1130"
  766. tblId: "16"
  767. */
  768. echo '<?xml version="1.0" encoding="UTF-8"?>';
  769. ?>
  770. <wfs:FeatureCollection xmlns:nasa="http://nasa.gov" xmlns:topp="http://www.openplans.org/topp" xmlns:usgs="http://www.usgs.gov/" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ows="http://www.opengis.net/ows" xmlns:ne="http://naturalearthdata.com" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gml="http://www.opengis.net/gml" xmlns:osm="http://openstreemap.org" xmlns:nurc="http://www.nurc.nato.int" xmlns:og="http://opengeo.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" numberOfFeatures="4" timeStamp="2014-07-16T13:22:43.307Z" xsi:schemaLocation="http://opengeo.org http://demo.opengeo.org:80/geoserver/wfs?service=WFS&amp;version=1.1.0&amp;request=DescribeFeatureType&amp;typeName=og%3Arestricted http://www.opengis.net/wfs http://demo.opengeo.org:80/geoserver/schemas/wfs/1.1.0/wfs.xsd">
  771. <!--
  772. <?php echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($buildingsGml);echo'</pre>'; ?>
  773. -->
  774. <gml:boundedBy>
  775. <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
  776. <gml:lowerCorner>-180 -90</gml:lowerCorner>
  777. <gml:upperCorner>180 90</gml:upperCorner>
  778. </gml:Envelope>
  779. </gml:boundedBy>
  780. <gml:featureMembers>
  781. <?php foreach ($buildingsGml as $kId => $vGml) : ?>
  782. <og:restricted gml:id="restricted.<?php echo $kId; ?>">
  783. <?php echo $vGml; ?>
  784. <og:recordId><?php echo $kId; ?></og:recordId>
  785. <og:tblId><?php echo $tblId; ?></og:tblId>
  786. </og:restricted>
  787. <?php endforeach; ?>
  788. </gml:featureMembers>
  789. </wfs:FeatureCollection>
  790. <?php
  791. }
  792. }
  793. class WpsServer {
  794. private $_fun;// config for identifiers
  795. public function __construct() {
  796. $this->_fun['przypiszDoRekordu'] = new WpsActionPrzypiszDoRekordu();
  797. $this->_wfsAction = new WfsAction();
  798. }
  799. public function parseXMLRequest() {
  800. $data = array();
  801. $reqContent = file_get_contents('php://input');
  802. $xml = new SimpleXMLElement($reqContent);
  803. if ('GetFeature' == $xml->getName()) {
  804. // TODO: parse xml and set query params
  805. $this->_wfsAction->execute($data);
  806. }
  807. else if (isset($xml->children('ows', TRUE)->Identifier)) {
  808. $identifier = (string)$xml->children('ows', TRUE)->Identifier;
  809. if (array_key_exists($identifier, $this->_fun)) {
  810. foreach ($xml->children('wps', TRUE)->DataInputs->children('wps', TRUE) as $input) {
  811. $inputIdentifier = (string)$input->children('ows', TRUE)->Identifier;
  812. if (array_key_exists($inputIdentifier, $this->_fun[$identifier]->dataInputs)) {
  813. $inputType = (string)$this->_fun[$identifier]->dataInputs[$inputIdentifier]->type;
  814. switch ($inputType) {
  815. case 'integer':
  816. $data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->LiteralData;
  817. break;
  818. case 'geom':
  819. $data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->ComplexData;
  820. break;
  821. default:
  822. }
  823. } else {
  824. // brak zdefiniowanego inputa
  825. }
  826. }
  827. $this->_fun['przypiszDoRekordu']->execute($data);
  828. } else {
  829. echo "TODO: brak zdefiniowanej funkcji '{$identifier}'";
  830. var_dump($identifier);
  831. }
  832. }
  833. else {
  834. echo "TODO: '" . $xml->getName() . "' ...";
  835. }
  836. }
  837. public function getCapabilitiesAction() {
  838. echo '<?xml version="1.0" encoding="UTF-8"?>';
  839. ?>
  840. <wps:Capabilities xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
  841. <ows:ServiceIdentification>
  842. <ows:Title>Prototype GeoServer WPS</ows:Title>
  843. <ows:Abstract />
  844. <ows:Keywords>
  845. <ows:Keyword>wps</ows:Keyword>
  846. <ows:Keyword>geoserver</ows:Keyword>
  847. </ows:Keywords>
  848. <ows:ServiceType>WPS</ows:ServiceType>
  849. <ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
  850. <ows:Fees>NONE</ows:Fees>
  851. <ows:AccessConstraints>NONE</ows:AccessConstraints>
  852. </ows:ServiceIdentification>
  853. <ows:ServiceProvider>
  854. <ows:ProviderName>GeoServer</ows:ProviderName>
  855. <ows:ProviderSite />
  856. <ows:ServiceContact />
  857. </ows:ServiceProvider>
  858. <ows:OperationsMetadata>
  859. <ows:Operation name="GetCapabilities">
  860. <ows:DCP>
  861. <ows:HTTP>
  862. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  863. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  864. </ows:HTTP>
  865. </ows:DCP>
  866. </ows:Operation>
  867. <ows:Operation name="DescribeProcess">
  868. <ows:DCP>
  869. <ows:HTTP>
  870. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  871. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  872. </ows:HTTP>
  873. </ows:DCP>
  874. </ows:Operation>
  875. <ows:Operation name="Execute">
  876. <ows:DCP>
  877. <ows:HTTP>
  878. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  879. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  880. </ows:HTTP>
  881. </ows:DCP>
  882. </ows:Operation>
  883. </ows:OperationsMetadata>
  884. <wps:ProcessOfferings>
  885. <?php foreach($this->_fun as $kFun => $vFun) : ?>
  886. <wps:Process wps:processVersion="1.0.0">
  887. <ows:Identifier><?php echo $kFun; ?></ows:Identifier>
  888. <ows:Title><?php echo $vFun->title; ?></ows:Title>
  889. <ows:Abstract><?php echo $vFun->description; ?></ows:Abstract>
  890. </wps:Process>
  891. <?php endforeach; ?>
  892. </wps:ProcessOfferings>
  893. <wps:Languages>
  894. <wps:Default>
  895. <ows:Language>en-US</ows:Language>
  896. </wps:Default>
  897. <wps:Supported>
  898. <ows:Language>en-US</ows:Language>
  899. </wps:Supported>
  900. </wps:Languages>
  901. </wps:Capabilities>
  902. <?php
  903. }
  904. public function describeProcessAction($args) {
  905. // TODO: xml z opiesem procese $args['IDENTIFIER']
  906. /**
  907. * should work like JTS:densify - geom field (map object) and integer field (record ID)
  908. * http://openlayers.org/dev/examples/proxy.cgi?url=http%3A%2F%2Fdemo.opengeo.org%2Fgeoserver%2Fwps%3FSERVICE%3DWPS%26REQUEST%3DDescribeProcess%26VERSION%3D1.0.0%26IDENTIFIER%3DJTS%253Adensify
  909. * http://demo.opengeo.org/geoserver/wps?SERVICE=WPS&REQUEST=DescribeProcess&VERSION=1.0.0&IDENTIFIER=JTS%3Adensify
  910. */
  911. echo '<?xml version="1.0" encoding="UTF-8"?>';
  912. if (array_key_exists($args['IDENTIFIER'], $this->_fun)) {
  913. $identifier = $this->_fun[$args['IDENTIFIER']];
  914. ?>
  915. <wps:ProcessDescriptions xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en" service="WPS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
  916. <ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true">
  917. <ows:Identifier><?php echo $args['IDENTIFIER']; ?></ows:Identifier>
  918. <ows:Title><?php echo $identifier->title; ?></ows:Title>
  919. <ows:Abstract><?php echo $identifier->description; ?></ows:Abstract>
  920. <DataInputs>
  921. <?php foreach ($identifier->dataInputs as $kInput => $vInput) : ?>
  922. <Input maxOccurs="1" minOccurs="1">
  923. <ows:Identifier><?php echo $kInput; ?></ows:Identifier>
  924. <ows:Title><?php echo $vInput->title; ?></ows:Title>
  925. <ows:Abstract><?php echo $vInput->description; ?></ows:Abstract>
  926. <?php if ($vInput->type == 'geom') : ?>
  927. <ComplexData>
  928. <Default>
  929. <Format>
  930. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  931. </Format>
  932. </Default>
  933. <Supported>
  934. <Format>
  935. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  936. </Format>
  937. <Format>
  938. <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
  939. </Format>
  940. <Format>
  941. <MimeType>application/wkt</MimeType>
  942. </Format>
  943. <Format>
  944. <MimeType>application/gml-3.1.1</MimeType>
  945. </Format>
  946. <Format>
  947. <MimeType>application/gml-2.1.2</MimeType>
  948. </Format>
  949. </Supported>
  950. </ComplexData>
  951. <?php elseif ($vInput->type == 'integer') : ?>
  952. <LiteralData>
  953. <ows:DataType>xs:integer</ows:DataType>
  954. <ows:AnyValue />
  955. </LiteralData>
  956. <?php else : ?>
  957. <?php endif; ?>
  958. </Input>
  959. <?php endforeach; ?>
  960. </DataInputs>
  961. <ProcessOutputs>
  962. <Output>
  963. <ows:Identifier>result</ows:Identifier>
  964. <ows:Title>result</ows:Title>
  965. <ComplexOutput>
  966. <Default>
  967. <Format>
  968. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  969. </Format>
  970. </Default>
  971. <Supported>
  972. <Format>
  973. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  974. </Format>
  975. <Format>
  976. <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
  977. </Format>
  978. <Format>
  979. <MimeType>application/wkt</MimeType>
  980. </Format>
  981. <Format>
  982. <MimeType>application/gml-3.1.1</MimeType>
  983. </Format>
  984. <Format>
  985. <MimeType>application/gml-2.1.2</MimeType>
  986. </Format>
  987. </Supported>
  988. </ComplexOutput>
  989. </Output>
  990. </ProcessOutputs>
  991. </ProcessDescription>
  992. </wps:ProcessDescriptions>
  993. <?php
  994. } else {
  995. echo 'TODO: brak funkcji';
  996. }
  997. }
  998. }