
var crscache=[];
var errorOnWCTS=false;
var SRS="";
var srsname="";
function getUOM(xmlDoc){
var luom="meters";
if(typeof xmlDoc.getElementsByTagNameNS!='undefined'){
x=xmlDoc.getElementsByTagNameNS("http://www.opengis.net/gml","CoordinateSystemAxis");
}
else{
x=xmlDoc.getElementsByTagName("gml:CoordinateSystemAxis");
}
for(var j=0;j<x.length;j++){
var gmluom;
if(typeof x[0].getAttributeNS!='undefined'){
gmluom=x[0].getAttributeNS('http://www.opengis.net/gml','uom');
}
else{
gmluom=x[0].getAttribute('gml:uom');
}
if(gmluom){
var deg=/degree/g;
var fet=/feet/g;
var fot=/foot/g;
var degrees=gmluom.match(deg);
var feet=gmluom.match(fet);
var foot=gmluom.match(fot);
if(degrees){
luom="degrees";
}
if(feet||foot){
luom="feet";
}
}
}
return luom;
}
function showSRSName(doc,really,sc){
top.srsname=getSRSName(doc);
top.uom=getUOM(doc);
crs[sc]=new CRS(top.srsname,top.uom);
if(really){
if(!top.srsname)top.srsname=top.SRS;
var doc;
if(top.main)doc=top.main.document;
else doc=document;
var srsout=doc.getElementById('activeSRS');
if(srsout){
srsout.innerHTML=srsname;
}
var coor=doc.getElementById('coords');
if(coor){
coor.title=srsname;
}
}
}
function getSRSName(xmlDoc){
var x;
var srsname="";
if(typeof xmlDoc.getElementsByTagNameNS!='undefined'){
x=xmlDoc.getElementsByTagNameNS("http://www.opengis.net/gml","srsName");
}
else{
x=xmlDoc.getElementsByTagName("gml:srsName");
}
if(x.length){
srsname=x[0].firstChild.nodeValue;
}
return srsname;
}
function CRS(title,uom){
this.title=title;
this.uom=uom;
this.toString=CRSout;
}
function CRSout(){
return("title:"+this.title+" uom:"+this.uom);
}
var crs=[];
function convertCRS(cra){
var newCRS="urn:ogc:def:crs:";
var crsa=cra.replace("EPSG","EPSG:6.0");
var crsb=crsa.replace("CRS:","OGC:1.3:CRS");
var crsc=crsb.replace("AUTO2:","OGC:1.3:AUTO");
var crsd=crsc.replace("AUTO42001","AUTO42001:99:8888");
var crse=crsd.replace("AUTO42002","AUTO42002:99:8888");
var crsf=crse.replace("AUTO42003","AUTO42003:99:8888");
var crsg=crsf.replace("AUTO42004","AUTO42004:99:8888");
var crsh=crsg.replace("AUTO42005","AUTO42005:99");
var crsi=crsh.replace("MicroImages","MicroImages:1.0");
newCRS+=crsi;
return newCRS;
}
function DescribeCRS(getcapurl,cra,setting){
if(top.standalone&&top.wctsurl==""){
createIni();
}
if(!cra||cra.indexOf('AUTO')!=-1||cra.indexOf("none")!=-1||cra.indexOf("NONE")!=-1){
return;
}
var sc=cra.replace(":","");
if(setting){
var srsout;
if(top.main){
srsout=top.main.document.getElementById('activeSRS');
}
else{
srsout=document.getElementById('activeSRS');
}
if(srsout)srsout.innerHTML=cra;
if(cra=="EPSG:4326"||cra=="CRS:84"){
top.uom="degrees";
top.srsname="WGS84 / Geographic";
if(srsout)srsout.innerHTML=top.srsname;
}
if(top.crs[sc]){
top.srsname=top.crs[sc].title;
top.uom=top.crs[sc].uom;
}
}
if(typeof top.crs[sc]=="undefined"){
var xml=crscache[sc];
if(xml){
if(top.SRS==cra){
showSRSName(xml,true,sc);
}
}
else{
var wctsurl=top.wctsurl;
if(top.isTNT&&top.useSrcServer)wctsurl=wmsurl;
fullurl=fixUrlEnd(wctsurl)+"request=DescribeCRS&service=WCTS&version=0.3.0";
fullurl+="&CRSs="+convertCRS(cra);
if(!top.standalone&&!isLocal(wctsurl)){
proxy=fixUrlEnd(top.getcapproxy,true);
fullurl=proxy+"url="+escape(fullurl);
}
GetCRS(fullurl,(setting||top.SRS==cra),cra);
}
}
}
function GetCRS(fullurl,setting,cra){
if(top.setStatus)setStatus("Retrieving WCTS CRS description from service at "+fullurl);
var crs_req;
/*@cc_on @*/
/*@if(@_jscript_version>=5)
try{
crs_req=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
crs_req=new ActiveXObject("Microsoft.XMLHTTP");
}catch(E){
crs_req=false;
}
}
@end @*/
try{
if(!crs_req&&typeof XMLHttpRequest!='undefined'){
crs_req=new XMLHttpRequest();
}
}
catch(error){
}
crs_req.open("GET",fullurl,true);
crs_req.onreadystatechange=function(){
switch(crs_req.readyState){
case 4:if(top.setStatus)top.setStatus(finished+" CRS Description");
var response=crs_req.responseText;
if(typeof ActiveXObject!='undefined'){
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="true";
xmlDoc.validateOnParse=false;
if(response){
xmlDoc.loadXML(response);
if(xmlDoc.parseError.errorCode){
}
else{
if(xmlDoc.childNodes.length==0){
return;
}
var sc=cra.replace(":","");
if(getSRSName(xmlDoc)){
crscache[sc]=xmlDoc;
showSRSName(xmlDoc,setting,sc);
if(typeof setElementNames!="undefined"){
setElementNames(crs,getSRSName(xmlDoc));
}
}
}
}
else{
setStatus("Unable to connect to current Coordinate Transformation Server or Server Responded with blank "+fullurl);
if(!top.errorOnWCTS&&top.standalone){
top.errorOnWCTS=true;
var ch=confirm("Unable to connect to current Coordinate Transformation Server or Server response is empty \n"+fullurl+"\nDo you wish to reset your Coordinate Transformation Server ("+wctsurl+")?");
if(ch){
var newurl=prompt("Please input an appropriate Coordinate Transformation Server URL",top.wmsurl);
if(newurl!=top.wctsurl){
top.wctsurl=newurl;
if(top.standalone)createIni();
top.errorOnWCTS=false;
}
}
}
}
}
else{
if(crs_req.responseXML){
var xmlDoc=crs_req.responseXML;
var sanscolon=cra.replace(":","");
crscache[sanscolon]=crs_req.responseXML;
top.setStatus("CRS description - xml response received");
if(xmlDoc.childNodes.length==0){
return;
}
showSRSName(xmlDoc,setting,sc);
if(typeof setElementNames!="undefined"){
setElementNames(crs,getSRSName(xmlDoc));
}
}
else{
if(crs_req.status==200){
top.setStatus("Incomplete or Invalid xml response for CRS Description received");
}
else{
alert(crs_req.getAllResponseHeaders());
if(crs_req.responseText)showIt(crs_req.responseText);
}
}
}
break;
case 3:top.setStatus(receiving+" Describe CRS response");break;
case 2:top.setStatus(waiting+" Describe CRS response");break;
case 1:top.setStatus(sent+" Describe CRS Request");
}
};
top.setStatus(sending+" Describe CRS request");
setTimeout("top.setStatus('&nbsp;');",3000);
crs_req.send(null)
}

