// DHTML.js // Global vars for browser type and version var isNav = (navigator.appName.indexOf("Netscape")>=0); var isNav4 = false; var isIE4 = false; var is5up = false; var isIE = false; var isMac = (navigator.platform.indexOf("Mac")>=0); if (isNav) { if (parseFloat(navigator.appVersion)<5) { isNav4=true; } else { is5up = true; } } else { isIE=true; isIE4=true; if (navigator.appVersion.indexOf("MSIE 5")>0) { isIE4 = false; is5up = true; } } // Pour assurer compatibilité NS4 / autres navigateurs if(isNav4) { hspc = 0; vspc = 0; } // Autres variables globales var zooming = false; var panning = false; var toolMode = 1; // Global vars to save mouse position var mouseX=0; var mouseY=0; var x1=0; var y1=0; var x2=0; var y2=0; var zleft=0; var zright=0; var ztop=0; var zbottom=0; // Pour la capture des événements de la souris sur la carte function startUp() { //return false; if (isNav) { document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP); } document.onmousedown = mapTool; document.onmouseup = chkMouseUp; document.onmousemove = getMouse; } function stopEvts() { //return false; if (isNav) { document.captureEvents(); } document.onmousedown = ""; document.onmouseup = ""; document.onmousemove = ""; } // Pour la capture des événements de la souris sur la carte OverMap function ovStartUp() { if (isNav) { document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP); } document.onmousedown = ovMapTool; document.onmouseup = ovChkMouseUp; document.onmousemove = ovGetMouse; } /* *************************************************************************************** DHTML layer functions - used to create and manipulate style sheets These functions are used by the ArcIMS HTML Viewer - found in aimsDHTML.js *************************************************************************************** */ // Create a DHTML layer function createLayer(name, inleft, intop, width, height, visible, content) { var layer; if (isNav4) { document.writeln(''); document.writeln(content); document.writeln(''); } else { document.writeln('
'); document.writeln(content); //if(name.indexOf("primmenu1")>=0) //prompt('jkkjl',content); document.writeln('
'); //alert(name); } } // get the layer object called "name" function getLayer(name) { if (isNav4) return(document.layers[name]); else if (isIE4) { layer = eval('document.all.' + name + '.style'); return(layer); } else if (is5up) { var theObj = document.getElementById(name); return theObj.style } else return(null); } function isVisible(name) { var layer = getLayer(name); if (isNav && layer.visibility == "show") return(true); if (isIE && layer.visibility == "visible") return(true); return(false); } // move layer to x,y function moveLayer(name, x, y) { var layer = getLayer(name); if (isNav4) layer.moveTo(x, y); //if (document.all) { else { layer.left = x + "px"; layer.top = y + "px"; } } // set layer background color function setLayerBackgroundColor(name, color) { var layer = getLayer(name); if (isNav4) layer.bgColor = color; //else if (document.all) else layer.backgroundColor = color; } // toggle layer to invisible function hideLayer(name) { var layer = getLayer(name); if (isNav4) layer.visibility = "hide"; //if (document.all) else layer.visibility = "hidden"; //layer.display="none"; } // toggle layer to visible function showLayer(name) { var layer = getLayer(name); if (isNav4) layer.visibility = "show"; //if (document.all) else layer.visibility = "visible"; //layer.display="block"; } // clip layer display to clipleft, cliptip, clipright, clipbottom // Not working with Mozilla Milestone 12 (Nav5) function clipLayer2(name, clipleft, cliptop, clipright, clipbottom) { var layer = getLayer(name); if (isNav4) { layer.clip.left = clipleft; layer.clip.top = cliptop; layer.clip.right = clipright; layer.clip.bottom = clipbottom; } //if (document.all) else if (isIE) { layer.clip = 'rect(' + cliptop + ' ' + clipright + ' ' + clipbottom + ' ' + clipleft +')'; } } function clipLayer(name, clipleft, cliptop, clipright, clipbottom) { var layer = getLayer(name); if (isNav4) { layer.clip.left = clipleft; layer.clip.top = cliptop; layer.clip.right = clipright; layer.clip.bottom = clipbottom; } else layer.clip = 'rect(' + cliptop + ' ' + clipright + ' ' + clipbottom + ' ' + clipleft +')'; } function boxIt(theLeft,theTop,theRight,theBottom) { if (is5up && isNav) { theLeft = theLeft+hspc; theRight = theRight+hspc; theTop = theTop+vspc; theBottom = theBottom+vspc; moveLayer("zoomBoxTop",theLeft,theTop); moveLayer("zoomBoxBottom",theRight-cornerOffset,theBottom-cornerOffset); moveLayer("zoomBoxLeft",theLeft,theBottom-cornerOffset); moveLayer("zoomBoxRight",theRight-cornerOffset,theTop); } else { /* if(isNav4) { theLeft = theLeft+hspc; theRight = theRight+hspc; theTop = theTop+vspc; theBottom = theBottom+vspc; }*/ clipLayer("zoomBoxTop",theLeft,theTop,theRight,theTop+ovBoxSize); clipLayer("zoomBoxLeft",theLeft,theTop,theLeft+ovBoxSize,theBottom); clipLayer("zoomBoxRight",theRight-ovBoxSize,theTop,theRight,theBottom); clipLayer("zoomBoxBottom",theLeft,theBottom-ovBoxSize,theRight,theBottom); } showLayer("zoomBoxTop"); showLayer("zoomBoxLeft"); showLayer("zoomBoxRight"); showLayer("zoomBoxBottom"); } /* *************************************************************************************** Navigation functions - used to resize zoom box Extended versions of these functions are used by the ArcIMS HTML Viewer - found in aimsNavigation.js *************************************************************************************** */ // get cursor location function getImageXY(e) { if (isNav) { mouseX=e.pageX; mouseY=e.pageY; if(isNav4) { mouseX = mouseX - parent.carteaelb.document.layers.lyrNS4.pageX ; mouseY = mouseY - parent.carteaelb.document.layers.lyrNS4.pageY ; } } else { mouseX=event.clientX + document.body.scrollLeft; mouseY=event.clientY + document.body.scrollTop; } // subtract offsets from page left and top mouseX = mouseX-hspc; mouseY = mouseY-vspc; } // get cursor location function ovGetImageXY(e) { if (isNav) { mouseX=e.pageX; mouseY=e.pageY; if(isNav4) { mouseX = mouseX - document.layers.theMap.pageX ; mouseY = mouseY - document.layers.theMap.pageY ; mouseX = mouseX+hspc; mouseY = mouseY+vspc; /* } else { mouseX = mouseX-hspc; mouseY = mouseY-vspc; */ } } else { mouseX=event.clientX + document.body.scrollLeft; mouseY=event.clientY + document.body.scrollTop; } // subtract offsets from page left and top //mouseX = mouseX-hspc; //mouseY = mouseY-vspc; } // start zoom in.... box displayed function startZoomBox(e) { if(overMenu) return false; moveLayer("theMap",hspc,vspc); getImageXY(e); // keep it within the MapImage if ((mouseX0) && (mouseY>0)) { if (zooming) { stopZoomBox(e); } else { x1=mouseX; y1=mouseY x2=x1+1; y2=y1+1; zleft=x1; ztop=y1; zbottom=y1; zright=x1 boxIt(x1,y1,x2,y2); zooming=true; } } return false; } // stop zoom box display... function stopZoomBox(e) { zooming=false; hideLayer("zoomBoxTop"); hideLayer("zoomBoxLeft"); hideLayer("zoomBoxRight"); hideLayer("zoomBoxBottom"); window.scrollTo(0,0); if(toolMode==1) parent.processmap.doAction('zinbox',x1,y1,x2,y2); else if(toolMode==2) parent.processmap.doAction('zoubox',x1,y1,x2,y2); return true; } // start zoom in.... box displayed function ovStartZoomBox(e) { //moveLayer("theMap",hspc,vspc); ovGetImageXY(e); // keep it within the MapImage if ((mouseX<(iWidth+hspc)) && (mouseY<(iHeight+vspc)) && (mouseX>hspc) && (mouseY>vspc)) { if (zooming) { ovStopZoomBox(e); } else { x1=mouseX; y1=mouseY x2=x1+1; y2=y1+1; zleft=x1; ztop=y1; zbottom=y1; zright=x1 if(isNav && !isNav4) boxIt(x1-hspc,y1-vspc,x2-hspc,y2-vspc); else boxIt(x1,y1,x2,y2); zooming=true; } } return false; } // stop zoom box display... function ovStopZoomBox(e) { zooming=false; hideLayer("zoomBoxTop"); hideLayer("zoomBoxLeft"); hideLayer("zoomBoxRight"); hideLayer("zoomBoxBottom"); window.scrollTo(0,0); if(toolMode==1) zoom(x1,y1,x2,y2); return true; } // select by click function selClick(e) { if(overMenu) return false; moveLayer("theMap",hspc,vspc); getImageXY(e); // keep it within the MapImage if ((mouseX0) && (mouseY>0)) { x1=mouseX; y1=mouseY x2=x1+1; y2=y1+1; parent.processmap.doAction('selrect',x1,y1,'','',parent.carteaelb.getLayerActif()); } return true; } // identify function identify(e) { if(overMenu) return false; moveLayer("theMap",hspc,vspc); getImageXY(e); // keep it within the MapImage if ((mouseX0) && (mouseY>0)) { x1=mouseX; y1=mouseY x2=x1+1; y2=y1+1; parent.processmap.doAction('identify',x1,y1); } return true; } // start zoom in.... box displayed function startSelBox(e) { if(overMenu) return false; moveLayer("theMap",hspc,vspc); getImageXY(e); // keep it within the MapImage if ((mouseX0) && (mouseY>0)) { if (zooming) { stopSelBox(e); } else { x1=mouseX; y1=mouseY x2=x1+1; y2=y1+1; zleft=x1; ztop=y1; zbottom=y1; zright=x1 boxIt(x1,y1,x2,y2); zooming=true; } } return false; } // stop zoom box display... function stopSelBox(e) { zooming=false; hideLayer("zoomBoxTop"); hideLayer("zoomBoxLeft"); hideLayer("zoomBoxRight"); hideLayer("zoomBoxBottom"); window.scrollTo(0,0); parent.processmap.doAction('selrect',x1,y1,x2,y2,parent.carteaelb.getLayerActif()); return true; } // get the coords at mouse position function getMouse(e) { window.status=""; getImageXY(e); if ((mouseX>iWidth) || (mouseY>iHeight) || (mouseX<=0) ||(mouseY<=0)) { chkMouseUp(e); } else { if (zooming) { x2=mouseX; y2=mouseY; setClip(); } else if (panning) { x2=mouseX; y2=mouseY; panMouse(); } var mouseString = ""; //if (zooming) mouseString += "ZoomBox: [" + x1 + "," + y1 + " x " + x2 + "," + y2 + "] "; mouseString += "Echelle=1:" + Math.round(getMapScale()) + " X=" + Math.round(getMapXFromImgX(mouseX)) + " Y=" + Math.round(getMapYFromImgY(mouseY)); window.status = mouseString; } // next line needed for Mac return false; } // get the coords at mouse position function ovGetMouse(e) { window.status=""; ovGetImageXY(e); if ((mouseX>(iWidth+hspc)) || (mouseY>(iHeight+vspc)) || (mouseX<=hspc) ||(mouseY<=vspc)) { ovChkMouseUp(e); } else { if (zooming) { x2=mouseX; y2=mouseY; ovSetClip(); } else if (panning) { x2=mouseX; y2=mouseY; panMouse(); } var mouseString = ""; //if (zooming) mouseString += "OvZoomBox: [" + x1 + "," + y1 + " x " + x2 + "," + y2 + "] "; mouseString += "X=" + Math.round(getMapXFromImgX(mouseX-hspc)) + " Y=" + Math.round(getMapYFromImgY(mouseY-vspc)); window.status = mouseString; } // next line needed for Mac return false; } // clip zoom box layer to mouse coords function setClip() { var tempX=x1; var tempY=y1; if (x1>x2) { zright=x1; zleft=x2; } else { zleft=x1; zright=x2; } if (y1>y2) { zbottom=y1; ztop=y2; } else { ztop=y1; zbottom=y2; } if ((x1 != x2) && (y1 != y2)) { boxIt(zleft,ztop,zright,zbottom); } //return false; } // clip zoom box layer to mouse coords function ovSetClip() { var tempX=x1; var tempY=y1; if (x1>x2) { zright=x1; zleft=x2; } else { zleft=x1; zright=x2; } if (y1>y2) { zbottom=y1; ztop=y2; } else { ztop=y1; zbottom=y2; } if ((x1 != x2) && (y1 != y2)) { if(isNav && !isNav4) boxIt(zleft-hspc,ztop-vspc,zright-hspc,zbottom-vspc); else boxIt(zleft,ztop,zright,zbottom); } //return false; } // start pan.... image will move function startPan(e) { if(overMenu) return false; moveLayer("theMap",hspc,vspc); getImageXY(e); // keep it within the MapImage if ((mouseX0) { cLeft = 0; cRight = iWidth - xMove; } if (yMove>0) { cTop = 0; cBottom = iHeight - yMove; } clipLayer("theMap",cLeft,cTop,cRight,cBottom); moveLayer("theMap",xMove+hspc,yMove+vspc); //return false; } /* *************************************************************************************** Click/Mouse functions - used to catch mouse button events Extended versions of these functions are used by the ArcIMS HTML Viewer - found in aimsClick.js *************************************************************************************** */ // check for mouseup function chkMouseUp(e) { // we are only demo'ing the zoombox . . . so only one thing to do if ((toolMode == 1) && (zooming)) { stopZoomBox(e); } if ((toolMode == 2) && (zooming)) { stopZoomBox(e); } if ((toolMode == 3) && (panning)) { stopPan(e); } if ((toolMode == 5) && (zooming)) { stopSelBox(e); } // next line needed for Mac return false; } // perform appropriate action with mapTool function mapTool (e) { var clickType=1; if (isNav) clickType=e.which; else if(isIE) clickType=event.button; if (clickType!=1) return false; //alert(overMenu); if(parent.carteaelb.isWorking()) alert("Le serveur n'a pas encore répondu à votre dernière requête"); else { switch(toolMode) { case 1: startZoomBox(e); return false; break case 2: startZoomBox(e); return false; break case 3: startPan(e); return false; break case 4: selClick(e); return false; break case 5: startSelBox(e); return false; break case 6: identify(e); return false; break default: break; } } return false; } // check for mouseup function ovChkMouseUp(e) { // we are only demo'ing the zoombox . . . so only one thing to do if ((toolMode == 1) && (zooming)) { ovStopZoomBox(e); } // next line needed for Mac return false; } // perform appropriate action with mapTool function ovMapTool (e) { var clickType=1; if (isNav) clickType=e.which; else if(isIE) clickType=event.button; if (clickType!=1) return false; switch(toolMode) { case 1: ovStartZoomBox(e); return false; break default: break; } }