TableAjaxMap.php 50 KB

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