基于Skyline的TerraExplorer6.1.1如何通过二次开发实现折线和多边形对象的手动绘制
2013-01-25 17:41
615 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type = "text/javascript" language = "javascript"> var gPolyObj = null; function CreateSGObj() { var obj = $("sgworld"); if (obj == null) { obj = document.createElement('object'); document.body.appendChild(obj); obj.name = "sgworld"; obj.id = "sgworld"; obj.classid = "CLSID:3a4f91b0-65a8-11d5-85c1-0001023952c1"; } return obj; } function $(id) { return window.document.getElementById(id); } //********************************************绘制多边形 var gPolylineText = gPolygonText = "Test"; var gDrawPolyClick = null; function DrawPolyLButtonDown(Flags, X, Y) { var SGWorld = CreateSGObj(); var CursorCoord = SGWorld.Window.pixelToWorld(X, Y); if (CursorCoord == null) return false; if (gPolyObj == null) { // We always start with a polyline and change it to Polygon (for area) after the second click) var myGeometry = SGWorld.Creator.GeometryCreator.CreateLineStringGeometry([CursorCoord.Position.x, CursorCoord.Position.y, 0, CursorCoord.Position.x, CursorCoord.Position.y, 0]) gPolyObj = SGWorld.Creator.createPolyline(myGeometry, SGWorld.Creator.CreateColor(0, 255, 0, 1), 2, 0, gPolylineText); gPolyObj.LineStyle.Width = 1; gPolyObj.Geometry.StartEdit(); } else { if (gPolyMethod == 2) // Polygon { if (gPolyObj.ObjectType == 1) { // Deleting the temporary line var x = gPolyObj.Geometry.Points.Item(0).X; var y = gPolyObj.Geometry.Points.Item(0).Y; SGWorld.Creator.DeleteObject(gPolyObj.ID); // Creating the polygon var myGeometry = SGWorld.Creator.GeometryCreator.CreateLinearRingGeometry([x, y, 0, CursorCoord.Position.x, CursorCoord.Position.y, 0, CursorCoord.Position.x, CursorCoord.Position.y, 0]) gPolyObj = SGWorld.Creator.createPolygon(myGeometry, SGWorld.Creator.CreateColor(0, 255, 0, 1), SGWorld.Creator.CreateColor(0, 255, 0, 0.5), 2, 0, gPolygonText); gPolyObj.LineStyle.Width = 1; gPolyObj.Terrain.GroundObject = true; gPolyObj.Geometry.StartEdit(); } else { gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).X = CursorCoord.Position.x; gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).Y = CursorCoord.Position.y; gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).Z = 0; gPolyObj.Geometry.Rings(0).Points.AddPoint(CursorCoord.Position.x, CursorCoord.Position.y, 0); } } else { gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).X = CursorCoord.Position.x; gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).Y = CursorCoord.Position.y; gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).Z = 0; gPolyObj.Geometry.Points.AddPoint(CursorCoord.Position.x, CursorCoord.Position.y, 0); } } // if (gDrawPolyClick != null) // gDrawPolyClick(gPolyObj.Geometry, gPolyObj.ObjectType); // return true; } //----------- // onFrame //----------- function DrawPolyOnFrame() { var SGWorld = CreateSGObj(); if (gPolyObj != null) { try { var mouseInfo = SGWorld.Window.GetMouseInfo() var CursorCoord = SGWorld.Window.pixelToWorld(mouseInfo.X, mouseInfo.Y); if (CursorCoord == null) return false; if (gPolyObj.ObjectType == 2) { gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).X = CursorCoord.Position.x; gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).Y = CursorCoord.Position.y; gPolyObj.Geometry.Rings(0).Points.Item(gPolyObj.Geometry.Rings(0).Points.count - 1).Z = 0; } else { gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).X = CursorCoord.Position.x; gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).Y = CursorCoord.Position.y; gPolyObj.Geometry.Points.Item(gPolyObj.Geometry.Points.count - 1).Z = 0; } } catch (e) { } } } //------------- //DrawPolyInputModeChanged function DrawPolyInputModeChanged(NewMode) { // if (NewMode != 1) // if (gPolyObj != null) // Reset(0, 1); } //------------- // DrawPolyRButtonUp function DrawPolyRButtonUp(Flags, X, Y) { var SGWorld = CreateSGObj(); if (gPolyObj == null || ((gPolyObj.ObjectType == 1 && gPolyObj.Geometry.Points.count <= 2) || (gPolyObj.ObjectType == 2 && gPolyObj.Geometry.Rings(0).Points.count <= 3))) { // Reset(0, 0); return false; } if (gPolyObj.ObjectType == 1) gPolyObj.Geometry.Points.DeletePoint(gPolyObj.Geometry.Points.count - 1); else gPolyObj.Geometry.Rings(0).Points.DeletePoint(gPolyObj.Geometry.Rings(0).Points.count - 1); gPolyObj.Geometry.EndEdit(); gPolyObj = null; gPolyMethod = null; return true; } function ExCreate(value) { var SGWorld = CreateSGObj(); if (value == 0) { gPolyMethod = 1; SGWorld.AttachEvent("OnLButtonDown", DrawPolyLButtonDown); SGWorld.AttachEvent("OnRButtonUp", DrawPolyRButtonUp); //SGWorld.AttachEvent("OnFrame", DrawPolyOnFrame); } else if (value == 1) { gPolyMethod = 2; SGWorld.AttachEvent("OnLButtonDown", DrawPolyLButtonDown); SGWorld.AttachEvent("OnRButtonUp", DrawPolyRButtonUp); //SGWorld.AttachEvent("OnFrame", DrawPolyOnFrame); } else { } } </script> </head> <body> <table> <tr> <td> <input id="Button1" type="button" value="线Polyline" onclick="ExCreate(0)" /> </td> </tr> <tr> <td> <input id="Button2" type="button" value="多边形Polygon" onclick="ExCreate(1)" /> </td> </tr> </table> </body> </html>
相关文章推荐
- 基于Skyline的TerraExplorer6.1.1如何通过二次开发实现圆形对象的手动绘制
- 基于Skyline的TerraExplorer6.1.1如何通过二次开发实现矢量图层的空间查询和属性查询
- 如何基于纯GDI实现alpha通道的矢量和文字绘制
- 关于在MFC中实用在基于对话框窗口上面绘制折线的实现方法
- JavaScript中如何通过arguments对象实现对象的重载
- 第四章 基于对象的编程风格(如何实现一个class)
- 如何通过SuperMap iCloudManager实现基于nginx的Web应用的负载均衡
- OpenGL中如何实现通过鼠标点击选取对象(正交投影)
- SharePoint基于windows验证的如何通过组策略实现IE自动以当前域账号登录SP站点
- 基于Skyline的TerraExplorer6.1实现选中对象的高亮显示
- 一种通过鼠标操作实现多边形的绘制的实现方法
- U3D 通过预置对象实现手动创建精灵
- 思考一个问题:如何将map里面的值,映射到一个对象里的属性,不通过手动方式设置!!!
- 如何基于纯GDI实现alpha通道的矢量和文字绘制
- 在TerraExplorer中如何批量根据shape多边形对象创建TerrainModify对象?
- Android基于mAppWidget实现手绘地图(十三)–如何显示/隐藏任意类型的地图对象
- js如何判断一个对象是array ,instanceof 是基于什么实现的呢?
- js如何判断一个对象是array ,instanceof 是基于什么实现的呢?
- 基于ASP.net C#技术来实现,介绍如何处理Session对象变量失效的问题
- Android基于mAppWidget实现手绘地图(六)–如何展示地图对象