Jesus Loves GRASS

Technical blog about GRASS/GIS,open source geoinformatics and MAPSERVER.

Friday, April 20, 2007

OWS_request

The Legend is static and is drawn at the start up so I couldn't make a link in the download icon making a specific WxS request.

The solution was a javascript function that is called when the icon is pressed. This function will get the service and the name of the layer, later it will request adicional information (getDescription) so that a proper WxC can be performed.

After getting all the information the functions opens a window and calls a PHP file (passing by GET all the information for the WxS). The new pop-up will have all the values hidden inside a form. When the user click on "submit" the final WxS will be performed. The pop-up also containes a table with all the information on the request

function OWS_request (OWS_name, OWS_service) {
//example of request
//ows.php?service=srtm10x&request=getCoverage&COVERAGE=srtm10x+&CRS=epgs:4326&BBOX=41,75,45,50&RESX=0.00833&RESY=0.00833&FORMAT=GEOTIFFINT16';


//Creation of the XTMLHTTP object and request of information coverage
request=new getXMLHTTP()
var URL='ows.php?service=WCS&request=describeCoverage&coverage='+OWS_name;
request.open ('GET',URL,false) ; //wait for response
request.send(null);
var xmldoc=request.responseXML;
//necessary info: CRS,RESX,RESY,FORMAT,BBOX the name is alreay given
//the XML programming was from the AJAX for Dummies
//for example the tag gml:offsetVector has the name offsetVector the GML is nothing
var CRSnode=xmldoc.getElementsByTagName("requestResponseCRSs");
var CRS=CRSnode[0].firstChild.nodeValue;
var RESnode=xmldoc.getElementsByTagName("offsetVector");
var sRESX=RESnode[0].firstChild.nodeValue;
var RESX=sRESX.split(" "); //array with resx in this case the first value is the important one
var sRESY=RESnode[1].firstChild.nodeValue;
var RESY=sRESY.split(" ");
var FORMATnode=xmldoc.getElementsByTagName("formats");
var FORMAT=FORMATnode[0].firstChild.nodeValue;

/*The BBOX comes from the getGeoExtents, were it is defined that
gminx=minx;
gmaxx=maxx;
gmaxy=maxy;
gminy=miny;

These are golbal variables, so no problem to access them, also they are always changed according to the events of kamap

BBOX = lower left (min x, min y) and upper right (max x, max y)
*/
var BBOX = new Array(gminx,gminy,gmaxx,gmaxy);

//creation of the URL that passes the information to the popup.php
//note: RESY fix in the string (it canot be negative)
var url_str='popup.php?service='+OWS_service+'&request=getCoverage&COVERAGE='+OWS_name+'&CRS='+CRS+'&BBOX='+BBOX.join(",")+'&RESX='+RESX[0]+'&RESY='+(-1*parseFloat(RESY[1]))+'&FORMAT='+FORMAT;

//open window
var window_popup=window.open(url_str,null,"height=300,width=375");
};

Labels: , ,

0 Comments:

Post a Comment

<< Home