TableAjaxMap.php 44 KB

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