Type TMapTileXY(fX As Long, fY As Long)
Type TMapLatLng(fLat As Double, fLng As Double)
Type tBorderPointTypes(iTopLine As Int, _
iRightLine As Int, _
iBottomLine As Int, _
iLeftLine As Int, _
iLeftTopCorner90 As Int, _
iRightTopCorner90 As Int, _
iRightBottomCorner90 As Int, _
iLeftBottomCorner90 As Int, _
iLeftTopCorner270 As Int, _
iRightTopCorner270 As Int, _
iRightBottomCorner270 As Int, _
iLeftBottomCorner270 As Int, _
iLeftTopAndRightBottomTouchingAtCornerOnly As Int, _
iRightTopAndLeftBottomTouchingAtCornerOnly As Int, _
iNotAtEdge As Int)
Public eBorderPointTypes As tBorderPointTypes
eBorderPointTypes.iTopLine = 0
eBorderPointTypes.iRightLine = 1
eBorderPointTypes.iBottomLine = 2
eBorderPointTypes.iLeftLine = 3
eBorderPointTypes.iLeftTopCorner90 = 4
eBorderPointTypes.iRightTopCorner90 = 5
eBorderPointTypes.iRightBottomCorner90 = 6
eBorderPointTypes.iLeftBottomCorner90 = 7
eBorderPointTypes.iLeftTopCorner270 = 8
eBorderPointTypes.iRightTopCorner270 = 9
eBorderPointTypes.iRightBottomCorner270 = 10
eBorderPointTypes.iLeftBottomCorner270 = 11
eBorderPointTypes.iLeftTopAndRightBottomTouchingAtCornerOnly = 12
eBorderPointTypes.iRightTopAndLeftBottomTouchingAtCornerOnly = 13
eBorderPointTypes.iNotAtEdge = 14
'return a TTileXY from X and Y
Public Sub initTileXY(aX As Long, aY As Long) As TMapTileXY
Dim fTileXY As TMapTileXY
fTileXY.Initialize
fTileXY.fX=aX
fTileXY.fY=aY
Return fTileXY
End Sub
'return a TLatLng from lat/lng
Public Sub initLatLng(aLat As Double,aLng As Double) As TMapLatLng
Dim ll As TMapLatLng
ll.Initialize
ll.fLat=validLat(aLat)
ll.fLng=validLng(aLng)
Return ll
End Sub
Sub GetBorderLinePointType(tMTXY As TMapTileXY, mapTileLookup As Map) As Int
Dim iRightBottom As Int
Dim iLeftBottom As Int
Dim iLeftTop As Int
Dim iRightTop As Int
Dim iPointType As Int
If mapTileLookup.ContainsKey(tMTXY.fX & "_" & tMTXY.fY) Then
iRightBottom = 1
End If
If mapTileLookup.ContainsKey((tMTXY.fX - 1) & "_" & tMTXY.fY) Then
iLeftBottom = 2
End If
If mapTileLookup.ContainsKey((tMTXY.fX - 1) & "_" & (tMTXY.fY - 1)) Then
iLeftTop = 4
End If
If mapTileLookup.ContainsKey(tMTXY.fX & "_" & (tMTXY.fY - 1)) Then
iRightTop = 8
End If
iPointType = iRightBottom + iLeftBottom + iLeftTop + iRightTop
'90 and 270 are to do with the clock-wise rotation and the turn to make at the corner
'------------------------------------------------------------------------------------
Select Case iPointType
Case 1
Return Enums.eBorderPointTypes.iLeftTopCorner90
Case 2
Return Enums.eBorderPointTypes.iRightTopCorner90
Case 3
Return Enums.eBorderPointTypes.iTopLine
Case 4
Return Enums.eBorderPointTypes.iRightBottomCorner90
Case 5
'this is a special case: top left tile and right bottom tile
Return Enums.eBorderPointTypes.iLeftTopAndRightBottomTouchingAtCornerOnly
Case 6
Return Enums.eBorderPointTypes.iRightLine
Case 7
Return Enums.eBorderPointTypes.iRightTopCorner270
Case 8
Return Enums.eBorderPointTypes.iLeftBottomCorner90
Case 9
Return Enums.eBorderPointTypes.iLeftLine
Case 10
'this is a special case: top right tile and left bottom tile
Return Enums.eBorderPointTypes.iRightTopAndLeftBottomTouchingAtCornerOnly
Case 11
Return Enums.eBorderPointTypes.iLeftTopCorner270
Case 12
Return Enums.eBorderPointTypes.iBottomLine
Case 13
Return Enums.eBorderPointTypes.iLeftBottomCorner270
Case 14
Return Enums.eBorderPointTypes.iRightBottomCorner270
Case 15
'all 4 tiles surrounding, so not at an edge, so no line to be drawn
Return Enums.eBorderPointTypes.iNotAtEdge
End Select
Return Enums.eBorderPointTypes.iNotAtEdge
End Sub
Public Sub GetPolygonListFromAreaBorderTiles(tMTXY_Start As TMapTileXY, mapTileLookup As Map, iZoom As Int) As List
Dim tMTXY As TMapTileXY 'indicating the current XY point
Dim lstTilesLatLng As List
Dim iPointType As Int
lstTilesLatLng.Initialize
tMTXY = initTileXY(tMTXY_Start.fX, tMTXY_Start.fY)
Dim tLL As TMapLatLng = Tile2LatLon(tMTXY.fX, tMTXY.fY, iZoom)
lstTilesLatLng.Add(tLL)
Do While True
iPointType = GetBorderLinePointType(tMTXY, mapTileLookup)
Select Case iPointType
Case Enums.eBorderPointTypes.iTopLine
'go right
Dim tLL As TMapLatLng = Tile2LatLon((tMTXY.fX + 1), tMTXY.fY, iZoom)
lstTilesLatLng.Add(tLL)
tMTXY = initTileXY(tMTXY.fX + 1, tMTXY.fY)
Case Enums.eBorderPointTypes.iRightLine
'go down
Dim tLL As TMapLatLng = Tile2LatLon((tMTXY.fX), tMTXY.fY + 1, iZoom)
lstTilesLatLng.Add(tLL)
tMTXY = initTileXY(tMTXY.fX, tMTXY.fY + 1)
Case Enums.eBorderPointTypes.iBottomLine
'go left
Dim tLL As TMapLatLng = Tile2LatLon((tMTXY.fX - 1), tMTXY.fY, iZoom)
lstTilesLatLng.Add(tLL)
tMTXY = initTileXY(tMTXY.fX - 1, tMTXY.fY)
Case Enums.eBorderPointTypes.iLeftLine
'go up
Dim tLL As TMapLatLng = Tile2LatLon((tMTXY.fX), tMTXY.fY - 1, iZoom)
lstTilesLatLng.Add(tLL)
tMTXY = initTileXY(tMTXY.fX, tMTXY.fY - 1)
Case Enums.eBorderPointTypes.iLeftTopCorner90
'go right
Dim tLL As TMapLatLng = Tile2LatLon((tMTXY.fX + 1), tMTXY.fY, iZoom)
lstTilesLatLng.Add(tLL)
tMTXY = initTileXY(tMTXY.fX + 1, tMTXY.fY)
Case Enums.eBorderPointTypes.iRightTopCorner90
'go down
Dim tLL As TMapLatLng = Tile2LatLon((tMTXY.fX), tMTXY.fY + 1, iZoom)
lstTilesLatLng.Add(tLL)
tMTXY = initTileXY(tMTXY.fX, tMTXY.fY + 1)
Case Enums.eBorderPointTypes.iRightBottomCorner90
'go left
Dim tLL As TMapLatLng = Tile2LatLon((tMTXY.fX - 1), tMTXY.fY, iZoom)
lstTilesLatLng.Add(tLL)
tMTXY = initTileXY(tMTXY.fX - 1, tMTXY.fY)
Case Enums.eBorderPointTypes.iLeftBottomCorner90
'go up
Dim tLL As TMapLatLng = Tile2LatLon((tMTXY.fX), tMTXY.fY - 1, iZoom)
lstTilesLatLng.Add(tLL)
tMTXY = initTileXY(tMTXY.fX, tMTXY.fY - 1)
Case Enums.eBorderPointTypes.iLeftTopCorner270
'go up
Dim tLL As TMapLatLng = Tile2LatLon((tMTXY.fX), tMTXY.fY - 1, iZoom)
lstTilesLatLng.Add(tLL)
tMTXY = initTileXY(tMTXY.fX, tMTXY.fY - 1)
Case Enums.eBorderPointTypes.iRightTopCorner270
'go right
Dim tLL As TMapLatLng = Tile2LatLon((tMTXY.fX + 1), tMTXY.fY, iZoom)
lstTilesLatLng.Add(tLL)
tMTXY = initTileXY(tMTXY.fX + 1, tMTXY.fY)
Case Enums.eBorderPointTypes.iRightBottomCorner270
'go down
Dim tLL As TMapLatLng = Tile2LatLon((tMTXY.fX), tMTXY.fY + 1, iZoom)
lstTilesLatLng.Add(tLL)
tMTXY = initTileXY(tMTXY.fX, tMTXY.fY + 1)
Case Enums.eBorderPointTypes.iLeftBottomCorner270
'go left
Dim tLL As TMapLatLng = Tile2LatLon((tMTXY.fX - 1), tMTXY.fY, iZoom)
lstTilesLatLng.Add(tLL)
tMTXY = initTileXY(tMTXY.fX - 1, tMTXY.fY)
Case Enums.eBorderPointTypes.iLeftTopAndRightBottomTouchingAtCornerOnly, Enums.eBorderPointTypes.iRightTopAndLeftBottomTouchingAtCornerOnly
'go to tiles touching point >> may need attention as tMTXY remains the same
Dim tLL As TMapLatLng = Tile2LatLon((tMTXY.fX - 1), tMTXY.fY, iZoom)
lstTilesLatLng.Add(tLL)
Case Enums.eBorderPointTypes.iNotAtEdge
'no line to draw, so no tLL added to list
End Select
'check for returned to start
If tMTXY.fX = tMTXY_Start.fX Then
If tMTXY.fY = tMTXY_Start.fY Then
Exit
End If
End If
Loop
Return lstTilesLatLng
End Sub
[CODE]
All working fine, but only lightly tested.
RBS