TableAjaxMap.php 52 KB

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