TableAjaxMap.php 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  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. 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. 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. 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. 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. 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. 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. 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. 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. 2035059.4410645328, 7200979.560689885, 2113330.958028555, 7279251.0776539035
  350. //18.281250002544773, 54.16243397333987, 18.984375002642665, 54.57206166093501
  351. ),
  352. controls: [
  353. toolbar,
  354. new OpenLayers.Control.ZoomPanel(),
  355. new OpenLayers.Control.PanPanel(),
  356. new OpenLayers.Control.LayerSwitcher(),
  357. new OpenLayers.Control.ScaleLine(),
  358. new OpenLayers.Control.KeyboardDefaults()
  359. ],
  360. layers: [gphy,_layer]
  361. });
  362. _map.events.register("zoomend", this, function(e) {
  363. var zoom = _map.getZoom();
  364. if (zoom > 15 && _layer.strategies[1].active) {
  365. _layer.strategies[1].deactivate();
  366. _layer.refresh({force:true});
  367. } else if (zoom <= 15 && !_layer.strategies[1].active) {
  368. _layer.strategies[1].activate();
  369. _layer.refresh({force:true});
  370. }
  371. });
  372. _map.zoomToMaxExtent();
  373. };
  374. priv.updateState = function() {
  375. // TODO: update state view
  376. //console.log('updateState: _selectedFeature:', _selectedFeature, ' _selectedRecordId:', _selectedRecordId);
  377. if (_selectedFeature || _selectedRecordId) {
  378. } else {
  379. }
  380. };
  381. priv.setSelectedFeature = function(feature) {
  382. _selectedFeature = feature;
  383. priv.updateState();
  384. };
  385. priv.setSelectedRecordId = function(id) {
  386. _selectedRecordId = id;
  387. priv.updateState();
  388. };
  389. priv.getSelectedRecordId = function() {
  390. return _selectedRecordId;
  391. };
  392. priv.isSelectedRecordId = function() {
  393. return _selectedRecordId > 0;
  394. };
  395. priv.isSelectedFeature = function() {
  396. console.log('_selectedFeature:', _selectedFeature);
  397. return (_selectedFeature)? true : false;
  398. };
  399. priv.cancelSelectedFeatureModifications = function() {
  400. if (!_selectedFeature) return false;
  401. if (_selectedFeature.attributes._newRecordId) {
  402. delete _selectedFeature.attributes._newRecordId;
  403. }
  404. if (_selectedFeature.attributes._modified) {
  405. delete _selectedFeature.attributes._modified;
  406. }
  407. };
  408. priv.isSelectedFeatureModified = function() {
  409. if (!_selectedFeature) return false;
  410. if (_selectedFeature.attributes) {
  411. if (_selectedFeature.attributes._newRecordId) {
  412. return true;
  413. }
  414. if (_selectedFeature.attributes._modified) {
  415. return true;
  416. }
  417. }
  418. };
  419. priv.saveSelectedFeature = function() {
  420. if (priv.isSelectedFeatureModified()) {
  421. if (typeof priv.options.onSaveFeature == "function") {
  422. var selFeatureExtent = new OpenLayers.Format.WKT().write(_selectedFeature);
  423. priv.options.onSaveFeature.call(this, _selectedRecordId, selFeatureExtent);
  424. }
  425. }
  426. }
  427. priv.checkSelectedFeatureModifications = function(when) {
  428. if (priv.isSelectedFeatureModified()) {
  429. if (confirm('Czy zapisać zmiany wprowadzone dla zaznaczonego elementu?')) {
  430. // _layer.refresh();
  431. priv.saveSelectedFeature();
  432. priv.cancelSelectedFeatureModifications();
  433. }
  434. else {
  435. priv.cancelSelectedFeatureModifications();
  436. _layer.refresh({force:true});
  437. }
  438. }
  439. };
  440. // using OpenLayers.Format.WPSCapabilities to read the capabilities
  441. priv.getCapabilities = function() {
  442. OpenLayers.Request.GET({
  443. url: priv.options.wpsUrl,
  444. params: {
  445. "SERVICE": "WPS",
  446. "REQUEST": "GetCapabilities"
  447. },
  448. success: function(response){
  449. _capabilities = new OpenLayers.Format.WPSCapabilities().read(
  450. response.responseText
  451. );
  452. var dropdown = _nodeProcesses;
  453. var offerings = _capabilities.processOfferings, option;
  454. // populate the dropdown
  455. for (var p in offerings) {
  456. option = document.createElement("option");
  457. option.innerHTML = offerings[p].identifier;
  458. option.value = p;
  459. dropdown.append(option);
  460. }
  461. }
  462. });
  463. };
  464. priv.buildForm = function() {
  465. _nodeAbstract.html(_process["abstract"]);
  466. _nodeInput.html("<h3>Input:</h3>");
  467. _nodeOutput.html('');
  468. var inputs = _process.dataInputs, supported = true,
  469. sld = "text/xml; subtype=sld/1.0.0",
  470. input;
  471. for (var i = 0, ii = inputs.length; i < ii; ++i) {
  472. input = inputs[i];
  473. if (input.complexData) {
  474. var formats = input.complexData.supported.formats;
  475. if (formats["application/wkt"]) {
  476. priv.addWKTInput(input);
  477. } else if (formats["text/xml; subtype=wfs-collection/1.0"]) {
  478. priv.addWFSCollectionInput(input);
  479. } else if (formats["image/tiff"]) {
  480. //priv.addRasterInput(input);
  481. } else if (formats[sld]) {
  482. priv.addXMLInput(input, sld);
  483. } else {
  484. supported = false;
  485. }
  486. } else if (input.boundingBoxData) {
  487. priv.addBoundingBoxInput(input);
  488. } else if (input.literalData) {
  489. priv.addLiteralInput(input);
  490. } else {
  491. supported = false;
  492. }
  493. if (input.minOccurs > 0) {
  494. _nodeInput.append(document.createTextNode("* "));
  495. }
  496. }
  497. if (supported) {
  498. var executeButton = document.createElement("button");
  499. executeButton.innerHTML = "Execute";
  500. _nodeInput.append(executeButton);
  501. executeButton.onclick = priv.execute;
  502. } else {
  503. _nodeInput.html('<span class="notsupported">' +
  504. "Sorry, the WPS builder does not support the selected process." +
  505. "</span>");
  506. }
  507. };
  508. // helper function to dynamically create a textarea for geometry (WKT) data
  509. // input
  510. priv.addWKTInput = function(input, previousSibling) {
  511. var name = input.identifier;
  512. var container = _nodeInput.get(0);
  513. var label = document.createElement("label");
  514. label["for"] = name;
  515. label.title = input["abstract"];
  516. label.innerHTML = name + " (select feature, then click field):";
  517. previousSibling && previousSibling.nextSibling ?
  518. container.insertBefore(label, previousSibling.nextSibling) :
  519. container.appendChild(label);
  520. var field = document.createElement("textarea");
  521. field.onclick = function () {
  522. if (_layer.selectedFeatures.length) {
  523. this.innerHTML = new OpenLayers.Format.WKT().write(
  524. _layer.selectedFeatures[0]
  525. );
  526. console.log('_layer.selectedFeatures[0]: ', _layer.selectedFeatures[0]);
  527. }
  528. priv.createCopy(input, this, priv.addWKTInput);
  529. };
  530. field.onblur = function() {
  531. input.data = field.value ? {
  532. complexData: {
  533. mimeType: "application/wkt",
  534. value: this.value
  535. }
  536. } : undefined;
  537. };
  538. field.title = input["abstract"];
  539. field.id = name;
  540. previousSibling && previousSibling.nextSibling ?
  541. container.insertBefore(field, previousSibling.nextSibling.nextSibling) :
  542. container.appendChild(field);
  543. };
  544. // helper function for xml input
  545. priv.addXMLInput = function(input, type) {
  546. var name = input.identifier;
  547. var field = document.createElement("input");
  548. field.title = input["abstract"];
  549. field.value = name + " (" + type + ")";
  550. field.onblur = function() {
  551. input.data = field.value ? {
  552. complexData: {
  553. mimeType: type,
  554. value: this.value
  555. }
  556. } : undefined;
  557. };
  558. _nodeInput.append(field);
  559. };
  560. // helper function to dynamically create a WFS collection reference input
  561. priv.addWFSCollectionInput = function(input) {
  562. var name = input.identifier;
  563. var field = document.createElement("input");
  564. field.title = input["abstract"];
  565. field.value = name + " (layer on demo server)";
  566. priv.addValueHandlers(field, function() {
  567. input.reference = field.value ? {
  568. mimeType: "text/xml; subtype=wfs-collection/1.0",
  569. href: "http://geoserver/wfs",
  570. method: "POST",
  571. body: {
  572. wfs: {
  573. version: "1.0.0",
  574. outputFormat: "GML2",
  575. featureType: field.value
  576. }
  577. }
  578. } : undefined;
  579. });
  580. _nodeInput.append(field);
  581. };
  582. // helper function to dynamically create a raster (GeoTIFF) url input
  583. priv.addRasterInput = function(input) {
  584. var name = input.identifier;
  585. var field = document.createElement("input");
  586. field.title = input["abstract"];
  587. var url = window.location.href.split("?")[0];
  588. field.value = url.substr(0, url.lastIndexOf("/")+1) + "data/tazdem.tiff";// TODO: file path to options
  589. document.getElementById("input").appendChild(field);
  590. (field.onblur = function() {
  591. input.reference = {
  592. mimeType: "image/tiff",
  593. href: field.value,
  594. method: "GET"
  595. };
  596. })();
  597. };
  598. // helper function to dynamically create a bounding box input
  599. priv.addBoundingBoxInput = function(input) {
  600. var name = input.identifier;
  601. var field = document.createElement("input");
  602. field.title = input["abstract"];
  603. field.value = "left,bottom,right,top (EPSG:4326)";
  604. _nodeInput.append(field);
  605. priv.addValueHandlers(field, function() {
  606. input.boundingBoxData = {
  607. projection: "EPSG:4326",
  608. bounds: OpenLayers.Bounds.fromString(field.value)
  609. };
  610. });
  611. };
  612. // helper function to create a literal input textfield or dropdown
  613. priv.addLiteralInput = function(input, previousSibling) {
  614. var name = input.identifier;
  615. var container = _nodeInput.get(0);
  616. var anyValue = input.literalData.anyValue;
  617. // anyValue means textfield, otherwise we create a dropdown
  618. var field = document.createElement(anyValue ? "input" : "select");
  619. field.id = name;
  620. field.title = input["abstract"];
  621. previousSibling && previousSibling.nextSibling ?
  622. container.insertBefore(field, previousSibling.nextSibling) :
  623. container.appendChild(field);
  624. if (anyValue) {
  625. var dataType = input.literalData.dataType;
  626. field.value = name + (dataType ? " (" + dataType + ")" : "");
  627. priv.addValueHandlers(field, function() {
  628. input.data = field.value ? {
  629. literalData: {
  630. value: field.value
  631. }
  632. } : undefined;
  633. priv.createCopy(input, field, priv.addLiteralInput);
  634. });
  635. } else {
  636. var option;
  637. option = document.createElement("option");
  638. option.innerHTML = name;
  639. field.appendChild(option);
  640. for (var v in input.literalData.allowedValues) {
  641. option = document.createElement("option");
  642. option.value = v;
  643. option.innerHTML = v;
  644. field.appendChild(option);
  645. }
  646. field.onchange = function() {
  647. priv.createCopy(input, field, priv.addLiteralInput);
  648. input.data = this.selectedIndex ? {
  649. literalData: {
  650. value: this.options[this.selectedIndex].value
  651. }
  652. } : undefined;
  653. };
  654. }
  655. };
  656. // if maxOccurs is > 1, this will add a copy of the field
  657. priv.createCopy = function(input, field, fn) {
  658. if (input.maxOccurs && input.maxOccurs > 1 && !field.userSelected) {
  659. // add another copy of the field - we don't check maxOccurs
  660. field.userSelected = true;
  661. var newInput = OpenLayers.Util.extend({}, input);
  662. // we recognize copies by the occurrence property
  663. newInput.occurrence = (input.occurrence || 0) + 1;
  664. _process.dataInputs.push(newInput);
  665. fn(newInput, field);
  666. }
  667. };
  668. // helper function for adding events to form fields
  669. priv.addValueHandlers = function(field, onblur) {
  670. field.onclick = function() {
  671. if (!this.initialValue) {
  672. this.initialValue = this.value;
  673. this.value = "";
  674. }
  675. };
  676. field.onblur = function() {
  677. if (!this.value) {
  678. this.value = this.initialValue;
  679. delete this.initialValue;
  680. }
  681. onblur.apply(this, arguments);
  682. };
  683. };
  684. // execute the process
  685. priv.execute = function() {
  686. var output = _process.processOutputs[0];
  687. var input;
  688. // remove occurrences that the user has not filled out
  689. for (var i = _process.dataInputs.length - 1; i >= 0; --i) {
  690. input = _process.dataInputs[i];
  691. if ((input.minOccurs === 0 || input.occurrence) && !input.data && !input.reference) {
  692. OpenLayers.Util.removeItem(_process.dataInputs, input);
  693. }
  694. }
  695. _process.responseForm = {
  696. rawDataOutput: {
  697. identifier: output.identifier
  698. }
  699. };
  700. if (output.complexOutput && output.complexOutput.supported.formats["application/wkt"]) {
  701. _process.responseForm.rawDataOutput.mimeType = "application/wkt";
  702. }
  703. OpenLayers.Request.POST({
  704. url: priv.options.wpsUrl,
  705. data: new OpenLayers.Format.WPSExecute().write(_process),
  706. success: priv.showOutput
  707. });
  708. }
  709. // add the process's output to the page
  710. priv.showOutput = function(response) {
  711. var result = _nodeOutput.get(0);
  712. result.innerHTML = "<h3>Output:</h3>";
  713. var features;
  714. var contentType = response.getResponseHeader("Content-Type");
  715. if (contentType == "application/wkt") {
  716. features = new OpenLayers.Format.WKT().read(response.responseText);
  717. } else if (contentType == "text/xml; subtype=wfs-collection/1.0") {
  718. features = new OpenLayers.Format.WFST.v1_0_0().read(response.responseText);
  719. }
  720. if (features && (features instanceof OpenLayers.Feature.Vector || features.length)) {
  721. _layer.addFeatures(features);
  722. result.innerHTML += "The result should also be visible on the map.";
  723. }
  724. result.innerHTML += "<textarea>" + response.responseText + "</textarea>";
  725. }
  726. publ.updateSize = function() {
  727. _map.updateSize();
  728. };
  729. publ.zoomToExtent = function(extent) {
  730. if (!extent) return;
  731. var sourceProj = new OpenLayers.Projection("EPSG:4326");
  732. var targetProj = _map.getProjectionObject();
  733. var extentBounds = OpenLayers.Geometry.fromWKT(extent).transform(sourceProj, targetProj).getBounds();
  734. _map.zoomToExtent(extentBounds);
  735. };
  736. publ.selectRecord = function(recordId, extent) {
  737. if (priv.isSelectedRecordId()) {
  738. if (priv.getSelectedRecordId() != recordId) {
  739. if (priv.isSelectedFeature()) {
  740. if (confirm('Aktualnie przypisany rekord to ' + priv.getSelectedRecordId() + ' czy zmienić na ' + recordId + '?')) {
  741. priv.setSelectedRecordId(recordId);
  742. }
  743. } else {
  744. priv.setSelectedRecordId(recordId);
  745. publ.zoomToExtent(extent);
  746. }
  747. } else {
  748. publ.zoomToExtent(extent);
  749. }
  750. }
  751. else {
  752. priv.setSelectedRecordId(recordId);
  753. publ.zoomToExtent(extent);
  754. }
  755. };
  756. publ.init = function(options) {
  757. if (priv.options.debug) console.log('TableAjaxMap initialization...', options);
  758. //merge supplied options with defaults
  759. $.extend(priv.options, defaults, options);
  760. priv.init();
  761. return publ;
  762. };
  763. return publ;
  764. };
  765. $.fn.TableAjaxMapUpdateSize = function(options) {
  766. options = options || {};
  767. return this.each(function() {
  768. var tblAjaxMap = $(this).data('TableAjaxMap');
  769. if (tblAjaxMap) {
  770. tblAjaxMap.updateSize();
  771. }
  772. });
  773. return this;
  774. };
  775. $.fn.TableAjaxMapZoomToExtent = function(extent) {
  776. if (!extent) return;
  777. return this.each(function() {
  778. var tblAjaxMap = $(this).data('TableAjaxMap');
  779. if (tblAjaxMap) {
  780. tblAjaxMap.zoomToExtent(extent);
  781. }
  782. });
  783. return this;
  784. };
  785. $.fn.TableAjaxMapSelectRecord = function(recordId, extent) {
  786. if (!recordId) return;
  787. return this.each(function() {
  788. var tblAjaxMap = $(this).data('TableAjaxMap');
  789. if (tblAjaxMap) {
  790. tblAjaxMap.selectRecord(recordId, extent);
  791. }
  792. });
  793. return this;
  794. };
  795. $.fn.TableAjaxMap = function(options) {
  796. options = options || {};
  797. return this.each(function() {
  798. options.id = this;
  799. if (!$(this).data('TableAjaxMap')) {
  800. $(this).data('TableAjaxMap', new TableAjaxMap().init(options));
  801. }
  802. });
  803. return this;
  804. };
  805. }(jQuery));
  806. </script>
  807. <?php
  808. }
  809. public function ajaxTask($task) {
  810. switch ($task) {
  811. case 'PROXY': {
  812. $this->sendAjaxProxy($_REQUEST);
  813. break;
  814. }
  815. default:
  816. //$this->sendAjaxData($_REQUEST);
  817. }
  818. }
  819. public function sendAjaxProxy($args) {
  820. $url = V::get('url', '', $args);
  821. // 1. http%3A%2F%2Fbiuro.biall-net.pl%2Fwps%3FSERVICE%3DWPS%26REQUEST%3DGetCapabilities
  822. // 2. http%3A%2F%2Fbiuro.biall-net.pl%2Fwps%3FSERVICE%3DWPS%26REQUEST%3DDescribeProcess%26VERSION%3D1.0.0%26IDENTIFIER%3Dpozdrawiam
  823. header('Content-Type: application/xml; charset=utf-8');
  824. $urlParts = parse_url($url);
  825. $urlQuery = array();
  826. $urlQueryTmp = V::get('query', '', $urlParts);
  827. $urlQueryTmp = explode('&', $urlQueryTmp);
  828. foreach ($urlQueryTmp as $vQuery) {
  829. $parts = explode('=', $vQuery, 2);
  830. $urlQuery[$parts[0]] = $parts[1];
  831. }
  832. $wpsServer = new TableAjaxMapWpsServer($this->_acl);
  833. if ('WPS' == V::get('SERVICE', '', $urlQuery)) {
  834. $req = V::get('REQUEST', '', $urlQuery);
  835. $methodName = "{$req}Action";
  836. if (method_exists($wpsServer, $methodName)) {
  837. $wpsServer->$methodName($urlQuery);
  838. }
  839. }
  840. else {
  841. $wpsServer->parseXMLRequest();
  842. }
  843. exit;
  844. }
  845. }
  846. class TableAjaxMapWfsAction {
  847. private $_acl;
  848. private $_zasobID;
  849. public function __construct($acl) {
  850. $this->_acl = $acl;
  851. $this->_zasobID = $acl->getID();
  852. }
  853. /**
  854. * example: MULTIPOLYGON(((2072016.74395199 7234076.79293037,2072016.74395199 7234115.01144451,2072131.3994944 7234115.01144451,2072131.3994944 7234076.79293037,2072016.74395199 7234076.79293037)))
  855. */
  856. public function generateGmlFromWKT($wkt) {
  857. $gml = '';
  858. $wktParts = explode('(', $wkt, 2);
  859. ob_start();
  860. switch ($wktParts[0]) {
  861. case 'MULTIPOLYGON':
  862. case 'POLYGON': {
  863. $points = trim($wktParts[1], '() ');
  864. $points = str_replace(',', "\n", $points);
  865. ?>
  866. <gml:boundedBy>
  867. <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
  868. <gml:lowerCorner>-180 -90</gml:lowerCorner>
  869. <gml:upperCorner>180 90</gml:upperCorner>
  870. </gml:Envelope>
  871. </gml:boundedBy>
  872. <og:the_geom>
  873. <gml:MultiSurface srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
  874. <gml:surfaceMember>
  875. <gml:Polygon srsDimension="2">
  876. <gml:exterior>
  877. <gml:LinearRing srsDimension="2">
  878. <gml:posList>
  879. <?php echo $points; ?>
  880. </gml:posList>
  881. </gml:LinearRing>
  882. </gml:exterior>
  883. </gml:Polygon>
  884. </gml:surfaceMember>
  885. </gml:MultiSurface>
  886. </og:the_geom>
  887. <?php
  888. }
  889. break;
  890. default:
  891. ?>
  892. <!-- UNKNOWN WKT:<?php echo $wkt; ?> -->
  893. <?php
  894. }
  895. $gml = ob_get_contents();
  896. ob_clean();
  897. return $gml;
  898. }
  899. public function execute($args) {
  900. /*
  901. * Mapa odczytywanie punktów: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
  902. *
  903. * CI50:
  904. 18.613243103027344 54.33614429135817
  905. 18.613243103027344 54.33634445792519
  906. 18.614273071289062 54.33634445792519
  907. 18.614273071289062 54.33614429135817
  908. */
  909. Lib::loadClass('Data_Source');
  910. $dataSource = new Data_Source($this->_acl->getDB());
  911. $dataSource->setTable($this->_acl->getName());
  912. $dataSource->addCol('ID');
  913. $dataSource->addCol('the_geom');
  914. $dataSource->setColTypes($this->_acl->getTypes());
  915. $params = array();
  916. $params['limit'] = 1000;
  917. if (!empty($args['BBOX'])) {
  918. $params['f_the_geom'] = 'BBOX:' . implode(',', $args['BBOX']);
  919. }
  920. $items = $dataSource->getItems($params);
  921. $buildingsGml = array();
  922. foreach ($items as $r) {
  923. if (!empty($r->the_geom)) {
  924. $buildingsGml[$r->ID] = $this->generateGmlFromWKT($r->the_geom);
  925. }
  926. }
  927. /**
  928. * <og:recordId><?php echo $kId; ?></og:recordId>
  929. * <og:tblId><?php echo $tblId; ?></og:tblId>
  930. *
  931. * goes to js: @see priv.addWKTInput _layer.selectedFeatures[0]
  932. *
  933. * attributes: Object
  934. recordId: "1130"
  935. tblId: "16"
  936. */
  937. echo '<?xml version="1.0" encoding="UTF-8"?>';
  938. ?>
  939. <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">
  940. <gml:boundedBy>
  941. <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
  942. <gml:lowerCorner>-180 -90</gml:lowerCorner>
  943. <gml:upperCorner>180 90</gml:upperCorner>
  944. </gml:Envelope>
  945. </gml:boundedBy>
  946. <gml:featureMembers>
  947. <?php foreach ($buildingsGml as $kId => $vGml) : ?>
  948. <og:restricted gml:id="restricted.<?php echo $kId; ?>">
  949. <?php echo $vGml; ?>
  950. <og:recordId><?php echo $kId; ?></og:recordId>
  951. <og:tblId><?php echo $this->_zasobID; ?></og:tblId>
  952. </og:restricted>
  953. <?php endforeach; ?>
  954. </gml:featureMembers>
  955. </wfs:FeatureCollection>
  956. <?php
  957. }
  958. }
  959. class WpsActionBase {
  960. public $title = '';
  961. public $description = '';
  962. public $dataInputs = array();
  963. public function execute($args) {
  964. var_dump($args);
  965. }
  966. }
  967. class WpsActionPrzypiszDoRekordu extends WpsActionBase {
  968. public function __construct() {
  969. $this->title = 'Przypisz';
  970. $this->description = 'Przypisuje położenie do wybranego rekordu w tabeli.';
  971. $this->dataInputs['geom'] = new stdClass();
  972. $this->dataInputs['geom']->title = 'geom';
  973. $this->dataInputs['geom']->description = 'Input geometry';
  974. $this->dataInputs['geom']->type = 'geom';// CoomplexData
  975. $this->dataInputs['idTable'] = new stdClass();
  976. $this->dataInputs['idTable']->title = 'geom';
  977. $this->dataInputs['idTable']->description = 'Table ID';
  978. $this->dataInputs['idTable']->type = 'integer';// LiteralData: xs:integer
  979. $this->dataInputs['idRecord'] = new stdClass();
  980. $this->dataInputs['idRecord']->title = 'idRecord';
  981. $this->dataInputs['idRecord']->description = 'Record ID';
  982. $this->dataInputs['idRecord']->type = 'integer';// LiteralData: xs:integer
  983. }
  984. }
  985. class TableAjaxMapWpsServer {
  986. private $_fun;// config for identifiers
  987. private $_wfsAction;
  988. private $_zasobID;
  989. private $_acl;
  990. public function __construct($acl) {
  991. $this->_fun['przypiszDoRekordu'] = new WpsActionPrzypiszDoRekordu();
  992. $this->_acl = $acl;
  993. $this->_zasobID = $acl->getID();
  994. $this->_wfsAction = new TableAjaxMapWfsAction($this->_acl);
  995. }
  996. public function parseXMLRequest() {
  997. $data = array();
  998. $reqContent = file_get_contents('php://input');
  999. $xml = new SimpleXMLElement($reqContent);
  1000. if ('GetFeature' == $xml->getName()) {
  1001. // TODO: parse xml and set query params
  1002. /*
  1003. <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">
  1004. <wfs:Query typeName="feature:restricted" srsName="EPSG:4326" xmlns:feature="http://opengeo.org">
  1005. <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
  1006. <ogc:BBOX>
  1007. <ogc:PropertyName>the_geom</ogc:PropertyName>
  1008. <gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
  1009. <gml:lowerCorner>17.226562502593 53.887024366231</gml:lowerCorner>
  1010. <gml:upperCorner>20.039062502593 54.847089981191</gml:upperCorner>
  1011. </gml:Envelope>
  1012. </ogc:BBOX>
  1013. </ogc:Filter>
  1014. </wfs:Query>
  1015. </wfs:GetFeature>
  1016. */
  1017. $corners = null;
  1018. $xmlTag = $xml->children("wfs", TRUE)->Query;
  1019. if (!empty($xmlTag)) {
  1020. $xmlTag = $xmlTag->children("ogc", TRUE)->Filter;
  1021. if (!empty($xmlTag)) {
  1022. $xmlTag = $xmlTag->BBOX;
  1023. if (!empty($xmlTag)) {
  1024. $xmlTag = $xmlTag->children("gml", TRUE)->Envelope;
  1025. if (!empty($xmlTag)) {
  1026. $corners = (object)array('lowerCorner' => (string)$xmlTag->lowerCorner, 'upperCorner' => (string)$xmlTag->upperCorner);
  1027. }
  1028. }
  1029. }
  1030. }
  1031. if ($corners) {
  1032. $lowerCorner = (string) $corners->lowerCorner;
  1033. $upperCorner = (string) $corners->upperCorner;
  1034. $lowerCorner = explode(" ", trim($lowerCorner));
  1035. $upperCorner = explode(" ", trim($upperCorner));
  1036. if (count($lowerCorner) == 2 && count($upperCorner) == 2) {
  1037. $points = array();
  1038. $points[] = $upperCorner[1];// top
  1039. $points[] = $upperCorner[0];// right
  1040. $points[] = $lowerCorner[1];// bottom
  1041. $points[] = $lowerCorner[0];// left
  1042. $isAllNumeric = true;
  1043. foreach ($points as $point) {
  1044. if (!is_numeric($point)) $isAllNumeric = false;
  1045. }
  1046. if ($isAllNumeric) {
  1047. $data['BBOX'] = $points;
  1048. }
  1049. }
  1050. } else {
  1051. // inna struktura xml'a
  1052. }
  1053. $this->_wfsAction->execute($data);
  1054. }
  1055. else if (isset($xml->children('ows', TRUE)->Identifier)) {
  1056. $identifier = (string)$xml->children('ows', TRUE)->Identifier;
  1057. if (array_key_exists($identifier, $this->_fun)) {
  1058. foreach ($xml->children('wps', TRUE)->DataInputs->children('wps', TRUE) as $input) {
  1059. $inputIdentifier = (string)$input->children('ows', TRUE)->Identifier;
  1060. if (array_key_exists($inputIdentifier, $this->_fun[$identifier]->dataInputs)) {
  1061. $inputType = (string)$this->_fun[$identifier]->dataInputs[$inputIdentifier]->type;
  1062. switch ($inputType) {
  1063. case 'integer':
  1064. $data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->LiteralData;
  1065. break;
  1066. case 'geom':
  1067. $data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->ComplexData;
  1068. break;
  1069. default:
  1070. }
  1071. } else {
  1072. // brak zdefiniowanego inputa
  1073. }
  1074. }
  1075. $this->_fun['przypiszDoRekordu']->execute($data);
  1076. } else {
  1077. echo "TODO: brak zdefiniowanej funkcji '{$identifier}'";
  1078. var_dump($identifier);
  1079. }
  1080. }
  1081. else {
  1082. echo "TODO: '" . $xml->getName() . "' ...";
  1083. }
  1084. }
  1085. public function getCapabilitiesAction() {
  1086. echo '<?xml version="1.0" encoding="UTF-8"?>';
  1087. ?>
  1088. <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">
  1089. <ows:ServiceIdentification>
  1090. <ows:Title>Prototype GeoServer WPS</ows:Title>
  1091. <ows:Abstract />
  1092. <ows:Keywords>
  1093. <ows:Keyword>wps</ows:Keyword>
  1094. <ows:Keyword>geoserver</ows:Keyword>
  1095. </ows:Keywords>
  1096. <ows:ServiceType>WPS</ows:ServiceType>
  1097. <ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
  1098. <ows:Fees>NONE</ows:Fees>
  1099. <ows:AccessConstraints>NONE</ows:AccessConstraints>
  1100. </ows:ServiceIdentification>
  1101. <ows:ServiceProvider>
  1102. <ows:ProviderName>GeoServer</ows:ProviderName>
  1103. <ows:ProviderSite />
  1104. <ows:ServiceContact />
  1105. </ows:ServiceProvider>
  1106. <ows:OperationsMetadata>
  1107. <ows:Operation name="GetCapabilities">
  1108. <ows:DCP>
  1109. <ows:HTTP>
  1110. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  1111. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  1112. </ows:HTTP>
  1113. </ows:DCP>
  1114. </ows:Operation>
  1115. <ows:Operation name="DescribeProcess">
  1116. <ows:DCP>
  1117. <ows:HTTP>
  1118. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  1119. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  1120. </ows:HTTP>
  1121. </ows:DCP>
  1122. </ows:Operation>
  1123. <ows:Operation name="Execute">
  1124. <ows:DCP>
  1125. <ows:HTTP>
  1126. <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  1127. <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
  1128. </ows:HTTP>
  1129. </ows:DCP>
  1130. </ows:Operation>
  1131. </ows:OperationsMetadata>
  1132. <wps:ProcessOfferings>
  1133. <?php foreach($this->_fun as $kFun => $vFun) : ?>
  1134. <wps:Process wps:processVersion="1.0.0">
  1135. <ows:Identifier><?php echo $kFun; ?></ows:Identifier>
  1136. <ows:Title><?php echo $vFun->title; ?></ows:Title>
  1137. <ows:Abstract><?php echo $vFun->description; ?></ows:Abstract>
  1138. </wps:Process>
  1139. <?php endforeach; ?>
  1140. </wps:ProcessOfferings>
  1141. <wps:Languages>
  1142. <wps:Default>
  1143. <ows:Language>en-US</ows:Language>
  1144. </wps:Default>
  1145. <wps:Supported>
  1146. <ows:Language>en-US</ows:Language>
  1147. </wps:Supported>
  1148. </wps:Languages>
  1149. </wps:Capabilities>
  1150. <?php
  1151. }
  1152. public function describeProcessAction($args) {
  1153. // TODO: xml z opiesem procese $args['IDENTIFIER']
  1154. /**
  1155. * should work like JTS:densify - geom field (map object) and integer field (record ID)
  1156. * 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
  1157. * http://demo.opengeo.org/geoserver/wps?SERVICE=WPS&REQUEST=DescribeProcess&VERSION=1.0.0&IDENTIFIER=JTS%3Adensify
  1158. */
  1159. echo '<?xml version="1.0" encoding="UTF-8"?>';
  1160. if (array_key_exists($args['IDENTIFIER'], $this->_fun)) {
  1161. $identifier = $this->_fun[$args['IDENTIFIER']];
  1162. ?>
  1163. <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">
  1164. <ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true">
  1165. <ows:Identifier><?php echo $args['IDENTIFIER']; ?></ows:Identifier>
  1166. <ows:Title><?php echo $identifier->title; ?></ows:Title>
  1167. <ows:Abstract><?php echo $identifier->description; ?></ows:Abstract>
  1168. <DataInputs>
  1169. <?php foreach ($identifier->dataInputs as $kInput => $vInput) : ?>
  1170. <Input maxOccurs="1" minOccurs="1">
  1171. <ows:Identifier><?php echo $kInput; ?></ows:Identifier>
  1172. <ows:Title><?php echo $vInput->title; ?></ows:Title>
  1173. <ows:Abstract><?php echo $vInput->description; ?></ows:Abstract>
  1174. <?php if ($vInput->type == 'geom') : ?>
  1175. <ComplexData>
  1176. <Default>
  1177. <Format>
  1178. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  1179. </Format>
  1180. </Default>
  1181. <Supported>
  1182. <Format>
  1183. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  1184. </Format>
  1185. <Format>
  1186. <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
  1187. </Format>
  1188. <Format>
  1189. <MimeType>application/wkt</MimeType>
  1190. </Format>
  1191. <Format>
  1192. <MimeType>application/gml-3.1.1</MimeType>
  1193. </Format>
  1194. <Format>
  1195. <MimeType>application/gml-2.1.2</MimeType>
  1196. </Format>
  1197. </Supported>
  1198. </ComplexData>
  1199. <?php elseif ($vInput->type == 'integer') : ?>
  1200. <LiteralData>
  1201. <ows:DataType>xs:integer</ows:DataType>
  1202. <ows:AnyValue />
  1203. </LiteralData>
  1204. <?php else : ?>
  1205. <?php endif; ?>
  1206. </Input>
  1207. <?php endforeach; ?>
  1208. </DataInputs>
  1209. <ProcessOutputs>
  1210. <Output>
  1211. <ows:Identifier>result</ows:Identifier>
  1212. <ows:Title>result</ows:Title>
  1213. <ComplexOutput>
  1214. <Default>
  1215. <Format>
  1216. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  1217. </Format>
  1218. </Default>
  1219. <Supported>
  1220. <Format>
  1221. <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
  1222. </Format>
  1223. <Format>
  1224. <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
  1225. </Format>
  1226. <Format>
  1227. <MimeType>application/wkt</MimeType>
  1228. </Format>
  1229. <Format>
  1230. <MimeType>application/gml-3.1.1</MimeType>
  1231. </Format>
  1232. <Format>
  1233. <MimeType>application/gml-2.1.2</MimeType>
  1234. </Format>
  1235. </Supported>
  1236. </ComplexOutput>
  1237. </Output>
  1238. </ProcessOutputs>
  1239. </ProcessDescription>
  1240. </wps:ProcessDescriptions>
  1241. <?php
  1242. } else {
  1243. echo 'TODO: brak funkcji';
  1244. }
  1245. }
  1246. }