TableAjaxMap.php 47 KB

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