TableAjaxMap.php 33 KB

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