TableAjaxMap.php 49 KB

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