TableAjaxMap.php 54 KB

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