superedit-OPEN_LAYERS_WPS.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  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);
  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. <script src="stuff/open-layers/OpenLayers.js"></script>
  151. <!-- <script src="stuff/open-layers/wps.js"></script> -->
  152. <script>
  153. (function ( $ ) {
  154. var TableAjaxMap = function() {
  155. var priv = {}; //private api
  156. var publ = {}; //public api
  157. priv.options = {};
  158. var defaults = {
  159. wpsUrl: '',
  160. wfsUrl: '',
  161. domProcessId: '',
  162. urlInit: true, // try to load services on init
  163. preloadData: null,
  164. menuid: '',
  165. debug: false
  166. };
  167. var _nodeMapId;
  168. var _nodeMap;
  169. var _nodeProcesses;
  170. var _nodeAbstract;
  171. var _nodeInput;
  172. var _nodeOutput;
  173. var _capabilities;
  174. var _process;
  175. var _layer;
  176. /*
  177. initialize the plugin.
  178. */
  179. priv.init = function() {
  180. console.log('test jQuery plugin init...', priv);
  181. // create dom:
  182. /*
  183. <div id="map" class="smallmap"></div>
  184. <div>
  185. <select id="processes"><option>Select a process</option></select>
  186. <p id="abstract"></p>
  187. <div id="input"></div>
  188. <div id="output"></div>
  189. </div>
  190. */
  191. _nodeMapId = 'Map-' + Math.random(1).toString().substr(2);
  192. _nodeMap = $('<div id="' + _nodeMapId + '" class="smallmap"></div>');
  193. _nodeProcesses = $('<select></select>');
  194. _nodeProcesses.append('<option>Wybierz funkcję</option>');
  195. _nodeAbstract = $('<p></p>');
  196. _nodeInput = $('<div></div>');
  197. _nodeOutput = $('<div></div>');
  198. var div = $('<div></div>');
  199. div.append(_nodeProcesses);
  200. div.append(_nodeAbstract);
  201. div.append(_nodeInput);
  202. div.append(_nodeOutput);
  203. $(priv.options.id).append(_nodeMap);
  204. $(priv.options.id).append(div);
  205. _nodeProcesses.on('change', function() {
  206. console.log("onchange this:", this, this.selectedIndex, this.options);
  207. var selection = this.options[this.selectedIndex].value;
  208. if (this.selectedIndex > 0) {
  209. OpenLayers.Request.GET({
  210. url: priv.options.wpsUrl,
  211. params: {
  212. "SERVICE": "WPS",
  213. "REQUEST": "DescribeProcess",
  214. "VERSION": _capabilities.version,
  215. "IDENTIFIER": selection
  216. },
  217. success: function(response) {
  218. _process = new OpenLayers.Format.WPSDescribeProcess().read(
  219. response.responseText
  220. ).processDescriptions[selection];
  221. console.log("Process:", _process);
  222. priv.buildForm();
  223. }
  224. });
  225. }
  226. });
  227. priv.getCapabilities();
  228. _layer = new OpenLayers.Layer.Vector("Warstwa rysowania", {
  229. strategies: [new OpenLayers.Strategy.BBOX()],
  230. projection: new OpenLayers.Projection("EPSG:900913"),
  231. protocol: new OpenLayers.Protocol.WFS({
  232. version: "1.1.0",
  233. srsName: "EPSG:900913",
  234. url: priv.options.wfsUrl,
  235. featureNS : "http://opengeo.org",
  236. featureType: "restricted",
  237. geometryName: "the_geom",
  238. schema: "http://demo.opengeo.org/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=og:restricted"
  239. })
  240. });
  241. var toolbar = new OpenLayers.Control.EditingToolbar(_layer);
  242. toolbar.addControls([new OpenLayers.Control.ModifyFeature(_layer, {
  243. title: "Wybierz",
  244. mode: OpenLayers.Control.ModifyFeature.DRAG | OpenLayers.Control.ModifyFeature.RESHAPE
  245. })]);
  246. var btnZoomToPoly = new OpenLayers.Control.Button({
  247. displayClass: "olControlZoomToPoly",
  248. title: "Zbliz",
  249. trigger:
  250. function() {
  251. var multiPolygon = OpenLayers.Geometry.fromWKT(
  252. "MULTIPOLYGON(((2072016.74395199 7234076.79293037,2072016.74395199 7234115.01144451,2072131.3994944 7234115.01144451,2072131.3994944 7234076.79293037,2072016.74395199 7234076.79293037)))"
  253. ).getBounds();
  254. map.zoomToExtent(multiPolygon);
  255. }
  256. });
  257. toolbar.addControls([btnZoomToPoly]);
  258. var btnRefresh = new OpenLayers.Control.Button({
  259. displayClass: "olControlRefresh",
  260. title: "Odswiez",
  261. trigger:
  262. function() {
  263. _layer.refresh({force:true});
  264. }
  265. });
  266. toolbar.addControls([btnRefresh]);
  267. var deleteFeatureControl = new OpenLayers.Control.SelectFeature(_layer, OpenLayers.Handler.Path, {
  268. clickout: false,
  269. toggle: false,
  270. displayClass: "olControlDelete",
  271. title: "Usun"
  272. });
  273. deleteFeatureControl.events.register("featurehighlighted", this, function(e) {
  274. if (confirm('Czy na pewno chcesz usunąć ten obiekt?')) {
  275. _layer.removeFeatures([e.feature]);
  276. deleteFeatureControl.deactivate();
  277. } else {
  278. deleteFeatureControl.unselect(e.feature);
  279. }
  280. });
  281. toolbar.addControls([deleteFeatureControl]);
  282. function report(event) {
  283. OpenLayers.Console.log(event.type, event.feature ? event.feature.id : event.components);
  284. }
  285. _layer.events.on({
  286. "beforefeaturemodified": report,
  287. "featuremodified": report,
  288. "afterfeaturemodified": report,
  289. "vertexmodified": report,
  290. "sketchmodified": report,
  291. "sketchstarted": report,
  292. "sketchcomplete": report
  293. });
  294. var extent = new OpenLayers.Bounds(
  295. 2035059.4410645328, 7200979.560689885, 2113330.958028555, 7279251.0776539035
  296. );
  297. var gphy = new OpenLayers.Layer.OSM("Mapa", null, {
  298. resolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
  299. 19567.87923828125, 9783.939619140625, 4891.9698095703125,
  300. 2445.9849047851562, 1222.9924523925781, 611.4962261962891,
  301. 305.74811309814453, 152.87405654907226, 76.43702827453613,
  302. 38.218514137268066, 19.109257068634033, 9.554628534317017,
  303. 4.777314267158508, 2.388657133579254, 1.194328566789627,
  304. 0.5971642833948135, 0.25, 0.1, 0.05],
  305. serverResolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
  306. 19567.87923828125, 9783.939619140625,
  307. 4891.9698095703125, 2445.9849047851562,
  308. 1222.9924523925781, 611.4962261962891,
  309. 305.74811309814453, 152.87405654907226,
  310. 76.43702827453613, 38.218514137268066,
  311. 19.109257068634033, 9.554628534317017,
  312. 4.777314267158508, 2.388657133579254,
  313. 1.194328566789627, 0.5971642833948135],
  314. transitionEffect: 'resize'
  315. });
  316. var map = new OpenLayers.Map(_nodeMapId, {
  317. projection: new OpenLayers.Projection("EPSG:900913"),
  318. displayProjection: new OpenLayers.Projection("EPSG:4326"),
  319. restrictedExtent: extent,
  320. controls: [
  321. toolbar,
  322. new OpenLayers.Control.ZoomPanel(),
  323. new OpenLayers.Control.PanPanel(),
  324. new OpenLayers.Control.LayerSwitcher(),
  325. new OpenLayers.Control.ScaleLine(),
  326. new OpenLayers.Control.KeyboardDefaults()
  327. // new OpenLayers.Control.MousePosition()
  328. ], layers: [gphy,_layer]
  329. });
  330. map.zoomToMaxExtent();
  331. // var draw = new OpenLayers.Control.DrawFeature(
  332. // _layer, OpenLayers.Handler.Path
  333. // );
  334. // map.addControl(_draw);
  335. // draw.activate();
  336. // OpenLayers.Event.observe(document, "keydown", function(evt) {
  337. // var handled = false;
  338. // switch (evt.keyCode) {
  339. // case 90: // z
  340. // if (evt.metaKey || evt.ctrlKey) {
  341. // draw.undo();
  342. // handled = true;
  343. // }
  344. // break;
  345. // case 89: // y
  346. // if (evt.metaKey || evt.ctrlKey) {
  347. // draw.redo();
  348. // handled = true;
  349. // }
  350. // break;
  351. // case 27: // esc
  352. // draw.cancel();
  353. // handled = true;
  354. // break;
  355. // }
  356. // if (handled) {
  357. // OpenLayers.Event.stop(evt);
  358. // }
  359. // });
  360. };
  361. // using OpenLayers.Format.WPSCapabilities to read the capabilities
  362. priv.getCapabilities = function() {
  363. OpenLayers.Request.GET({
  364. url: priv.options.wpsUrl,
  365. params: {
  366. "SERVICE": "WPS",
  367. "REQUEST": "GetCapabilities"
  368. },
  369. success: function(response){
  370. _capabilities = new OpenLayers.Format.WPSCapabilities().read(
  371. response.responseText
  372. );
  373. var dropdown = _nodeProcesses;
  374. var offerings = _capabilities.processOfferings, option;
  375. // populate the dropdown
  376. for (var p in offerings) {
  377. option = document.createElement("option");
  378. option.innerHTML = offerings[p].identifier;
  379. option.value = p;
  380. dropdown.append(option);
  381. }
  382. }
  383. });
  384. };
  385. priv.buildForm = function() {
  386. _nodeAbstract.html(_process["abstract"]);
  387. _nodeInput.html("<h3>Input:</h3>");
  388. _nodeOutput.html('');
  389. var inputs = _process.dataInputs, supported = true,
  390. sld = "text/xml; subtype=sld/1.0.0",
  391. input;
  392. for (var i = 0, ii = inputs.length; i < ii; ++i) {
  393. input = inputs[i];
  394. if (input.complexData) {
  395. var formats = input.complexData.supported.formats;
  396. if (formats["application/wkt"]) {
  397. priv.addWKTInput(input);
  398. } else if (formats["text/xml; subtype=wfs-collection/1.0"]) {
  399. priv.addWFSCollectionInput(input);
  400. } else if (formats["image/tiff"]) {
  401. //priv.addRasterInput(input);
  402. } else if (formats[sld]) {
  403. priv.addXMLInput(input, sld);
  404. } else {
  405. supported = false;
  406. }
  407. } else if (input.boundingBoxData) {
  408. priv.addBoundingBoxInput(input);
  409. } else if (input.literalData) {
  410. priv.addLiteralInput(input);
  411. } else {
  412. supported = false;
  413. }
  414. if (input.minOccurs > 0) {
  415. _nodeInput.append(document.createTextNode("* "));
  416. }
  417. }
  418. if (supported) {
  419. var executeButton = document.createElement("button");
  420. executeButton.innerHTML = "Execute";
  421. _nodeInput.append(executeButton);
  422. executeButton.onclick = priv.execute;
  423. } else {
  424. _nodeInput.html('<span class="notsupported">' +
  425. "Sorry, the WPS builder does not support the selected process." +
  426. "</span>");
  427. }
  428. };
  429. // helper function to dynamically create a textarea for geometry (WKT) data
  430. // input
  431. priv.addWKTInput = function(input, previousSibling) {
  432. var name = input.identifier;
  433. var container = _nodeInput.get(0);
  434. var label = document.createElement("label");
  435. label["for"] = name;
  436. label.title = input["abstract"];
  437. label.innerHTML = name + " (select feature, then click field):";
  438. previousSibling && previousSibling.nextSibling ?
  439. container.insertBefore(label, previousSibling.nextSibling) :
  440. container.appendChild(label);
  441. var field = document.createElement("textarea");
  442. field.onclick = function () {
  443. if (_layer.selectedFeatures.length) {
  444. this.innerHTML = new OpenLayers.Format.WKT().write(
  445. _layer.selectedFeatures[0]
  446. );
  447. console.log('_layer.selectedFeatures[0]: ', _layer.selectedFeatures[0]);
  448. }
  449. priv.createCopy(input, this, priv.addWKTInput);
  450. };
  451. field.onblur = function() {
  452. input.data = field.value ? {
  453. complexData: {
  454. mimeType: "application/wkt",
  455. value: this.value
  456. }
  457. } : undefined;
  458. };
  459. field.title = input["abstract"];
  460. field.id = name;
  461. previousSibling && previousSibling.nextSibling ?
  462. container.insertBefore(field, previousSibling.nextSibling.nextSibling) :
  463. container.appendChild(field);
  464. };
  465. // helper function for xml input
  466. priv.addXMLInput = function(input, type) {
  467. var name = input.identifier;
  468. var field = document.createElement("input");
  469. field.title = input["abstract"];
  470. field.value = name + " (" + type + ")";
  471. field.onblur = function() {
  472. input.data = field.value ? {
  473. complexData: {
  474. mimeType: type,
  475. value: this.value
  476. }
  477. } : undefined;
  478. };
  479. _nodeInput.append(field);
  480. };
  481. // helper function to dynamically create a WFS collection reference input
  482. priv.addWFSCollectionInput = function(input) {
  483. var name = input.identifier;
  484. var field = document.createElement("input");
  485. field.title = input["abstract"];
  486. field.value = name + " (layer on demo server)";
  487. priv.addValueHandlers(field, function() {
  488. input.reference = field.value ? {
  489. mimeType: "text/xml; subtype=wfs-collection/1.0",
  490. href: "http://geoserver/wfs",
  491. method: "POST",
  492. body: {
  493. wfs: {
  494. version: "1.0.0",
  495. outputFormat: "GML2",
  496. featureType: field.value
  497. }
  498. }
  499. } : undefined;
  500. });
  501. _nodeInput.append(field);
  502. };
  503. // helper function to dynamically create a raster (GeoTIFF) url input
  504. priv.addRasterInput = function(input) {
  505. var name = input.identifier;
  506. var field = document.createElement("input");
  507. field.title = input["abstract"];
  508. var url = window.location.href.split("?")[0];
  509. field.value = url.substr(0, url.lastIndexOf("/")+1) + "data/tazdem.tiff";// TODO: file path to options
  510. document.getElementById("input").appendChild(field);
  511. (field.onblur = function() {
  512. input.reference = {
  513. mimeType: "image/tiff",
  514. href: field.value,
  515. method: "GET"
  516. };
  517. })();
  518. };
  519. // helper function to dynamically create a bounding box input
  520. priv.addBoundingBoxInput = function(input) {
  521. var name = input.identifier;
  522. var field = document.createElement("input");
  523. field.title = input["abstract"];
  524. field.value = "left,bottom,right,top (EPSG:4326)";
  525. _nodeInput.append(field);
  526. priv.addValueHandlers(field, function() {
  527. input.boundingBoxData = {
  528. projection: "EPSG:4326",
  529. bounds: OpenLayers.Bounds.fromString(field.value)
  530. };
  531. });
  532. };
  533. // helper function to create a literal input textfield or dropdown
  534. priv.addLiteralInput = function(input, previousSibling) {
  535. var name = input.identifier;
  536. var container = _nodeInput.get(0);
  537. var anyValue = input.literalData.anyValue;
  538. // anyValue means textfield, otherwise we create a dropdown
  539. var field = document.createElement(anyValue ? "input" : "select");
  540. field.id = name;
  541. field.title = input["abstract"];
  542. previousSibling && previousSibling.nextSibling ?
  543. container.insertBefore(field, previousSibling.nextSibling) :
  544. container.appendChild(field);
  545. if (anyValue) {
  546. var dataType = input.literalData.dataType;
  547. field.value = name + (dataType ? " (" + dataType + ")" : "");
  548. priv.addValueHandlers(field, function() {
  549. input.data = field.value ? {
  550. literalData: {
  551. value: field.value
  552. }
  553. } : undefined;
  554. priv.createCopy(input, field, priv.addLiteralInput);
  555. });
  556. } else {
  557. var option;
  558. option = document.createElement("option");
  559. option.innerHTML = name;
  560. field.appendChild(option);
  561. for (var v in input.literalData.allowedValues) {
  562. option = document.createElement("option");
  563. option.value = v;
  564. option.innerHTML = v;
  565. field.appendChild(option);
  566. }
  567. field.onchange = function() {
  568. priv.createCopy(input, field, priv.addLiteralInput);
  569. input.data = this.selectedIndex ? {
  570. literalData: {
  571. value: this.options[this.selectedIndex].value
  572. }
  573. } : undefined;
  574. };
  575. }
  576. };
  577. // if maxOccurs is > 1, this will add a copy of the field
  578. priv.createCopy = function(input, field, fn) {
  579. if (input.maxOccurs && input.maxOccurs > 1 && !field.userSelected) {
  580. // add another copy of the field - we don't check maxOccurs
  581. field.userSelected = true;
  582. var newInput = OpenLayers.Util.extend({}, input);
  583. // we recognize copies by the occurrence property
  584. newInput.occurrence = (input.occurrence || 0) + 1;
  585. _process.dataInputs.push(newInput);
  586. fn(newInput, field);
  587. }
  588. };
  589. // helper function for adding events to form fields
  590. priv.addValueHandlers = function(field, onblur) {
  591. field.onclick = function() {
  592. if (!this.initialValue) {
  593. this.initialValue = this.value;
  594. this.value = "";
  595. }
  596. };
  597. field.onblur = function() {
  598. if (!this.value) {
  599. this.value = this.initialValue;
  600. delete this.initialValue;
  601. }
  602. onblur.apply(this, arguments);
  603. };
  604. };
  605. // execute the process
  606. priv.execute = function() {
  607. var output = _process.processOutputs[0];
  608. var input;
  609. // remove occurrences that the user has not filled out
  610. for (var i = _process.dataInputs.length - 1; i >= 0; --i) {
  611. input = _process.dataInputs[i];
  612. if ((input.minOccurs === 0 || input.occurrence) && !input.data && !input.reference) {
  613. OpenLayers.Util.removeItem(_process.dataInputs, input);
  614. }
  615. }
  616. _process.responseForm = {
  617. rawDataOutput: {
  618. identifier: output.identifier
  619. }
  620. };
  621. if (output.complexOutput && output.complexOutput.supported.formats["application/wkt"]) {
  622. _process.responseForm.rawDataOutput.mimeType = "application/wkt";
  623. }
  624. OpenLayers.Request.POST({
  625. url: priv.options.wpsUrl,
  626. data: new OpenLayers.Format.WPSExecute().write(_process),
  627. success: priv.showOutput
  628. });
  629. }
  630. // add the process's output to the page
  631. priv.showOutput = function(response) {
  632. var result = _nodeOutput.get(0);
  633. result.innerHTML = "<h3>Output:</h3>";
  634. var features;
  635. var contentType = response.getResponseHeader("Content-Type");
  636. if (contentType == "application/wkt") {
  637. features = new OpenLayers.Format.WKT().read(response.responseText);
  638. } else if (contentType == "text/xml; subtype=wfs-collection/1.0") {
  639. features = new OpenLayers.Format.WFST.v1_0_0().read(response.responseText);
  640. }
  641. if (features && (features instanceof OpenLayers.Feature.Vector || features.length)) {
  642. _layer.addFeatures(features);
  643. result.innerHTML += "The result should also be visible on the map.";
  644. }
  645. result.innerHTML += "<textarea>" + response.responseText + "</textarea>";
  646. }
  647. publ.init = function(options) {
  648. if (priv.options.debug) console.log('TableAjaxMap initialization...');
  649. //merge supplied options with defaults
  650. $.extend(priv.options, defaults, options);
  651. priv.init();
  652. return publ;
  653. };
  654. return publ;
  655. };
  656. $.fn.TableAjaxMap = function(options) {
  657. options = options || {};
  658. return this.each(function() {
  659. options.id = this;
  660. $(this).data('TableAjaxMap', new TableAjaxMap().init(options));
  661. });
  662. return this;
  663. };
  664. }(jQuery));
  665. </script>
  666. <script>
  667. OpenLayers.ProxyHost = "index.php?FUNCTION_INIT=<?php echo __FUNCTION__; ?>&HEADER_NOT_INIT=YES&task=proxy&url=";
  668. jQuery('#TreeTableMap').TableAjaxMap({
  669. wpsUrl: 'http://biuro.biall-net.pl/wps',
  670. wfsUrl: 'http://biuro.biall-net.pl/wps'
  671. });
  672. </script>
  673. <?php
  674. }
  675. class WpsActionBase {
  676. public $title = '';
  677. public $description = '';
  678. public $dataInputs = array();
  679. public function execute($args) {
  680. var_dump($args);
  681. }
  682. }
  683. class WpsActionPrzypiszDoRekordu extends WpsActionBase {
  684. public function __construct() {
  685. $this->title = 'Przypisz';
  686. $this->description = 'Przypisuje położenie do wybranego rekordu w tabeli.';
  687. $this->dataInputs['geom'] = new stdClass();
  688. $this->dataInputs['geom']->title = 'geom';
  689. $this->dataInputs['geom']->description = 'Input geometry';
  690. $this->dataInputs['geom']->type = 'geom';// CoomplexData
  691. $this->dataInputs['idTable'] = new stdClass();
  692. $this->dataInputs['idTable']->title = 'geom';
  693. $this->dataInputs['idTable']->description = 'Table ID';
  694. $this->dataInputs['idTable']->type = 'integer';// LiteralData: xs:integer
  695. $this->dataInputs['idRecord'] = new stdClass();
  696. $this->dataInputs['idRecord']->title = 'idRecord';
  697. $this->dataInputs['idRecord']->description = 'Record ID';
  698. $this->dataInputs['idRecord']->type = 'integer';// LiteralData: xs:integer
  699. }
  700. }
  701. class WfsAction {
  702. /**
  703. * example: MULTIPOLYGON(((2072016.74395199 7234076.79293037,2072016.74395199 7234115.01144451,2072131.3994944 7234115.01144451,2072131.3994944 7234076.79293037,2072016.74395199 7234076.79293037)))
  704. */
  705. public function generateGmlFromWKT($wkt) {
  706. $gml = '';
  707. $wktParts = explode('(', $wkt, 2);
  708. ob_start();
  709. switch ($wktParts[0]) {
  710. case 'MULTIPOLYGON':
  711. case 'POLYGON': {
  712. $points = trim($wktParts[1], '() ');
  713. $points = str_replace(',', "\n", $points);
  714. ?>
  715. <gml:boundedBy>
  716. <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
  717. <gml:lowerCorner>-180 -90</gml:lowerCorner>
  718. <gml:upperCorner>180 90</gml:upperCorner>
  719. </gml:Envelope>
  720. </gml:boundedBy>
  721. <og:the_geom>
  722. <gml:MultiSurface srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#900913">
  723. <gml:surfaceMember>
  724. <gml:Polygon srsDimension="2">
  725. <gml:exterior>
  726. <gml:LinearRing srsDimension="2">
  727. <gml:posList>
  728. <?php echo $points; ?>
  729. </gml:posList>
  730. </gml:LinearRing>
  731. </gml:exterior>
  732. </gml:Polygon>
  733. </gml:surfaceMember>
  734. </gml:MultiSurface>
  735. </og:the_geom>
  736. <?php
  737. }
  738. break;
  739. default:
  740. }
  741. $gml = ob_get_contents();
  742. ob_clean();
  743. return $gml;
  744. }
  745. public function execute($args) {
  746. /*
  747. * Mapa odczytywanie punktów: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
  748. *
  749. * CI50:
  750. 18.613243103027344 54.33614429135817
  751. 18.613243103027344 54.33634445792519
  752. 18.614273071289062 54.33634445792519
  753. 18.614273071289062 54.33614429135817
  754. */
  755. $tblId = 16;// `BUILDINGS`
  756. $buildingsGml = array();
  757. $db = DB::getDB();
  758. $sql = "select b.`ID`, AsWKT(b.`the_geom`) as the_geom
  759. from `BUILDINGS` as b
  760. where b.`the_geom` is not null and b.`the_geom`!=''
  761. limit 10;
  762. ";
  763. $res = $db->query($sql);
  764. while ($r = $db->fetch($res)) {
  765. $buildingsGml[$r->ID] = $this->generateGmlFromWKT($r->the_geom);
  766. }
  767. /**
  768. * <og:recordId><?php echo $kId; ?></og:recordId>
  769. * <og:tblId><?php echo $tblId; ?></og:tblId>
  770. *
  771. * goes to js: @see priv.addWKTInput _layer.selectedFeatures[0]
  772. *
  773. * attributes: Object
  774. recordId: "1130"
  775. tblId: "16"
  776. */
  777. echo '<?xml version="1.0" encoding="UTF-8"?>';
  778. ?>
  779. <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">
  780. <!--
  781. <?php echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;text-align:left;"> (' . __CLASS__ . '::' . __FUNCTION__ . ':' . __LINE__ . '): ';print_r($buildingsGml);echo'</pre>'; ?>
  782. -->
  783. <gml:boundedBy>
  784. <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
  785. <gml:lowerCorner>-180 -90</gml:lowerCorner>
  786. <gml:upperCorner>180 90</gml:upperCorner>
  787. </gml:Envelope>
  788. </gml:boundedBy>
  789. <gml:featureMembers>
  790. <?php foreach ($buildingsGml as $kId => $vGml) : ?>
  791. <og:restricted gml:id="restricted.<?php echo $kId; ?>">
  792. <?php echo $vGml; ?>
  793. <og:recordId><?php echo $kId; ?></og:recordId>
  794. <og:tblId><?php echo $tblId; ?></og:tblId>
  795. </og:restricted>
  796. <?php endforeach; ?>
  797. </gml:featureMembers>
  798. </wfs:FeatureCollection>
  799. <?php
  800. }
  801. }
  802. class WpsServer {
  803. private $_fun;// config for identifiers
  804. public function __construct() {
  805. $this->_fun['przypiszDoRekordu'] = new WpsActionPrzypiszDoRekordu();
  806. $this->_wfsAction = new WfsAction();
  807. }
  808. public function parseXMLRequest() {
  809. $data = array();
  810. $reqContent = file_get_contents('php://input');
  811. $xml = new SimpleXMLElement($reqContent);
  812. if ('GetFeature' == $xml->getName()) {
  813. // TODO: parse xml and set query params
  814. $this->_wfsAction->execute($data);
  815. }
  816. else if (isset($xml->children('ows', TRUE)->Identifier)) {
  817. $identifier = (string)$xml->children('ows', TRUE)->Identifier;
  818. if (array_key_exists($identifier, $this->_fun)) {
  819. foreach ($xml->children('wps', TRUE)->DataInputs->children('wps', TRUE) as $input) {
  820. $inputIdentifier = (string)$input->children('ows', TRUE)->Identifier;
  821. if (array_key_exists($inputIdentifier, $this->_fun[$identifier]->dataInputs)) {
  822. $inputType = (string)$this->_fun[$identifier]->dataInputs[$inputIdentifier]->type;
  823. switch ($inputType) {
  824. case 'integer':
  825. $data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->LiteralData;
  826. break;
  827. case 'geom':
  828. $data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->ComplexData;
  829. break;
  830. default:
  831. }
  832. } else {
  833. // brak zdefiniowanego inputa
  834. }
  835. }
  836. $this->_fun['przypiszDoRekordu']->execute($data);
  837. } else {
  838. echo "TODO: brak zdefiniowanej funkcji '{$identifier}'";
  839. var_dump($identifier);
  840. }
  841. }
  842. else {
  843. echo "TODO: '" . $xml->getName() . "' ...";
  844. }
  845. }
  846. public function getCapabilitiesAction() {
  847. echo '<?xml version="1.0" encoding="UTF-8"?>';
  848. ?>
  849. <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">
  850. <ows:ServiceIdentification>
  851. <ows:Title>Prototype GeoServer WPS</ows:Title>
  852. <ows:Abstract />
  853. <ows:Keywords>
  854. <ows:Keyword>wps</ows:Keyword>
  855. <ows:Keyword>geoserver</ows:Keyword>
  856. </ows:Keywords>
  857. <ows:ServiceType>WPS</ows:ServiceType>
  858. <ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
  859. <ows:Fees>NONE</ows:Fees>
  860. <ows:AccessConstraints>NONE</ows:AccessConstraints>
  861. </ows:ServiceIdentification>
  862. <ows:ServiceProvider>
  863. <ows:ProviderName>GeoServer</ows:ProviderName>
  864. <ows:ProviderSite />
  865. <ows:ServiceContact />
  866. </ows:ServiceProvider>
  867. <ows:OperationsMetadata>
  868. <ows:Operation name="GetCapabilities">
  869. <ows:DCP>
  870. <ows:HTTP>
  871. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  872. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  873. </ows:HTTP>
  874. </ows:DCP>
  875. </ows:Operation>
  876. <ows:Operation name="DescribeProcess">
  877. <ows:DCP>
  878. <ows:HTTP>
  879. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  880. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  881. </ows:HTTP>
  882. </ows:DCP>
  883. </ows:Operation>
  884. <ows:Operation name="Execute">
  885. <ows:DCP>
  886. <ows:HTTP>
  887. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  888. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  889. </ows:HTTP>
  890. </ows:DCP>
  891. </ows:Operation>
  892. </ows:OperationsMetadata>
  893. <wps:ProcessOfferings>
  894. <?php foreach($this->_fun as $kFun => $vFun) : ?>
  895. <wps:Process wps:processVersion="1.0.0">
  896. <ows:Identifier><?php echo $kFun; ?></ows:Identifier>
  897. <ows:Title><?php echo $vFun->title; ?></ows:Title>
  898. <ows:Abstract><?php echo $vFun->description; ?></ows:Abstract>
  899. </wps:Process>
  900. <?php endforeach; ?>
  901. </wps:ProcessOfferings>
  902. <wps:Languages>
  903. <wps:Default>
  904. <ows:Language>en-US</ows:Language>
  905. </wps:Default>
  906. <wps:Supported>
  907. <ows:Language>en-US</ows:Language>
  908. </wps:Supported>
  909. </wps:Languages>
  910. </wps:Capabilities>
  911. <?php
  912. }
  913. public function describeProcessAction($args) {
  914. // TODO: xml z opiesem procese $args['IDENTIFIER']
  915. /**
  916. * should work like JTS:densify - geom field (map object) and integer field (record ID)
  917. * 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
  918. * http://demo.opengeo.org/geoserver/wps?SERVICE=WPS&REQUEST=DescribeProcess&VERSION=1.0.0&IDENTIFIER=JTS%3Adensify
  919. */
  920. echo '<?xml version="1.0" encoding="UTF-8"?>';
  921. if (array_key_exists($args['IDENTIFIER'], $this->_fun)) {
  922. $identifier = $this->_fun[$args['IDENTIFIER']];
  923. ?>
  924. <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">
  925. <ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true">
  926. <ows:Identifier><?php echo $args['IDENTIFIER']; ?></ows:Identifier>
  927. <ows:Title><?php echo $identifier->title; ?></ows:Title>
  928. <ows:Abstract><?php echo $identifier->description; ?></ows:Abstract>
  929. <DataInputs>
  930. <?php foreach ($identifier->dataInputs as $kInput => $vInput) : ?>
  931. <Input maxOccurs="1" minOccurs="1">
  932. <ows:Identifier><?php echo $kInput; ?></ows:Identifier>
  933. <ows:Title><?php echo $vInput->title; ?></ows:Title>
  934. <ows:Abstract><?php echo $vInput->description; ?></ows:Abstract>
  935. <?php if ($vInput->type == 'geom') : ?>
  936. <ComplexData>
  937. <Default>
  938. <Format>
  939. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  940. </Format>
  941. </Default>
  942. <Supported>
  943. <Format>
  944. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  945. </Format>
  946. <Format>
  947. <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
  948. </Format>
  949. <Format>
  950. <MimeType>application/wkt</MimeType>
  951. </Format>
  952. <Format>
  953. <MimeType>application/gml-3.1.1</MimeType>
  954. </Format>
  955. <Format>
  956. <MimeType>application/gml-2.1.2</MimeType>
  957. </Format>
  958. </Supported>
  959. </ComplexData>
  960. <?php elseif ($vInput->type == 'integer') : ?>
  961. <LiteralData>
  962. <ows:DataType>xs:integer</ows:DataType>
  963. <ows:AnyValue />
  964. </LiteralData>
  965. <?php else : ?>
  966. <?php endif; ?>
  967. </Input>
  968. <?php endforeach; ?>
  969. </DataInputs>
  970. <ProcessOutputs>
  971. <Output>
  972. <ows:Identifier>result</ows:Identifier>
  973. <ows:Title>result</ows:Title>
  974. <ComplexOutput>
  975. <Default>
  976. <Format>
  977. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  978. </Format>
  979. </Default>
  980. <Supported>
  981. <Format>
  982. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  983. </Format>
  984. <Format>
  985. <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
  986. </Format>
  987. <Format>
  988. <MimeType>application/wkt</MimeType>
  989. </Format>
  990. <Format>
  991. <MimeType>application/gml-3.1.1</MimeType>
  992. </Format>
  993. <Format>
  994. <MimeType>application/gml-2.1.2</MimeType>
  995. </Format>
  996. </Supported>
  997. </ComplexOutput>
  998. </Output>
  999. </ProcessOutputs>
  1000. </ProcessDescription>
  1001. </wps:ProcessDescriptions>
  1002. <?php
  1003. } else {
  1004. echo 'TODO: brak funkcji';
  1005. }
  1006. }
  1007. }