Salah satu contoh kod yang diaplikasikan dari trigonometri
CODE
Public Function AddDynamicLineLabel(p_Extents As MapWinGIS.Extents, sLayer As String, sField As String, bNoDuplicate As Boolean) As Boolean
Dim p_Shapefile As MapWinGIS.Shapefile
Dim i As Long, j As Long, k As Long, handle As Long
Dim selectedShapes As Variant
Dim strLabel As String
Dim Stack() As StackData
Dim Data As StackData
Dim yLen As Double, xLen As Double
Dim xMin As Double, yMin As Double, zMin As Double, xMax As Double, yMax As Double, zMax As Double
Dim MidPointIndex As Long
Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double, Angle As Double
ReDim Stack(0)
' TODO: to differentiate shape type
'Get the minimum and maximum values of x and y that define the map extents
p_Extents.GetBounds xMin, yMin, zMin, xMax, yMax, zMax
exitLastLoop = False
'Get the handle of the layer
handle = getLyrHandle(sLayer)
'Get the shapefile in the specified layer
Set p_Shapefile = m_Map.GetObject(handle)
If p_Shapefile Is Nothing Then Exit Function
If p_Shapefile.SelectShapes(p_Extents, 0, MapWinGIS.SelectMode.INTERSECTION, selectedShapes) Then
For i = 0 To UBound(selectedShapes)
If exitLastLoop = True Then GoTo LastLoop
If m_Map.ShapeVisible(handle, selectedShapes(i)) = False Then GoTo NextRecordFirstLoop
j = getFieldIndex(handle, sField)
If j < 0 Then GoTo LastLoop
strLabel = p_Shapefile.CellValue(j, selectedShapes(i))
If Len(strLabel) = 0 Then GoTo NextRecordFirstLoop
MidPointIndex = p_Shapefile.Shape(selectedShapes(i)).numPoints / 2
x1 = p_Shapefile.QuickPoint(selectedShapes(i), MidPointIndex - 1).x
x2 = p_Shapefile.QuickPoint(selectedShapes(i), MidPointIndex).x
y1 = p_Shapefile.QuickPoint(selectedShapes(i), MidPointIndex - 1).y
y2 = p_Shapefile.QuickPoint(selectedShapes(i), MidPointIndex).y
If x2 - x1 <> 0 Then
Angle = (Atn((y2 - y1) / (x2 - x1)) * 180) / 3.14159265358979
Else
Angle = 90
End If
If bNoDuplicate = True Then
For k = 1 To UBound(Stack)
If exitLastLoop = True Then GoTo LastLoop
Data = Stack(k)
If LCase(Data.Label) = LCase(strLabel) Then
GoTo NextRecordFirstLoop
End If
Next
End If
ReDim Preserve Stack(UBound(Stack) + 1)
Data.Label = strLabel
Stack(UBound(Stack)) = Data
If (x1 + x2) / 2 > xMin And (x1 + x2) / 2 < xMax And (y1 + y2) / 2 > yMin And (y1 + y2) / 2 < yMax Then
Call m_Map.AddLabelEx(handle, strLabel, RGB(0, 0, 0), (x1 + x2) / 2, (y1 + y2) / 2, MapWinGIS.tkHJustification.hjCenter, Angle)
End If
NextRecordFirstLoop:
Next
AddDynamicLineLabel = True
End If
LastLoop:
Erase Stack
exitLastLoop = True
End Function
Maaf, koding rojak sikit. Baru nak siapkan framework.