Delete markers (wip CTRL key)

This commit is contained in:
djes
2016-09-16 11:42:20 +02:00
parent 60288ffbef
commit 95ec4c41de

View File

@@ -58,6 +58,7 @@ DeclareModule PBMap
Declare.i AddMarker(Latitude.d, Longitude.d, Legend.s = "", color.l=-1, CallBackPointer.i = -1) Declare.i AddMarker(Latitude.d, Longitude.d, Legend.s = "", color.l=-1, CallBackPointer.i = -1)
Declare ClearMarkers() Declare ClearMarkers()
Declare DeleteMarker(*Ptr) Declare DeleteMarker(*Ptr)
Declare DeleteSelectedMarkers()
Declare Quit() Declare Quit()
Declare Error(msg.s) Declare Error(msg.s)
Declare Refresh() Declare Refresh()
@@ -206,7 +207,7 @@ Module PBMap
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 track.GeographicCoordinates() ; To display a GPX track
List Markers.Marker() ; To diplay marker List Markers.Marker() ; To diplay marker
EditMarker.l EditMarker.l
ImgLoading.i ; Image Loading Tile ImgLoading.i ; Image Loading Tile
@@ -884,14 +885,14 @@ Module PBMap
EndIf EndIf
Else Else
;If PBMap\Layers()\Name = "" ;If PBMap\Layers()\Name = ""
MovePathCursor(px, py) MovePathCursor(px, py)
DrawVectorImage(ImageID(PBMap\ImgNothing)) DrawVectorImage(ImageID(PBMap\ImgNothing))
;EndIf ;EndIf
EndIf EndIf
Next Next
Next Next
EndProcedure EndProcedure
Procedure DrawPointer(*Drawing.DrawingParameters) Procedure DrawPointer(*Drawing.DrawingParameters)
If PBMap\CallBackMainPointer > 0 If PBMap\CallBackMainPointer > 0
; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib) ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib)
@@ -1009,12 +1010,12 @@ Module PBMap
;Trace Track ;Trace Track
ForEach PBMap\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\track(), @Pixel, PBMap\Zoom) LatLon2PixelRel(@PBMap\track(), @Pixel, PBMap\Zoom)
If ListIndex(PBMap\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))
@@ -1081,16 +1082,25 @@ Module PBMap
DrawVectorParagraph(Legend, 100, Height, #PB_VectorParagraph_Center) DrawVectorParagraph(Legend, 100, Height, #PB_VectorParagraph_Center)
EndIf EndIf
EndProcedure EndProcedure
Procedure ClearMarkers() Procedure ClearMarkers()
ClearList(PBMap\Markers()) ClearList(PBMap\Markers())
EndProcedure EndProcedure
Procedure DeleteMarker(*Ptr) Procedure DeleteMarker(*Ptr)
ChangeCurrentElement(PBMap\Markers(), *Ptr) ChangeCurrentElement(PBMap\Markers(), *Ptr)
DeleteElement(PBMap\Markers()) DeleteElement(PBMap\Markers())
EndProcedure EndProcedure
Procedure DeleteSelectedMarkers()
ForEach PBMap\Markers()
If PBMap\Markers()\Selected
DeleteElement(PBMap\Markers())
PBMap\Redraw = #True
EndIf
Next
EndProcedure
Procedure.i AddMarker(Latitude.d, Longitude.d, Legend.s = "", Color.l=-1, CallBackPointer.i = -1) Procedure.i AddMarker(Latitude.d, Longitude.d, Legend.s = "", Color.l=-1, CallBackPointer.i = -1)
Protected *Ptr = AddElement(PBMap\Markers()) Protected *Ptr = AddElement(PBMap\Markers())
If *Ptr If *Ptr
@@ -1139,7 +1149,7 @@ Module PBMap
Next Next
DrawVectorText(Str(ThreadCounter)) DrawVectorText(Str(ThreadCounter))
EndProcedure EndProcedure
;-*** Main drawing ;-*** Main drawing
Procedure Drawing() Procedure Drawing()
Protected *Drawing.DrawingParameters = @PBMap\Drawing Protected *Drawing.DrawingParameters = @PBMap\Drawing
@@ -1391,11 +1401,42 @@ Module PBMap
Procedure CanvasEvents() Procedure CanvasEvents()
Protected MouseX.i, MouseY.i Protected MouseX.i, MouseY.i
Protected MarkerCoords.PixelCoordinates, *Tile.Tile, MapWidth = Pow(2, PBMap\Zoom) * PBMap\TileSize Protected MarkerCoords.PixelCoordinates, *Tile.Tile, MapWidth = Pow(2, PBMap\Zoom) * PBMap\TileSize
Protected key.s Protected key.s, Touch.i, CtrlKey.i
PBMap\Moving = #False PBMap\Moving = #False
Select EventType() Select EventType()
Case #PB_EventType_KeyUp
Select GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_Key)
Case #PB_Shortcut_Delete
DeleteSelectedMarkers()
Case #PB_Canvas_Control
CtrlKey = #False
EndSelect
Case #PB_EventType_KeyDown
Select GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_Key)
Case #PB_Canvas_Control
CtrlKey = #True
EndSelect
Case #PB_EventType_LeftDoubleClick Case #PB_EventType_LeftDoubleClick
GotoPixelRel(GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX), GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)) If PBMap\Mode = #MODE_DEFAULT Or PBMap\Mode = #MODE_SELECT
;Check if the mouse touch a marker, if so, jump to it
LatLon2Pixel(@PBMap\GeographicCoordinates, @PBMap\PixelCoordinates, PBMap\Zoom)
MouseX = PBMap\PixelCoordinates\x - GadgetWidth(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
MouseY = PBMap\PixelCoordinates\y - GadgetHeight(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
;Clip MouseX to the map range (in X, the map is infinite)
MouseX = Mod(Mod(MouseX, MapWidth) + MapWidth, MapWidth)
Touch = #False
ForEach PBMap\Markers()
LatLon2Pixel(@PBMap\Markers()\GeographicCoordinates, @MarkerCoords, PBMap\Zoom)
If Distance(MarkerCoords\x, MarkerCoords\y, MouseX, MouseY) < 8
Touch = #True
SetLocation(PBMap\Markers()\GeographicCoordinates\Latitude, PBMap\Markers()\GeographicCoordinates\Longitude)
Break
EndIf
Next
EndIf
If Not Touch
GotoPixelRel(GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX), GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY))
EndIf
Case #PB_EventType_MouseWheel Case #PB_EventType_MouseWheel
If PBMap\Options\WheelMouseRelative If PBMap\Options\WheelMouseRelative
;Relative zoom (centered on the mouse) ;Relative zoom (centered on the mouse)
@@ -1432,19 +1473,19 @@ Module PBMap
MouseY = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) - PBMap\MoveStartingPoint\y MouseY = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) - PBMap\MoveStartingPoint\y
;Move selected markers ;Move selected markers
If PBMap\EditMarker And (PBMap\Mode = #MODE_DEFAULT Or PBMap\Mode = #MODE_SELECT) If PBMap\EditMarker And (PBMap\Mode = #MODE_DEFAULT Or PBMap\Mode = #MODE_SELECT)
ForEach PBMap\Markers() ForEach PBMap\Markers()
If PBMap\Markers()\Selected If PBMap\Markers()\Selected
LatLon2Pixel(@PBMap\Markers()\GeographicCoordinates, @MarkerCoords, PBMap\Zoom) LatLon2Pixel(@PBMap\Markers()\GeographicCoordinates, @MarkerCoords, PBMap\Zoom)
MarkerCoords\x + MouseX MarkerCoords\x + MouseX
MarkerCoords\y + MouseY MarkerCoords\y + MouseY
Pixel2LatLon(@MarkerCoords, @PBMap\Markers()\GeographicCoordinates, PBMap\Zoom) Pixel2LatLon(@MarkerCoords, @PBMap\Markers()\GeographicCoordinates, PBMap\Zoom)
EndIf EndIf
Next Next
ElseIf PBMap\Mode = #MODE_DEFAULT Or PBMap\Mode = #MODE_HAND ElseIf PBMap\Mode = #MODE_DEFAULT Or PBMap\Mode = #MODE_HAND
;Move map only ;Move map only
LatLon2Pixel(@PBMap\GeographicCoordinates, @PBMap\PixelCoordinates, PBMap\Zoom) ;This line could be removed as the coordinates don't have to change but I want to be sure we rely only on geographic coordinates LatLon2Pixel(@PBMap\GeographicCoordinates, @PBMap\PixelCoordinates, PBMap\Zoom) ;This line could be removed as the coordinates don't have to change but I want to be sure we rely only on geographic coordinates
;Ensures that pixel position stay in the range [0..2^Zoom*PBMap\TileSize[ coz of the wrapping of the map
PBMap\PixelCoordinates\x - MouseX PBMap\PixelCoordinates\x - MouseX
;Ensures that pixel position stay in the range [0..2^Zoom*PBMap\TileSize[ coz of the wrapping of the map
PBMap\PixelCoordinates\x = Mod(Mod(PBMap\PixelCoordinates\x, MapWidth) + MapWidth, MapWidth) PBMap\PixelCoordinates\x = Mod(Mod(PBMap\PixelCoordinates\x, MapWidth) + MapWidth, MapWidth)
PBMap\PixelCoordinates\y - MouseY PBMap\PixelCoordinates\y - MouseY
Pixel2LatLon(@PBMap\PixelCoordinates, @PBMap\GeographicCoordinates, PBMap\Zoom) Pixel2LatLon(@PBMap\PixelCoordinates, @PBMap\GeographicCoordinates, PBMap\Zoom)
@@ -1469,7 +1510,9 @@ Module PBMap
If Distance(MarkerCoords\x, MarkerCoords\y, MouseX, MouseY) < 8 If Distance(MarkerCoords\x, MarkerCoords\y, MouseX, MouseY) < 8
PBMap\Markers()\Focus = #True PBMap\Markers()\Focus = #True
Else Else
PBMap\Markers()\Focus = #False If CtrlKey = #False
PBMap\Markers()\Focus = #False
EndIf
EndIf EndIf
Next Next
EndIf EndIf
@@ -1514,6 +1557,7 @@ Module PBMap
BindGadgetEvent(PBMap\Gadget, @CanvasEvents()) BindGadgetEvent(PBMap\Gadget, @CanvasEvents())
AddWindowTimer(PBMap\Window, PBMap\Timer, PBMap\Options\TimerInterval) AddWindowTimer(PBMap\Window, PBMap\Timer, PBMap\Options\TimerInterval)
BindEvent(#PB_Event_Timer, @TimerEvents()) BindEvent(#PB_Event_Timer, @TimerEvents())
;AddKeyboardShortcut(#PB_Shortcut_Delete
EndProcedure EndProcedure
EndModule EndModule
@@ -1641,7 +1685,7 @@ CompilerIf #PB_Compiler_IsMainFile
PBMap::SetCallBackMainPointer(@MainPointer()) ; To change the main pointer (center of the view) PBMap::SetCallBackMainPointer(@MainPointer()) ; To change the main pointer (center of the view)
PBMap::SetCallBackLocation(@UpdateLocation()) ; To obtain realtime coordinates PBMap::SetCallBackLocation(@UpdateLocation()) ; To obtain realtime coordinates
PBMap::SetLocation(-36.81148, 175.08634,12) ; Change the PBMap coordinates PBMap::SetLocation(-36.81148, 175.08634,12) ; Change the PBMap coordinates
PBMAP::SetMapScaleUnit(PBMAP::#SCALE_KM) ; To change the scale unit PBMAP::SetMapScaleUnit(PBMAP::#SCALE_KM) ; To change the scale unit
PBMap::AddMarker(49.0446828398, 2.0349812508, "", -1, @MyMarker()) ; To add a marker with a customised GFX PBMap::AddMarker(49.0446828398, 2.0349812508, "", -1, @MyMarker()) ; To add a marker with a customised GFX
Repeat Repeat
@@ -1697,8 +1741,8 @@ CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.50 (Windows - x64) ; IDE Options = PureBasic 5.50 (Windows - x64)
; CursorPosition = 1675 ; CursorPosition = 1514
; FirstLine = 1654 ; FirstLine = 1487
; Folding = ------------- ; Folding = -------------
; EnableThread ; EnableThread
; EnableXP ; EnableXP