• 基于Skyline的TerraExplorer6.1.1如何通过二次开发实现折线和多边形对象的手动绘制


      1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      2 
      3 <html xmlns="http://www.w3.org/1999/xhtml">
      4 <head>
      5     <title></title>
      6     <script type = "text/javascript" language = "javascript">
      7         var gPolyObj = null;
      8         function CreateSGObj() {
      9             var obj = $("sgworld");
     10             if (obj == null) {
     11                 obj = document.createElement('object');
     12                 document.body.appendChild(obj);
     13                 obj.name = "sgworld";
     14                 obj.id = "sgworld";
     15                 obj.classid = "CLSID:3a4f91b0-65a8-11d5-85c1-0001023952c1";
     16             }
     17             return obj;
     18         }
     19         function $(id) {
     20             return window.document.getElementById(id);
     21         }
     22         //********************************************绘制多边形
     23         var gPolylineText = gPolygonText = "Test";
     24         var gDrawPolyClick = null;
     25         
     26         function DrawPolyLButtonDown(Flags, X, Y) {
     27             var SGWorld = CreateSGObj();
     28             var CursorCoord = SGWorld.Window.pixelToWorld(X, Y);
     29             if (CursorCoord == null)
     30                 return false;
     31 
     32             if (gPolyObj == null) {
     33                 // We always start with a polyline and change it to Polygon (for area) after the second click)
     34                 var myGeometry = SGWorld.Creator.GeometryCreator.CreateLineStringGeometry([CursorCoord.Position.x, CursorCoord.Position.y, 0, CursorCoord.Position.x, CursorCoord.Position.y, 0])
     35                 gPolyObj = SGWorld.Creator.createPolyline(myGeometry, SGWorld.Creator.CreateColor(0, 255, 0, 1), 2, 0, gPolylineText);
     36                 gPolyObj.LineStyle.Width = 1;
     37                 gPolyObj.Geometry.StartEdit();
     38 
     39             }
     40             else {
     41                 if (gPolyMethod == 2) // Polygon 
     42                 {
     43                     if (gPolyObj.ObjectType == 1) {
     44                         // Deleting the temporary line
     45                         var x = gPolyObj.Geometry.Points.Item(0).X;
     46                         var y = gPolyObj.Geometry.Points.Item(0).Y;
     47                         SGWorld.Creator.DeleteObject(gPolyObj.ID);
     48 
     49                         // Creating the polygon
     50                         var myGeometry = SGWorld.Creator.GeometryCreator.CreateLinearRingGeometry([x, y, 0, CursorCoord.Position.x, CursorCoord.Position.y, 0, CursorCoord.Position.x, CursorCoord.Position.y, 0])
     51                         gPolyObj = SGWorld.Creator.createPolygon(myGeometry, SGWorld.Creator.CreateColor(0, 255, 0, 1), SGWorld.Creator.CreateColor(0, 255, 0, 0.5), 2, 0, gPolygonText);
     52                         gPolyObj.LineStyle.Width = 1;
     53                         gPolyObj.Terrain.GroundObject = true;
     54                         gPolyObj.Geometry.StartEdit();
     55                     }
     56                     else {
     57                         gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).X = CursorCoord.Position.x;
     58                         gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).Y = CursorCoord.Position.y;
     59                         gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).Z = 0;
     60                         gPolyObj.Geometry.Rings(0).Points.AddPoint(CursorCoord.Position.x, CursorCoord.Position.y, 0);
     61                     }
     62                 }
     63                 else {                    
     64                     gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).X = CursorCoord.Position.x;
     65                     gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).Y = CursorCoord.Position.y;
     66                     gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).Z = 0;
     67                     gPolyObj.Geometry.Points.AddPoint(CursorCoord.Position.x, CursorCoord.Position.y, 0);
     68                 }
     69             }
     70 //            if (gDrawPolyClick != null)
     71 //                gDrawPolyClick(gPolyObj.Geometry, gPolyObj.ObjectType);
     72 //            return true;
     73         }
     74         //-----------
     75         // onFrame
     76         //-----------
     77         function DrawPolyOnFrame() {
     78             var SGWorld = CreateSGObj();
     79             if (gPolyObj != null) {
     80                 try {
     81                     var mouseInfo = SGWorld.Window.GetMouseInfo()
     82                     var CursorCoord = SGWorld.Window.pixelToWorld(mouseInfo.X, mouseInfo.Y);
     83                     if (CursorCoord == null)
     84                         return false;
     85                     if (gPolyObj.ObjectType == 2) {
     86                         gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).X = CursorCoord.Position.x;
     87                         gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).Y = CursorCoord.Position.y;
     88                         gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).Z = 0;
     89                     }
     90                     else {
     91                         gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).X = CursorCoord.Position.x;
     92                         gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).Y = CursorCoord.Position.y;
     93                         gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).Z = 0;
     94                     }
     95                 }
     96                 catch (e) { }
     97             }
     98         }
     99 
    100         //-------------
    101         //DrawPolyInputModeChanged
    102         function DrawPolyInputModeChanged(NewMode) {
    103 
    104 //            if (NewMode != 1)
    105 //                if (gPolyObj != null)
    106 //                    Reset(0, 1);
    107         }
    108         //-------------
    109         // DrawPolyRButtonUp
    110         function DrawPolyRButtonUp(Flags, X, Y) {
    111             var SGWorld = CreateSGObj();            
    112             if (gPolyObj == null || ((gPolyObj.ObjectType == 1 && gPolyObj.Geometry.Points.count <= 2) || (gPolyObj.ObjectType == 2 && gPolyObj.Geometry.Rings(0).Points.count <= 3))) {
    113 //                Reset(0, 0);
    114                 return false;
    115             }
    116             if (gPolyObj.ObjectType == 1)
    117                 gPolyObj.Geometry.Points.DeletePoint(gPolyObj.Geometry.Points.count - 1);
    118             else
    119                 gPolyObj.Geometry.Rings(0).Points.DeletePoint(gPolyObj.Geometry.Rings(0).Points.count - 1);
    120 
    121             gPolyObj.Geometry.EndEdit();
    122 
    123             gPolyObj = null;
    124             gPolyMethod = null;
    125             return true;
    126         }
    127 
    128         function ExCreate(value) {
    129             var SGWorld = CreateSGObj();
    130             if (value == 0) {
    131                 gPolyMethod = 1;
    132                 SGWorld.AttachEvent("OnLButtonDown", DrawPolyLButtonDown);
    133                 SGWorld.AttachEvent("OnRButtonUp", DrawPolyRButtonUp);
    134                 //SGWorld.AttachEvent("OnFrame", DrawPolyOnFrame);
    135             }
    136             else if (value == 1)
    137             {
    138                 gPolyMethod = 2;
    139                 SGWorld.AttachEvent("OnLButtonDown", DrawPolyLButtonDown);
    140                 SGWorld.AttachEvent("OnRButtonUp", DrawPolyRButtonUp);
    141                 //SGWorld.AttachEvent("OnFrame", DrawPolyOnFrame);
    142             }
    143             else
    144             {
    145             
    146             }
    147         }
    148     </script>
    149 </head>
    150 <body>
    151     <table>
    152         <tr>
    153             <td>
    154                 <input id="Button1" type="button" value="线Polyline" onclick="ExCreate(0)" />
    155             </td>
    156         </tr>
    157         <tr>
    158             <td>
    159                 <input id="Button2" type="button" value="多边形Polygon" onclick="ExCreate(1)" />
    160             </td>
    161         </tr>
    162     </table>
    163 </body>
    164 </html>
  • 相关阅读:
    数据库
    计算机基础知识系列
    《大话数据结构》参考
    数据结构与算法系列
    python cookbook
    Python教程 廖雪峰
    Python入门学习系列
    认识 React——声明式,高效且灵活的用于构建用户界面的 JavaScript 库
    线程---同步(synchronized)
    线程---插队和礼让执行(join和yield)
  • 原文地址:https://www.cnblogs.com/yitianhe/p/2877106.html
Copyright © 2020-2023  润新知