السلام عليكم ورحمة الله
عندي كود لخريطه يعرض نقطة لدولتك والنقطه الثانيه لدوله اخرى في الخريطة عن طريق كتابة احداثيات الدول
Latitude
Longitude
اريد ارسم خط بين النقطه الاولى والثانيه
مثال
وهذا الكود
والمثال على المشروع في المرفق
بارك الله فيكم وشكرا
عندي كود لخريطه يعرض نقطة لدولتك والنقطه الثانيه لدوله اخرى في الخريطة عن طريق كتابة احداثيات الدول
Latitude
Longitude
اريد ارسم خط بين النقطه الاولى والثانيه
مثال
وهذا الكود
كود :
Public Class form1
Dim dat As Date
Dim year, month, day, hours, minutes, seconds As Integer
Public Const pi As Double = 3.141599265
Public Const RtoD As Double = 180 / pi
Public Const DtoR As Double = pi / 180
Public Const RE As Double = 6371.29
Public timeString As String
Public locOffset As Double
Public SunLon As Single
Dim SunLat As Single
Const xL As Single = 0
Dim latitude, longitude, dec, GHA As Double
Const hoehe As Double = 0.0
ReadOnly K As Double = Math.PI / 180.0
Dim CHomelat As Double
Dim CHomeLon As Double
Dim OPLatitude As String
Dim OPLongitude As String
ReadOnly SpotMarker(100) As Label
Public Homemarker As Label
Dim SN As Integer
Public tzOffset As Short
ReadOnly sunpen As New Pen(Brushes.Yellow, 2)
Dim sunBrush = New SolidBrush(Color.Yellow)
ReadOnly shadepen As New Pen(Color.FromArgb(90, 23, 56, 78), 1)
Public Declare Sub GetSystemTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME)
Structure SYSTEMTIME
Dim wYear As Short
Dim wMonth As Short
Dim wDayOfWeek As Short
Dim wDay As Short
Dim wHour As Short
Dim wMinute As Short
Dim wSecond As Short
Dim wMilliseconds As Short
End Structure
Public Function GMTNow() As Date
Dim st As SYSTEMTIME
On Error Resume Next
GetSystemTime(st)
With st
GMTNow = CDate(String.Format("{0}-{1}-{2} {3}:{4}:{5}", .wYear, .wMonth, .wDay, .wHour, .wMinute, .wSecond))
End With
End Function
Public Function computeHeight() As Double
Dim height As Double
Dim sinHeight As Double = Math.Sin(dec * K) * Math.Sin(latitude * K) + Math.Cos(dec * K) * Math.Cos(K * latitude) * Math.Cos(K * (GHA + longitude))
height = Math.Asin(sinHeight)
height = height / K
Return height
End Function
Public Function computeAzimut() As Double
Dim Az As Double
Dim cosAz As Double = (Math.Sin(dec * K) - Math.Sin(latitude * K) * Math.Sin(hoehe * K)) / (Math.Cos(hoehe * K) * Math.Cos(K * latitude))
Az = Math.PI / 2.0 - Math.Asin(cosAz)
If Math.Sin(K * (GHA + longitude)) < 0 Then
Az = Az / K
Else
Az = Az / K
End If
If (Math.Sin(K * (GHA + longitude)) > 0) Then
Az = 360.0 - Az
End If
Return Az
End Function
Public Function computeLat(ByVal longitude As Single, ByVal dec As Double) As Single
Dim itan As Double
Dim tan As Double = -Math.Cos(longitude * K) / Math.Tan(dec * K)
itan = Math.Atan(tan)
itan = itan / K
'Return Math.Round(itan)
Return itan
End Function
Public Sub paintTerm()
PictureBox1.Refresh()
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseMove
Debug.Print(String.Format("X={0} Y= {1}", e.X, e.Y))
Debug.Print(String.Format("Long: {0} Lat: {1}", e.X - 180, 90 - e.Y))
End Sub
Private Sub Form1_ResizeBegin(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.ResizeBegin
Dim x As Short
For x = 0 To (SN - 1)
SpotMarker(x).Visible = False
PictureBox1.Refresh()
PictureBox1.Controls.Remove(SpotMarker(x))
Next
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
ComputeSun()
paintTerm()
End Sub
Public Sub ComputeSun()
Dim TNoon As Object
Dim Tilt As Object
Dim YrAng As Object
Dim t0 As Object
Dim D0 As Object
Dim M0 As Object
Dim t As String = DateAndTime.TimeString
Dim d As String = DateString
' d$ = "03-21-2013" 'DateString
M0 = Val(d$) - 1
D0 = Val(Mid$(d$, 4))
t0 = Val(t$) + tzOffset + Val(Mid$(t$, 4)) / 60
If t0 > 24 Then t0 = t0 - 24
If t0 < 0 Then t0 = t0 + 24
YrAng = 0.0172 * (10 + 30.4 * M0 + D0)
Tilt = -0.409 * Math.Cos(YrAng)
TNoon = 12 + 0.13 * Math.Sin(YrAng) + 0.156 * Math.Sin(2 * YrAng)
SunLat = Tilt * RtoD
SunLon = (-2 * pi * (t0 - TNoon) / 24) * RtoD
Debug.Print("SunLat,Lon {0}, {1}", SunLat, SunLon)
End Sub
Private Sub PlotSpots()
Dim x As Short
For x = 0 To (SN - 1)
SpotMarker(x).Visible = False
PictureBox1.Refresh()
PictureBox1.Controls.Remove(SpotMarker(x))
Next
Array.Clear(SpotMarker, 0, SpotMarker.Length)
SN = 0
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If LAT.Text = "" Then
Dim x As Short
For x = 0 To (SN - 1)
SpotMarker(x).Visible = False
PictureBox1.Refresh()
PictureBox1.Controls.Remove(SpotMarker(x))
Next
Array.Clear(SpotMarker, 0, SpotMarker.Length)
SN = 0
If OPLatitude = "" Then
Else
mapcoords(OPLatitude, OPLongitude)
End If
Else
Dim x As Short
For x = 0 To (SN - 1)
SpotMarker(x).Visible = False
PictureBox1.Refresh()
PictureBox1.Controls.Remove(SpotMarker(x))
Next
Array.Clear(SpotMarker, 0, SpotMarker.Length)
SN = 0
mapcoords(LAT.Text, LON.Text)
If OPLatitude = "" Then
Else
mapcoords(OPLatitude, OPLongitude)
End If
End If
End Sub
Private Sub Formmap_Load(sender As Object, e As EventArgs) Handles MyBase.Load
OPLatitude = "25.266900"
OPLongitude = "55.410140"
Dim ts As TimeSpan = GMTNow() - DateTime.Now
tzOffset = CInt(ts.TotalHours)
PlotSpots()
ComputeSun()
paintTerm()
End Sub
Sub mapcoords(ByVal latitude As Double, ByVal longitude As Double)
Dim latcord As Double
Dim longcord As Double = (((longitude + 180) / 360) * PictureBox1.Width)
latcord = (((90 - latitude) / 180) * PictureBox1.Height)
SpotMarker(SN) = New Label
AddHandler SpotMarker(SN).Click, AddressOf Spotmarker_Click
SpotMarker(SN).AutoSize = False
SpotMarker(SN).Tag = String.Format("Test{0} Lat: {1} Lon: {2}", SN, latcord, longcord)
SpotMarker(SN).Name = "SpotMarker-" & SN
ToolTip1.SetToolTip(SpotMarker(SN), SpotMarker(SN).Tag)
SpotMarker(SN).Visible = True
SpotMarker(SN).Size = New Size(7, 7)
SpotMarker(SN).Location = New Point(CLng(longcord) - 1, CLng(latcord) - 1)
SpotMarker(SN).BackColor = Color.Red
PictureBox1.Controls.Add(SpotMarker(SN))
SN = SN + 1
End Sub
Sub ComputeHomeCoords(ByVal latitude As Double, ByVal longitude As Double)
Dim latcord As Double
Dim longcord As Double = (((longitude + 180) / 360) * PictureBox1.Width)
latcord = (((90 - latitude) / 180) * PictureBox1.Height)
CHomelat = latcord
CHomeLon = longcord
End Sub
Private Sub Spotmarker_Click(ByVal sender As Object, ByVal e As EventArgs)
Debug.Print("Its here")
Dim S As Label = sender
Debug.Print(S.Name)
End Sub
Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.ResizeEnd
PlotSpots()
ComputeSun()
paintTerm()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles PictureBox1.Paint
Dim g As Graphics = e.Graphics
Dim datestr As Integer
Dim x0 As Single = PictureBox1.Width / 2 '180
Dim y0 As Single = PictureBox1.Height / 2 '90
Const Radius As Integer = 3
Dim X, y, yy As Single
Dim yy2 As Single
Dim s As String
Dim tempStr As String
Dim tdy As Single
Dim TC As Double
Dim F As Single
Dim TempSunLon As Single
dat = New Date()
dat = Now
' dat = #3/20/2013 11:46:47 PM#
day = dat.Day
datestr = dat.Month
month = dat.Month
year = dat.Year
hours = Format(dat, "hh")
minutes = dat.Minute
seconds = dat.Second
' compute and write Declination
If tzOffset > 0 Then locOffset = (tzOffset * -1)
If tzOffset < 0 Then locOffset = Math.Abs(tzOffset)
'STD = 1.0 * (hours - locOffset) + (minutes / 60.0) + (seconds / 3600.0)
tdy = (360 / 365.25) * (dat.DayOfYear + dat.Hour / 24) * K
dec = 0.396372 - 22.91327 * Math.Cos(tdy) + 4.02543 * Math.Sin(tdy) - 0.387205 * Math.Cos(2 * tdy) + +0.051967 * Math.Sin(2 * tdy) - 0.154527 * Math.Cos(3 * tdy) + 0.084798 * Math.Sin(3 * tdy)
tempStr = Str(Math.Round(100.0 * dec) / 100.0)
s = tempStr
Debug.Print(String.Format("Declin.={0} degs", s))
' compute and write Greenwich Hour Angle
TC = 0.004297 + 0.107029 * Math.Cos(tdy) - 1.837877 * Math.Sin(tdy) - 0.837378 * Math.Cos(2 * tdy) - 2.340475 * Math.Sin(2 * tdy)
If SunLon < 0 Then TempSunLon = Math.Abs(SunLon)
If SunLon > 0 Then TempSunLon = SunLon * -1
GHA = TempSunLon
tempStr = Str(Math.Round(10.0 * GHA) / 10.0)
s = tempStr
Debug.Print(String.Format("GHA = {0} degs", s))
Dim xscalef As Single = PictureBox1.ClientSize.Width / 360
Dim yscalef As Single = PictureBox1.ClientSize.Height / 180
X = x0 - Math.Round(GHA) * xscalef
If (X < 0) Then X = X + PictureBox1.ClientSize.Width
If (X > PictureBox1.ClientSize.Width) Then X = X - PictureBox1.ClientSize.Width '360
Dim yy1 As Single = y0 - 23.5
yy2 = y0 + 23.5
y = y0 - 90 + 23.5
yy = y0 + 90 - 23.5
y = y0 - dec * yscalef
'Draw SUN
g.DrawEllipse(sunpen, xL + X - Radius, y - Radius, 2 * Radius, 2 * Radius)
g.FillEllipse(sunBrush, xL + X - Radius, y - Radius, 2 * Radius, 2 * Radius) 'DrawsunCoords() '
'Draw terminator
If (dec > 0) Then
F = 1
Else
F = -1
End If
' Dim a As Integer = -X
' For i = -180 To 180 ' PictureBox1.Width 'Note: picturebox1.width should be replaced with 180 but does not show across the screen using that.
Dim i, ii As Single
For xt As Integer = 0 To PictureBox1.Width
i = (SunLon - xt / xscalef) - 180
ii = (SunLon - (xt + 1) / xscalef) - 180
yy = computeLat(i, dec)
yy1 = computeLat(ii, dec)
g.DrawLine(shadepen, xt, y0 - yy * yscalef, xt + xscalef, y0 - yy1 * yscalef)
g.DrawLine(shadepen, xt, y0 - yy * yscalef, xt, y0 + F * PictureBox1.Height - 2) 'If (i Mod 7 = 0) Then
Next
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Timer2.Stop()
If LAT.Text = "" Then
Dim x As Short
For x = 0 To (SN - 1)
SpotMarker(x).Visible = False
PictureBox1.Refresh()
PictureBox1.Controls.Remove(SpotMarker(x))
Next
Array.Clear(SpotMarker, 0, SpotMarker.Length)
SN = 0
If OPLatitude = "" Then
Else
mapcoords(OPLatitude, OPLongitude)
End If
Else
Dim x As Short
For x = 0 To (SN - 1)
SpotMarker(x).Visible = False
PictureBox1.Refresh()
PictureBox1.Controls.Remove(SpotMarker(x))
Next
Array.Clear(SpotMarker, 0, SpotMarker.Length)
SN = 0
mapcoords(LAT.Text, LON.Text)
If OPLatitude = "" Then
Else
mapcoords(OPLatitude, OPLongitude)
End If
End If
End Sub
Private Sub LAT_TextChanged(sender As Object, e As EventArgs) Handles LAT.TextChanged
If LAT.Text = "" Then
Timer2.Start()
Else
Timer2.Start()
End If
End Sub
End Class
بارك الله فيكم وشكرا