TableAjaxMap.php 46 KB

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