zhyiwww
          用平實的筆,記錄編程路上的點點滴滴………
          posts - 536,comments - 394,trackbacks - 0
          <html xmlns:v="http://www.aygfsteel.com/zhyiwww/">
          ?? ?<head>
          ?? ??? ?<title></title>
          ?? ??? ?
          ??????? <meta name="Generator" content="EditPlus" />
          ?? ??? ?<meta name="Author" content="eglic" />
          ?? ??? ?<meta name="ContentType" content="text/html" />
          ?? ??? ?<meta name="CharSet" content="GB2312" />
          ?? ??? ?
          ??????? <link rel="stylesheet" type="text/css" href="/style/default.css" />
          ?? ??? ?
          ??????? <style type="text/css">
          ??????????? v\:*?? {behavior:url(#default#VML);} ?
          ??????? </style>
          ?? ??? ?
          ?? ??? ?
          ?????? ?
          ?? ?</head>
          ?? ?<body>
          ?????? ?
          ?? ??? ?<div id='lineDiv'?? ??? ?
          ?? ??? ??? ?onmousedown = 'down(event)'?? ?
          ?? ??? ??? ?onmouseup='up(event)'
          ?? ??? ??? ?onmousemove='move(event)'
          ?? ??? ??? ?style='top:30px;left:30px;width:800px;height:600px;visibility:visible;border:solid 1px blue;background-color: #FF99FF'
          ?? ??? ?>?? ?
          ??????? ?
          ????? ?
          ????? </div>
          ?????? ?
          ??????? <script type="text/javascript">
          ?????? ?
          ?? ??? ??? ? /**
          ?? ??? ??? ? * 定義點對象,也就是鼠標的位置的封裝
          ?? ??? ??? ? */
          ?? ??? ??? ?function Point(){
          ?? ??? ??? ??? ?return this;
          ?? ??? ??? ?}
          ?? ??? ??? ?Point.prototype.setX = function(screenX){
          ?? ??? ??? ?};
          ?? ??? ??? ?Point.prototype.setY = function(screenY){
          ?? ??? ??? ?}
          ?? ??? ??? ?
          ?? ??? ??? ?
          ?? ??? ??? ?/**
          ?? ??? ??? ? * 定義的屏幕點對象
          ?? ??? ??? ? */
          ?? ??? ??? ?function ScreenPoint(screenX,screenY){
          ?? ??? ??? ??? ?this.screenX = screenX;
          ?? ??? ??? ??? ?this.screenY = screenY;
          ?? ??? ??? ??? ?return this;
          ?? ??? ??? ?}
          ?????? ??? ?ScreenPoint.prototype = new Point();
          ?? ??? ??? ?
          ?? ??? ??? ?ScreenPoint.prototype.setX = function (screenX){
          ?? ??? ??? ??? ?this.screenX = screenX;
          ?? ??? ??? ?};
          ?? ??? ??? ?ScreenPoint.prototype.setY = function (screenY){
          ?? ??? ??? ??? ?this.screenY = screenY;
          ?? ??? ??? ?};
          ?? ??? ??? ?
          ?? ??? ??? ?/**
          ?? ??? ??? ? * 重載toString方法
          ?? ??? ??? ? */
          ?? ??? ??? ?ScreenPoint.prototype.toString = function(){
          ?? ??? ??? ??? ?return this.screenX.toString() + " ---? " + this.screenY.toString();
          ?? ??? ??? ??? ?//return "-----------";
          ?? ??? ??? ?}; ?
          ?? ??? ??? ?
          ??????? </script>
          ?????? ?
          ?? ??? ?<script language="javascript">
          ?? ??? ??? ?
          ?? ??? ??? ?// 你所點過的鼠標位置的數組,是點對象數組
          ?? ??? ??? ?var disPoints = new Array();
          ?? ??? ??? ?

          ?? ??? ??? ?// 是否處于鼠標按下狀態
          ?? ??? ??? ?var? select = false;
          ?? ??? ??? ?
          ?? ??? ??? ?// 記錄鼠標按下點的位置 ,默認是(0,0) ?
          ?? ??? ??? ?var? downX = 0; ?
          ?? ??? ??? ?var? downY = 0;
          ?? ??? ??? ?
          ?? ??? ??? ?// 當前用于畫線的層?? ??? ??? ?
          ?? ??? ??? ?var lineDiv = document.getElementById("lineDiv");
          ?? ??? ??? ?
          ?? ??? ??? ?// 當前你鼠標畫的線,在鼠標抬起前的那一條
          ?? ??? ??? ?var line = null;
          ?? ??? ??? ?
          ?? ??? ??? ?/**
          ?? ??? ??? ?* 處理鼠標按下事件
          ?? ??? ??? ?*/
          ??????????? function down(event){?????????? ??? ?
          ?????????? ??? ?
          ?????????? ??? ?//alert(event);
          ?????????? ??? ?
          ?? ??? ??? ??? ?// 取得你選取的最后一個點
          ?? ??? ??? ??? ?var lastPoint = disPoints[disPoints.length - 1];
          ?? ??? ??? ??? ?//alert(lastPoint);
          ?? ??? ??? ??? ?
          ?? ??? ??? ??? ?// 判斷是否是第一個點
          ?? ??? ??? ??? ?if(lastPoint == null){
          ?? ??? ??? ??? ??? ?// 鼠標按下點屏幕坐標
          ?? ??? ??? ??? ??? ?var mouseX1 = event.clientX -? getDivOffsetLeft();
          ?? ??? ??? ??? ??? ?var mouseY1 = event.clientY -? getDivOffsetTop();
          ?? ??? ??? ??? ??? ?
          ?? ??? ??? ??? ??? ?// 記錄鼠標按下點的屏幕坐標
          ?? ??? ??? ??? ??? ?downX = mouseX1;
          ?? ??? ??? ??? ??? ?downY = mouseY1;
          ?? ??? ??? ??? ??? ?
          ?? ??? ??? ??? ??? ?// 記錄第一個點
          ?? ??? ??? ??? ??? ?lastPoint = new ScreenPoint(downX,downY);
          ?? ??? ??? ??? ??? ?disPoints[0] = lastPoint;
          ?? ??? ??? ??? ??? ?//return;
          ?? ??? ??? ??? ?}
          ?? ??? ??? ??? ?
          ?? ??? ??? ??? ?// 如果不是第一個點
          ?? ??? ??? ??? ?// 取得當前鼠標點的位置
          ?? ??? ??? ??? ?var mouseX2 = event.clientX -? getDivOffsetLeft();
          ?? ??? ??? ??? ?var mouseY2 = event.clientY -? getDivOffsetTop();
          ?? ??? ??? ??? ?
          ?? ??? ??? ??? ?// 定義當前點
          ?? ??? ??? ??? ?var tmpPoint = new ScreenPoint(mouseX2,mouseY2);
          ?? ??? ??? ??? ??? ??? ??? ??? ?
          ?? ??? ??? ??? ?// 定義線的ID,用于,取得線的對象
          ?? ??? ??? ??? ?var lineID = "the_line_" + (disPoints.length-1);
          ?? ??? ??? ??? ?
          ?? ??? ??? ??? ?// 在當前點,和最后一個點,兩點畫線
          ?? ??? ??? ??? ?line = drawLine(lineID,lastPoint,tmpPoint);
          ?? ??? ??? ??? ??? ??? ??? ?
          ?? ??? ??? ??? ?// 鼠標按下,記錄按下的狀態
          ?? ??? ??? ??? ?select = true;
          ?? ??? ??? ??? ??? ?
          ??????????? }
          ?????????? ?
          ??????????? /**
          ?? ??? ??? ?* 處理鼠標抬起事件
          ?? ??? ??? ?*/
          ?? ??? ??? ? function up(event){?? ??? ?
          ?? ??? ??? ? ?? ??? ?//alert("up");?? ??? ??? ?
          ?? ??? ??? ??? ??? ?// 取得鼠標抬起點的坐標,也就是確定點的坐標
          ?? ??? ??? ??? ??? ?var mouseX3 = event.clientX -? getDivOffsetLeft();
          ?? ??? ??? ??? ??? ?var mouseY3 = event.clientY -? getDivOffsetTop();
          ?? ??? ??? ??? ??? ?
          ?? ??? ??? ??? ??? ?// 最終確定的點的對象
          ?? ??? ??? ??? ??? ?var currentPoint = new ScreenPoint(mouseX3,mouseY3);
          ?? ??? ??? ??? ??? ?
          ?? ??? ??? ??? ??? ?// 把此點放入到線的端點數組里面,這個點,相對于下一次的操作來說,就是最后一個點
          ?? ??? ??? ??? ??? ?disPoints[disPoints.length] = currentPoint;
          ?? ??? ??? ??? ??? ?select = false;?? ??? ?
          ?? ???????????? }?? ?
          ??????????? /**
          ?? ??? ??? ?* 處理鼠標移動事件
          ?? ??? ??? ?*/
          ?? ??? ??? ? function move(event){
          ?? ??? ??? ? ?? ??? ?// 是否鼠標按下
          ?? ??? ??? ??? ??? ?if(select){?? ??? ?
          ?? ??? ??? ??? ??? ??? ?// 取得當前鼠標的位置坐標
          ?? ??? ??? ??? ??? ??? ?var mouseX2 = event.clientX -? getDivOffsetLeft();
          ?? ??? ??? ??? ??? ??? ?var mouseY2 = event.clientY -? getDivOffsetTop();
          ?? ??? ??? ??? ??? ??? ?
          ?? ??? ??? ??? ??? ??? ?// 把線,從最后一個點畫到當前位置
          ?? ??? ??? ??? ??? ??? ?line.to = mouseX2 + "," + mouseY2;?? ??? ??? ?
          ?? ??? ??? ??? ??? ?}
          ?? ??? ??? ??? ??? ?/*
          ?? ??? ??? ??? ??? ? * 取消事件冒泡,否則不能響應鼠標的抬起事件
          ?? ??? ??? ??? ??? ? */
          ?? ??? ??? ??? ??? ?window.event.cancelBubble = true;
          ?? ??? ??? ??? ??? ?window.event.returnValue = false;?? ?
          ?? ???????????? }?? ?
          ?????????? ?
          ?? ??? ??? ?
          ??????????? function getDivOffsetLeft(){
          ?? ??? ??? ??? ?var lay1 = document.getElementById("lineDiv");
          ?? ??? ??? ??? ?//var rect = document.getElementById("rect");
          ?? ??? ??? ??? ?return lay1.offsetLeft;
          ?? ??? ??? ?}
          ?? ??? ??? ?function getDivOffsetTop(){
          ?? ??? ??? ??? ?var lay1 = document.getElementById("lineDiv");
          ?? ??? ??? ??? ?//var rect = document.getElementById("rect");
          ?? ??? ??? ??? ?return lay1.offsetTop;
          ?? ??? ??? ?}
          ?? ??? ???? ?
          ?? ??? ???? ?
          ??? ?
          ?? ??? ???? /**?? ??? ??????? ?
          ?? ??? ???? * 畫線操作
          ?? ??? ???? * 用VML 實現
          ?? ??? ???? */
          ?? ??? ??? ?function drawLine(id,startPoint,endPoint){
          ?? ??? ??? ??? ?//alert("start -- ");
          ?? ??? ??? ???? var?? s="<v:line?? " +
          ?? ??? ??? ??? ??? ?+ ?? ?"id="
          ?? ??? ??? ??? ??? ?+ ?? ?id
          ?? ??? ??? ??? ??? ?+?? ?"?? from="
          ?? ??? ??? ??? ??? ?+?? ?"'"
          ?? ??? ??? ??? ??? ?+ ?? ?startPoint.screenX
          ?? ??? ??? ??? ??? ?+?? ?","
          ?? ??? ??? ??? ??? ?+ ?? ?startPoint.screenY
          ?? ??? ??? ??? ??? ?+?? ?"'"
          ?? ??? ??? ??? ??? ?+ ?? ?"?? to="
          ?? ??? ??? ??? ??? ?+ ?? ?"'"
          ?? ??? ??? ??? ??? ?+ ?? ?endPoint.screenX
          ?? ??? ??? ??? ??? ?+?? ?","
          ?? ??? ??? ??? ??? ?+ ?? ?endPoint.screenY
          ?? ??? ??? ??? ??? ?+?? ?"'"
          ?? ??? ??? ??? ??? ?+?? ?"? style='position:absolute;left:0px;top:0px;'></v:line>";
          ?? ??? ??? ?
          ?? ??? ??? ??? ?var? o = document.createElement(s);?

          ??? ?? ?? ?? ?? // 這個方法,使在特定的位置添加對象,具體使用,請參考其它的資料
          ?? ??? ??? ??? ?document.body.insertAdjacentElement('BeforeEnd',o); ?
          ?? ??? ??? ??? ?
          ?? ??? ??? ??? ?return o;
          ?? ??? ??? ?}
          ?? ??? ??? ?
          ?? ??? ??? ?
          ?? ??? ?</script>
          ?? ?</body>
          </html>



          |----------------------------------------------------------------------------------------|
                                     版權聲明  版權所有 @zhyiwww
                      引用請注明來源 http://www.aygfsteel.com/zhyiwww   
          |----------------------------------------------------------------------------------------|
          posted on 2007-04-05 19:32 zhyiwww 閱讀(8440) 評論(11)  編輯  收藏 所屬分類: gisvml

          FeedBack:
          # re: javascript鼠標畫線的VML實現
          2007-04-06 13:05 | BeanSoft
          先支持一下  回復  更多評論
            
          # re: javascript鼠標畫線的VML實現
          2007-07-09 15:20 | ~~
          Good~~~~  回復  更多評論
            
          # re: javascript鼠標畫線的VML實現
          2007-11-09 16:40 | 馬大哈
          先頂一下 太好了 謝謝樓主  回復  更多評論
            
          # re: javascript鼠標畫線的VML實現
          2007-11-21 15:51 | irene
          謝謝樓主,頂一個!
          不過要如何控制畫線結束呢?  回復  更多評論
            
          # re: javascript鼠標畫線的VML實現
          2007-11-21 23:56 | vml
          是啊
          要是能夠控制畫線的結束就好了額
          不過還是謝謝哈!  回復  更多評論
            
          # re: javascript鼠標畫線的VML實現
          2007-11-23 09:33 | zhyiwww
          這幾天沒有時間了,等些天,如果有時間,再修改一下,完善一下功能.  回復  更多評論
            
          # re: javascript鼠標畫線的VML實現
          2007-11-24 21:21 | vml
          等待你的修改哦 我也一直在想這個問題,但是水平有限啊!弄不出來
          不想的能不能夠實現在屏幕上添加一個按鈕 這樣點一下按鈕就可以畫一個點 或者畫一條線 能夠實現這樣的就好了  回復  更多評論
            
          # re: javascript鼠標畫線的VML實現
          2008-01-15 14:01 | gis_cn
          能不能加上這個功能呢, 線畫好后, 每個點都是可以拖動的, 這樣可以調整線  回復  更多評論
            
          # re: javascript鼠標畫線的VML實現[未登錄]
          2008-03-08 10:51 |
          謝謝!  回復  更多評論
            
          # re: javascript鼠標畫線的VML實現
          2008-04-27 15:24 | sk
          不錯,謝了  回復  更多評論
            
          # re: javascript鼠標畫線的VML實現
          2009-03-20 17:42 | 是是非非
          <meta name="Author" content="eglic" />

          都不記得啥時候寫的了。。。  回復  更多評論
            
          主站蜘蛛池模板: 栾川县| 台中市| 平凉市| 开鲁县| 客服| 洪江市| 五寨县| 昌邑市| 上林县| 通许县| 军事| 鸡东县| 潜山县| 潢川县| 揭西县| 平利县| 攀枝花市| 平陆县| 密山市| 榆中县| 荔浦县| 尤溪县| 格尔木市| 察隅县| 临朐县| 鸡泽县| 巴马| 夏津县| 定兴县| 新乡市| 林周县| 铁岭县| 桃园县| 阿城市| 宜宾县| 汉中市| 西青区| 常山县| 双城市| 额济纳旗| 丹江口市|