Delete markers (wip CTRL key)
This commit is contained in:
52
PBMap.pb
52
PBMap.pb
@@ -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()
|
||||||
@@ -1091,6 +1092,15 @@ Module PBMap
|
|||||||
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
|
||||||
@@ -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
|
||||||
|
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))
|
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)
|
||||||
@@ -1443,8 +1484,8 @@ Module PBMap
|
|||||||
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,8 +1510,10 @@ 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
|
||||||
|
If CtrlKey = #False
|
||||||
PBMap\Markers()\Focus = #False
|
PBMap\Markers()\Focus = #False
|
||||||
EndIf
|
EndIf
|
||||||
|
EndIf
|
||||||
Next
|
Next
|
||||||
EndIf
|
EndIf
|
||||||
PBMap\Redraw = #True
|
PBMap\Redraw = #True
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
|
Reference in New Issue
Block a user