TableAjaxMap.php 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  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 .olControlSelectFeatureItemInactive { background-image:url(stuff/open-layers/theme/default/img/move_feature_off.png); }
  33. .olControlEditingToolbar .olControlSelectFeatureItemActive { background-image:url(stuff/open-layers/theme/default/img/move_feature_on.png); }
  34. .olControlEditingToolbar .olControlRefreshItemInactive { background-image: url(stuff/open-layers/theme/default/img/refresh_feature_off.png); }
  35. .olControlEditingToolbar .olControlRefreshItemActive { background-image: url(stuff/open-layers/theme/default/img/refresh_feature_on.png); }
  36. .olControlEditingToolbar .olControlSaveItemInactive { background-image: url(stuff/open-layers/theme/default/img/save_features_off.png); }
  37. .olControlEditingToolbar .olControlSaveItemActive { background-image: url(stuff/open-layers/theme/default/img/save_features_on.png); }
  38. .olControlLayerSwitcher .layersDiv { border-radius:10px 0 0 10px; opacity:0.75; filter:alpha(opacity=75); }
  39. .notsupported { color:red; }
  40. .TableAjaxMap .layersDiv input { margin:0; }
  41. .TableAjaxMap .layersDiv label { display:inline; }
  42. </style>
  43. <?php
  44. }
  45. public function printJS() {
  46. ?>
  47. <script src="stuff/open-layers/OpenLayers.js"></script>
  48. <script>
  49. OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_task=PROXY&url=";
  50. (function( $ ) {
  51. var TableAjaxMap = function() {
  52. var priv = {}; //private api
  53. var publ = {}; //public api
  54. priv.options = {};
  55. var defaults = {
  56. wpsUrl: '',
  57. wfsUrl: '',
  58. layerName: 'Warstwa rysowania',
  59. debug: false
  60. };
  61. var _nodeMapId;
  62. var _nodeMap;
  63. var _nodeProcesses;
  64. var _nodeAbstract;
  65. var _nodeInput;
  66. var _nodeOutput;
  67. var _capabilities;
  68. var _process;
  69. var _layer;
  70. var _map;
  71. /*
  72. initialize the plugin.
  73. */
  74. priv.init = function() {
  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. _selectedFeature = null;
  92. _selectedRecordId = 0;
  93. var div = $('<div></div>');
  94. div.append(_nodeProcesses);
  95. div.append(_nodeAbstract);
  96. div.append(_nodeInput);
  97. div.append(_nodeOutput);
  98. $(priv.options.id).append(_nodeMap);
  99. $(priv.options.id).append(div);
  100. _nodeProcesses.on('change', function() {
  101. if (priv.options.debug) console.log("onchange this:", this, this.selectedIndex, this.options);
  102. var selection = this.options[this.selectedIndex].value;
  103. if (this.selectedIndex > 0) {
  104. OpenLayers.Request.GET({
  105. url: priv.options.wpsUrl,
  106. params: {
  107. "SERVICE": "WPS",
  108. "REQUEST": "DescribeProcess",
  109. "VERSION": _capabilities.version,
  110. "IDENTIFIER": selection
  111. },
  112. success: function(response) {
  113. _process = new OpenLayers.Format.WPSDescribeProcess().read(
  114. response.responseText
  115. ).processDescriptions[selection];
  116. if (priv.options.debug) console.log("Process:", _process);
  117. priv.buildForm();
  118. }
  119. });
  120. }
  121. });
  122. priv.getCapabilities();
  123. _layer = new OpenLayers.Layer.Vector(priv.options.layerName, {
  124. strategies: [new OpenLayers.Strategy.BBOX(), new OpenLayers.Strategy.Cluster({distance:30, threshold:3})],
  125. projection: new OpenLayers.Projection("EPSG:4326"),
  126. protocol: new OpenLayers.Protocol.WFS({
  127. version: "1.1.0",
  128. srsName: "EPSG:4326",
  129. url: priv.options.wfsUrl,
  130. featureNS : "http://opengeo.org",
  131. featureType: "restricted",
  132. geometryName: "the_geom",
  133. schema: "http://demo.opengeo.org/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=og:restricted"
  134. }),
  135. styleMap: new OpenLayers.StyleMap({
  136. 'default': new OpenLayers.Style(null, {
  137. rules: [
  138. new OpenLayers.Rule({
  139. symbolizer: {
  140. stroke: true,
  141. strokeWidth: 3,
  142. fill: true,
  143. fillColor: "#ee9900",
  144. strokeColor: "#ee9900",
  145. }
  146. })
  147. , new OpenLayers.Rule({
  148. symbolizer: {
  149. stroke: true,
  150. fill: true,
  151. strokeWidth: 3,
  152. fillColor: "#ee9900",
  153. strokeColor: "#ee9900",
  154. },
  155. filter: new OpenLayers.Filter.Comparison({
  156. type: OpenLayers.Filter.Comparison.GREATER_THAN,
  157. property: "recordId",
  158. value: 0
  159. })
  160. })
  161. , new OpenLayers.Rule({
  162. symbolizer: {
  163. stroke: true,
  164. fill: true,
  165. strokeWidth: 3,
  166. fillColor: "#ff0000",
  167. strokeColor: "#ff0000",
  168. },
  169. filter: new OpenLayers.Filter.Comparison({
  170. type: OpenLayers.Filter.Comparison.GREATER_THAN,
  171. property: "_newRecordId",
  172. value: 0
  173. })
  174. })
  175. , new OpenLayers.Rule({
  176. symbolizer: {
  177. stroke: true,
  178. fill: true,
  179. strokeWidth: 3,
  180. fillColor: "#ff0000",
  181. strokeColor: "#ff0000",
  182. },
  183. filter: new OpenLayers.Filter.Comparison({
  184. type: OpenLayers.Filter.Comparison.GREATER_THAN,
  185. property: "_modified",
  186. value: 0
  187. })
  188. })
  189. ]
  190. })
  191. })
  192. });
  193. _layer.events.on({
  194. 'beforefeaturemodified': function(e) {
  195. if (priv.options.debug) console.log('Event: beforefeaturemodified modified(', e.feature.attributes._modified, ')', e.feature.attributes, ' selAttras', (_selectedFeature)? _selectedFeature.attributes : 'null');// TODO: DBG
  196. // NOTE: beforefeaturemodified from new node is fired before afterfeaturemodified from old node when click from one node to enother
  197. priv.checkSelectedFeatureModifications('before');
  198. priv.setSelectedFeature(e.feature);
  199. },
  200. 'featuremodified': function(e) {
  201. if (priv.options.debug) console.log('Event: featuremodified modified(', e.feature.attributes._modified, ') ', e.feature.attributes, ' selAttras', (_selectedFeature)? _selectedFeature.attributes : 'null');// TODO: DBG
  202. _selectedFeature.attributes._modified = 1;
  203. },
  204. 'afterfeaturemodified': function(e) {
  205. if (priv.options.debug) console.log('Event: afterfeaturemodified fid('+e.feature.fid+'/'+(_selectedFeature ? _selectedFeature.fid : 'null')+') modified(', e.feature.attributes._modified, ') ', e.feature.attributes, ' selAttras', (_selectedFeature)? _selectedFeature.attributes : 'null');// TODO: DBG
  206. if (_selectedFeature && _selectedFeature.fid != e.feature.fid) {
  207. if (priv.options.debug) console.log('Event: afterfeaturemodified pomiń check!');
  208. } else {
  209. priv.checkSelectedFeatureModifications('after');
  210. priv.setSelectedFeature(null);
  211. }
  212. }
  213. });
  214. var toolbar = new OpenLayers.Control.EditingToolbar(_layer);
  215. toolbar.addControls([
  216. new OpenLayers.Control.ModifyFeature(_layer, {
  217. title: "Edytuj"
  218. , mode: OpenLayers.Control.ModifyFeature.DRAG | OpenLayers.Control.ModifyFeature.RESHAPE
  219. })
  220. ]);
  221. var btnSelectFeature = new OpenLayers.Control.SelectFeature(_layer, {
  222. title: "Select Test",
  223. clickout: false,
  224. toggle: false,
  225. multiple: false,
  226. hover: false,
  227. toggleKey: "ctrlKey", // ctrl key removes from selection
  228. multipleKey: "shiftKey", // shift key adds to selection
  229. box: true
  230. /* copy from OpenLayers source lib/OpenLayers/Control/SelectFeature.js
  231. * add bounds to trigger "boxselectionend" event
  232. */
  233. , selectBox: function(position) {
  234. if (position instanceof OpenLayers.Bounds) {
  235. var minXY = this.map.getLonLatFromPixel({
  236. x: position.left,
  237. y: position.bottom
  238. });
  239. var maxXY = this.map.getLonLatFromPixel({
  240. x: position.right,
  241. y: position.top
  242. });
  243. var bounds = new OpenLayers.Bounds(
  244. minXY.lon, minXY.lat, maxXY.lon, maxXY.lat
  245. );
  246. // if multiple is false, first deselect currently selected features
  247. if (!this.multipleSelect()) {
  248. this.unselectAll();
  249. }
  250. // because we're using a box, we consider we want multiple selection
  251. var prevMultiple = this.multiple;
  252. this.multiple = true;
  253. var layers = this.layers || [this.layer];
  254. this.events.triggerEvent("boxselectionstart", {layers: layers});
  255. var layer;
  256. for(var l=0; l<layers.length; ++l) {
  257. layer = layers[l];
  258. for(var i=0, len = layer.features.length; i<len; ++i) {
  259. var feature = layer.features[i];
  260. // check if the feature is displayed
  261. if (!feature.getVisibility()) {
  262. continue;
  263. }
  264. if (this.geometryTypes == null || OpenLayers.Util.indexOf(
  265. this.geometryTypes, feature.geometry.CLASS_NAME) > -1) {
  266. if (bounds.toGeometry().intersects(feature.geometry)) {
  267. if (OpenLayers.Util.indexOf(layer.selectedFeatures, feature) == -1) {
  268. this.select(feature);
  269. }
  270. }
  271. }
  272. }
  273. }
  274. this.multiple = prevMultiple;
  275. this.events.triggerEvent("boxselectionend", {layers: layers, bounds: bounds});
  276. }
  277. }
  278. });
  279. btnSelectFeature.events.on({
  280. "boxselectionend": function(e) {
  281. if (priv.options.debug) console.log('SelectFeature boxselectionend event', e, e.bounds);
  282. if (typeof priv.options.onSelectBox == "function") {
  283. var layerProj = _map.getProjectionObject();
  284. var targetProj = new OpenLayers.Projection("EPSG:4326");
  285. var bounds = e.bounds.transform(layerProj, targetProj);
  286. if (priv.options.debug) console.log('SelectFeature boxselectionend event bounds', bounds);
  287. priv.options.onSelectBox.call(this, bounds);
  288. }
  289. }
  290. });
  291. toolbar.addControls([btnSelectFeature]);
  292. toolbar.addControls([
  293. new OpenLayers.Control.Button({
  294. title: "Refresh",
  295. displayClass: "olControlRefresh",
  296. trigger: function() {
  297. _layer.refresh({force: true});
  298. }
  299. })
  300. ]);
  301. toolbar.addControls([
  302. new OpenLayers.Control.Button({
  303. title: "Zapisz zmiany",
  304. displayClass: "olControlSave",
  305. trigger: function() {
  306. if (_selectedFeature) {
  307. if (!_selectedRecordId) {
  308. alert('Wybierz rekord tabeli');
  309. }
  310. else {
  311. priv.saveSelectedFeature();
  312. priv.cancelSelectedFeatureModifications();
  313. }
  314. }
  315. else {
  316. alert('Wybierz element na mapie');
  317. }
  318. }
  319. })
  320. ]);
  321. var gphy = new OpenLayers.Layer.OSM("Mapa", null, {
  322. resolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
  323. 19567.87923828125, 9783.939619140625, 4891.9698095703125,
  324. 2445.9849047851562, 1222.9924523925781, 611.4962261962891,
  325. 305.74811309814453, 152.87405654907226, 76.43702827453613,
  326. 38.218514137268066, 19.109257068634033, 9.554628534317017,
  327. 4.777314267158508, 2.388657133579254, 1.194328566789627,
  328. 0.5971642833948135, 0.25, 0.1, 0.05],
  329. serverResolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
  330. 19567.87923828125, 9783.939619140625,
  331. 4891.9698095703125, 2445.9849047851562,
  332. 1222.9924523925781, 611.4962261962891,
  333. 305.74811309814453, 152.87405654907226,
  334. 76.43702827453613, 38.218514137268066,
  335. 19.109257068634033, 9.554628534317017,
  336. 4.777314267158508, 2.388657133579254,
  337. 1.194328566789627, 0.5971642833948135],
  338. transitionEffect: 'resize'
  339. });
  340. /* NOTE: map is in projection EPSG:900913 even if projection and displayProjection is set to EPSG:4326
  341. * _map.getProjectionObject(); returns EPSG:900913
  342. * restrictedExtent should be set in EPSG:900913
  343. * zoomToExtent should use EPSG:900913 - need to transform from EPSG:4326 to EPSG:900913
  344. */
  345. _map = new OpenLayers.Map(_nodeMapId, {
  346. projection: new OpenLayers.Projection("EPSG:4326"),
  347. displayProjection: new OpenLayers.Projection("EPSG:4326"),
  348. restrictedExtent: new OpenLayers.Bounds(
  349. 1526390.4410645328, 6273526.00, 2693330.958028555, 7352240.00
  350. ),
  351. controls: [
  352. toolbar,
  353. new OpenLayers.Control.ZoomPanel(),
  354. new OpenLayers.Control.PanPanel(),
  355. new OpenLayers.Control.LayerSwitcher(),
  356. new OpenLayers.Control.ScaleLine(),
  357. new OpenLayers.Control.KeyboardDefaults()
  358. ],
  359. layers: [gphy,_layer]
  360. });
  361. _map.events.register("zoomend", this, function(e) {
  362. var zoom = _map.getZoom();
  363. if (zoom > 15 && _layer.strategies[1].active) {
  364. _layer.strategies[1].deactivate();
  365. _layer.refresh({force:true});
  366. } else if (zoom <= 15 && !_layer.strategies[1].active) {
  367. _layer.strategies[1].activate();
  368. _layer.refresh({force:true});
  369. }
  370. });
  371. _map.zoomToMaxExtent();
  372. };
  373. priv.updateState = function() {
  374. // TODO: update state view
  375. //if (priv.options.debug) console.log('updateState: _selectedFeature:', _selectedFeature, ' _selectedRecordId:', _selectedRecordId);
  376. if (_selectedFeature || _selectedRecordId) {
  377. } else {
  378. }
  379. };
  380. priv.setSelectedFeature = function(feature) {
  381. _selectedFeature = feature;
  382. priv.updateState();
  383. };
  384. priv.setSelectedRecordId = function(id) {
  385. _selectedRecordId = id;
  386. priv.updateState();
  387. };
  388. priv.getSelectedRecordId = function() {
  389. return _selectedRecordId;
  390. };
  391. priv.isSelectedRecordId = function() {
  392. return _selectedRecordId > 0;
  393. };
  394. priv.isSelectedFeature = function() {
  395. if (priv.options.debug) console.log('_selectedFeature:', _selectedFeature);
  396. return (_selectedFeature)? true : false;
  397. };
  398. priv.cancelSelectedFeatureModifications = function() {
  399. if (!_selectedFeature) return false;
  400. if (_selectedFeature.attributes._newRecordId) {
  401. delete _selectedFeature.attributes._newRecordId;
  402. }
  403. if (_selectedFeature.attributes._modified) {
  404. delete _selectedFeature.attributes._modified;
  405. }
  406. };
  407. priv.isSelectedFeatureModified = function() {
  408. if (!_selectedFeature) return false;
  409. if (_selectedFeature.attributes) {
  410. if (_selectedFeature.attributes._newRecordId) {
  411. return true;
  412. }
  413. if (_selectedFeature.attributes._modified) {
  414. return true;
  415. }
  416. }
  417. };
  418. priv.saveSelectedFeature = function() {
  419. if (priv.isSelectedFeatureModified()) {
  420. if (typeof priv.options.onSaveFeature == "function") {
  421. var sourceProj = _map.getProjectionObject();
  422. var targetProj = new OpenLayers.Projection("EPSG:4326");
  423. var selFeatureGeometry = _selectedFeature.geometry.clone();
  424. var selFeatureGeomTransformed = selFeatureGeometry.transform(sourceProj, targetProj);
  425. var selFeatureExtent = new OpenLayers.Format.WKT().extractGeometry(selFeatureGeomTransformed);
  426. priv.options.onSaveFeature.call(this, _selectedRecordId, selFeatureExtent);
  427. }
  428. }
  429. }
  430. priv.checkSelectedFeatureModifications = function(when) {
  431. if (priv.isSelectedFeatureModified()) {
  432. if (confirm('Czy zapisać zmiany wprowadzone dla zaznaczonego elementu?')) {
  433. // _layer.refresh();
  434. priv.saveSelectedFeature();
  435. priv.cancelSelectedFeatureModifications();
  436. }
  437. else {
  438. priv.cancelSelectedFeatureModifications();
  439. _layer.refresh({force:true});
  440. }
  441. }
  442. };
  443. // using OpenLayers.Format.WPSCapabilities to read the capabilities
  444. priv.getCapabilities = function() {
  445. OpenLayers.Request.GET({
  446. url: priv.options.wpsUrl,
  447. params: {
  448. "SERVICE": "WPS",
  449. "REQUEST": "GetCapabilities"
  450. },
  451. success: function(response){
  452. _capabilities = new OpenLayers.Format.WPSCapabilities().read(
  453. response.responseText
  454. );
  455. var dropdown = _nodeProcesses;
  456. var offerings = _capabilities.processOfferings, option;
  457. // populate the dropdown
  458. for (var p in offerings) {
  459. option = document.createElement("option");
  460. option.innerHTML = offerings[p].identifier;
  461. option.value = p;
  462. dropdown.append(option);
  463. }
  464. }
  465. });
  466. };
  467. priv.buildForm = function() {
  468. _nodeAbstract.html(_process["abstract"]);
  469. _nodeInput.html("<h3>Input:</h3>");
  470. _nodeOutput.html('');
  471. var inputs = _process.dataInputs, supported = true,
  472. sld = "text/xml; subtype=sld/1.0.0",
  473. input;
  474. for (var i = 0, ii = inputs.length; i < ii; ++i) {
  475. input = inputs[i];
  476. if (input.complexData) {
  477. var formats = input.complexData.supported.formats;
  478. if (formats["application/wkt"]) {
  479. priv.addWKTInput(input);
  480. } else if (formats["text/xml; subtype=wfs-collection/1.0"]) {
  481. priv.addWFSCollectionInput(input);
  482. } else if (formats["image/tiff"]) {
  483. //priv.addRasterInput(input);
  484. } else if (formats[sld]) {
  485. priv.addXMLInput(input, sld);
  486. } else {
  487. supported = false;
  488. }
  489. } else if (input.boundingBoxData) {
  490. priv.addBoundingBoxInput(input);
  491. } else if (input.literalData) {
  492. priv.addLiteralInput(input);
  493. } else {
  494. supported = false;
  495. }
  496. if (input.minOccurs > 0) {
  497. _nodeInput.append(document.createTextNode("* "));
  498. }
  499. }
  500. if (supported) {
  501. var executeButton = document.createElement("button");
  502. executeButton.innerHTML = "Execute";
  503. _nodeInput.append(executeButton);
  504. executeButton.onclick = priv.execute;
  505. } else {
  506. _nodeInput.html('<span class="notsupported">' +
  507. "Sorry, the WPS builder does not support the selected process." +
  508. "</span>");
  509. }
  510. };
  511. // helper function to dynamically create a textarea for geometry (WKT) data
  512. // input
  513. priv.addWKTInput = function(input, previousSibling) {
  514. var name = input.identifier;
  515. var container = _nodeInput.get(0);
  516. var label = document.createElement("label");
  517. label["for"] = name;
  518. label.title = input["abstract"];
  519. label.innerHTML = name + " (select feature, then click field):";
  520. previousSibling && previousSibling.nextSibling ?
  521. container.insertBefore(label, previousSibling.nextSibling) :
  522. container.appendChild(label);
  523. var field = document.createElement("textarea");
  524. field.onclick = function () {
  525. if (_layer.selectedFeatures.length) {
  526. this.innerHTML = new OpenLayers.Format.WKT().write(
  527. _layer.selectedFeatures[0]
  528. );
  529. if (priv.options.debug) console.log('_layer.selectedFeatures[0]: ', _layer.selectedFeatures[0]);
  530. }
  531. priv.createCopy(input, this, priv.addWKTInput);
  532. };
  533. field.onblur = function() {
  534. input.data = field.value ? {
  535. complexData: {
  536. mimeType: "application/wkt",
  537. value: this.value
  538. }
  539. } : undefined;
  540. };
  541. field.title = input["abstract"];
  542. field.id = name;
  543. previousSibling && previousSibling.nextSibling ?
  544. container.insertBefore(field, previousSibling.nextSibling.nextSibling) :
  545. container.appendChild(field);
  546. };
  547. // helper function for xml input
  548. priv.addXMLInput = function(input, type) {
  549. var name = input.identifier;
  550. var field = document.createElement("input");
  551. field.title = input["abstract"];
  552. field.value = name + " (" + type + ")";
  553. field.onblur = function() {
  554. input.data = field.value ? {
  555. complexData: {
  556. mimeType: type,
  557. value: this.value
  558. }
  559. } : undefined;
  560. };
  561. _nodeInput.append(field);
  562. };
  563. // helper function to dynamically create a WFS collection reference input
  564. priv.addWFSCollectionInput = function(input) {
  565. var name = input.identifier;
  566. var field = document.createElement("input");
  567. field.title = input["abstract"];
  568. field.value = name + " (layer on demo server)";
  569. priv.addValueHandlers(field, function() {
  570. input.reference = field.value ? {
  571. mimeType: "text/xml; subtype=wfs-collection/1.0",
  572. href: "http://geoserver/wfs",
  573. method: "POST",
  574. body: {
  575. wfs: {
  576. version: "1.0.0",
  577. outputFormat: "GML2",
  578. featureType: field.value
  579. }
  580. }
  581. } : undefined;
  582. });
  583. _nodeInput.append(field);
  584. };
  585. // helper function to dynamically create a raster (GeoTIFF) url input
  586. priv.addRasterInput = function(input) {
  587. var name = input.identifier;
  588. var field = document.createElement("input");
  589. field.title = input["abstract"];
  590. var url = window.location.href.split("?")[0];
  591. field.value = url.substr(0, url.lastIndexOf("/")+1) + "data/tazdem.tiff";// TODO: file path to options
  592. document.getElementById("input").appendChild(field);
  593. (field.onblur = function() {
  594. input.reference = {
  595. mimeType: "image/tiff",
  596. href: field.value,
  597. method: "GET"
  598. };
  599. })();
  600. };
  601. // helper function to dynamically create a bounding box input
  602. priv.addBoundingBoxInput = function(input) {
  603. var name = input.identifier;
  604. var field = document.createElement("input");
  605. field.title = input["abstract"];
  606. field.value = "left,bottom,right,top (EPSG:4326)";
  607. _nodeInput.append(field);
  608. priv.addValueHandlers(field, function() {
  609. input.boundingBoxData = {
  610. projection: "EPSG:4326",
  611. bounds: OpenLayers.Bounds.fromString(field.value)
  612. };
  613. });
  614. };
  615. // helper function to create a literal input textfield or dropdown
  616. priv.addLiteralInput = function(input, previousSibling) {
  617. var name = input.identifier;
  618. var container = _nodeInput.get(0);
  619. var anyValue = input.literalData.anyValue;
  620. // anyValue means textfield, otherwise we create a dropdown
  621. var field = document.createElement(anyValue ? "input" : "select");
  622. field.id = name;
  623. field.title = input["abstract"];
  624. previousSibling && previousSibling.nextSibling ?
  625. container.insertBefore(field, previousSibling.nextSibling) :
  626. container.appendChild(field);
  627. if (anyValue) {
  628. var dataType = input.literalData.dataType;
  629. field.value = name + (dataType ? " (" + dataType + ")" : "");
  630. priv.addValueHandlers(field, function() {
  631. input.data = field.value ? {
  632. literalData: {
  633. value: field.value
  634. }
  635. } : undefined;
  636. priv.createCopy(input, field, priv.addLiteralInput);
  637. });
  638. } else {
  639. var option;
  640. option = document.createElement("option");
  641. option.innerHTML = name;
  642. field.appendChild(option);
  643. for (var v in input.literalData.allowedValues) {
  644. option = document.createElement("option");
  645. option.value = v;
  646. option.innerHTML = v;
  647. field.appendChild(option);
  648. }
  649. field.onchange = function() {
  650. priv.createCopy(input, field, priv.addLiteralInput);
  651. input.data = this.selectedIndex ? {
  652. literalData: {
  653. value: this.options[this.selectedIndex].value
  654. }
  655. } : undefined;
  656. };
  657. }
  658. };
  659. // if maxOccurs is > 1, this will add a copy of the field
  660. priv.createCopy = function(input, field, fn) {
  661. if (input.maxOccurs && input.maxOccurs > 1 && !field.userSelected) {
  662. // add another copy of the field - we don't check maxOccurs
  663. field.userSelected = true;
  664. var newInput = OpenLayers.Util.extend({}, input);
  665. // we recognize copies by the occurrence property
  666. newInput.occurrence = (input.occurrence || 0) + 1;
  667. _process.dataInputs.push(newInput);
  668. fn(newInput, field);
  669. }
  670. };
  671. // helper function for adding events to form fields
  672. priv.addValueHandlers = function(field, onblur) {
  673. field.onclick = function() {
  674. if (!this.initialValue) {
  675. this.initialValue = this.value;
  676. this.value = "";
  677. }
  678. };
  679. field.onblur = function() {
  680. if (!this.value) {
  681. this.value = this.initialValue;
  682. delete this.initialValue;
  683. }
  684. onblur.apply(this, arguments);
  685. };
  686. };
  687. // execute the process
  688. priv.execute = function() {
  689. var output = _process.processOutputs[0];
  690. var input;
  691. // remove occurrences that the user has not filled out
  692. for (var i = _process.dataInputs.length - 1; i >= 0; --i) {
  693. input = _process.dataInputs[i];
  694. if ((input.minOccurs === 0 || input.occurrence) && !input.data && !input.reference) {
  695. OpenLayers.Util.removeItem(_process.dataInputs, input);
  696. }
  697. }
  698. _process.responseForm = {
  699. rawDataOutput: {
  700. identifier: output.identifier
  701. }
  702. };
  703. if (output.complexOutput && output.complexOutput.supported.formats["application/wkt"]) {
  704. _process.responseForm.rawDataOutput.mimeType = "application/wkt";
  705. }
  706. OpenLayers.Request.POST({
  707. url: priv.options.wpsUrl,
  708. data: new OpenLayers.Format.WPSExecute().write(_process),
  709. success: priv.showOutput
  710. });
  711. }
  712. // add the process's output to the page
  713. priv.showOutput = function(response) {
  714. var result = _nodeOutput.get(0);
  715. result.innerHTML = "<h3>Output:</h3>";
  716. var features;
  717. var contentType = response.getResponseHeader("Content-Type");
  718. if (contentType == "application/wkt") {
  719. features = new OpenLayers.Format.WKT().read(response.responseText);
  720. } else if (contentType == "text/xml; subtype=wfs-collection/1.0") {
  721. features = new OpenLayers.Format.WFST.v1_0_0().read(response.responseText);
  722. }
  723. if (features && (features instanceof OpenLayers.Feature.Vector || features.length)) {
  724. _layer.addFeatures(features);
  725. result.innerHTML += "The result should also be visible on the map.";
  726. }
  727. result.innerHTML += "<textarea>" + response.responseText + "</textarea>";
  728. }
  729. publ.updateSize = function() {
  730. _map.updateSize();
  731. };
  732. publ.zoomToExtent = function(extent) {
  733. if (!extent) return;
  734. var sourceProj = new OpenLayers.Projection("EPSG:4326");
  735. var targetProj = _map.getProjectionObject();
  736. var extentBounds = OpenLayers.Geometry.fromWKT(extent).transform(sourceProj, targetProj).getBounds();
  737. _map.zoomToExtent(extentBounds);
  738. };
  739. publ.selectRecord = function(recordId, extent) {
  740. if (priv.isSelectedRecordId()) {
  741. if (priv.getSelectedRecordId() != recordId) {
  742. if (priv.isSelectedFeature()) {
  743. if (confirm('Aktualnie przypisany rekord to ' + priv.getSelectedRecordId() + ' czy zmienić na ' + recordId + '?')) {
  744. priv.setSelectedRecordId(recordId);
  745. }
  746. } else {
  747. priv.setSelectedRecordId(recordId);
  748. publ.zoomToExtent(extent);
  749. }
  750. } else {
  751. publ.zoomToExtent(extent);
  752. }
  753. }
  754. else {
  755. priv.setSelectedRecordId(recordId);
  756. publ.zoomToExtent(extent);
  757. }
  758. };
  759. publ.init = function(options) {
  760. if (priv.options.debug) console.log('TableAjaxMap initialization...', options);
  761. //merge supplied options with defaults
  762. $.extend(priv.options, defaults, options);
  763. priv.init();
  764. return publ;
  765. };
  766. return publ;
  767. };
  768. $.fn.TableAjaxMapUpdateSize = function(options) {
  769. options = options || {};
  770. return this.each(function() {
  771. var tblAjaxMap = $(this).data('TableAjaxMap');
  772. if (tblAjaxMap) {
  773. tblAjaxMap.updateSize();
  774. }
  775. });
  776. return this;
  777. };
  778. $.fn.TableAjaxMapZoomToExtent = function(extent) {
  779. if (!extent) return;
  780. return this.each(function() {
  781. var tblAjaxMap = $(this).data('TableAjaxMap');
  782. if (tblAjaxMap) {
  783. tblAjaxMap.zoomToExtent(extent);
  784. }
  785. });
  786. return this;
  787. };
  788. $.fn.TableAjaxMapSelectRecord = function(recordId, extent) {
  789. if (!recordId) return;
  790. return this.each(function() {
  791. var tblAjaxMap = $(this).data('TableAjaxMap');
  792. if (tblAjaxMap) {
  793. tblAjaxMap.selectRecord(recordId, extent);
  794. }
  795. });
  796. return this;
  797. };
  798. $.fn.TableAjaxMap = function(options) {
  799. options = options || {};
  800. return this.each(function() {
  801. options.id = this;
  802. if (!$(this).data('TableAjaxMap')) {
  803. $(this).data('TableAjaxMap', new TableAjaxMap().init(options));
  804. }
  805. });
  806. return this;
  807. };
  808. }(jQuery));
  809. </script>
  810. <?php
  811. }
  812. public function ajaxTask($task) {
  813. switch ($task) {
  814. case 'PROXY': {
  815. $this->sendAjaxProxy($_REQUEST);
  816. break;
  817. }
  818. default:
  819. //$this->sendAjaxData($_REQUEST);
  820. }
  821. }
  822. public function sendAjaxProxy($args) {
  823. $url = V::get('url', '', $args);
  824. // 1. http%3A%2F%2Fbiuro.biall-net.pl%2Fwps%3FSERVICE%3DWPS%26REQUEST%3DGetCapabilities
  825. // 2. http%3A%2F%2Fbiuro.biall-net.pl%2Fwps%3FSERVICE%3DWPS%26REQUEST%3DDescribeProcess%26VERSION%3D1.0.0%26IDENTIFIER%3Dpozdrawiam
  826. header('Content-Type: application/xml; charset=utf-8');
  827. $urlParts = parse_url($url);
  828. $urlQuery = array();
  829. $urlQueryTmp = V::get('query', '', $urlParts);
  830. $urlQueryTmp = explode('&', $urlQueryTmp);
  831. foreach ($urlQueryTmp as $vQuery) {
  832. $parts = explode('=', $vQuery, 2);
  833. $urlQuery[$parts[0]] = $parts[1];
  834. }
  835. $wpsServer = new TableAjaxMapWpsServer($this->_acl);
  836. if ('WPS' == V::get('SERVICE', '', $urlQuery)) {
  837. $req = V::get('REQUEST', '', $urlQuery);
  838. $methodName = "{$req}Action";
  839. if (method_exists($wpsServer, $methodName)) {
  840. $wpsServer->$methodName($urlQuery);
  841. }
  842. }
  843. else {
  844. $wpsServer->parseXMLRequest();
  845. }
  846. exit;
  847. }
  848. }
  849. class TableAjaxMapWfsAction {
  850. private $_acl;
  851. private $_zasobID;
  852. public function __construct($acl) {
  853. $this->_acl = $acl;
  854. $this->_zasobID = $acl->getID();
  855. }
  856. /**
  857. * example: MULTIPOLYGON(((2072016.74395199 7234076.79293037,2072016.74395199 7234115.01144451,2072131.3994944 7234115.01144451,2072131.3994944 7234076.79293037,2072016.74395199 7234076.79293037)))
  858. */
  859. public function generateGmlFromWKT($wkt) {
  860. $gml = '';
  861. $wktParts = explode('(', $wkt, 2);
  862. ob_start();
  863. switch ($wktParts[0]) {
  864. case 'MULTIPOLYGON':
  865. case 'POLYGON': {
  866. $points = trim($wktParts[1], '() ');
  867. $points = str_replace(',', "\n", $points);
  868. ?>
  869. <gml:boundedBy>
  870. <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
  871. <gml:lowerCorner>-180 -90</gml:lowerCorner>
  872. <gml:upperCorner>180 90</gml:upperCorner>
  873. </gml:Envelope>
  874. </gml:boundedBy>
  875. <og:the_geom>
  876. <gml:MultiSurface srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
  877. <gml:surfaceMember>
  878. <gml:Polygon srsDimension="2">
  879. <gml:exterior>
  880. <gml:LinearRing srsDimension="2">
  881. <gml:posList>
  882. <?php echo $points; ?>
  883. </gml:posList>
  884. </gml:LinearRing>
  885. </gml:exterior>
  886. </gml:Polygon>
  887. </gml:surfaceMember>
  888. </gml:MultiSurface>
  889. </og:the_geom>
  890. <?php
  891. }
  892. break;
  893. default:
  894. ?>
  895. <!-- UNKNOWN WKT:<?php echo $wkt; ?> -->
  896. <?php
  897. }
  898. $gml = ob_get_contents();
  899. ob_clean();
  900. return $gml;
  901. }
  902. public function execute($args) {
  903. /*
  904. * Mapa odczytywanie punktów: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
  905. *
  906. * CI50:
  907. 18.613243103027344 54.33614429135817
  908. 18.613243103027344 54.33634445792519
  909. 18.614273071289062 54.33634445792519
  910. 18.614273071289062 54.33614429135817
  911. */
  912. Lib::loadClass('Data_Source');
  913. $dataSource = new Data_Source($this->_acl->getDB());
  914. $dataSource->setTable($this->_acl->getName());
  915. $dataSource->addCol('ID');
  916. $dataSource->addCol('the_geom');
  917. $dataSource->setColTypes($this->_acl->getTypes());
  918. $params = array();
  919. $params['limit'] = 1000;
  920. if (!empty($args['BBOX'])) {
  921. $params['f_the_geom'] = 'BBOX:' . implode(',', $args['BBOX']);
  922. }
  923. $items = $dataSource->getItems($params);
  924. $buildingsGml = array();
  925. foreach ($items as $r) {
  926. if (!empty($r->the_geom)) {
  927. $buildingsGml[$r->ID] = $this->generateGmlFromWKT($r->the_geom);
  928. }
  929. }
  930. /**
  931. * <og:recordId><?php echo $kId; ?></og:recordId>
  932. * <og:tblId><?php echo $tblId; ?></og:tblId>
  933. *
  934. * goes to js: @see priv.addWKTInput _layer.selectedFeatures[0]
  935. *
  936. * attributes: Object
  937. recordId: "1130"
  938. tblId: "16"
  939. */
  940. echo '<?xml version="1.0" encoding="UTF-8"?>';
  941. ?>
  942. <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">
  943. <gml:boundedBy>
  944. <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
  945. <gml:lowerCorner>-180 -90</gml:lowerCorner>
  946. <gml:upperCorner>180 90</gml:upperCorner>
  947. </gml:Envelope>
  948. </gml:boundedBy>
  949. <gml:featureMembers>
  950. <?php foreach ($buildingsGml as $kId => $vGml) : ?>
  951. <og:restricted gml:id="restricted.<?php echo $kId; ?>">
  952. <?php echo $vGml; ?>
  953. <og:recordId><?php echo $kId; ?></og:recordId>
  954. <og:tblId><?php echo $this->_zasobID; ?></og:tblId>
  955. </og:restricted>
  956. <?php endforeach; ?>
  957. </gml:featureMembers>
  958. </wfs:FeatureCollection>
  959. <?php
  960. }
  961. }
  962. class WpsActionBase {
  963. public $title = '';
  964. public $description = '';
  965. public $dataInputs = array();
  966. public function execute($args) {
  967. var_dump($args);
  968. }
  969. }
  970. class WpsActionPrzypiszDoRekordu extends WpsActionBase {
  971. public function __construct() {
  972. $this->title = 'Przypisz';
  973. $this->description = 'Przypisuje położenie do wybranego rekordu w tabeli.';
  974. $this->dataInputs['geom'] = new stdClass();
  975. $this->dataInputs['geom']->title = 'geom';
  976. $this->dataInputs['geom']->description = 'Input geometry';
  977. $this->dataInputs['geom']->type = 'geom';// CoomplexData
  978. $this->dataInputs['idTable'] = new stdClass();
  979. $this->dataInputs['idTable']->title = 'geom';
  980. $this->dataInputs['idTable']->description = 'Table ID';
  981. $this->dataInputs['idTable']->type = 'integer';// LiteralData: xs:integer
  982. $this->dataInputs['idRecord'] = new stdClass();
  983. $this->dataInputs['idRecord']->title = 'idRecord';
  984. $this->dataInputs['idRecord']->description = 'Record ID';
  985. $this->dataInputs['idRecord']->type = 'integer';// LiteralData: xs:integer
  986. }
  987. }
  988. class TableAjaxMapWpsServer {
  989. private $_fun;// config for identifiers
  990. private $_wfsAction;
  991. private $_zasobID;
  992. private $_acl;
  993. public function __construct($acl) {
  994. $this->_fun['przypiszDoRekordu'] = new WpsActionPrzypiszDoRekordu();
  995. $this->_acl = $acl;
  996. $this->_zasobID = $acl->getID();
  997. $this->_wfsAction = new TableAjaxMapWfsAction($this->_acl);
  998. }
  999. public function parseXMLRequest() {
  1000. $data = array();
  1001. $reqContent = file_get_contents('php://input');
  1002. $xml = new SimpleXMLElement($reqContent);
  1003. if ('GetFeature' == $xml->getName()) {
  1004. // TODO: parse xml and set query params
  1005. /*
  1006. <wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" service="WFS" version="1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd http://opengeo.org http://demo.opengeo.org/geoserver/wfs/DescribeFeatureType?version=1.1.0&amp;typename=og:restricted">
  1007. <wfs:Query typeName="feature:restricted" srsName="EPSG:4326" xmlns:feature="http://opengeo.org">
  1008. <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
  1009. <ogc:BBOX>
  1010. <ogc:PropertyName>the_geom</ogc:PropertyName>
  1011. <gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
  1012. <gml:lowerCorner>17.226562502593 53.887024366231</gml:lowerCorner>
  1013. <gml:upperCorner>20.039062502593 54.847089981191</gml:upperCorner>
  1014. </gml:Envelope>
  1015. </ogc:BBOX>
  1016. </ogc:Filter>
  1017. </wfs:Query>
  1018. </wfs:GetFeature>
  1019. */
  1020. $corners = null;
  1021. $xmlTag = $xml->children("wfs", TRUE)->Query;
  1022. if (!empty($xmlTag)) {
  1023. $xmlTag = $xmlTag->children("ogc", TRUE)->Filter;
  1024. if (!empty($xmlTag)) {
  1025. $xmlTag = $xmlTag->BBOX;
  1026. if (!empty($xmlTag)) {
  1027. $xmlTag = $xmlTag->children("gml", TRUE)->Envelope;
  1028. if (!empty($xmlTag)) {
  1029. $corners = (object)array('lowerCorner' => (string)$xmlTag->lowerCorner, 'upperCorner' => (string)$xmlTag->upperCorner);
  1030. }
  1031. }
  1032. }
  1033. }
  1034. if ($corners) {
  1035. $lowerCorner = (string) $corners->lowerCorner;
  1036. $upperCorner = (string) $corners->upperCorner;
  1037. $lowerCorner = explode(" ", trim($lowerCorner));
  1038. $upperCorner = explode(" ", trim($upperCorner));
  1039. if (count($lowerCorner) == 2 && count($upperCorner) == 2) {
  1040. $points = array();
  1041. $points[] = $upperCorner[1];// top
  1042. $points[] = $upperCorner[0];// right
  1043. $points[] = $lowerCorner[1];// bottom
  1044. $points[] = $lowerCorner[0];// left
  1045. $isAllNumeric = true;
  1046. foreach ($points as $point) {
  1047. if (!is_numeric($point)) $isAllNumeric = false;
  1048. }
  1049. if ($isAllNumeric) {
  1050. $data['BBOX'] = $points;
  1051. }
  1052. }
  1053. } else {
  1054. // inna struktura xml'a
  1055. }
  1056. $this->_wfsAction->execute($data);
  1057. }
  1058. else if (isset($xml->children('ows', TRUE)->Identifier)) {
  1059. $identifier = (string)$xml->children('ows', TRUE)->Identifier;
  1060. if (array_key_exists($identifier, $this->_fun)) {
  1061. foreach ($xml->children('wps', TRUE)->DataInputs->children('wps', TRUE) as $input) {
  1062. $inputIdentifier = (string)$input->children('ows', TRUE)->Identifier;
  1063. if (array_key_exists($inputIdentifier, $this->_fun[$identifier]->dataInputs)) {
  1064. $inputType = (string)$this->_fun[$identifier]->dataInputs[$inputIdentifier]->type;
  1065. switch ($inputType) {
  1066. case 'integer':
  1067. $data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->LiteralData;
  1068. break;
  1069. case 'geom':
  1070. $data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->ComplexData;
  1071. break;
  1072. default:
  1073. }
  1074. } else {
  1075. // brak zdefiniowanego inputa
  1076. }
  1077. }
  1078. $this->_fun['przypiszDoRekordu']->execute($data);
  1079. } else {
  1080. echo "TODO: brak zdefiniowanej funkcji '{$identifier}'";
  1081. var_dump($identifier);
  1082. }
  1083. }
  1084. else {
  1085. echo "TODO: '" . $xml->getName() . "' ...";
  1086. }
  1087. }
  1088. public function getCapabilitiesAction() {
  1089. echo '<?xml version="1.0" encoding="UTF-8"?>';
  1090. ?>
  1091. <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">
  1092. <ows:ServiceIdentification>
  1093. <ows:Title>Prototype GeoServer WPS</ows:Title>
  1094. <ows:Abstract />
  1095. <ows:Keywords>
  1096. <ows:Keyword>wps</ows:Keyword>
  1097. <ows:Keyword>geoserver</ows:Keyword>
  1098. </ows:Keywords>
  1099. <ows:ServiceType>WPS</ows:ServiceType>
  1100. <ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
  1101. <ows:Fees>NONE</ows:Fees>
  1102. <ows:AccessConstraints>NONE</ows:AccessConstraints>
  1103. </ows:ServiceIdentification>
  1104. <ows:ServiceProvider>
  1105. <ows:ProviderName>GeoServer</ows:ProviderName>
  1106. <ows:ProviderSite />
  1107. <ows:ServiceContact />
  1108. </ows:ServiceProvider>
  1109. <ows:OperationsMetadata>
  1110. <ows:Operation name="GetCapabilities">
  1111. <ows:DCP>
  1112. <ows:HTTP>
  1113. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  1114. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  1115. </ows:HTTP>
  1116. </ows:DCP>
  1117. </ows:Operation>
  1118. <ows:Operation name="DescribeProcess">
  1119. <ows:DCP>
  1120. <ows:HTTP>
  1121. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  1122. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  1123. </ows:HTTP>
  1124. </ows:DCP>
  1125. </ows:Operation>
  1126. <ows:Operation name="Execute">
  1127. <ows:DCP>
  1128. <ows:HTTP>
  1129. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  1130. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  1131. </ows:HTTP>
  1132. </ows:DCP>
  1133. </ows:Operation>
  1134. </ows:OperationsMetadata>
  1135. <wps:ProcessOfferings>
  1136. <?php foreach($this->_fun as $kFun => $vFun) : ?>
  1137. <wps:Process wps:processVersion="1.0.0">
  1138. <ows:Identifier><?php echo $kFun; ?></ows:Identifier>
  1139. <ows:Title><?php echo $vFun->title; ?></ows:Title>
  1140. <ows:Abstract><?php echo $vFun->description; ?></ows:Abstract>
  1141. </wps:Process>
  1142. <?php endforeach; ?>
  1143. </wps:ProcessOfferings>
  1144. <wps:Languages>
  1145. <wps:Default>
  1146. <ows:Language>en-US</ows:Language>
  1147. </wps:Default>
  1148. <wps:Supported>
  1149. <ows:Language>en-US</ows:Language>
  1150. </wps:Supported>
  1151. </wps:Languages>
  1152. </wps:Capabilities>
  1153. <?php
  1154. }
  1155. public function describeProcessAction($args) {
  1156. // TODO: xml z opiesem procese $args['IDENTIFIER']
  1157. /**
  1158. * should work like JTS:densify - geom field (map object) and integer field (record ID)
  1159. * 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
  1160. * http://demo.opengeo.org/geoserver/wps?SERVICE=WPS&REQUEST=DescribeProcess&VERSION=1.0.0&IDENTIFIER=JTS%3Adensify
  1161. */
  1162. echo '<?xml version="1.0" encoding="UTF-8"?>';
  1163. if (array_key_exists($args['IDENTIFIER'], $this->_fun)) {
  1164. $identifier = $this->_fun[$args['IDENTIFIER']];
  1165. ?>
  1166. <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">
  1167. <ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true">
  1168. <ows:Identifier><?php echo $args['IDENTIFIER']; ?></ows:Identifier>
  1169. <ows:Title><?php echo $identifier->title; ?></ows:Title>
  1170. <ows:Abstract><?php echo $identifier->description; ?></ows:Abstract>
  1171. <DataInputs>
  1172. <?php foreach ($identifier->dataInputs as $kInput => $vInput) : ?>
  1173. <Input maxOccurs="1" minOccurs="1">
  1174. <ows:Identifier><?php echo $kInput; ?></ows:Identifier>
  1175. <ows:Title><?php echo $vInput->title; ?></ows:Title>
  1176. <ows:Abstract><?php echo $vInput->description; ?></ows:Abstract>
  1177. <?php if ($vInput->type == 'geom') : ?>
  1178. <ComplexData>
  1179. <Default>
  1180. <Format>
  1181. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  1182. </Format>
  1183. </Default>
  1184. <Supported>
  1185. <Format>
  1186. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  1187. </Format>
  1188. <Format>
  1189. <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
  1190. </Format>
  1191. <Format>
  1192. <MimeType>application/wkt</MimeType>
  1193. </Format>
  1194. <Format>
  1195. <MimeType>application/gml-3.1.1</MimeType>
  1196. </Format>
  1197. <Format>
  1198. <MimeType>application/gml-2.1.2</MimeType>
  1199. </Format>
  1200. </Supported>
  1201. </ComplexData>
  1202. <?php elseif ($vInput->type == 'integer') : ?>
  1203. <LiteralData>
  1204. <ows:DataType>xs:integer</ows:DataType>
  1205. <ows:AnyValue />
  1206. </LiteralData>
  1207. <?php else : ?>
  1208. <?php endif; ?>
  1209. </Input>
  1210. <?php endforeach; ?>
  1211. </DataInputs>
  1212. <ProcessOutputs>
  1213. <Output>
  1214. <ows:Identifier>result</ows:Identifier>
  1215. <ows:Title>result</ows:Title>
  1216. <ComplexOutput>
  1217. <Default>
  1218. <Format>
  1219. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  1220. </Format>
  1221. </Default>
  1222. <Supported>
  1223. <Format>
  1224. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  1225. </Format>
  1226. <Format>
  1227. <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
  1228. </Format>
  1229. <Format>
  1230. <MimeType>application/wkt</MimeType>
  1231. </Format>
  1232. <Format>
  1233. <MimeType>application/gml-3.1.1</MimeType>
  1234. </Format>
  1235. <Format>
  1236. <MimeType>application/gml-2.1.2</MimeType>
  1237. </Format>
  1238. </Supported>
  1239. </ComplexOutput>
  1240. </Output>
  1241. </ProcessOutputs>
  1242. </ProcessDescription>
  1243. </wps:ProcessDescriptions>
  1244. <?php
  1245. } else {
  1246. echo 'TODO: brak funkcji';
  1247. }
  1248. }
  1249. }