TableAjaxMap.php 46 KB

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