JorgeDeJesus

Untitled

Oct 21st, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2.   <head>
  3.     <title>OpenLayers-Controls in Panels organisieren</title>
  4.     <style type="text/css">
  5.         .olControlPanel {
  6.           left: 50px;
  7.           top: 3px
  8.         }
  9.         .olControlPanel div {
  10.                   display:block;
  11.                   width: 35px;
  12.                   height: 35px;
  13.                   margin: 5px;
  14.         }
  15.    
  16.         .olControlPanel .singleActionButtonItemActive {
  17.           background-image: url(GhostAlphaDc3.gif);
  18.         }
  19.         .olControlPanel .singleActionButtonItemInactive {
  20.           background-image: url(GhostAlphaDc3.gif);
  21.         }
  22.  
  23.         .olControlPanel .conversionButtonItemActive {
  24.           background-image: url(GhostAlphaLc0.gif);
  25.         }
  26.         .olControlPanel .conversionButtonItemInactive {
  27.           background-image: url(GhostAlphaLc0.gif);
  28.         }
  29.  
  30.  
  31.     </style>
  32.    <script src="http://openlayers.org/dev/OpenLayers.js"></script>
  33.  
  34.     <script src="OpenLayers.Control.Click.js"></script>
  35.     <script src="WPS.js"></script>
  36.     <script type="text/javascript">
  37.  
  38.        
  39.     var map, button, panel, wpsObj, urlWPS, vlayer,inputTiff,imagelayer;
  40.     inputTiff = "http://photojournal.jpl.nasa.gov/tiff/PIA17427.tif"
  41.  
  42.     //var urlWPS = "http://localhost/cgi-bin/pywps.cgi";
  43.     var urlWPS= "http://localhost/wps/pywps.cgi";
  44.     vlayer = new OpenLayers.Layer.Vector("Editable Layer");
  45.  
  46.     var wpsCaller2 = function callWPS2() {
  47.        try {
  48.           wpsObj = new OpenLayers.WPS(urlWPS,{onGotCapabilities: onGetCapabilities,onSucceeded: onExecuted2, onFailed: onError2});
  49.           alert("WPS instance created successfully");
  50.           console.log("wpsCaller2")
  51.        } catch (e) {
  52.           alert("Error while creating WPS instance");
  53.        }
  54.  
  55.        try {
  56.           var geotiff = new OpenLayers.WPS.ComplexPut({identifier: "geotiff", asReference:true, format:{mimeType:'image/tiff'}, value: inputTiff});
  57.           var jpeg = new OpenLayers.WPS.ComplexPut({identifier: "jpeg", asReference: true, format:{mimeType:'image/jpeg'}});
  58.           alert("Input set successfully");
  59.        } catch (e) {
  60.           alert("Error while setting input");
  61.        }
  62.  
  63.        try {
  64.           var conversionprocess = new OpenLayers.WPS.Process({
  65.              identifier: "imageconvert",
  66.              inputs: [geotiff],
  67.              outputs: [jpeg]
  68.           });
  69.           console.log(conversionprocess);
  70.           wpsObj.addProcess(conversionprocess);
  71.          
  72.           wpsObj.execute("imageconvert");
  73.           alert("Process added to WPS successfully");
  74.        } catch (e) {
  75.           alert("Error while adding process to WPS and execute");
  76.        }
  77.  
  78.  
  79.     }
  80.  
  81.     function onGetCapabilities(){
  82.         console.log(wpsObj)
  83.     }
  84.  
  85.     function onExecuted2(process) {
  86.        
  87.        resultURL = process.getOutput("jpeg").value;
  88.        console.log(resultURL)
  89.        console.log("preparing jpeg")
  90.        //ACHTUNG !!!! NOT LAT LONG BUT SPHERICAL MERCATOR
  91.        var imagelayer = new OpenLayers.Layer.Image(
  92.                'Raster Output',
  93.                resultURL,
  94.                map.getExtent(),
  95.                new OpenLayers.Size(540, 270),
  96.                {
  97.                    isBaseLayer: false,
  98.                    opacity: 0.3,
  99.                    displayOutsideMaxExtend: true
  100.                }
  101.        );
  102.        map.addLayer(imagelayer);       
  103.        outstring = "";
  104.        outstring += "Der Prozess "+process.identifier+" wurde erfolgreich ausgefuehrt";
  105.        console.log(outstring);
  106.     }
  107.  
  108.     function onError2(process) {
  109.        textData="Error Code: "+process.exception.code+"<br />"+"Text: "+process.exception.text;
  110.        alert(textData);
  111.     }
  112.  
  113.  
  114.     var wpsCaller = function callWPS() {
  115.        try {
  116.           wpsObj = new OpenLayers.WPS(urlWPS,{onSucceeded: onExecuted, onFailed: onError});
  117.           alert("WPS instance created successfully");
  118.        } catch (e) {
  119.           alert("Error while creating WPS instance");
  120.        }
  121.  
  122.        try {
  123.           var inputdata = new OpenLayers.WPS.ComplexPut({identifier: "data", value: OpenLayers.Format.GML.prototype.write(vlayer.features), asReference:false, format:{mimeType:'text/xml', schema:'http://schemas.opengis.net/gml/2.1.2/feature.xsd', encoding: 'UTF8'}});
  124.           var inputsize = new OpenLayers.WPS.LiteralPut({identifier: "size", value: 0.1});
  125.           var output = new OpenLayers.WPS.ComplexPut({identifier: "buffer", asReference: true, format:{mimeType:'text/xml', schema: 'http://schemas.opengis.net/gml/2.1.2/feature.xsd', encoding: 'UTF-8'}});
  126.           alert("Input set successfully");
  127.        } catch (e) {
  128.           alert("Error while setting input");
  129.        }
  130.  
  131.        try {
  132.           var bufferprocess = new OpenLayers.WPS.Process({
  133.              identifier: "buffer2",
  134.              inputs: [inputdata, inputsize],
  135.              outputs: [output]
  136.           });
  137.  
  138.           wpsObj.addProcess(bufferprocess);
  139.           alert("Process added to WPS and executed successfully");
  140.        } catch (e) {
  141.           alert("Error while adding process to WPS and execute");
  142.        }
  143.        
  144.        wpsObj.execute("buffer2");
  145.     }
  146.  
  147.     function onExecuted(process) {
  148.        resultURL = process.getOutput("buffer").value;
  149.        var buffLayer = new OpenLayers.Layer.GML("Buffered Features", resultURL);
  150.        map.addLayer(buffLayer);
  151.        outstring = "";
  152.        outstring += "Der Prozess "+process.identifier+" wurde erfolgreich ausgefuehrt";
  153.        alert(outstring);
  154.     }
  155.  
  156.     function onError(process) {
  157.        textData="Error Code: "+process.exception.code+"<br />"+"Text: "+process.exception.text;
  158.        alert(textData);
  159.     }
  160.  
  161.     function init() {
  162.        map = new OpenLayers.Map( 'map' );
  163.        var osm = new OpenLayers.Layer.OSM();
  164.        map.addLayers([osm, vlayer]);
  165.  
  166.        button = new OpenLayers.Control.Button({
  167.           displayClass: 'singleActionButton',
  168.           trigger: wpsCaller,
  169.           title: 'Create buffer around features of editable layer'
  170.        });
  171.  
  172.        button2 = new OpenLayers.Control.Button({
  173.           displayClass: 'conversionButton',
  174.           trigger: wpsCaller2,
  175.           title: 'Convert GeoTIFF to JPEG'
  176.        });
  177.  
  178.  
  179.        panel = new OpenLayers.Control.Panel({defaultControl: button});
  180.        panel.addControls([
  181.           button,
  182.           button2
  183.        ]);
  184.  
  185.        map.addControl( panel );
  186.  
  187.        editTb = new OpenLayers.Control.EditingToolbar(vlayer);
  188.        ls = new OpenLayers.Control.LayerSwitcher();
  189.        map.addControl(editTb);
  190.        map.addControl(ls);
  191.  
  192.        map.zoomToMaxExtent();
  193.     }
  194.  
  195.     </script>
  196.   </head>
  197.   <body onload="init();">
  198.     <h1>OpenLayers-Controls in Panels organisieren</h1>
  199.     <div
  200.       id="map"
  201.       style="width:1024px; height:512px; border:3px solid #000">
  202.     </div>
  203.   </body>
  204. </html>
Advertisement
Add Comment
Please, Sign In to add comment