| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561 |
- <?php
- /**
- * usage:
- *
- <script>
- jQuery('#TreeTableMap').TableAjaxMap({
- wpsUrl: 'http://biuro.biall-net.pl/wps',
- wfsUrl: 'http://biuro.biall-net.pl/wps'
- });
- </script>
- *
- */
- class TableAjaxMap {
- private $_acl;
- private $_zasobID;
- private $_width;
- private $_height;
- public function __construct($tblAcl, $width = 512, $height = 256) {
- $this->_acl = $tblAcl;
- $this->_zasobID = $tblAcl->getID();
- $this->_width = $width;
- $this->_height = $height;
- }
- public function printCSS() {
- // <link rel="stylesheet" href="stuff/open-layers/theme/default/style.css" type="text/css">
- // <link rel="stylesheet" href="stuff/open-layers/style.css" type="text/css">
- ?>
- <style type="text/css">
- .TableAjaxMap { width:100%; height:<?php echo $this->_height; ?>px; }
- .olControlEditingToolbar .olControlModifyFeatureItemInactive { background-image:url(stuff/open-layers/theme/default/img/draw_point_off.png); }
- .olControlEditingToolbar .olControlModifyFeatureItemActive { background-image:url(stuff/open-layers/theme/default/img/draw_point_on.png); }
- .olControlEditingToolbar .olControlSelectFeatureItemInactive { background-image:url(stuff/open-layers/theme/default/img/move_feature_off.png); }
- .olControlEditingToolbar .olControlSelectFeatureItemActive { background-image:url(stuff/open-layers/theme/default/img/move_feature_on.png); }
- .olControlEditingToolbar .olControlRefreshItemInactive { background-image: url(stuff/open-layers/theme/default/img/refresh_feature_off.png); }
- .olControlEditingToolbar .olControlRefreshItemActive { background-image: url(stuff/open-layers/theme/default/img/refresh_feature_on.png); }
- .olControlEditingToolbar .olControlSaveItemInactive { background-image: url(stuff/open-layers/theme/default/img/save_features_off.png); }
- .olControlEditingToolbar .olControlSaveItemActive { background-image: url(stuff/open-layers/theme/default/img/save_features_on.png); }
- .olControlEditingToolbar .olControlUserLocationItemInactive { background-image: url(stuff/open-layers/theme/default/img/geolocation-off.png); }
- .olControlEditingToolbar .olControlUserLocationItemActive { background-image: url(stuff/open-layers/theme/default/img/geolocation-on.png); }
- .olControlLayerSwitcher .layersDiv { border-radius:10px 0 0 10px; opacity:0.75; filter:alpha(opacity=75); }
- .notsupported { color:red; }
- .TableAjaxMap .layersDiv input { margin:0; }
- .TableAjaxMap .layersDiv label { display:inline; }
- </style>
- <?php
- }
- public function printJS() {
- ?>
- <script src="stuff/open-layers/OpenLayers.js"></script>
- <script>
- OpenLayers.ProxyHost = "index-ajax.php?_zasobID=<?php echo $this->_zasobID; ?>&_cls=<?php echo __CLASS__; ?>&_task=PROXY&url=";
- (function( $ ) {
- var TableAjaxMap = function() {
- var priv = {}; //private api
- var publ = {}; //public api
- priv.options = {};
- var defaults = {
- wpsUrl: '',
- wfsUrl: '',
- layerName: 'Warstwa rysowania',
- zoomStrategyActivate: 15,
- onSaveFeature: null,
- onSelectBox: null,
- addBtn: null,
- debug: true
- };
- var _nodeMapId;
- var _nodeMap;
- var _nodeProcesses;
- var _nodeAbstract;
- var _nodeInput;
- var _nodeOutput;
- var _capabilities;
- var _process;
- var _layer;
- var _map;
- var _styleMap;
- /*
- initialize the plugin.
- */
- priv.init = function() {
- /*
- <div id="map" class="TableAjaxMap"></div>
- <div>
- <select id="processes"><option>Select a process</option></select>
- <p id="abstract"></p>
- <div id="input"></div>
- <div id="output"></div>
- </div>
- */
- _nodeMapId = 'Map-' + Math.random(1).toString().substr(2);
- _nodeMap = $('<div id="' + _nodeMapId + '" class="TableAjaxMap"></div>');
- _nodeProcesses = $('<select></select>');
- _nodeProcesses.append('<option>Wybierz funkcję</option>');
- _nodeAbstract = $('<p></p>');
- _nodeInput = $('<div></div>');
- _nodeOutput = $('<div></div>');
- _selectedFeature = null;
- _selectedRecordId = 0;
- priv.options.zoomStrategyActivate = (priv.options.zoomStrategyActivate > 0)? priv.options.zoomStrategyActivate : 15;
- var div = $('<div></div>');
- div.append(_nodeProcesses);
- div.append(_nodeAbstract);
- div.append(_nodeInput);
- div.append(_nodeOutput);
- $(priv.options.id).append(_nodeMap);
- $(priv.options.id).append(div);
- _nodeProcesses.on('change', function() {
- if (priv.options.debug) console.log("onchange this:", this, this.selectedIndex, this.options);
- var selection = this.options[this.selectedIndex].value;
- if (this.selectedIndex > 0) {
- OpenLayers.Request.GET({
- url: priv.options.wpsUrl,
- params: {
- "SERVICE": "WPS",
- "REQUEST": "DescribeProcess",
- "VERSION": _capabilities.version,
- "IDENTIFIER": selection
- },
- success: function(response) {
- _process = new OpenLayers.Format.WPSDescribeProcess().read(
- response.responseText
- ).processDescriptions[selection];
- if (priv.options.debug) console.log("Process:", _process);
- priv.buildForm();
- }
- });
- }
- });
- priv.getCapabilities();
- _styleMap = new OpenLayers.StyleMap({
- 'default': new OpenLayers.Style(null, {
- rules: [
- new OpenLayers.Rule({
- symbolizer: {
- stroke: true,
- strokeWidth: 3,
- fill: true,
- fillColor: "#ee9900",
- strokeColor: "#ee9900",
- }
- })
- , new OpenLayers.Rule({
- symbolizer: {
- stroke: true,
- fill: true,
- strokeWidth: 3,
- fillColor: "#ee9900",
- strokeColor: "#ee9900",
- // label : "rekord: ${recordId}",
- fontColor : "#333",
- fontOpacity: 0.7,
- ontSize: "12px",
- },
- filter: new OpenLayers.Filter.Comparison({
- type: OpenLayers.Filter.Comparison.GREATER_THAN,
- property: "recordId",
- value: 0
- })
- })
- , new OpenLayers.Rule({
- symbolizer: {
- stroke: true,
- fill: true,
- strokeWidth: 3,
- fillColor: "#ff0000",
- strokeColor: "#ff0000",
- // label : "rekord: ${_newRecordId}",
- fontColor : "#333",
- fontOpacity: 0.7,
- ontSize: "12px",
- },
- filter: new OpenLayers.Filter.Comparison({
- type: OpenLayers.Filter.Comparison.GREATER_THAN,
- property: "_newRecordId",
- value: 0
- })
- })
- , new OpenLayers.Rule({
- symbolizer: {
- stroke: true,
- fill: true,
- strokeWidth: 3,
- fillColor: "#ff0000",
- strokeColor: "#ff0000",
- },
- filter: new OpenLayers.Filter.Comparison({
- type: OpenLayers.Filter.Comparison.GREATER_THAN,
- property: "_modified",
- value: 0
- })
- })
- ]
- })
- });
- _layer = new OpenLayers.Layer.Vector(priv.options.layerName, {
- strategies: [new OpenLayers.Strategy.BBOX(), new OpenLayers.Strategy.Cluster({distance:30, threshold:3})],
- projection: new OpenLayers.Projection("EPSG:4326"),
- protocol: new OpenLayers.Protocol.WFS({
- version: "1.1.0",
- srsName: "EPSG:4326",
- url: priv.options.wfsUrl,
- featureNS : "http://opengeo.org",
- featureType: "restricted",
- geometryName: "the_geom",
- schema: "http://demo.opengeo.org/geoserver/wfs/DescribeFeatureType?version=1.1.0&typename=og:restricted"
- }),
- // @doc: http://dev.openlayers.org/releases/OpenLayers-2.13.1/doc/apidocs/files/OpenLayers/Feature/Vector-js.html
- styleMap: _styleMap
- });
- // @doc OpanLayers events http://dev.openlayers.org/docs/files/OpenLayers/Layer/Vector-js.html#link33
- _layer.events.on({
- 'sketchcomplete': function(e) {// turn off cluster strategy on start drawing
- if (priv.options.debug) console.log('Event: sketchcomplete e.feature.attributes: ', e.feature.attributes, '; selAttras', (_selectedFeature)? _selectedFeature.attributes : 'null');
- if (priv.isSelectedRecordId()) {
- e.feature.attributes._newRecordId = priv.getSelectedRecordId();
- }
- },
- 'sketchstarted': function(e) {// turn off cluster strategy on start drawing
- if (priv.options.debug) console.log('Event: sketchstarted e.feature.attributes: ', e.feature.attributes, '; selAttras', (_selectedFeature)? _selectedFeature.attributes : 'null');
- if (!priv.isSelectedRecordId()) {
- alert('Najpierw wybierz rekord z tabeli, żeby móc narysować dla niego figurę.');
- return false;
- }
- _layer.strategies[1].deactivate();
- _layer.refresh({force:false});
- },
- // 'beforefeatureadded': function(e) {
- // if (priv.options.debug) console.log('Event: beforefeatureadded e.feature.attributes: ', e.feature.attributes, '; selAttras', (_selectedFeature)? _selectedFeature.attributes : 'null');
- // if (priv.options.debug) console.log('Event: beforefeatureadded attr.count(' + e.feature.attributes.count + ')')
- // },
- 'beforefeaturemodified': function(e) {
- if (priv.options.debug) console.log('Event: beforefeaturemodified modified(', e.feature.attributes._modified, ')', e.feature.attributes, ' selAttras', (_selectedFeature)? _selectedFeature.attributes : 'null');// TODO: DBG
- // NOTE: beforefeaturemodified from new node is fired before afterfeaturemodified from old node when click from one node to enother
- priv.checkSelectedFeatureModifications('before');
- priv.setSelectedFeature(e.feature);
- priv.showPopup(e.feature);
- },
- 'featuremodified': function(e) {
- if (priv.options.debug) console.log('Event: featuremodified modified(', e.feature.attributes._modified, ') ', e.feature.attributes, ' selAttras', (_selectedFeature)? _selectedFeature.attributes : 'null');// TODO: DBG
- if (_selectedFeature && _selectedFeature.attributes) {
- _selectedFeature.attributes._modified = 1;
- }
- },
- 'afterfeaturemodified': function(e) {
- 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
- if (_selectedFeature && _selectedFeature.fid != e.feature.fid) {
- if (priv.options.debug) console.log('Event: afterfeaturemodified pomiń check!');
- } else {
- priv.checkSelectedFeatureModifications('after');
- priv.setSelectedFeature(null);
- }
- priv.hidePopup(e.feature);
- }
- });
- var toolbar = new OpenLayers.Control.EditingToolbar(_layer);
- toolbar.addControls([
- new OpenLayers.Control.Button({
- title: "Twoja lokalizacja",
- displayClass: "olControlUserLocation",
- trigger: function() {
- if (!priv.isSelectedRecordId()) {
- alert('Najpierw wybierz rekord z tabeli, żeby móc narysować dla niego figurę.');
- return false;
- }
- if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(drawFromUserLocation);
- } else {
- alert("Geolocation is not supported by this browser.");
- }
- function drawFromUserLocation(position) {
- var coords = position.coords;
- console.log("Latitude: " + coords.latitude + "<br>Longitude: " + coords.longitude);
- publ.zoomToExtent('POINT(' + coords.longitude + ' ' + coords.latitude + ')');
- setTimeout(function() {
- var geometry = new OpenLayers.Geometry.Point(coords.longitude, coords.latitude);
- var sourceProj = new OpenLayers.Projection("EPSG:4326");
- var targetProj = _map.getProjectionObject();
- var geometryTransformed = geometry.transform(sourceProj, targetProj);
- var pointFeature = new OpenLayers.Feature.Vector(geometryTransformed, {_newRecordId: priv.getSelectedRecordId()});//, _styleMap);
- pointFeature.geometry.clearBounds();
- console.log("pointFeature: ", pointFeature);
- _layer.addFeatures([pointFeature], {silent: true});
- _selectedFeature = pointFeature;
- console.log("_layer: ", _layer);
- }, 200);
- }
- console.log('TODO: getUserLocation!');
- return;
- if (_selectedFeature) {
- if (!_selectedRecordId) {
- alert('Wybierz rekord tabeli');
- }
- else {
- }
- }
- else {
- alert('Wybierz element na mapie');
- }
- }
- })
- ]);
- toolbar.addControls([
- new OpenLayers.Control.ModifyFeature(_layer, {
- title: "Edytuj"
- , mode: OpenLayers.Control.ModifyFeature.DRAG | OpenLayers.Control.ModifyFeature.RESHAPE
- })
- ]);
- var btnSelectFeature = new OpenLayers.Control.SelectFeature(_layer, {
- title: "Select Test",
- clickout: false,
- toggle: false,
- multiple: false,
- hover: false,
- toggleKey: "ctrlKey", // ctrl key removes from selection
- multipleKey: "shiftKey", // shift key adds to selection
- box: true
- /* copy from OpenLayers source lib/OpenLayers/Control/SelectFeature.js
- * add bounds to trigger "boxselectionend" event
- */
- , selectBox: function(position) {
- if (position instanceof OpenLayers.Bounds) {
- var minXY = this.map.getLonLatFromPixel({
- x: position.left,
- y: position.bottom
- });
- var maxXY = this.map.getLonLatFromPixel({
- x: position.right,
- y: position.top
- });
- var bounds = new OpenLayers.Bounds(
- minXY.lon, minXY.lat, maxXY.lon, maxXY.lat
- );
- // if multiple is false, first deselect currently selected features
- if (!this.multipleSelect()) {
- this.unselectAll();
- }
- // because we're using a box, we consider we want multiple selection
- var prevMultiple = this.multiple;
- this.multiple = true;
- var layers = this.layers || [this.layer];
- this.events.triggerEvent("boxselectionstart", {layers: layers});
- var layer;
- for(var l=0; l<layers.length; ++l) {
- layer = layers[l];
- for(var i=0, len = layer.features.length; i<len; ++i) {
- var feature = layer.features[i];
- // check if the feature is displayed
- if (!feature.getVisibility()) {
- continue;
- }
- if (this.geometryTypes == null || OpenLayers.Util.indexOf(
- this.geometryTypes, feature.geometry.CLASS_NAME) > -1) {
- if (bounds.toGeometry().intersects(feature.geometry)) {
- if (OpenLayers.Util.indexOf(layer.selectedFeatures, feature) == -1) {
- this.select(feature);
- }
- }
- }
- }
- }
- this.multiple = prevMultiple;
- this.events.triggerEvent("boxselectionend", {layers: layers, bounds: bounds});
- }
- }
- });
- btnSelectFeature.events.on({
- "boxselectionend": function(e) {
- if (priv.options.debug) console.log('SelectFeature boxselectionend event', e, e.bounds);
- if (typeof priv.options.onSelectBox == "function") {
- var layerProj = _map.getProjectionObject();
- var targetProj = new OpenLayers.Projection("EPSG:4326");
- var bounds = e.bounds.transform(layerProj, targetProj);
- if (priv.options.debug) console.log('SelectFeature boxselectionend event bounds', bounds);
- priv.options.onSelectBox.call(this, bounds);
- }
- }
- });
- toolbar.addControls([btnSelectFeature]);
- toolbar.addControls([
- new OpenLayers.Control.Button({
- title: "Refresh",
- displayClass: "olControlRefresh",
- trigger: function() {
- _layer.refresh({force: true});
- }
- })
- ]);
- toolbar.addControls([
- new OpenLayers.Control.Button({
- title: "Zapisz zmiany",
- displayClass: "olControlSave",
- trigger: function() {
- if (_selectedFeature) {
- if (!_selectedRecordId) {
- alert('Wybierz rekord tabeli');
- }
- else {
- priv.saveSelectedFeature();
- priv.cancelSelectedFeatureModifications();
- }
- }
- else {
- alert('Wybierz element na mapie');
- }
- }
- })
- ]);
- if (priv.options.addBtn) {
- toolbar.addControls([
- new OpenLayers.Control.Button({
- title: priv.options.addBtn.title,
- displayClass: priv.options.addBtn.displayClass,
- trigger: function() {
- if (typeof priv.options.addBtn.trigger == "function") {
- priv.options.addBtn.trigger.call(this);
- }
- }
- })
- ]);
- }
- var gphy = new OpenLayers.Layer.OSM("Mapa", null, {
- resolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
- 19567.87923828125, 9783.939619140625, 4891.9698095703125,
- 2445.9849047851562, 1222.9924523925781, 611.4962261962891,
- 305.74811309814453, 152.87405654907226, 76.43702827453613,
- 38.218514137268066, 19.109257068634033, 9.554628534317017,
- 4.777314267158508, 2.388657133579254, 1.194328566789627,
- 0.5971642833948135, 0.25, 0.1, 0.05],
- serverResolutions: [156543.03390625, 78271.516953125, 39135.7584765625,
- 19567.87923828125, 9783.939619140625,
- 4891.9698095703125, 2445.9849047851562,
- 1222.9924523925781, 611.4962261962891,
- 305.74811309814453, 152.87405654907226,
- 76.43702827453613, 38.218514137268066,
- 19.109257068634033, 9.554628534317017,
- 4.777314267158508, 2.388657133579254,
- 1.194328566789627, 0.5971642833948135],
- transitionEffect: 'resize'
- });
- /* NOTE: map is in projection EPSG:900913 even if projection and displayProjection is set to EPSG:4326
- * _map.getProjectionObject(); returns EPSG:900913
- * restrictedExtent should be set in EPSG:900913
- * zoomToExtent should use EPSG:900913 - need to transform from EPSG:4326 to EPSG:900913
- */
- _map = new OpenLayers.Map(_nodeMapId, {
- projection: new OpenLayers.Projection("EPSG:4326"),
- displayProjection: new OpenLayers.Projection("EPSG:4326"),
- restrictedExtent: new OpenLayers.Bounds(
- 1526390.4410645328, 6273526.00, 2693330.958028555, 7352240.00
- ),
- controls: [
- toolbar,
- new OpenLayers.Control.ZoomPanel(),
- new OpenLayers.Control.PanPanel(),
- new OpenLayers.Control.LayerSwitcher(),
- new OpenLayers.Control.ScaleLine(),
- // TODO: add box with selected record from table, x for remove selection
- new OpenLayers.Control.KeyboardDefaults()
- ],
- layers: [gphy,_layer]
- });
- _map.events.register("zoomend", this, function(e) {
- var zoom = _map.getZoom();
- if (priv.options.debug) console.log('zoom(',zoom,', ',priv.options.zoomStrategyActivate,')');
- if (zoom > priv.options.zoomStrategyActivate && _layer.strategies[1].active) {
- _layer.strategies[1].deactivate();
- _layer.refresh({force:true});
- } else if (zoom <= priv.options.zoomStrategyActivate && !_layer.strategies[1].active) {
- _layer.strategies[1].activate();
- _layer.refresh({force:true});
- }
- });
- _map.zoomToMaxExtent();
- };
- priv.showPopup = function(feature) {
- if (priv.options.debug) console.log('showPopup() ... ');
- if (!feature) return;
- var popupContent = '';
- if (feature.attributes._newRecordId > 0) {
- popupContent = 'Rekord: ' + feature.attributes._newRecordId;
- } else if (feature.attributes.recordId > 0) {
- popupContent = 'Rekord: ' + feature.attributes.recordId;
- }
- if (!popupContent) return;
- popupContent = '<div style="font-size:.8em">' + popupContent + '</div>';
- var popup = new OpenLayers.Popup("popups",
- feature.geometry.getBounds().getCenterLonLat(),
- new OpenLayers.Size(100,20),
- popupContent,
- true);
- popup.setBorder('1px solid #333');
- popup.setOpacity(0.7);
- feature.popup = popup;
- _map.addPopup(popup);
- };
- priv.hidePopup = function(feature) {
- if (priv.options.debug) console.log('hidePopup() ... ');
- if (feature && feature.popup) {
- _map.removePopup(feature.popup);
- feature.popup.destroy();
- feature.popup = null;
- }
- };
- priv.onPopupClose = function() {
- if (priv.options.debug) console.log('onPopupClose() ...');
- priv.hidePopup(_selectedFeature);
- };
- priv.updateState = function() {
- // TODO: update state view
- if (priv.options.debug) console.log('updateState: _selectedRecordId:', _selectedRecordId, ' _selectedFeature:', _selectedFeature);
- if (_selectedFeature || _selectedRecordId) {
-
- } else {
-
- }
- };
- priv.setSelectedFeature = function(feature) {
- _selectedFeature = feature;
- if (_selectedFeature && _selectedFeature.attributes && _selectedFeature.attributes.recordId > 0) {
- if (_selectedFeature.attributes.recordId != _selectedRecordId) {
- _selectedRecordId = _selectedFeature.attributes.recordId;
- }
- }
- priv.updateState();
- };
- priv.setSelectedRecordId = function(id) {
- _selectedRecordId = id;
- priv.updateState();
- };
- priv.getSelectedRecordId = function() {
- return _selectedRecordId;
- };
- priv.isSelectedRecordId = function() {
- return _selectedRecordId > 0;
- };
- priv.isSelectedFeature = function() {
- if (priv.options.debug) console.log('_selectedFeature:', _selectedFeature);
- return (_selectedFeature)? true : false;
- };
- priv.changeSelectedFeatureRecordId = function(recordId) {
- if (priv.options.debug) console.log('priv.changeSelectedFeatureRecordId(',recordId,')::_selectedFeature:', _selectedFeature);
- if (_selectedFeature) {
- _selectedFeature.attributes.recordId = recordId;
- _selectedFeature.attributes._modified = 1;
- }
- };
- priv.cancelSelectedFeatureModifications = function() {
- if (!_selectedFeature) return false;
- if (_selectedFeature.attributes._newRecordId) {
- delete _selectedFeature.attributes._newRecordId;
- }
- if (_selectedFeature.attributes._modified) {
- delete _selectedFeature.attributes._modified;
- }
- };
- priv.isSelectedFeatureModified = function() {
- if (!_selectedFeature) return false;
- if (_selectedFeature.attributes) {
- if (_selectedFeature.attributes._newRecordId) {
- return true;
- }
- if (_selectedFeature.attributes._modified) {
- return true;
- }
- }
- return false;
- };
- priv.saveSelectedFeature = function() {
- if (priv.isSelectedFeatureModified()) {
- if (typeof priv.options.onSaveFeature == "function") {
- var sourceProj = _map.getProjectionObject();
- var targetProj = new OpenLayers.Projection("EPSG:4326");
- var selFeatureGeometry = _selectedFeature.geometry.clone();
- var selFeatureGeomTransformed = selFeatureGeometry.transform(sourceProj, targetProj);
- var selFeatureExtent = new OpenLayers.Format.WKT().extractGeometry(selFeatureGeomTransformed);
- priv.options.onSaveFeature.call(this, _selectedRecordId, selFeatureExtent);
- }
- }
- }
- priv.checkSelectedFeatureModifications = function(when) {
- if (priv.isSelectedFeatureModified()) {
- var msgRecordId = (_selectedRecordId > 0)? ' - rekord nr ' + _selectedRecordId : '';
- // TODO: if !_selectedRecordId then "Create new record"
- if (confirm('Czy zapisać zmiany wprowadzone dla zaznaczonego elementu' + msgRecordId + '?')) {
- // _layer.refresh();
- priv.saveSelectedFeature();
- priv.cancelSelectedFeatureModifications();
- }
- else {
- priv.cancelSelectedFeatureModifications();
- _layer.refresh({force:true});
- }
- }
- };
- // using OpenLayers.Format.WPSCapabilities to read the capabilities
- priv.getCapabilities = function() {
- OpenLayers.Request.GET({
- url: priv.options.wpsUrl,
- params: {
- "SERVICE": "WPS",
- "REQUEST": "GetCapabilities"
- },
- success: function(response){
- _capabilities = new OpenLayers.Format.WPSCapabilities().read(
- response.responseText
- );
- var dropdown = _nodeProcesses;
- var offerings = _capabilities.processOfferings, option;
- // populate the dropdown
- for (var p in offerings) {
- option = document.createElement("option");
- option.innerHTML = offerings[p].identifier;
- option.value = p;
- dropdown.append(option);
- }
- }
- });
- };
- priv.buildForm = function() {
- _nodeAbstract.html(_process["abstract"]);
- _nodeInput.html("<h3>Input:</h3>");
- _nodeOutput.html('');
- var inputs = _process.dataInputs, supported = true,
- sld = "text/xml; subtype=sld/1.0.0",
- input;
- for (var i = 0, ii = inputs.length; i < ii; ++i) {
- input = inputs[i];
- if (input.complexData) {
- var formats = input.complexData.supported.formats;
- if (formats["application/wkt"]) {
- priv.addWKTInput(input);
- } else if (formats["text/xml; subtype=wfs-collection/1.0"]) {
- priv.addWFSCollectionInput(input);
- } else if (formats["image/tiff"]) {
- //priv.addRasterInput(input);
- } else if (formats[sld]) {
- priv.addXMLInput(input, sld);
- } else {
- supported = false;
- }
- } else if (input.boundingBoxData) {
- priv.addBoundingBoxInput(input);
- } else if (input.literalData) {
- priv.addLiteralInput(input);
- } else {
- supported = false;
- }
- if (input.minOccurs > 0) {
- _nodeInput.append(document.createTextNode("* "));
- }
- }
-
- if (supported) {
- var executeButton = document.createElement("button");
- executeButton.innerHTML = "Execute";
- _nodeInput.append(executeButton);
- executeButton.onclick = priv.execute;
- } else {
- _nodeInput.html('<span class="notsupported">' +
- "Sorry, the WPS builder does not support the selected process." +
- "</span>");
- }
- };
- // helper function to dynamically create a textarea for geometry (WKT) data
- // input
- priv.addWKTInput = function(input, previousSibling) {
- var name = input.identifier;
- var container = _nodeInput.get(0);
- var label = document.createElement("label");
- label["for"] = name;
- label.title = input["abstract"];
- label.innerHTML = name + " (select feature, then click field):";
- previousSibling && previousSibling.nextSibling ?
- container.insertBefore(label, previousSibling.nextSibling) :
- container.appendChild(label);
- var field = document.createElement("textarea");
- field.onclick = function () {
- if (_layer.selectedFeatures.length) {
- this.innerHTML = new OpenLayers.Format.WKT().write(
- _layer.selectedFeatures[0]
- );
- if (priv.options.debug) console.log('_layer.selectedFeatures[0]: ', _layer.selectedFeatures[0]);
- }
- priv.createCopy(input, this, priv.addWKTInput);
- };
- field.onblur = function() {
- input.data = field.value ? {
- complexData: {
- mimeType: "application/wkt",
- value: this.value
- }
- } : undefined;
- };
- field.title = input["abstract"];
- field.id = name;
- previousSibling && previousSibling.nextSibling ?
- container.insertBefore(field, previousSibling.nextSibling.nextSibling) :
- container.appendChild(field);
- };
- // helper function for xml input
- priv.addXMLInput = function(input, type) {
- var name = input.identifier;
- var field = document.createElement("input");
- field.title = input["abstract"];
- field.value = name + " (" + type + ")";
- field.onblur = function() {
- input.data = field.value ? {
- complexData: {
- mimeType: type,
- value: this.value
- }
- } : undefined;
- };
- _nodeInput.append(field);
- };
- // helper function to dynamically create a WFS collection reference input
- priv.addWFSCollectionInput = function(input) {
- var name = input.identifier;
- var field = document.createElement("input");
- field.title = input["abstract"];
- field.value = name + " (layer on demo server)";
- priv.addValueHandlers(field, function() {
- input.reference = field.value ? {
- mimeType: "text/xml; subtype=wfs-collection/1.0",
- href: "http://geoserver/wfs",
- method: "POST",
- body: {
- wfs: {
- version: "1.0.0",
- outputFormat: "GML2",
- featureType: field.value
- }
- }
- } : undefined;
- });
- _nodeInput.append(field);
- };
- // helper function to dynamically create a raster (GeoTIFF) url input
- priv.addRasterInput = function(input) {
- var name = input.identifier;
- var field = document.createElement("input");
- field.title = input["abstract"];
- var url = window.location.href.split("?")[0];
- field.value = url.substr(0, url.lastIndexOf("/")+1) + "data/tazdem.tiff";// TODO: file path to options
- document.getElementById("input").appendChild(field);
- (field.onblur = function() {
- input.reference = {
- mimeType: "image/tiff",
- href: field.value,
- method: "GET"
- };
- })();
- };
- // helper function to dynamically create a bounding box input
- priv.addBoundingBoxInput = function(input) {
- var name = input.identifier;
- var field = document.createElement("input");
- field.title = input["abstract"];
- field.value = "left,bottom,right,top (EPSG:4326)";
- _nodeInput.append(field);
- priv.addValueHandlers(field, function() {
- input.boundingBoxData = {
- projection: "EPSG:4326",
- bounds: OpenLayers.Bounds.fromString(field.value)
- };
- });
- };
- // helper function to create a literal input textfield or dropdown
- priv.addLiteralInput = function(input, previousSibling) {
- var name = input.identifier;
- var container = _nodeInput.get(0);
- var anyValue = input.literalData.anyValue;
- // anyValue means textfield, otherwise we create a dropdown
- var field = document.createElement(anyValue ? "input" : "select");
- field.id = name;
- field.title = input["abstract"];
- previousSibling && previousSibling.nextSibling ?
- container.insertBefore(field, previousSibling.nextSibling) :
- container.appendChild(field);
- if (anyValue) {
- var dataType = input.literalData.dataType;
- field.value = name + (dataType ? " (" + dataType + ")" : "");
- priv.addValueHandlers(field, function() {
- input.data = field.value ? {
- literalData: {
- value: field.value
- }
- } : undefined;
- priv.createCopy(input, field, priv.addLiteralInput);
- });
- } else {
- var option;
- option = document.createElement("option");
- option.innerHTML = name;
- field.appendChild(option);
- for (var v in input.literalData.allowedValues) {
- option = document.createElement("option");
- option.value = v;
- option.innerHTML = v;
- field.appendChild(option);
- }
- field.onchange = function() {
- priv.createCopy(input, field, priv.addLiteralInput);
- input.data = this.selectedIndex ? {
- literalData: {
- value: this.options[this.selectedIndex].value
- }
- } : undefined;
- };
- }
- };
- // if maxOccurs is > 1, this will add a copy of the field
- priv.createCopy = function(input, field, fn) {
- if (input.maxOccurs && input.maxOccurs > 1 && !field.userSelected) {
- // add another copy of the field - we don't check maxOccurs
- field.userSelected = true;
- var newInput = OpenLayers.Util.extend({}, input);
- // we recognize copies by the occurrence property
- newInput.occurrence = (input.occurrence || 0) + 1;
- _process.dataInputs.push(newInput);
- fn(newInput, field);
- }
- };
- // helper function for adding events to form fields
- priv.addValueHandlers = function(field, onblur) {
- field.onclick = function() {
- if (!this.initialValue) {
- this.initialValue = this.value;
- this.value = "";
- }
- };
- field.onblur = function() {
- if (!this.value) {
- this.value = this.initialValue;
- delete this.initialValue;
- }
- onblur.apply(this, arguments);
- };
- };
- // execute the process
- priv.execute = function() {
- var output = _process.processOutputs[0];
- var input;
- // remove occurrences that the user has not filled out
- for (var i = _process.dataInputs.length - 1; i >= 0; --i) {
- input = _process.dataInputs[i];
- if ((input.minOccurs === 0 || input.occurrence) && !input.data && !input.reference) {
- OpenLayers.Util.removeItem(_process.dataInputs, input);
- }
- }
- _process.responseForm = {
- rawDataOutput: {
- identifier: output.identifier
- }
- };
- if (output.complexOutput && output.complexOutput.supported.formats["application/wkt"]) {
- _process.responseForm.rawDataOutput.mimeType = "application/wkt";
- }
- OpenLayers.Request.POST({
- url: priv.options.wpsUrl,
- data: new OpenLayers.Format.WPSExecute().write(_process),
- success: priv.showOutput
- });
- }
- // add the process's output to the page
- priv.showOutput = function(response) {
- var result = _nodeOutput.get(0);
- result.innerHTML = "<h3>Output:</h3>";
- var features;
- var contentType = response.getResponseHeader("Content-Type");
- if (contentType == "application/wkt") {
- features = new OpenLayers.Format.WKT().read(response.responseText);
- } else if (contentType == "text/xml; subtype=wfs-collection/1.0") {
- features = new OpenLayers.Format.WFST.v1_0_0().read(response.responseText);
- }
- if (features && (features instanceof OpenLayers.Feature.Vector || features.length)) {
- _layer.addFeatures(features);
- result.innerHTML += "The result should also be visible on the map.";
- }
- result.innerHTML += "<textarea>" + response.responseText + "</textarea>";
- }
- publ.updateSize = function() {
- _map.updateSize();
- };
- publ.refresh = function(options) {
- if (priv.options.debug) console.log('publ.refresh ... ', options);
- _layer.refresh({force:true});
- };
- publ.zoomToExtent = function(extent) {
- if (!extent) return;
- var sourceProj = new OpenLayers.Projection("EPSG:4326");
- var targetProj = _map.getProjectionObject();
- var extentBounds = OpenLayers.Geometry.fromWKT(extent).transform(sourceProj, targetProj).getBounds();
- _map.zoomToExtent(extentBounds);
- };
- publ.selectRecord = function(recordId, extent) {
- if (priv.isSelectedRecordId()) {
- if (priv.getSelectedRecordId() != recordId) {
- if (priv.isSelectedFeature()) {
- if (confirm('Aktualnie przypisany rekord to ' + priv.getSelectedRecordId() + ' czy zmienić na ' + recordId + '?')) {
- priv.setSelectedRecordId(recordId);
- priv.changeSelectedFeatureRecordId(recordId);
- }
- } else {
- priv.setSelectedRecordId(recordId);
- publ.zoomToExtent(extent);
- }
- } else {
- publ.zoomToExtent(extent);
- }
- }
- else {
- priv.setSelectedRecordId(recordId);
- publ.zoomToExtent(extent);
- }
- };
- publ.init = function(options) {
- if (priv.options.debug) console.log('TableAjaxMap initialization...', options);
- //merge supplied options with defaults
- $.extend(priv.options, defaults, options);
- priv.init();
- return publ;
- };
- return publ;
- };
- $.fn.TableAjaxMapUpdateSize = function(options) {
- options = options || {};
- return this.each(function() {
- var tblAjaxMap = $(this).data('TableAjaxMap');
- if (tblAjaxMap) {
- tblAjaxMap.updateSize();
- }
- });
- return this;
- };
- $.fn.TableAjaxMapRefresh = function(options) {
- options = options || {};
- return this.each(function() {
- var tblAjaxMap = $(this).data('TableAjaxMap');
- if (tblAjaxMap) {
- tblAjaxMap.refresh(options);
- }
- });
- return this;
- };
- $.fn.TableAjaxMapZoomToExtent = function(extent) {
- if (!extent) return;
- return this.each(function() {
- var tblAjaxMap = $(this).data('TableAjaxMap');
- if (tblAjaxMap) {
- tblAjaxMap.zoomToExtent(extent);
- }
- });
- return this;
- };
- $.fn.TableAjaxMapSelectRecord = function(recordId, extent) {
- if (!recordId) return;
- return this.each(function() {
- var tblAjaxMap = $(this).data('TableAjaxMap');
- if (tblAjaxMap) {
- tblAjaxMap.selectRecord(recordId, extent);
- }
- });
- return this;
- };
- $.fn.TableAjaxMap = function(options) {
- options = options || {};
- return this.each(function() {
- options.id = this;
- if (!$(this).data('TableAjaxMap')) {
- $(this).data('TableAjaxMap', new TableAjaxMap().init(options));
- }
- });
- return this;
- };
- }(jQuery));
- </script>
- <?php
- }
- public function ajaxTask($task) {
- switch ($task) {
- case 'PROXY': {
- $this->sendAjaxProxy($_REQUEST);
- break;
- }
- default:
- //$this->sendAjaxData($_REQUEST);
- }
- }
- public function sendAjaxProxy($args) {
- $url = V::get('url', '', $args);
- // 1. http%3A%2F%2Fbiuro.biall-net.pl%2Fwps%3FSERVICE%3DWPS%26REQUEST%3DGetCapabilities
- // 2. http%3A%2F%2Fbiuro.biall-net.pl%2Fwps%3FSERVICE%3DWPS%26REQUEST%3DDescribeProcess%26VERSION%3D1.0.0%26IDENTIFIER%3Dpozdrawiam
- header('Content-Type: application/xml; charset=utf-8');
- $urlParts = parse_url($url);
- $urlQuery = array();
- $urlQueryTmp = V::get('query', '', $urlParts);
- $urlQueryTmp = explode('&', $urlQueryTmp);
- foreach ($urlQueryTmp as $vQuery) {
- $parts = explode('=', $vQuery, 2);
- $urlQuery[$parts[0]] = $parts[1];
- }
- $wpsServer = new TableAjaxMapWpsServer($this->_acl);
- if ('WPS' == V::get('SERVICE', '', $urlQuery)) {
- $req = V::get('REQUEST', '', $urlQuery);
- $methodName = "{$req}Action";
- if (method_exists($wpsServer, $methodName)) {
- $wpsServer->$methodName($urlQuery);
- }
- }
- else {
- $wpsServer->parseXMLRequest();
- }
- exit;
- }
- }
- class TableAjaxMapWfsAction {
- private $_acl;
- private $_zasobID;
- public function __construct($acl) {
- $this->_acl = $acl;
- $this->_zasobID = $acl->getID();
- }
- /**
- * example: MULTIPOLYGON(((2072016.74395199 7234076.79293037,2072016.74395199 7234115.01144451,2072131.3994944 7234115.01144451,2072131.3994944 7234076.79293037,2072016.74395199 7234076.79293037)))
- */
- public function generateGmlFromWKT($wkt) {
- $gml = '';
- $wktParts = explode('(', $wkt, 2);
- ob_start();
- switch ($wktParts[0]) {
- case 'MULTIPOLYGON':
- case 'POLYGON': {
- $points = trim($wktParts[1], '() ');
- $points = str_replace(',', "\n", $points);
- ?>
- <gml:boundedBy>
- <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
- <gml:lowerCorner>-180 -90</gml:lowerCorner>
- <gml:upperCorner>180 90</gml:upperCorner>
- </gml:Envelope>
- </gml:boundedBy>
- <og:the_geom>
- <gml:MultiSurface srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
- <gml:surfaceMember>
- <gml:Polygon srsDimension="2">
- <gml:exterior>
- <gml:LinearRing srsDimension="2">
- <gml:posList>
- <?php echo $points; ?>
- </gml:posList>
- </gml:LinearRing>
- </gml:exterior>
- </gml:Polygon>
- </gml:surfaceMember>
- </gml:MultiSurface>
- </og:the_geom>
- <?php
- }
- break;
- case 'POINT':
- case 'MULTIPOINT': {
- $points = trim($wktParts[1], '() ');
- $points = str_replace(',', "\n", $points);
- // <gml:pos>45.67 88.56</gml:pos>
- // <gml:gml:coordinates>45.67, 88.56</gml:coordinates>
- ?>
- <gml:boundedBy>
- <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
- <gml:lowerCorner>-180 -90</gml:lowerCorner>
- <gml:upperCorner>180 90</gml:upperCorner>
- </gml:Envelope>
- </gml:boundedBy>
- <gml:Point srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
- <gml:pos><?php echo $points; ?></gml:pos>
- </gml:Point>
- <?php
- }
- break;
- case 'LINESTRING': {
- $points = trim($wktParts[1], '() ');
- $points = str_replace(',', "\n", $points);
- ?>
- <gml:boundedBy>
- <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
- <gml:lowerCorner>-180 -90</gml:lowerCorner>
- <gml:upperCorner>180 90</gml:upperCorner>
- </gml:Envelope>
- </gml:boundedBy>
- <gml:LineString srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
- <gml:posList><?php echo $points; ?></gml:posList>
- </gml:LineString>
- <?php
- }
- break;
- default:
- ?>
- <!-- UNKNOWN WKT:<?php echo $wkt; ?> -->
- <?php
- }
- $gml = ob_get_contents();
- ob_clean();
- return $gml;
- }
- public function execute($args) {
- /*
- * Mapa odczytywanie punktów: http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/
- *
- * CI50:
- 18.613243103027344 54.33614429135817
- 18.613243103027344 54.33634445792519
- 18.614273071289062 54.33634445792519
- 18.614273071289062 54.33614429135817
- */
- Lib::loadClass('Data_Source');
- $dataSource = new Data_Source($this->_acl->getDB());
- $dataSource->setTable($this->_acl->getName());
- $dataSource->addCol('ID');
- $dataSource->addCol('the_geom');
- $dataSource->setColTypes($this->_acl->getTypes());
- $params = array();
- $params['limit'] = 1000;
- if (!empty($args['BBOX'])) {
- $params['f_the_geom'] = 'BBOX:' . implode(',', $args['BBOX']);
- }
- $items = $dataSource->getItems($params);
- $buildingsGml = array();
- foreach ($items as $r) {
- if (!empty($r->the_geom)) {
- $buildingsGml[$r->ID] = $this->generateGmlFromWKT($r->the_geom);
- }
- }
- /**
- * <og:recordId><?php echo $kId; ?></og:recordId>
- * <og:tblId><?php echo $tblId; ?></og:tblId>
- *
- * goes to js: @see priv.addWKTInput _layer.selectedFeatures[0]
- *
- * attributes: Object
- recordId: "1130"
- tblId: "16"
- */
- echo '<?xml version="1.0" encoding="UTF-8"?>';
- ?>
- <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&version=1.1.0&request=DescribeFeatureType&typeName=og%3Arestricted http://www.opengis.net/wfs http://demo.opengeo.org:80/geoserver/schemas/wfs/1.1.0/wfs.xsd">
- <gml:boundedBy>
- <gml:Envelope srsDimension="2" srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
- <gml:lowerCorner>-180 -90</gml:lowerCorner>
- <gml:upperCorner>180 90</gml:upperCorner>
- </gml:Envelope>
- </gml:boundedBy>
- <gml:featureMembers>
- <?php foreach ($buildingsGml as $kId => $vGml) : ?>
- <og:restricted gml:id="restricted.<?php echo $kId; ?>">
- <?php echo $vGml; ?>
- <og:recordId><?php echo $kId; ?></og:recordId>
- <og:tblId><?php echo $this->_zasobID; ?></og:tblId>
- </og:restricted>
- <?php endforeach; ?>
- </gml:featureMembers>
- </wfs:FeatureCollection>
- <?php
- }
- }
- class WpsActionBase {
- public $title = '';
- public $description = '';
- public $dataInputs = array();
- public function execute($args) {
- var_dump($args);
- }
- }
- class WpsActionPrzypiszDoRekordu extends WpsActionBase {
- public function __construct() {
- $this->title = 'Przypisz';
- $this->description = 'Przypisuje położenie do wybranego rekordu w tabeli.';
- $this->dataInputs['geom'] = new stdClass();
- $this->dataInputs['geom']->title = 'geom';
- $this->dataInputs['geom']->description = 'Input geometry';
- $this->dataInputs['geom']->type = 'geom';// CoomplexData
- $this->dataInputs['idTable'] = new stdClass();
- $this->dataInputs['idTable']->title = 'geom';
- $this->dataInputs['idTable']->description = 'Table ID';
- $this->dataInputs['idTable']->type = 'integer';// LiteralData: xs:integer
- $this->dataInputs['idRecord'] = new stdClass();
- $this->dataInputs['idRecord']->title = 'idRecord';
- $this->dataInputs['idRecord']->description = 'Record ID';
- $this->dataInputs['idRecord']->type = 'integer';// LiteralData: xs:integer
- }
- }
- class TableAjaxMapWpsServer {
- private $_fun;// config for identifiers
- private $_wfsAction;
- private $_zasobID;
- private $_acl;
- public function __construct($acl) {
- $this->_fun['przypiszDoRekordu'] = new WpsActionPrzypiszDoRekordu();
- $this->_acl = $acl;
- $this->_zasobID = $acl->getID();
- $this->_wfsAction = new TableAjaxMapWfsAction($this->_acl);
- }
- public function parseXMLRequest() {
- $data = array();
- $reqContent = file_get_contents('php://input');
- $xml = new SimpleXMLElement($reqContent);
- if ('GetFeature' == $xml->getName()) {
- // TODO: parse xml and set query params
- /*
- <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&typename=og:restricted">
- <wfs:Query typeName="feature:restricted" srsName="EPSG:4326" xmlns:feature="http://opengeo.org">
- <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
- <ogc:BBOX>
- <ogc:PropertyName>the_geom</ogc:PropertyName>
- <gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
- <gml:lowerCorner>17.226562502593 53.887024366231</gml:lowerCorner>
- <gml:upperCorner>20.039062502593 54.847089981191</gml:upperCorner>
- </gml:Envelope>
- </ogc:BBOX>
- </ogc:Filter>
- </wfs:Query>
- </wfs:GetFeature>
- */
- $corners = null;
- $xmlTag = $xml->children("wfs", TRUE)->Query;
- if (!empty($xmlTag)) {
- $xmlTag = $xmlTag->children("ogc", TRUE)->Filter;
- if (!empty($xmlTag)) {
- $xmlTag = $xmlTag->BBOX;
- if (!empty($xmlTag)) {
- $xmlTag = $xmlTag->children("gml", TRUE)->Envelope;
- if (!empty($xmlTag)) {
- $corners = (object)array('lowerCorner' => (string)$xmlTag->lowerCorner, 'upperCorner' => (string)$xmlTag->upperCorner);
- }
- }
- }
- }
- if ($corners) {
- $lowerCorner = (string) $corners->lowerCorner;
- $upperCorner = (string) $corners->upperCorner;
- $lowerCorner = explode(" ", trim($lowerCorner));
- $upperCorner = explode(" ", trim($upperCorner));
- if (count($lowerCorner) == 2 && count($upperCorner) == 2) {
- $points = array();
- $points[] = $upperCorner[1];// top
- $points[] = $upperCorner[0];// right
- $points[] = $lowerCorner[1];// bottom
- $points[] = $lowerCorner[0];// left
- $isAllNumeric = true;
- foreach ($points as $point) {
- if (!is_numeric($point)) $isAllNumeric = false;
- }
- if ($isAllNumeric) {
- $data['BBOX'] = $points;
- }
- }
- } else {
- // inna struktura xml'a
- }
- $this->_wfsAction->execute($data);
- }
- else if (isset($xml->children('ows', TRUE)->Identifier)) {
- $identifier = (string)$xml->children('ows', TRUE)->Identifier;
- if (array_key_exists($identifier, $this->_fun)) {
- foreach ($xml->children('wps', TRUE)->DataInputs->children('wps', TRUE) as $input) {
- $inputIdentifier = (string)$input->children('ows', TRUE)->Identifier;
- if (array_key_exists($inputIdentifier, $this->_fun[$identifier]->dataInputs)) {
- $inputType = (string)$this->_fun[$identifier]->dataInputs[$inputIdentifier]->type;
- switch ($inputType) {
- case 'integer':
- $data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->LiteralData;
- break;
- case 'geom':
- $data[$inputIdentifier] = (string)$input->children('wps', TRUE)->Data->ComplexData;
- break;
- default:
-
- }
- } else {
- // brak zdefiniowanego inputa
- }
- }
- $this->_fun['przypiszDoRekordu']->execute($data);
- } else {
- echo "TODO: brak zdefiniowanej funkcji '{$identifier}'";
- var_dump($identifier);
- }
- }
- else {
- echo "TODO: '" . $xml->getName() . "' ...";
- }
- }
- public function getCapabilitiesAction() {
- echo '<?xml version="1.0" encoding="UTF-8"?>';
- ?>
- <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">
- <ows:ServiceIdentification>
- <ows:Title>Prototype GeoServer WPS</ows:Title>
- <ows:Abstract />
- <ows:Keywords>
- <ows:Keyword>wps</ows:Keyword>
- <ows:Keyword>geoserver</ows:Keyword>
- </ows:Keywords>
- <ows:ServiceType>WPS</ows:ServiceType>
- <ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>
- <ows:Fees>NONE</ows:Fees>
- <ows:AccessConstraints>NONE</ows:AccessConstraints>
- </ows:ServiceIdentification>
- <ows:ServiceProvider>
- <ows:ProviderName>GeoServer</ows:ProviderName>
- <ows:ProviderSite />
- <ows:ServiceContact />
- </ows:ServiceProvider>
- <ows:OperationsMetadata>
- <ows:Operation name="GetCapabilities">
- <ows:DCP>
- <ows:HTTP>
- <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
- <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
- </ows:HTTP>
- </ows:DCP>
- </ows:Operation>
- <ows:Operation name="DescribeProcess">
- <ows:DCP>
- <ows:HTTP>
- <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
- <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
- </ows:HTTP>
- </ows:DCP>
- </ows:Operation>
- <ows:Operation name="Execute">
- <ows:DCP>
- <ows:HTTP>
- <ows:Get xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
- <ows:Post xlink:href="http://demo.opengeo.org:80/geoserver/wps" />
- </ows:HTTP>
- </ows:DCP>
- </ows:Operation>
- </ows:OperationsMetadata>
- <wps:ProcessOfferings>
- <?php foreach($this->_fun as $kFun => $vFun) : ?>
- <wps:Process wps:processVersion="1.0.0">
- <ows:Identifier><?php echo $kFun; ?></ows:Identifier>
- <ows:Title><?php echo $vFun->title; ?></ows:Title>
- <ows:Abstract><?php echo $vFun->description; ?></ows:Abstract>
- </wps:Process>
- <?php endforeach; ?>
- </wps:ProcessOfferings>
- <wps:Languages>
- <wps:Default>
- <ows:Language>en-US</ows:Language>
- </wps:Default>
- <wps:Supported>
- <ows:Language>en-US</ows:Language>
- </wps:Supported>
- </wps:Languages>
- </wps:Capabilities>
- <?php
- }
- public function describeProcessAction($args) {
- // TODO: xml z opiesem procese $args['IDENTIFIER']
- /**
- * should work like JTS:densify - geom field (map object) and integer field (record ID)
- * 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
- * http://demo.opengeo.org/geoserver/wps?SERVICE=WPS&REQUEST=DescribeProcess&VERSION=1.0.0&IDENTIFIER=JTS%3Adensify
- */
- echo '<?xml version="1.0" encoding="UTF-8"?>';
- if (array_key_exists($args['IDENTIFIER'], $this->_fun)) {
- $identifier = $this->_fun[$args['IDENTIFIER']];
- ?>
- <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">
- <ProcessDescription wps:processVersion="1.0.0" statusSupported="true" storeSupported="true">
- <ows:Identifier><?php echo $args['IDENTIFIER']; ?></ows:Identifier>
- <ows:Title><?php echo $identifier->title; ?></ows:Title>
- <ows:Abstract><?php echo $identifier->description; ?></ows:Abstract>
- <DataInputs>
- <?php foreach ($identifier->dataInputs as $kInput => $vInput) : ?>
- <Input maxOccurs="1" minOccurs="1">
- <ows:Identifier><?php echo $kInput; ?></ows:Identifier>
- <ows:Title><?php echo $vInput->title; ?></ows:Title>
- <ows:Abstract><?php echo $vInput->description; ?></ows:Abstract>
- <?php if ($vInput->type == 'geom') : ?>
- <ComplexData>
- <Default>
- <Format>
- <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
- </Format>
- </Default>
- <Supported>
- <Format>
- <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
- </Format>
- <Format>
- <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
- </Format>
- <Format>
- <MimeType>application/wkt</MimeType>
- </Format>
- <Format>
- <MimeType>application/gml-3.1.1</MimeType>
- </Format>
- <Format>
- <MimeType>application/gml-2.1.2</MimeType>
- </Format>
- </Supported>
- </ComplexData>
- <?php elseif ($vInput->type == 'integer') : ?>
- <LiteralData>
- <ows:DataType>xs:integer</ows:DataType>
- <ows:AnyValue />
- </LiteralData>
- <?php else : ?>
- <?php endif; ?>
- </Input>
- <?php endforeach; ?>
- </DataInputs>
- <ProcessOutputs>
- <Output>
- <ows:Identifier>result</ows:Identifier>
- <ows:Title>result</ows:Title>
- <ComplexOutput>
- <Default>
- <Format>
- <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
- </Format>
- </Default>
- <Supported>
- <Format>
- <MimeType>text/xml; subtype=gml/3.1.1</MimeType>
- </Format>
- <Format>
- <MimeType>text/xml; subtype=gml/2.1.2</MimeType>
- </Format>
- <Format>
- <MimeType>application/wkt</MimeType>
- </Format>
- <Format>
- <MimeType>application/gml-3.1.1</MimeType>
- </Format>
- <Format>
- <MimeType>application/gml-2.1.2</MimeType>
- </Format>
- </Supported>
- </ComplexOutput>
- </Output>
- </ProcessOutputs>
- </ProcessDescription>
- </wps:ProcessDescriptions>
- <?php
- } else {
- echo 'TODO: brak funkcji';
- }
- }
- }
|