TableAjaxMap.php 49 KB

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