In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use API for Polygon dynamic plotting in the secondary development of TE. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
In the secondary development of TE, API is used for dynamic plotting of Polygon. In the CS program, when Polyon intersects itself, the program will throw an exception, but in the development of bs web pages, this error will not occur. However, CS development dynamic painting Polygon also has a solution to ensure that there are no exceptions in the process of painting. Share the detailed implementation code below.
Define the left mouse button, right button, real-time events in the secondary development of te to add their own, the code is mainly the detailed implementation of each event, the detailed CS code is as follows.
/ / left mouse button event
Protected bool sgworld_OnLButtonUp (int Flags, int X, int Y)
{
Try
{
Var ptw = sgworld.Window.PixelToWorld (X, Y, WorldPointType.WPT_TERRAIN)
/ / in order to achieve real-time dynamic effect, draw a line first, because the face needs at least 3 points
If (tPolyline = = null)
{
Double [] pointarray = {ptw.Position.X, ptw.Position.Y, ptw.Position.Altitude, ptw.Position.X, ptw.Position.Y, ptw.Position.Altitude + 0.1}
ILineString cPolygonGeometry = sgworld.Creator.GeometryCreator.CreateLineStringGeometry (pointarray)
TPolyline = sgworld.Creator.CreatePolyline (cPolygonGeometry, sgworld.Creator.CreateColor (lineColor.R, lineColor.G, lineColor.B, lineColor.A), AltitudeTypeCode.ATC_TERRAIN_RELATIVE, string.Empty, "tempPolyline")
/ / start editing lines
TPolyline.Geometry.StartEdit ()
}
Else
{
If (tPolygon = = null)
{
/ / get the coordinates of the line and prepare to draw polygon
Var _ temGeo = tPolyline.Geometry as ILineString
Dynamic _ temPoint = _ temGeo.Points [0]
Double [] arrr = new double [] {_ temPoint.X, _ temPoint.Y, _ temPoint.Z, ptw.Position.X, ptw.Position.Y, ptw.Position.Altitude, ptw.Position.X, ptw.Position.Y, ptw.Position.Altitude + 0.1}
Var myGeometry = sgworld.Creator.GeometryCreator.CreateLinearRingGeometry (arrr)
TPolyline.Geometry.EndEdit ()
Sgworld.Creator.DeleteObject (tPolyline.ID)
/ / draw polygon
TPolygon = sgworld.Creator.CreatePolygon (myGeometry, sgworld.Creator.CreateColor (lineColor.R, lineColor.G, lineColor.B, lineColor.A), sgworld.Creator.CreateColor (fillColor.R, fillColor.G, fillColor.B, fillColor.A), AltitudeTypeCode.ATC_ON_TERRAIN, groupid, "Polygon")
/ / set the polygon property and edit the polygon
TPolygon.FillStyle.Color.SetAlpha (fOpacity)
TPolygon.Geometry.StartEdit ()
}
Else
{
/ / Edit the coordinates of polyon
Polygon = tPolygon.Geometry as IPolygon
If (polygon! = null)
{
IRings1 = polygon.ExteriorRing as ILinearRing
IPoint Ipint = IRings1.Points [IRings1.Points.Count-1] as IPoint
Ipint.X = ptw.Position.X
Ipint.Y = ptw.Position.Y
Ipint.Z = ptw.Position.Altitude
IRings1.Points.AddPoint (ptw.Position.X, ptw.Position.Y, ptw.Position.Altitude)
}
}
}
}
Catch (Exception ex1)
{
Throw new Exception (ex1.Message)
}
Return false
}
/ / Real-time rendering of events
Protected void sgworld_OnFrame ()
{
Try
{
/ / obtain the mouse information and convert the spatial coordinate information
Var mouseinfo = sgworld.Window.GetMouseInfo ()
Var ptwtwo = sgworld.Window.PixelToWorld (mouseinfo.X, mouseinfo.Y)
If (tPolygon! = null)
{
Polygon = tPolygon.Geometry as IPolygon;// cast
If (polygon! = null)
{
/ / Editing coordinate information in polygon
IRings1 = polygon.ExteriorRing as ILinearRing
Var Ipint = IRings1.Points [IRings1.Points.Count-1] as IPoint
Ipint.X = ptwtwo.Position.X
Ipint.Y = ptwtwo.Position.Y
Ipint.Z = ptwtwo.Position.Altitude
}
}
Else if (tPolyline! = null)
{
/ / Editing coordinate information in Polyline
Var tLineStr = tPolyline.Geometry as ILineString
Var Ipint = tLineStr.Points [tLineStr.Points.Count-1] as IPoint as IPoint
Ipint.X = ptwtwo.Position.X
Ipint.Y = ptwtwo.Position.Y
Ipint.Z = ptwtwo.Position.Altitude
}
}
Catch (Exception ex2)
{
Throw new Exception (ex2.Message)
}
}
/ / right to end the event
Protected bool sgworld_OnRButtonUp (int Flags, int X, int Y)
{
If (tPolygon! = null)
{
TPolyline = null
Polygon = tPolygon.Geometry as IPolygon
If (polygon! = null)
{
IRings1 = polygon.ExteriorRing as ILinearRing
/ / end editing. If there are not enough coordinate points, delete the object.
If (IRings1.Points.Count > 3)
{
IRings1.Points.DeletePoint (IRings1.Points.Count-1)
TPolygon.Geometry.EndEdit ()
Polygon = null
}
Else
{
Sgworld.Creator.DeleteObject (tPolygon.ID)
TPolygon = null
}
}
}
Return false
}
This is the end of the article on "how to use API for dynamic plotting of Polygon in te secondary development". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.