TableAjaxMap.php 60 KB

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