TableAjaxMap.php 44 KB

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