117
PBMap.pb
117
PBMap.pb
@@ -40,7 +40,6 @@ DeclareModule PBMap
|
||||
#MODE_SELECT = 2
|
||||
#MODE_EDIT = 3
|
||||
|
||||
;-Declarations
|
||||
Declare InitPBMap(window)
|
||||
Declare SetOption(Option.s, Value.s)
|
||||
Declare LoadOptions(PreferencesFile.s = "PBMap.prefs")
|
||||
@@ -51,8 +50,7 @@ DeclareModule PBMap
|
||||
Declare SetLocation(latitude.d, longitude.d, Zoom = -1, mode.i = #PB_Absolute)
|
||||
Declare Drawing()
|
||||
Declare SetZoom(Zoom.i, mode.i = #PB_Relative)
|
||||
Declare ZoomToArea(MinY.d, MaxY.d, MinX.d, MaxX.d)
|
||||
Declare ZoomToTracks(*Tracks)
|
||||
Declare ZoomToArea()
|
||||
Declare SetCallBackLocation(*CallBackLocation)
|
||||
Declare SetCallBackMainPointer(CallBackMainPointer.i)
|
||||
Declare SetMapScaleUnit(ScaleUnit=PBMAP::#SCALE_KM)
|
||||
@@ -178,10 +176,6 @@ Module PBMap
|
||||
ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/
|
||||
EndStructure
|
||||
|
||||
Structure Tracks
|
||||
List Track.GeographicCoordinates() ; To display a GPX track
|
||||
EndStructure
|
||||
|
||||
;-PBMap Structure
|
||||
Structure PBMap
|
||||
Window.i ; Parent Window
|
||||
@@ -212,7 +206,7 @@ Module PBMap
|
||||
Moving.i
|
||||
Dirty.i ; To signal that drawing need a refresh
|
||||
|
||||
List TracksList.Tracks()
|
||||
List track.GeographicCoordinates() ; To display a GPX track
|
||||
List Markers.Marker() ; To diplay marker
|
||||
EditMarker.l
|
||||
|
||||
@@ -673,23 +667,21 @@ Module PBMap
|
||||
Protected *MainNode,*subNode,*child,child.l
|
||||
*MainNode=MainXMLNode(0)
|
||||
*MainNode=XMLNodeFromPath(*MainNode,"/gpx/trk/trkseg")
|
||||
Protected *NewTrack.Tracks = AddElement(PBMap\TracksList())
|
||||
;ClearList(PBMap\track())
|
||||
ClearList(PBMap\track())
|
||||
For child = 1 To XMLChildCount(*MainNode)
|
||||
*child = ChildXMLNode(*MainNode, child)
|
||||
AddElement(*NewTrack\Track())
|
||||
AddElement(PBMap\track())
|
||||
If ExamineXMLAttributes(*child)
|
||||
While NextXMLAttribute(*child)
|
||||
Select XMLAttributeName(*child)
|
||||
Case "lat"
|
||||
*NewTrack\Track()\Latitude=ValD(XMLAttributeValue(*child))
|
||||
PBMap\track()\Latitude=ValD(XMLAttributeValue(*child))
|
||||
Case "lon"
|
||||
*NewTrack\Track()\Longitude=ValD(XMLAttributeValue(*child))
|
||||
PBMap\track()\Longitude=ValD(XMLAttributeValue(*child))
|
||||
EndSelect
|
||||
Wend
|
||||
EndIf
|
||||
Next
|
||||
ZoomToTracks(LastElement(PBMap\TracksList())) ; <-To center the view, and zoom on the tracks
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
@@ -1010,16 +1002,16 @@ Module PBMap
|
||||
DrawVectorText(Str(dist))
|
||||
EndProcedure
|
||||
|
||||
Procedure DrawTracks(*Drawing.DrawingParameters)
|
||||
Procedure DrawTrack(*Drawing.DrawingParameters)
|
||||
Protected Pixel.PixelCoordinates
|
||||
Protected Location.GeographicCoordinates
|
||||
Protected km.f, memKm.i
|
||||
If ListSize(PBMap\track())>0
|
||||
;Trace Track
|
||||
ForEach PBMap\TracksList()
|
||||
ForEach PBMap\TracksList()\Track()
|
||||
ForEach PBMap\track()
|
||||
;If *Drawing\GeographicCoordinates\Latitude<>0 And *Drawing\GeographicCoordinates\Longitude<>0
|
||||
LatLon2PixelRel(@PBMap\TracksList()\Track(), @Pixel, PBMap\Zoom)
|
||||
If ListIndex(PBMap\TracksList()\Track()) = 0
|
||||
LatLon2PixelRel(@PBMap\track(), @Pixel, PBMap\Zoom)
|
||||
If ListIndex(PBMap\track())=0
|
||||
MovePathCursor(Pixel\X, Pixel\Y)
|
||||
Else
|
||||
AddPathLine(Pixel\X, Pixel\Y)
|
||||
@@ -1028,34 +1020,30 @@ Module PBMap
|
||||
Next
|
||||
VectorSourceColor(RGBA(0, 255, 0, 150))
|
||||
StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner)
|
||||
Next
|
||||
;Draw Distance
|
||||
If PBMap\Options\TrackShowKms
|
||||
BeginVectorLayer()
|
||||
ForEach PBMap\TracksList()
|
||||
km = 0
|
||||
ForEach PBMap\TracksList()\Track()
|
||||
ForEach PBMap\track()
|
||||
;Test Distance
|
||||
If ListIndex(PBMap\TracksList()\Track()) = 0
|
||||
Location\Latitude = PBMap\TracksList()\Track()\Latitude
|
||||
Location\Longitude = PBMap\TracksList()\Track()\Longitude
|
||||
If ListIndex(PBMap\track())=0
|
||||
Location\Latitude=PBMap\track()\Latitude
|
||||
Location\Longitude=PBMap\track()\Longitude
|
||||
Else
|
||||
km = km + HaversineInKM(@Location, @PBMap\TracksList()\Track())
|
||||
Location\Latitude = PBMap\TracksList()\Track()\Latitude
|
||||
Location\Longitude = PBMap\TracksList()\Track()\Longitude
|
||||
km=km+HaversineInKM(@Location,@PBMap\track()) ;<- display Distance
|
||||
Location\Latitude=PBMap\track()\Latitude
|
||||
Location\Longitude=PBMap\track()\Longitude
|
||||
EndIf
|
||||
LatLon2PixelRel(@PBMap\TracksList()\Track(), @Pixel, PBMap\Zoom)
|
||||
If Int(km) <> memKm
|
||||
memKm = Int(km)
|
||||
If PBMap\Zoom > 10
|
||||
|
||||
If PBMap\Options\TrackShowKms
|
||||
LatLon2PixelRel(@PBMap\track(),@Pixel, PBMap\Zoom)
|
||||
If Int(km)<>memKm
|
||||
memKm=Int(km)
|
||||
If PBMap\Zoom>10
|
||||
BeginVectorLayer()
|
||||
TrackPointer(Pixel\X , Pixel\Y, Int(km))
|
||||
EndIf
|
||||
EndIf
|
||||
Next
|
||||
Next
|
||||
EndVectorLayer()
|
||||
EndIf
|
||||
EndIf
|
||||
EndIf
|
||||
Next
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
Procedure DrawMarker(x.i, y.i, Nb, Color.l, Legend.s, Focus.i, Selected.i)
|
||||
@@ -1186,7 +1174,7 @@ Module PBMap
|
||||
DrawTiles(*Drawing, ListIndex(PBMap\Layers()))
|
||||
Next
|
||||
If PBMap\Options\ShowTrack
|
||||
DrawTracks(*Drawing)
|
||||
DrawTrack(*Drawing)
|
||||
EndIf
|
||||
If PBMap\Options\ShowMarkers
|
||||
DrawMarkers()
|
||||
@@ -1264,9 +1252,24 @@ Module PBMap
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
Procedure ZoomToArea(MinY.d, MaxY.d, MinX.d, MaxX.d)
|
||||
Procedure ZoomToArea()
|
||||
;Source => http://gis.stackexchange.com/questions/19632/how-to-calculate-the-optimal-zoom-level-to-display-two-or-more-points-on-a-map
|
||||
;bounding box in long/lat coords (x=long, y=lat)
|
||||
Protected MinY.d,MaxY.d,MinX.d,MaxX.d
|
||||
ForEach PBMap\track()
|
||||
If ListIndex(PBMap\track())=0 Or PBMap\track()\Longitude<MinX
|
||||
MinX=PBMap\track()\Longitude
|
||||
EndIf
|
||||
If ListIndex(PBMap\track())=0 Or PBMap\track()\Longitude>MaxX
|
||||
MaxX=PBMap\track()\Longitude
|
||||
EndIf
|
||||
If ListIndex(PBMap\track())=0 Or PBMap\track()\Latitude<MinY
|
||||
MinY=PBMap\track()\Latitude
|
||||
EndIf
|
||||
If ListIndex(PBMap\track())=0 Or PBMap\track()\Latitude>MaxY
|
||||
MaxY=PBMap\track()\Latitude
|
||||
EndIf
|
||||
Next
|
||||
Protected DeltaX.d=MaxX-MinX ;assumption ! In original code DeltaX have no source
|
||||
Protected centerX.d=MinX+DeltaX/2 ; assumption ! In original code CenterX have no source
|
||||
Protected paddingFactor.f= 1.2 ;paddingFactor: this can be used to get the "120%" effect ThomM refers to. Value of 1.2 would get you the 120%.
|
||||
@@ -1291,31 +1294,6 @@ Module PBMap
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
Procedure ZoomToTracks(*Tracks.Tracks)
|
||||
Protected MinY.d, MaxY.d, MinX.d, MaxX.d
|
||||
If ListSize(*Tracks\Track()) > 0
|
||||
With *Tracks\Track()
|
||||
FirstElement(*Tracks\Track())
|
||||
MinX = \Longitude : MaxX = MinX : MinY = \Latitude : MaxY = MinY
|
||||
ForEach *Tracks\Track()
|
||||
If \Longitude < MinX
|
||||
MinX = \Longitude
|
||||
EndIf
|
||||
If \Longitude > MaxX
|
||||
MaxX = \Longitude
|
||||
EndIf
|
||||
If \Latitude < MinY
|
||||
MinY = \Latitude
|
||||
EndIf
|
||||
If \Latitude > MaxY
|
||||
MaxY = \Latitude
|
||||
EndIf
|
||||
Next
|
||||
ZoomToArea(MinY.d, MaxY.d, MinX.d, MaxX.d)
|
||||
EndWith
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
Procedure SetZoom(Zoom.i, mode.i = #PB_Relative)
|
||||
Select mode
|
||||
Case #PB_Relative
|
||||
@@ -1734,6 +1712,7 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
PBMap::SetZoom( - 1)
|
||||
Case #Gdt_LoadGpx
|
||||
PBMap::LoadGpxFile(OpenFileRequester("Choose a file to load", "", "Gpx|*.gpx", 0))
|
||||
PBMap::ZoomToArea() ; <-To center the view, and zoom on the tracks
|
||||
Case #StringLatitude, #StringLongitude
|
||||
Select EventType()
|
||||
Case #PB_EventType_LostFocus
|
||||
@@ -1765,8 +1744,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
|
||||
CompilerEndIf
|
||||
; IDE Options = PureBasic 5.50 (Windows - x64)
|
||||
; CursorPosition = 1035
|
||||
; FirstLine = 1013
|
||||
; CursorPosition = 1500
|
||||
; FirstLine = 1478
|
||||
; Folding = -------------
|
||||
; EnableThread
|
||||
; EnableXP
|
||||
|
Reference in New Issue
Block a user