?? appfunctions.bas
字號:
Attribute VB_Name = "appFunctions"
Option Explicit
Function CreateTempLayer(ByRef map As MapXLib.map, ByVal strLayerName As String) As MapXLib.Layer
'****************************************************************************
'* This function creates a new temp layer with one column and adds it with the supplied name into the supplied map object
'****************************************************************************
Dim lyrInfo As MapXLib.LayerInfo
Dim flds As MapXLib.Fields
'we have to create a fields object to describe the structure of the temp table
Set flds = CreateObject(cFIELDSobject)
'we will make 1 column, string type, 15 characters wide
flds.AddStringField "ID", 15
' a layerinfo object will allow us to add or create a layer to the map
Set lyrInfo = CreateObject(cLAYERINFOobject)
'it's going to be a temp layer
lyrInfo.Type = miLayerInfoTypeTemp
'add the fields collection that we just created
lyrInfo.AddParameter "Fields", flds
' set the layer's name
lyrInfo.AddParameter "Name", strLayerName
'add the layer to the map
CreateTempLayer = map.Layers.Add(lyrInfo)
Set flds = Nothing
Set lyrInfo = Nothing
End Function
Function OpenTextFile(fileObject As File, strFileName As String, ByRef bFileopen As Boolean) As Integer
fileObject.Open strFileName, fsModeInput
bFileopen = True
End Function
Function CloseTextFile(fileObject As File, ByRef bFileopen As Boolean) As Boolean
fileObject.Close
bFileopen = False
End Function
Sub ShowAbout()
Dim sTemp As String
sTemp = "This application demonstrates how to display moving points in MapXMobile." & vbCrLf
sTemp = sTemp & "It is a very basic app that parses a NMEA-183 string and plots the point on the map." & vbCrLf
sTemp = sTemp & "Please use it to learn from and to enhance. " & vbCrLf
MsgBox sTemp, vbInformation, "About GPS sample..."
End Sub
Function FindComma(ByVal passstring As String, ByVal Which As Integer) As Integer
'****************************************************************************
'* This function returns the position of a specific comma within a string
Dim cnt, found As Integer
Dim tmpstr As String
tmpstr = passstring
'Loop through the string
For cnt = 1 To Which
If InStr(1, tmpstr, ",") > 0 Then
'There is still another comma in the string
tmpstr = Right(tmpstr, Len(tmpstr) - InStr(1, tmpstr, ",")) 'Shorten the string
found = InStr(1, passstring, tmpstr) - 1 'here is the position
Else
'There are no more commas
FindComma = 0 'not found
Exit Function
End If
Next
FindComma = found
End Function
Public Sub GetDirectionsFromAngle(ByVal dblAngle As Double, ByRef sDirection As String)
' **************************************************
' * this sub returns a description of an angle
' * with 0 degrees being due east
' **************************************************
If dblAngle >= 0 And dblAngle <= 22.5 Then
sDirection = "East"
Exit Sub
End If
If dblAngle > 22.5 And dblAngle <= 67.5 Then
sDirection = "Northeast"
Exit Sub
End If
If dblAngle > 67.5 And dblAngle <= 112.5 Then
sDirection = "North"
Exit Sub
End If
If dblAngle > 112.5 And dblAngle <= 157.5 Then
sDirection = "Northwest"
Exit Sub
End If
If dblAngle > 157.5 And dblAngle <= 202.5 Then
sDirection = "West"
Exit Sub
End If
If dblAngle >= 202.5 And dblAngle <= 247.5 Then
sDirection = "Southwest"
Exit Sub
End If
If dblAngle > 247.5 And dblAngle <= 292.5 Then
sDirection = "South"
Exit Sub
End If
If dblAngle > 292.5 And dblAngle <= 337.5 Then
sDirection = "Southeast"
Exit Sub
End If
If dblAngle > 337.5 And dblAngle <= 360 Then
sDirection = "East"
Exit Sub
End If
End Sub
Public Function ComputeAngle(ByVal x1 As Double, ByVal y1 As Double, _
ByVal x2 As Double, ByVal y2 As Double) As Double
'****************************************************************************
'*
'* Input
'* X1,Y1 -- Starting position
'* X2,Y2 -- Ending position
'*
'***********************************************************************cs.r1
Dim fAngle As Double
Dim fCompFactor As Double
Dim fTemp As Double
Dim fTemp2 As Double
If x1 = x2 And y1 = y2 Then
'start point = end point... return null and exit
ComputeAngle = 0
Exit Function
End If
'Compute the angle between the two points relative to the Eastern direction.
Const DEG_2_RAD = 0.01745329252
Const RAD_2_DEG = 57.29577951
fCompFactor = Cos(y2 * DEG_2_RAD / 2)
fTemp = ((x2 - x1) * fCompFactor)
'Arcsin(X) = Atn(X / Sqr(-X * X + 1))
fTemp2 = (y2 - y1) / Sqr((fTemp * fTemp) + ((y2 - y1) * (y2 - y1)))
If Abs(fTemp2) <> 1 Then
fAngle = Atn(fTemp2 / Sqr(-fTemp2 * fTemp2 + 1)) * RAD_2_DEG
Else 'Would have gotten a division by zero error in the above line if there was no latitude change
'Else set the direction to due west (180)
fAngle = 180
End If
If (x2 - x1) <= 0 Then fAngle = (180 - fAngle)
If (y2 - y1 <= 0) And (x2 - x1 >= 0) Then fAngle = (360 + fAngle)
If fAngle = 360 Then fAngle = 0
ComputeAngle = fAngle
End Function
Public Function ParseNMEAMessage( _
ByVal Message As String, _
ByRef dblXCoord As Double, ByRef dblYCoord As Double, _
ByRef sDate As String) As Boolean
'******************Search1*******************************************
'* This routine parses the NMEA message for a MapX X & Y coord
'* The NMEA format that is being used contains degrees and decimal minutes
'* message="$GPRMC, ,A, 4240.97,N, 07342.01 ,W ,06.8 ,040.2, ,13.,W*43"
' $GPRMC,222344,A, 4719.482,N, 11750.552,W ,0.0 , ,191101,0.0,E,*79
'
'If the NMEA message that you are receiving is different from the one used in this
'sample, simply make the changes in this function, and the rest of the application will work without any alteration.
Dim strDeg As String
Dim strMin As String
Dim iComma1 As Integer
Dim iComma2 As Integer
Dim iFollowingDecimalPoint As Integer
Dim strHemisphere As String
Dim iMult As Integer
'The y coordinate is stored between the third and fourth commas
iComma1 = FindComma(Message, 3) 'get the position of the third comma
iComma2 = FindComma(Message, 4) 'get the position of the fourth comma
iFollowingDecimalPoint = InStr(iComma1, Message, ".") 'Find the next decimal point
strHemisphere = Mid(Message, iComma2 + 1, 1) 'get the hemisphere
If strHemisphere = "N" Then
'the Y value is positive
iMult = 1
Else
'the y value is Neg
iMult = -1
End If
'The decimal minutes will be stored starting from 2 digits before the decimal
'point and continue to the next comma
strMin = Mid(Message, iFollowingDecimalPoint - 2, iComma2 - iFollowingDecimalPoint + 2)
'The first few characters after the 3rd comma are the Degrees
strDeg = Mid(Message, iComma1 + 1, iFollowingDecimalPoint - iComma1 - 3)
'Calculate the y component in decimal Degrees
dblYCoord = (CDbl(strDeg) + (CDbl(strMin) / 60) * iMult)
'************************************************************************
'The x coordinate is stored between the fifth and sixth commas
iComma1 = FindComma(Message, 5) 'get the position of the fifth comma
iComma2 = FindComma(Message, 6) 'get the position of the sixth comma
iFollowingDecimalPoint = InStr(iComma1, Message, ".") 'Find the next decimal point
strHemisphere = Mid(Message, iComma2 + 1, 1) 'get the hemisphere
If strHemisphere = "W" Then
'the Y value is Neg
iMult = -1
Else
'the y value is Pos
iMult = 1
End If
'The decimal minutes will be stored starting from 2 digits before the decimal
'point and continue to the next comma
strMin = Mid(Message, iFollowingDecimalPoint - 2, iComma2 - iFollowingDecimalPoint + 2)
'The first few characters after the 5th comma are the x component's Degrees
strDeg = Mid(Message, iComma1 + 1, iFollowingDecimalPoint - iComma1 - 3)
'Calculate the x component in decimal Degrees
dblXCoord = ((CDbl(strDeg) + (CDbl(strMin) / 60)) * iMult)
'In this data, the date was set between the 10th and 11th comma. This may be different depending on your equipment
iComma1 = FindComma(Message, 10) 'get the position of the ninth comma
iComma2 = FindComma(Message, 11) 'get the position of the tenth comma
Dim sTemp As String
sTemp = Mid(Message, iComma1 + 1, iComma2 - iComma1 - 1) 'get the elevation
If IsNull(sTemp) Then sTemp = 0
sDate = sTemp
ParseNMEAMessage = True
End Function
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -