Revert "Multiple tracks wip"

This reverts commit 87fe1be7d2.
This commit is contained in:
djes
2016-09-23 16:20:50 +02:00
parent 87fe1be7d2
commit 578a8b7c8b

125
PBMap.pb
View File

@@ -40,7 +40,6 @@ DeclareModule PBMap
#MODE_SELECT = 2 #MODE_SELECT = 2
#MODE_EDIT = 3 #MODE_EDIT = 3
;-Declarations
Declare InitPBMap(window) Declare InitPBMap(window)
Declare SetOption(Option.s, Value.s) Declare SetOption(Option.s, Value.s)
Declare LoadOptions(PreferencesFile.s = "PBMap.prefs") 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 SetLocation(latitude.d, longitude.d, Zoom = -1, mode.i = #PB_Absolute)
Declare Drawing() Declare Drawing()
Declare SetZoom(Zoom.i, mode.i = #PB_Relative) Declare SetZoom(Zoom.i, mode.i = #PB_Relative)
Declare ZoomToArea(MinY.d, MaxY.d, MinX.d, MaxX.d) Declare ZoomToArea()
Declare ZoomToTracks(*Tracks)
Declare SetCallBackLocation(*CallBackLocation) Declare SetCallBackLocation(*CallBackLocation)
Declare SetCallBackMainPointer(CallBackMainPointer.i) Declare SetCallBackMainPointer(CallBackMainPointer.i)
Declare SetMapScaleUnit(ScaleUnit=PBMAP::#SCALE_KM) Declare SetMapScaleUnit(ScaleUnit=PBMAP::#SCALE_KM)
@@ -178,10 +176,6 @@ Module PBMap
ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/ ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/
EndStructure EndStructure
Structure Tracks
List Track.GeographicCoordinates() ; To display a GPX track
EndStructure
;-PBMap Structure ;-PBMap Structure
Structure PBMap Structure PBMap
Window.i ; Parent Window Window.i ; Parent Window
@@ -212,7 +206,7 @@ Module PBMap
Moving.i Moving.i
Dirty.i ; To signal that drawing need a refresh 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 List Markers.Marker() ; To diplay marker
EditMarker.l EditMarker.l
@@ -673,23 +667,21 @@ Module PBMap
Protected *MainNode,*subNode,*child,child.l Protected *MainNode,*subNode,*child,child.l
*MainNode=MainXMLNode(0) *MainNode=MainXMLNode(0)
*MainNode=XMLNodeFromPath(*MainNode,"/gpx/trk/trkseg") *MainNode=XMLNodeFromPath(*MainNode,"/gpx/trk/trkseg")
Protected *NewTrack.Tracks = AddElement(PBMap\TracksList()) ClearList(PBMap\track())
;ClearList(PBMap\track())
For child = 1 To XMLChildCount(*MainNode) For child = 1 To XMLChildCount(*MainNode)
*child = ChildXMLNode(*MainNode, child) *child = ChildXMLNode(*MainNode, child)
AddElement(*NewTrack\Track()) AddElement(PBMap\track())
If ExamineXMLAttributes(*child) If ExamineXMLAttributes(*child)
While NextXMLAttribute(*child) While NextXMLAttribute(*child)
Select XMLAttributeName(*child) Select XMLAttributeName(*child)
Case "lat" Case "lat"
*NewTrack\Track()\Latitude=ValD(XMLAttributeValue(*child)) PBMap\track()\Latitude=ValD(XMLAttributeValue(*child))
Case "lon" Case "lon"
*NewTrack\Track()\Longitude=ValD(XMLAttributeValue(*child)) PBMap\track()\Longitude=ValD(XMLAttributeValue(*child))
EndSelect EndSelect
Wend Wend
EndIf EndIf
Next Next
ZoomToTracks(LastElement(PBMap\TracksList())) ; <-To center the view, and zoom on the tracks
EndIf EndIf
EndProcedure EndProcedure
@@ -1010,51 +1002,47 @@ Module PBMap
DrawVectorText(Str(dist)) DrawVectorText(Str(dist))
EndProcedure EndProcedure
Procedure DrawTracks(*Drawing.DrawingParameters) Procedure DrawTrack(*Drawing.DrawingParameters)
Protected Pixel.PixelCoordinates Protected Pixel.PixelCoordinates
Protected Location.GeographicCoordinates Protected Location.GeographicCoordinates
Protected km.f, memKm.i Protected km.f, memKm.i
;Trace Track If ListSize(PBMap\track())>0
ForEach PBMap\TracksList() ;Trace Track
ForEach PBMap\TracksList()\Track() ForEach PBMap\track()
;If *Drawing\GeographicCoordinates\Latitude<>0 And *Drawing\GeographicCoordinates\Longitude<>0 ;If *Drawing\GeographicCoordinates\Latitude<>0 And *Drawing\GeographicCoordinates\Longitude<>0
LatLon2PixelRel(@PBMap\TracksList()\Track(), @Pixel, PBMap\Zoom) LatLon2PixelRel(@PBMap\track(), @Pixel, PBMap\Zoom)
If ListIndex(PBMap\TracksList()\Track()) = 0 If ListIndex(PBMap\track())=0
MovePathCursor(Pixel\X, Pixel\Y) MovePathCursor(Pixel\X, Pixel\Y)
Else Else
AddPathLine(Pixel\X, Pixel\Y) AddPathLine(Pixel\X, Pixel\Y)
EndIf EndIf
;EndIf ;EndIf
Next Next
VectorSourceColor(RGBA(0, 255, 0, 150)) VectorSourceColor(RGBA(0, 255, 0, 150))
StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner)
Next ;Draw Distance
;Draw Distance ForEach PBMap\track()
If PBMap\Options\TrackShowKms ;Test Distance
BeginVectorLayer() If ListIndex(PBMap\track())=0
ForEach PBMap\TracksList() Location\Latitude=PBMap\track()\Latitude
km = 0 Location\Longitude=PBMap\track()\Longitude
ForEach PBMap\TracksList()\Track() Else
;Test Distance km=km+HaversineInKM(@Location,@PBMap\track()) ;<- display Distance
If ListIndex(PBMap\TracksList()\Track()) = 0 Location\Latitude=PBMap\track()\Latitude
Location\Latitude = PBMap\TracksList()\Track()\Latitude Location\Longitude=PBMap\track()\Longitude
Location\Longitude = PBMap\TracksList()\Track()\Longitude EndIf
Else If PBMap\Options\TrackShowKms
km = km + HaversineInKM(@Location, @PBMap\TracksList()\Track()) LatLon2PixelRel(@PBMap\track(),@Pixel, PBMap\Zoom)
Location\Latitude = PBMap\TracksList()\Track()\Latitude If Int(km)<>memKm
Location\Longitude = PBMap\TracksList()\Track()\Longitude memKm=Int(km)
EndIf If PBMap\Zoom>10
LatLon2PixelRel(@PBMap\TracksList()\Track(), @Pixel, PBMap\Zoom) BeginVectorLayer()
If Int(km) <> memKm
memKm = Int(km)
If PBMap\Zoom > 10
TrackPointer(Pixel\X , Pixel\Y, Int(km)) TrackPointer(Pixel\X , Pixel\Y, Int(km))
EndVectorLayer()
EndIf EndIf
EndIf EndIf
Next EndIf
Next Next
EndVectorLayer()
EndIf EndIf
EndProcedure EndProcedure
@@ -1186,7 +1174,7 @@ Module PBMap
DrawTiles(*Drawing, ListIndex(PBMap\Layers())) DrawTiles(*Drawing, ListIndex(PBMap\Layers()))
Next Next
If PBMap\Options\ShowTrack If PBMap\Options\ShowTrack
DrawTracks(*Drawing) DrawTrack(*Drawing)
EndIf EndIf
If PBMap\Options\ShowMarkers If PBMap\Options\ShowMarkers
DrawMarkers() DrawMarkers()
@@ -1264,9 +1252,24 @@ Module PBMap
EndIf EndIf
EndProcedure 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 ;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) ;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 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 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%. 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 EndIf
EndProcedure 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) Procedure SetZoom(Zoom.i, mode.i = #PB_Relative)
Select mode Select mode
Case #PB_Relative Case #PB_Relative
@@ -1734,6 +1712,7 @@ CompilerIf #PB_Compiler_IsMainFile
PBMap::SetZoom( - 1) PBMap::SetZoom( - 1)
Case #Gdt_LoadGpx Case #Gdt_LoadGpx
PBMap::LoadGpxFile(OpenFileRequester("Choose a file to load", "", "Gpx|*.gpx", 0)) 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 Case #StringLatitude, #StringLongitude
Select EventType() Select EventType()
Case #PB_EventType_LostFocus Case #PB_EventType_LostFocus
@@ -1765,8 +1744,8 @@ CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.50 (Windows - x64) ; IDE Options = PureBasic 5.50 (Windows - x64)
; CursorPosition = 1035 ; CursorPosition = 1500
; FirstLine = 1013 ; FirstLine = 1478
; Folding = ------------- ; Folding = -------------
; EnableThread ; EnableThread
; EnableXP ; EnableXP