http://giswiki.org/index.php?title=QuickWMS-Extension/WMSmap.js&feed=atom&action=history
QuickWMS-Extension/WMSmap.js - Versionsgeschichte
2024-03-28T15:59:55Z
Versionsgeschichte dieser Seite in GISWiki
MediaWiki 1.25.3
http://giswiki.org/index.php?title=QuickWMS-Extension/WMSmap.js&diff=6731&oldid=prev
84.137.174.26 am 19. August 2005 um 19:12 Uhr
2005-08-19T19:12:58Z
<p></p>
<a href="http://giswiki.org/index.php?title=QuickWMS-Extension/WMSmap.js&diff=6731&oldid=2657">Änderungen zeigen</a>
84.137.174.26
http://giswiki.org/index.php?title=QuickWMS-Extension/WMSmap.js&diff=2657&oldid=prev
HeinzJ am 17. August 2005 um 07:17 Uhr
2005-08-17T07:17:13Z
<p></p>
<p><b>Neue Seite</b></p><div><pre>/*<br />
* Project : Generic JavaScript WMS Client <br />
* File : WMSmap.js<br />
* Author : Pedro Pereira Gonçalves<br />
* email : pedro.goncalves@esa.int or pedro@inovagis.org<br />
* Version : 0.2<br />
* Description: Simple wms map client with a list of layers originating from <br />
* different servers. No mouse support present in this class <br />
* (check quickWMS class at WMSquick.js)<br />
* Tested on : Netscape 7.0, IE 5.5, IE 6.0<br />
* Last Change : 2003-06-20<br />
* Dependencies : WMSlayer.js, WMSbrowsers.js<br />
* Future Developments : <br />
* License : OpenSource (check license.txt in the same directory)<br />
* History :<br />
2003-10-24 : Added the option to select direct loading without using the transport image <br />
by default is false in all browsers except in IE 6 (because this browsers will always recall the image even if it has an object in memory)<br />
2003-04-28 : Write img of each layer passed to the layerWMS writeDOM method <br />
2003-04-23 : Documentation added<br />
2003-03-20 : File Created<br />
* Objects : mapWMS <br />
* Functions :<br />
function mouse2GeoX(obRef,mX)<br />
function mouse2GeoY(obRef,mY)<br />
function geo2MouseX(obRef,cX)<br />
function geo2MouseY(obRef,cY)<br />
function geoConstraints(obRef)<br />
<br />
*/<br />
<br />
function mapWMS(x1, y1, x2, y2, srs){<br />
<br />
this.caption = "";<br />
this.BBox = new Array(x1,y1,x2,y2);<br />
this.initBBox = new Array(x1,y1,x2,y2);<br />
this.lastBBox = new Array(x1,y1,x2,y2);<br />
this.lastLoaded = ""; //works for the status captions<br />
// default value for srs is EPSG:4326<br />
if (srs) this.srs=srs;<br />
else this.srs="EPSG:4326";<br />
<br />
// list of layers requests<br />
this.layers=new Array; <br />
this.directLoading=false; // if directLoading is true then it will not use a temporary image while receiving the requests<br />
// in IE60 this is true by default <br />
if (browser.isIE60) this.directLoading=true;<br />
<br />
// additional HTML lines to add to the main layer<br />
this.writeHTML=new Array;<br />
<br />
// geographical listeners events <br />
this.listeners = new Array; <br />
// private features - dont thouch :) <br />
// ***** none<br />
<br />
// not documented features <br />
// ***** none<br />
<br />
/// events <br />
this.onChange=null; // it must be defined as function(layer){}<br />
this.onBeforeChange=null; //it must be defined as function (wmsLayer,x1,y1,x2,y2)<br />
this.onError = null; // it must be defined as function(layer){}<br />
this.onSelecting = null;//it must be defined as function (wmsLayer,x1,y1,x2,y2)<br />
this.onSelection = null;//it must be defined as function (wmsLayer,x1,y1,x2,y2)<br />
<br />
// functions <br />
this.refresh = function (){ <br />
window.status="";<br />
showLayer(this.name+"Status"); <br />
this.setStatus(TXT_OnRequestingData); <br />
for(i=0; i<this.layers.length; i++) this.layers[i].refresh();<br />
this.waitFunction=null;<br />
this.waitFunction=setTimeout('waitfunction("'+ this.name + '")',200); <br />
return true;<br />
}<br />
<br />
this.addLayer = function(url,layer,version, caption){<br />
this.layers[this.layers.length] = new layerWMS(this, url, layer, caption, version);<br />
return true; <br />
}<br />
<br />
this.updateBBox = function (x1, y1, x2, y2){ <br />
if (this.onBeforeChange){this.onBeforeChange(this,x1,y1,x2,y2);}<br />
copy(this.BBox,this.lastBBox); <br />
this.BBox[0]=x1/1;this.BBox[1]=y1/1;<br />
this.BBox[2]=x2/1;this.BBox[3]=y2/1; <br />
geoConstraints(this); <br />
this.refresh();<br />
}<br />
<br />
this.cancelRequest = function(){<br />
hideLayer(this.name+"Status"); <br />
clearInterval(this.waitFunction); <br />
copy(this.lastBBox,this.BBox);<br />
this.refresh(); <br />
}<br />
<br />
this.zoomTo = function (x,y,zoomFactor){<br />
var sizeX=(this.BBox[2]-this.BBox[0])/zoomFactor;<br />
var sizeY=(this.BBox[3]-this.BBox[1])/zoomFactor;<br />
this.updateBBox(x-sizeX/2,y-sizeY/2,x+sizeX/2,y+sizeY/2); <br />
}<br />
<br />
this.notify= function(mapRef){<br />
}<br />
<br />
this.addListener = function(mapRef){ <br />
mapRef.listeners[mapRef.listeners.length]=this;<br />
}<br />
<br />
<br />
this.setStatus = function (value){<br />
if (browser.isOldNS) {<br />
// TO-DO : set the status for netscape 4.7<br />
}<br />
else{<br />
var content="<table style='position:absolute;top:0;left:0' width=100% height=100%><tr align='center' valign='bottom'><td class='statusText'>"<br />
content+= "<span style='cursor:wait'>"+value+"</span>"; <br />
content+="</td></tr></table>"; <br />
setLayerHTML(this.name+"StatusTXT", content); <br />
}<br />
}<br />
<br />
this.writeDOM = function (name, left, top, width, height, style){ <br />
this.name = name;<br />
this.width = width;<br />
this.height = height; <br />
this.top = top;<br />
this.left = left; <br />
document.open();<br />
if (style) openLayer(this.name,"",style, this.left, this.top, width, height, true);<br />
else openLayer(this.name,"","background-color:white;", this.left, this.top, width, height, true);<br />
for(i=0; i<this.layers.length; i++){<br />
this.layers[i].writeDOM(this.name+i,0,0,this.width,this.height,"");<br />
// we have to remove the onload function (defined in the WMSlayer.js) of the transportIMG <br />
// because here we use the wait function<br />
if (!this.directLoading) this.layers[i].transportIMG.onload=function (){this.loading=false;if (this.parent.parent) {this.parent.parent.lastLoaded=this.parent.caption}}<br />
else this.layers[i].DOMref.onload = function (){if (this.src.indexOf(empty_IMG)<0) {this.loading=false;if (this.parent.parent) {this.parent.parent.lastLoaded=this.parent.caption}}}<br />
<br />
}<br />
for(i=0; i<this.writeHTML.length; i++) this.writeHTML[i](this); <br />
this.topImage=writeIMG(name+"MapTop",empty_IMG,0,0,this.width,this.height,""); <br />
this.topImage.parent=this;<br />
<br />
//status layer <br />
// 2003-10-13 : change this from inherit to visible (ns71 problems)<br />
openLayer(this.name+"Status","","visibility:visible;",0, 0, this.width, this.height, true); <br />
if (browser.isOldNS) writeIMG(this.name+"Status_",empty_IMG,0,0,this.width,this.height,"")<br />
else writeIMG(this.name+"Status_",white_IMG,0,0,this.width,this.height,"filter:alpha(opacity="+statusThreshold+"); -moz-opacity:"+(statusThreshold/100)+";");<br />
//statusTXT <br />
openLayer(this.name+"StatusTXT","","position: absolute;visibility:inherit",0, 0, this.width, this.height/2, true); <br />
closeLayer();//statusTXT<br />
//statusIMG <br />
openLayer(this.name+"StatusIMG","","visibility:inherit;",0, this.height/2, this.width, this.height/2, true); <br />
//style="cursor:hour;"position:absolute;top:0,left:0;<br />
<br />
var content='<table border="0" width='+this.width+' height='+this.height/2 +'><tr align="center" valign="top"><td>'<br />
content+="<img src='"+waiting_IMG+"'>";<br />
content+="<BR><span class='cancelText' onclick=javascript:getLayer('"+this.name+"').reference.cancelRequest();return false;"; <br />
content+=" style='cursor:pointer'>CANCEL</span>";<br />
content+="</td></tr></table>"; <br />
document.write(content); <br />
closeLayer();//statusIMG <br />
closeLayer();//status <br />
closeLayer();//name<br />
<br />
//closeLayer();//name teste 2003-09-25<br />
document.writeln(); <br />
// retrieve the reference of the layer tag to add to the object <br />
<br />
if (browser.isOldNS){this.DOMref= findLayer(name,document);}<br />
else this.DOMref=document.getElementById(name); <br />
// set a reference to this object on the layer tag<br />
this.DOMref.reference=this; <br />
<br />
<br />
document.close();<br />
// if any of its descendents needs to initialize something we call this function<br />
if (this.initialize) this.initialize();<br />
return true;<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
// ******* geoConstraints(obRef) *************<br />
// Check for the geographical and proportions constrains of the bounding box<br />
function geoConstraints(obRef)<br />
{ <br />
// check min and max values<br />
if (obRef.BBox[0]>obRef.BBox[2]){<br />
var tmpX1=obRef.BBox[0];<br />
obRef.BBox[0]=obRef.BBox[2];<br />
obRef.BBox[2]=tmpX1;<br />
}<br />
if (obRef.BBox[1]>obRef.BBox[3]){<br />
var tmpY1=obRef.BBox[1];<br />
obRef.BBox[1]=obRef.BBox[3];<br />
obRef.BBox[3]=tmpY1;<br />
} <br />
// check first if current BBox obeys the initial proportions <br />
var initPropor = (obRef.initBBox[2] - obRef.initBBox[0]) / (obRef.initBBox[3] - obRef.initBBox[1]); <br />
var Propor = (obRef.BBox[2] - obRef.BBox[0]) / (obRef.BBox[3] - obRef.BBox[1]); <br />
if (initPropor!=Propor)<br />
{<br />
var sizeX = obRef.BBox[2] - obRef.BBox[0];<br />
var sizeY = obRef.BBox[3] - obRef.BBox[1];<br />
if (sizeY<sizeX){<br />
var midY= obRef.BBox[1] + (sizeY)/2;<br />
var newSizeY= (sizeX)/initPropor;<br />
obRef.BBox[1]= midY - newSizeY / 2;<br />
obRef.BBox[3]= midY + newSizeY / 2;<br />
}<br />
else{<br />
var midX= obRef.BBox[0] + (sizeX)/2;<br />
var newSizeX= (sizeY)*initPropor;<br />
obRef.BBox[0]= midX - newSizeX / 2;<br />
obRef.BBox[2]= midX + newSizeX / 2;<br />
} <br />
}<br />
<br />
// check if both BBox axis are inside the initial BBox<br />
// check X-axis <br />
var SizeX = obRef.BBox[2] - obRef.BBox[0];<br />
if (obRef.BBox[0]<obRef.initBBox[0])<br />
{ <br />
obRef.BBox[0] = obRef.initBBox[0];<br />
obRef.BBox[2] = obRef.BBox[0] + SizeX;<br />
if (obRef.BBox[2]>obRef.initBBox[2]) { obRef.BBox[2]=obRef.initBBox[2]}<br />
}<br />
else<br />
{<br />
if (obRef.BBox[2]>obRef.initBBox[2])<br />
{<br />
obRef.BBox[2] = obRef.initBBox[2];<br />
obRef.BBox[0] = obRef.BBox[2] - SizeX;<br />
}<br />
}<br />
// check Y-axis <br />
var SizeY = (obRef.BBox[3] - obRef.BBox[1]);<br />
<br />
if (obRef.BBox[1]<obRef.initBBox[1])<br />
{<br />
obRef.BBox[1] = obRef.initBBox[1];<br />
obRef.BBox[3] = obRef.BBox[1] + SizeY;<br />
if (obRef.BBox[3]>obRef.initBBox[3]) {obRef.BBox[3]=obRef.initBBox[3]}<br />
}<br />
else<br />
{<br />
if (obRef.BBox[3]>obRef.initBBox[3])<br />
{<br />
obRef.BBox[3]= obRef.initBBox[3];<br />
obRef.BBox[1]= obRef.BBox[3] - SizeY;<br />
}<br />
}<br />
/* to do : arrows should me made invisible<br />
if (document.getElementById(obRef.name+"Arrows")) {<br />
if ((obRef.Y2== obRef.initY2) && (obRef.Y1== obRef.initY1) &&<br />
(obRef.X2== obRef.initX2) && (obRef.X1== obRef.initX1))<br />
{hideArrows(obRef,true)}<br />
else<br />
{hideArrows(obRef,false)}<br />
}<br />
*/<br />
}<br />
<br />
// *** Mouse to geographical conversion function<br />
function mouse2GeoX(obRef,mX)<br />
{return obRef.BBox[0] + mX * (obRef.BBox[2] - obRef.BBox[0])/obRef.width;}<br />
function mouse2GeoY(obRef,mY)<br />
{return obRef.BBox[3] - mY * (obRef.BBox[3] - obRef.BBox[1])/ obRef.height;}<br />
<br />
// *** Geographical to mouse conversion function<br />
function geo2MouseX(obRef,cX)<br />
{return Math.round(obRef.width * (cX - obRef.BBox[0])/ (obRef.BBox[2] - obRef.BBox[0]) )}<br />
function geo2MouseY(obRef,cY)<br />
{return Math.round( obRef.height * (obRef.BBox[3] - cY) / ( obRef.BBox[3] - obRef.BBox[1] )); }<br />
<br />
<br />
<br />
// ************* waitfunction(mapName) ****************<br />
// function that waits for all the images to arrive<br />
// you should NOT call this function from your code<br />
function waitfunction(mapName){<br />
var missingName="";<br />
var layerRef=getLayer(mapName);<br />
<br />
if (layerRef.reference){<br />
var mapRef=layerRef.reference;<br />
var stillMissing = 0;<br />
for (i=0; i<mapRef.layers.length; i++){<br />
// if there is an image still loading <br />
if (!mapRef.directLoading) {<br />
if (mapRef.layers[i].transportIMG.loading){<br />
stillMissing+=1;<br />
missingName =mapRef.layers[i].caption;<br />
}<br />
}else{<br />
//alert(mapRef.layers[i].DOMref.loading);<br />
if (mapRef.layers[i].DOMref.loading){<br />
stillMissing+=1;<br />
missingName =mapRef.layers[i].caption;<br />
<br />
}<br />
} <br />
}<br />
if (stillMissing>0){<br />
if (stillMissing==1 && mapRef.layers.length>1) mapRef.setStatus(layerRef.reference.lastLoaded + " " + TXT_ReceivedLayer +"\n<br>" +TXT_WaitingFor +" " + missingName )//stillMissing + TXT_Request)<br />
else <br />
if (stillMissing==mapRef.layers.length) mapRef.setStatus( TXT_WaitingFor + stillMissing + TXT_Request);<br />
else mapRef.setStatus( layerRef.reference.lastLoaded + " " + TXT_ReceivedLayer +"\n<br>" +TXT_WaitingFor + stillMissing + TXT_Request);<br />
mapRef.waitFunction=setTimeout('waitfunction("'+ mapRef.name + '")',1000);<br />
}<br />
else{<br />
<br />
clearInterval(mapRef.waitFunction); <br />
mapRef.setStatus(TXT_LayerUpdated); <br />
if (!mapRef.directLoading) {<br />
for (i=0; i<mapRef.layers.length; i++)<br />
{mapRef.layers[i].DOMref.src=mapRef.layers[i].transportIMG.src;}; <br />
}<br />
hideLayer(mapName+"Status"); <br />
if(mapRef.onChange){mapRef.onChange(mapRef)};<br />
if(mapRef.listeners){<br />
for (i=0;i<mapRef.listeners.length;i++){mapRef.listeners[i].notify(mapRef, TXT_onChange)};<br />
}<br />
if (mapRef.setSelectionXY){<br />
if (isVisible(mapRef.name+"Selection")){ <br />
mapRef.setSelectionXY(); <br />
}<br />
}<br />
<br />
return true; <br />
}<br />
}<br />
}<br />
<br />
</pre></div>
HeinzJ