TableAjaxMap.php 45 KB

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