TableAjaxMap.php 45 KB

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