Multitracks wip, markers moving with cursor

This commit is contained in:
djes
2016-09-24 11:29:59 +02:00
parent b1a8db8b1e
commit e3b1bc8a6d
2 changed files with 97 additions and 65 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
PBMap.pb.bak

161
PBMap.pb
View File

@@ -40,6 +40,7 @@ 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")
@@ -50,7 +51,8 @@ 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() Declare ZoomToArea(MinY.d, MaxY.d, MinX.d, MaxX.d)
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)
@@ -111,8 +113,6 @@ Module PBMap
TileCoordinates.Coordinates TileCoordinates.Coordinates
Bounds.TileBounds Bounds.TileBounds
Canvas.i Canvas.i
PBMapTileX.i
PBMapTileY.i
PBMapZoom.i PBMapZoom.i
GeographicCoordinates.GeographicCoordinates GeographicCoordinates.GeographicCoordinates
CenterX.i CenterX.i
@@ -176,6 +176,9 @@ 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()
EndStructure
;-PBMap Structure ;-PBMap Structure
Structure PBMap Structure PBMap
Window.i ; Parent Window Window.i ; Parent Window
@@ -206,7 +209,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 track.GeographicCoordinates() ; To display a GPX track List TracksList.Tracks() ; To display a GPX track
List Markers.Marker() ; To diplay marker List Markers.Marker() ; To diplay marker
EditMarker.l EditMarker.l
@@ -672,21 +675,22 @@ 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")
ClearList(PBMap\track()) Protected *NewTrack.Tracks = AddElement(PBMap\TracksList())
For child = 1 To XMLChildCount(*MainNode) For child = 1 To XMLChildCount(*MainNode)
*child = ChildXMLNode(*MainNode, child) *child = ChildXMLNode(*MainNode, child)
AddElement(PBMap\track()) AddElement(*NewTrack\Track())
If ExamineXMLAttributes(*child) If ExamineXMLAttributes(*child)
While NextXMLAttribute(*child) While NextXMLAttribute(*child)
Select XMLAttributeName(*child) Select XMLAttributeName(*child)
Case "lat" Case "lat"
PBMap\track()\Latitude=ValD(XMLAttributeValue(*child)) *NewTrack\Track()\Latitude=ValD(XMLAttributeValue(*child))
Case "lon" Case "lon"
PBMap\track()\Longitude=ValD(XMLAttributeValue(*child)) *NewTrack\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
@@ -894,6 +898,14 @@ Module PBMap
DrawVectorImage(ImageID(PBMap\ImgNothing)) DrawVectorImage(ImageID(PBMap\ImgNothing))
;EndIf ;EndIf
EndIf EndIf
If PBMap\Options\ShowDebugInfos
VectorFont(FontID(PBMap\Font), 16)
VectorSourceColor(RGBA(0, 0, 0, 80))
MovePathCursor(px, py)
DrawVectorText("x:" + Str(tilex))
MovePathCursor(px, py + 16)
DrawVectorText("y:" + Str(tiley))
EndIf
Next Next
Next Next
EndProcedure EndProcedure
@@ -1007,47 +1019,56 @@ Module PBMap
DrawVectorText(Str(dist)) DrawVectorText(Str(dist))
EndProcedure EndProcedure
Procedure DrawTrack(*Drawing.DrawingParameters) Procedure DrawTracks(*Drawing.DrawingParameters)
Protected Pixel.PixelCoordinates Protected Pixel.PixelCoordinates
Protected Location.GeographicCoordinates Protected Location.GeographicCoordinates
Protected km.f, memKm.i Protected km.f, memKm.i
If ListSize(PBMap\track())>0 ;Trace Track
;Trace Track If ListSize(PBMap\TracksList()) > 0
ForEach PBMap\track() BeginVectorLayer()
;If *Drawing\GeographicCoordinates\Latitude<>0 And *Drawing\GeographicCoordinates\Longitude<>0 ForEach PBMap\TracksList()
LatLon2PixelRel(@PBMap\track(), @Pixel, PBMap\Zoom) If ListSize(PBMap\TracksList()\Track()) > 0
If ListIndex(PBMap\track())=0 ForEach PBMap\TracksList()\Track()
MovePathCursor(Pixel\X, Pixel\Y) ;If *Drawing\GeographicCoordinates\Latitude<>0 And *Drawing\GeographicCoordinates\Longitude<>0
Else LatLon2PixelRel(@PBMap\TracksList()\Track(), @Pixel, PBMap\Zoom)
AddPathLine(Pixel\X, Pixel\Y) If ListIndex(PBMap\TracksList()\Track()) = 0
EndIf MovePathCursor(Pixel\X, Pixel\Y)
;EndIf Else
Next AddPathLine(Pixel\X, Pixel\Y)
VectorSourceColor(RGBA(0, 255, 0, 150)) EndIf
StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) ;EndIf
;Draw Distance Next
ForEach PBMap\track() VectorSourceColor(RGBA(0, 255, 0, 150))
;Test Distance StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner)
If ListIndex(PBMap\track())=0
Location\Latitude=PBMap\track()\Latitude
Location\Longitude=PBMap\track()\Longitude
Else
km=km+HaversineInKM(@Location,@PBMap\track()) ;<- display Distance
Location\Latitude=PBMap\track()\Latitude
Location\Longitude=PBMap\track()\Longitude
EndIf EndIf
If PBMap\Options\TrackShowKms Next
LatLon2PixelRel(@PBMap\track(),@Pixel, PBMap\Zoom) EndVectorLayer()
If Int(km)<>memKm EndIf
memKm=Int(km) ;Draw Distance
If PBMap\Zoom>10 If PBMap\Options\TrackShowKms And ListSize(PBMap\TracksList()) > 0
BeginVectorLayer() BeginVectorLayer()
ForEach PBMap\TracksList()
km = 0 : memKm = -1
ForEach PBMap\TracksList()\Track()
;Test Distance
If ListIndex(PBMap\TracksList()\Track()) = 0
Location\Latitude = PBMap\TracksList()\Track()\Latitude
Location\Longitude = PBMap\TracksList()\Track()\Longitude
Else
km = km + HaversineInKM(@Location, @PBMap\TracksList()\Track())
Location\Latitude = PBMap\TracksList()\Track()\Latitude
Location\Longitude = PBMap\TracksList()\Track()\Longitude
EndIf
LatLon2PixelRel(@PBMap\TracksList()\Track(), @Pixel, PBMap\Zoom)
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
EndIf Next
Next Next
EndVectorLayer()
EndIf EndIf
EndProcedure EndProcedure
@@ -1153,6 +1174,8 @@ Module PBMap
EndIf EndIf
Next Next
DrawVectorText(Str(ThreadCounter)) DrawVectorText(Str(ThreadCounter))
MovePathCursor(50,110)
DrawVectorText(Str(PBMap\Zoom))
EndProcedure EndProcedure
;-*** Main drawing ;-*** Main drawing
@@ -1179,7 +1202,7 @@ Module PBMap
DrawTiles(*Drawing, ListIndex(PBMap\Layers())) DrawTiles(*Drawing, ListIndex(PBMap\Layers()))
Next Next
If PBMap\Options\ShowTrack If PBMap\Options\ShowTrack
DrawTrack(*Drawing) DrawTracks(*Drawing)
EndIf EndIf
If PBMap\Options\ShowMarkers If PBMap\Options\ShowMarkers
DrawMarkers() DrawMarkers()
@@ -1257,24 +1280,9 @@ Module PBMap
EndIf EndIf
EndProcedure EndProcedure
Procedure ZoomToArea() Procedure ZoomToArea(MinY.d, MaxY.d, MinX.d, MaxX.d)
;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%.
@@ -1299,6 +1307,30 @@ 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
@@ -1715,7 +1747,7 @@ CompilerIf #PB_Compiler_IsMainFile
;Our main gadget ;Our main gadget
PBMap::InitPBMap(#Window_0) PBMap::InitPBMap(#Window_0)
PBMap::SetOption("ShowDegrees", "1") PBMap::SetOption("ShowDegrees", "1")
PBMap::SetOption("ShowDebugInfos", "1") PBMap::SetOption("ShowDebugInfos", "0")
PBMap::SetOption("ShowScale", "1") PBMap::SetOption("ShowScale", "1")
PBMap::SetOption("ShowMarkersLegend", "1") PBMap::SetOption("ShowMarkersLegend", "1")
PBMap::SetOption("TrackShowKms", "1") PBMap::SetOption("TrackShowKms", "1")
@@ -1747,7 +1779,6 @@ 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
@@ -1778,10 +1809,10 @@ CompilerIf #PB_Compiler_IsMainFile
EndIf EndIf
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.42 LTS (Windows - x64) ; IDE Options = PureBasic 5.50 (Windows - x64)
; CursorPosition = 1433 ; CursorPosition = 11
; FirstLine = 1405
; Folding = ------------- ; Folding = -------------
; EnableUnicode
; EnableThread ; EnableThread
; EnableXP ; EnableXP
; DisableDebugger
; EnableUnicode