ArcIMS自定义事件

出自LajiWiki
跳转到: 导航, 搜索

目录

主要方法

在ArcIMSparam.js里的checkParams函数中增加事件的申明
document.onmousemove = getMouse;
//document.onmousedown = chkMouseDown;		
document.onmousedown = mapTool;
document.onmouseup = chkMouseUp;
//document.onmouseout = chkMouseOut;

示例

 主要功能:自定义一个工具 左键放大,按住中键拖动地图,滚轮放大缩小。

示例代码

 为方便代码编写,在ArcIMSparam.js中添加了一个全局变量。指示此工具是否在使用
 部分代码源于ArcIMS的Sample中的htmlviewer\Generic
var useModeFrame = true;

添加事件

还是在ArcIMSparam.js中加入

document.onmousewheel = chkMouseWheel;//CF修改,增加中键滚动响应

事件响应代码

1.中键滚动响应,在aimsNavigation_Mod.js中,我把aimsNavigation.js复制重命名了一份:-)

chkMouseWheel代码如下

function chkMouseWheel(e){  //CF修改 鼠标中键滚动	
  if (PanModUsed==true){
    if(event.wheelDelta ==120){ 	//向上滚动
      getMapXY(mouseX,mouseY);
      var tempLeft=lastLeft;
      var tempRight=lastRight;
      var tempTop=lastTop;
      var tempBottom=lastBottom;
      saveLastExtent();
      eLeft = mapX - (xHalf/zoomFactor);
      eRight = mapX + (xHalf/zoomFactor);
      eTop = mapY + (yHalf/zoomFactor);
      eBottom = mapY - (yHalf/zoomFactor);			
      sendMapXML();
      } else if(event.wheelDelta ==-120)	{	//向下滚动
      getMapXY(mouseX,mouseY);
      var tempLeft=lastLeft;
      var tempRight=lastRight;
      var tempTop=lastTop;
      var tempBottom=lastBottom;
      saveLastExtent();
      eLeft = mapX - (xDistance*zoomFactor/2);
      eRight = mapX + (xDistance*zoomFactor/2);
      eTop = mapY + (yDistance*zoomFactor/2);
      eBottom = mapY - (yDistance*zoomFactor/2);
      if (enforceFullExtent) {
        if ((eRight-eLeft)>fullWidth) {
          eLeft = fullLeft;
          eRight = fullRight;
          eTop = fullTop;
          eBottom = fullBottom;
          lastLeft=tempLeft;
          lastRight=tempRight;
          lastTop=tempTop;
          lastBottom=tempBottom;
        }
     }		
     sendMapXML();
    }
  }
}


2.改过的MouseUp,在aimsClick.js中

chkMouseUp代码如下

function chkMouseUp(e) { 	//CF修改 ,中键移动地图
	var theButton= 0;
	// get the button pushed... if right, ignore... let browser do the popup... it will anyway
	if (isNav) {
		theButton = e.which;
	} else {
		theButton =window.event.button;
	}
	if (theButton==leftButton) {
		if ((toolMode == 1) && (zooming)) {
				stopZoomBox(e);
 
		}
		if ((toolMode == 2) && (zooming)) {
				stopZoomOutBox(e);
		}
		if ((toolMode == 3) && (panning)) {
				stopPan(e);
		}
		if ((toolMode == 10) && (selectBox)) {
				stopSelectBox(e);
		}			
		return false;
	} else if (theButton==4 && PanModUsed==true) {	//中键		
		if ((toolMode == 3) && (panning)){		
			stopPan(e);
		}			
	}
 
}


3.修改过的MouseDown,此处的MouseDown事件响应函数为MapTool,在aimsClick.js中

MapTool代码如下

function mapTool (e) {  //CF修改
 
  var theButton= 0;
  // get the button pushed... if right, ignore... let browser do the popup... it will anyway
  if (isNav) {
    theButton = e.which;
  } else {
    theButton =window.event.button;
  }  
  if (theButton==leftButton && PanModUsed ==false) {    
    getImageXY(e);
    if ((mouseX>=0) && (mouseX<iWidth) && (mouseY>=0) && (mouseY<iHeight)) {
      //if ((!isNav) || (!is5up)) {
      if ((hasOVMap) && (ovIsVisible) && (mouseX<i2Width+ovBoxSize) && (mouseY<i2Height) && (ovMapIsLayer)) {
          //alert(mouseX + ", " + mouseY);
          ovMapClick(mouseX,mouseY);
 
          window.status = "On OV Map Area";
        //}
      } else {
        //alert(mouseX + "," + mouseY);        
        switch(toolMode) {
        case 1:
            startZoomBox(e);
            return false;
            break;
 
        case 2:
            startZoomOutBox(e);
            return false;
            break;
        case 3:
            startPan(e);
            return false;
            break;
 
        case 4:
          identify(e);
          break;
 
        case 5:
          // identify all
          identifyAll(e);
          break;
 
        // custom modes
        ///*
        case 6:
          // route - requires custom route routine - not in default
            // requires aimsRoute.js, aimsGeocode.js
          //routeClick = routeClick + 1;
          //if (routeClick > 2) routeClick = 2;
          //setRouteXY()
          //writeRoutePage();
          address(e);
          break;
        //*/
        case 7:
          // address - requires custom reverseGeocode routine - not in default
            // requires aimsRoute.js, aimsGeocode.js
          address(e);
          break;
        //*/
        case 10:
          //select(e);
            startSelectBox(e);
            return false;
            break;
        case 11:
          //select point
          if (checkIfActiveLayerAvailable()) {
            select(e);
          }
          break;
        case 12:
          //select line
          if (checkIfActiveLayerAvailable()) {
            clickType=2;
            clickAddPoint();
            if (useTextFrame) {
              if (parent.TextFrame.document.title!==modeList[60]) {
                parent.TextFrame.document.location= appDir + "selectline.htm";
              }
            }
          }
          break;
        case 13:
          //select polygon
          if (checkIfActiveLayerAvailable()) {
            clickType=3;
            clickAddPoint();
            if (useTextFrame) {
              if (parent.TextFrame.document.title!==modeList[7]) {
                parent.TextFrame.document.location= appDir + "selectpoly.htm";
              }
            }
          }
          break;
        case 15:
          // hyperlink
          hyperLink(e);
          break;
        case 16:
          //select shape
          if (checkIfActiveLayerAvailable()) {
            clickType=2;
            clickAddPoint();
            if (useTextFrame) {
              if (parent.TextFrame.document.title!==modeList[8]) {
                parent.TextFrame.document.location= appDir + "select.htm";
              }
            }
          }
          break;
          ///* 
        case 17:
          //buffer shape - 
          if (checkIfActiveLayerAvailable()) {
            clickType=2;
            clickAddPoint();
            if (useTextFrame) {
              if (parent.TextFrame.document.title!=modeList[11]) {
                parent.TextFrame.document.location= appDir + "shapeBuffer.htm";
              }
            }
          }
          break;
          //*/
        case 20:
          // measure
          clickType=1;
          clickAddPoint();
          break;
        case 21:
          // shape
          clickType=4;
          clickAddPoint();
          break;
        case 30:
          // hyperlink
          hyperLinkAny(e);
          break;
        case 40:
          // db identify - requires custom db query - not in default
          if (aimsDBPresent) {
            matchDBLinkLayer(dbLinkLayer);
            dbIdentify(e);
          }
          break;
        default:
          if (toolMode>=1000) {
            customMapTool(e);
          }
        }
      }
    }
  } else if ( theButton == 4){ //CF 修改 鼠标中键移动地图  
    toolMode = 3; //中键移动
    if (PanModUsed==true){
      setCursor("theTop", "move");
      getImageXY(e);
      if ((mouseX>=0) && (mouseX<iWidth) && (mouseY>=0) && (mouseY<iHeight)) 
      {
        //if ((!isNav) || (!is5up)) {
        if ((hasOVMap) && (ovIsVisible) && (mouseX<i2Width+ovBoxSize) && (mouseY<i2Height) && (ovMapIsLayer)) {
            //alert(mouseX + ", " + mouseY);
            ovMapClick(mouseX,mouseY);
 
            window.status = "On OV Map Area";
          //}
        } else {
          switch(toolMode) {
          case 1:
              startZoomBox(e);
              return false;
              break;    
          case 3:
              startPan(e);
              return false;
              break;  
          default:
            if (toolMode>=1000) {
              customMapTool(e);
            }
          }
 
        }
      }
    }
  }else if(theButton==leftButton && PanModUsed ==true ){//CF修改 自定义工具启用,双击放大,按下左键则拖动
    toolMode = 1; //左键放大
    setCursor("theTop", "crosshair");
    getImageXY(e);
    if ((mouseX>=0) && (mouseX<iWidth) && (mouseY>=0) && (mouseY<iHeight)) {
      //if ((!isNav) || (!is5up)) {
      if ((hasOVMap) && (ovIsVisible) && (mouseX<i2Width+ovBoxSize) && (mouseY<i2Height) && (ovMapIsLayer)) {
          //alert(mouseX + ", " + mouseY);
          ovMapClick(mouseX,mouseY);
 
          window.status = "On OV Map Area";
        //}
      } else {
        //alert(mouseX + "," + mouseY);        
        switch(toolMode) {
        case 1:
            startZoomBox(e);
            return false;
            break;  
        case 3:
            startPan(e);
            return false;
            break;              
        default:
          if (toolMode>=1000) {
            customMapTool(e);
          }
        }
      }
    }
  }
}


4.还得把工具自己加上去。。。

MapFrame.htm中加入代码

<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript" SRC="../javascript/aimsNavigation_Mod.js"></SCRIPT>


toolbar.htm中加入代码

  if (parent.MapFrame.usePanMod) {
          //CF修改 自定义工具 . . . requires aimsNavigation_Mod.js
          document.write('<tr>');
          document.write('<td align="center" valign="middle">');
          //document.write('<img src="images/lajiTest.gif" width=16 height=16 hspace=1 vspace=1 border=0 alt=" ' + t.buttonList[41] + '" onmousedown="parent.MapFrame.loadMapForm();" onmouseover="window.status=\' ' + t.buttonList[41] + '\'">');
          document.write('<img src="images/lajiTest.gif" width=16 height=16 hspace=1 vspace=1 border=0 alt=" ' + t.buttonList[21] + '" name="pan" onmousedown="parent.MapFrame.clickFunction(\'pan_Mod\'); setToolPic(\'pan_Mod\');" onmouseover="window.status=\' ' + t.buttonList[21] + '\'">');
          document.writeln('</td>');
          document.write('</tr>');
    }


5.最后还有工具的初始化代码,终于完鸟。。。

修改aimsClick.js中的clickFunction函数,代码如下

function clickFunction (toolName) {
  if (hasLayer("measureBox"))
    hideLayer("measureBox");
  PanModUsed = false;//CF修改,禁用自定义工具
  switch(toolName) {
  // Zooming functions
  case "pan_Mod"://CF修改,自定义工具  左键拉框放大,中键滚轮放大缩小地图,按住中键拖动地图
    PanModUsed = true;
    // zoom in mode
    toolMode = 1;
    panning=false;
    selectBox=false;
    setCursor("theTop", "crosshair");
    modeBlurb = modeList[0];
    //if (useTextFrame) parent.TextFrame.document.location= appDir + "text.htm";
    break;
  default:    
    alert(msgList[51]);
  }
  modeName=modeBlurb;
  if (useModeFrame) {
    writeModeFrame(modeBlurb);
  } else if ((drawFloatingMode) && (modeLayerOn)) {
    writeModeLayers(modeBlurb);
    //var theString = writeXML();
    sendMapXML();
  }
}


个人工具