New markers select/move
This commit is contained in:
106
PBMap.pb
106
PBMap.pb
@@ -137,7 +137,8 @@ Module PBMap
|
|||||||
|
|
||||||
Structure Marker
|
Structure Marker
|
||||||
GeographicCoordinates.GeographicCoordinates ; Marker latitude and longitude
|
GeographicCoordinates.GeographicCoordinates ; Marker latitude and longitude
|
||||||
color.l ; Marker color
|
Color.l ; Marker color
|
||||||
|
Selected.i ; Is the marker selected ?
|
||||||
CallBackPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib)
|
CallBackPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib)
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
@@ -196,7 +197,7 @@ Module PBMap
|
|||||||
|
|
||||||
List track.GeographicCoordinates() ; To display a GPX track
|
List track.GeographicCoordinates() ; To display a GPX track
|
||||||
List Marker.Marker() ; To diplay marker
|
List Marker.Marker() ; To diplay marker
|
||||||
EditMarkerIndex.l
|
EditMarker.l
|
||||||
|
|
||||||
ImgLoading.i ; Image Loading Tile
|
ImgLoading.i ; Image Loading Tile
|
||||||
ImgNothing.i ; Image Nothing Tile
|
ImgNothing.i ; Image Nothing Tile
|
||||||
@@ -429,8 +430,7 @@ Module PBMap
|
|||||||
PBMap\MoveStartingPoint\x = - 1
|
PBMap\MoveStartingPoint\x = - 1
|
||||||
PBMap\TileSize = 256
|
PBMap\TileSize = 256
|
||||||
PBMap\Dirty = #False
|
PBMap\Dirty = #False
|
||||||
;PBMap\TileThreadMutex = CreateMutex()
|
PBMap\EditMarker = #False
|
||||||
PBMap\EditMarkerIndex = -1 ;Initialised with "no marker selected"
|
|
||||||
PBMap\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold)
|
PBMap\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold)
|
||||||
PBMap\Window = Window
|
PBMap\Window = Window
|
||||||
PBMap\Timer = 1
|
PBMap\Timer = 1
|
||||||
@@ -1030,7 +1030,7 @@ Module PBMap
|
|||||||
EndIf
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure DrawMarker(x.i, y.i, color.l = 0)
|
Procedure DrawMarker(x.i, y.i, color.l = 0, Selected = #False)
|
||||||
VectorSourceColor(color)
|
VectorSourceColor(color)
|
||||||
MovePathCursor(x, y)
|
MovePathCursor(x, y)
|
||||||
AddPathLine(-8, -16, #PB_Path_Relative)
|
AddPathLine(-8, -16, #PB_Path_Relative)
|
||||||
@@ -1040,8 +1040,14 @@ Module PBMap
|
|||||||
;ClipPath(#PB_Path_Preserve)
|
;ClipPath(#PB_Path_Preserve)
|
||||||
AddPathCircle(0, -16, 5, 0, 360, #PB_Path_Relative)
|
AddPathCircle(0, -16, 5, 0, 360, #PB_Path_Relative)
|
||||||
VectorSourceColor(color)
|
VectorSourceColor(color)
|
||||||
FillPath(#PB_Path_Preserve):VectorSourceColor(color);RGBA(0, 0, 0, 255))
|
FillPath(#PB_Path_Preserve)
|
||||||
|
If Selected
|
||||||
|
VectorSourceColor(RGBA(255, 255, 0, 255))
|
||||||
|
StrokePath(3)
|
||||||
|
Else
|
||||||
|
VectorSourceColor(color)
|
||||||
StrokePath(1)
|
StrokePath(1)
|
||||||
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; Add a Marker To the Map
|
; Add a Marker To the Map
|
||||||
@@ -1063,9 +1069,9 @@ Module PBMap
|
|||||||
LatLon2PixelRel(PBMap\Marker()\GeographicCoordinates, @Pixel, PBMap\Zoom)
|
LatLon2PixelRel(PBMap\Marker()\GeographicCoordinates, @Pixel, PBMap\Zoom)
|
||||||
If Pixel\X >= 0 And Pixel\Y >= 0 And Pixel\X < GadgetWidth(PBMap\Gadget) And Pixel\Y < GadgetHeight(PBMap\Gadget) ; Only if visible ^_^
|
If Pixel\X >= 0 And Pixel\Y >= 0 And Pixel\X < GadgetWidth(PBMap\Gadget) And Pixel\Y < GadgetHeight(PBMap\Gadget) ; Only if visible ^_^
|
||||||
If PBMap\Marker()\CallBackPointer > 0
|
If PBMap\Marker()\CallBackPointer > 0
|
||||||
CallFunctionFast(PBMap\Marker()\CallBackPointer, Pixel\X, Pixel\Y)
|
CallFunctionFast(PBMap\Marker()\CallBackPointer, Pixel\X, Pixel\Y, PBMap\Marker()\Selected)
|
||||||
Else
|
Else
|
||||||
DrawMarker(Pixel\X, Pixel\Y, PBMap\Marker()\color)
|
DrawMarker(Pixel\X, Pixel\Y, PBMap\Marker()\Color, PBMap\Marker()\Selected)
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
@@ -1330,7 +1336,7 @@ Module PBMap
|
|||||||
|
|
||||||
Procedure CanvasEvents()
|
Procedure CanvasEvents()
|
||||||
Protected MouseX.i, MouseY.i
|
Protected MouseX.i, MouseY.i
|
||||||
Protected MarkerCoords.Coordinates, *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
|
||||||
PBMap\Moving = #False
|
PBMap\Moving = #False
|
||||||
Select EventType()
|
Select EventType()
|
||||||
@@ -1353,12 +1359,8 @@ Module PBMap
|
|||||||
If PBMap\Mode = #MODE_DEFAULT Or PBMap\Mode = #MODE_SELECT
|
If PBMap\Mode = #MODE_DEFAULT Or PBMap\Mode = #MODE_SELECT
|
||||||
;Check if we select a marker
|
;Check if we select a marker
|
||||||
ForEach PBMap\Marker()
|
ForEach PBMap\Marker()
|
||||||
LatLon2TileXY(@PBMap\Marker()\GeographicCoordinates, @MarkerCoords, 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
|
If PBMap\Marker()\Selected
|
||||||
MarkerCoords\x * PBMap\TileSize
|
PBMap\EditMarker = #True;ListIndex(PBMap\Marker())
|
||||||
MarkerCoords\y * PBMap\TileSize
|
|
||||||
;Debug "Pos : " + StrD(Marker\x) + " ; Drawing pos : " + StrD(PBMap\Drawing\TileCoordinates\x)
|
|
||||||
If Distance(MarkerCoords\x, MarkerCoords\y, MouseX, MouseY) < 8
|
|
||||||
PBMap\EditMarkerIndex = ListIndex(PBMap\Marker())
|
|
||||||
Break
|
Break
|
||||||
EndIf
|
EndIf
|
||||||
Next
|
Next
|
||||||
@@ -1371,15 +1373,19 @@ Module PBMap
|
|||||||
If PBMap\MoveStartingPoint\x <> - 1
|
If PBMap\MoveStartingPoint\x <> - 1
|
||||||
MouseX = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) - PBMap\MoveStartingPoint\x
|
MouseX = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) - PBMap\MoveStartingPoint\x
|
||||||
MouseY = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) - PBMap\MoveStartingPoint\y
|
MouseY = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) - PBMap\MoveStartingPoint\y
|
||||||
;Move marker
|
;Move selected markers
|
||||||
If PBMap\EditMarkerIndex > -1 And (PBMap\Mode = #MODE_DEFAULT Or PBMap\Mode = #MODE_SELECT)
|
If PBMap\EditMarker And (PBMap\Mode = #MODE_DEFAULT Or PBMap\Mode = #MODE_SELECT)
|
||||||
SelectElement(PBMap\Marker(), PBMap\EditMarkerIndex)
|
ForEach PBMap\Marker()
|
||||||
LatLon2TileXY(@PBMap\Marker()\GeographicCoordinates, @MarkerCoords, PBMap\Zoom)
|
If PBMap\Marker()\Selected
|
||||||
MarkerCoords\x + MouseX / PBMap\TileSize
|
LatLon2Pixel(@PBMap\Marker()\GeographicCoordinates, @MarkerCoords, PBMap\Zoom)
|
||||||
MarkerCoords\y + MouseY / PBMap\TileSize
|
MarkerCoords\x + MouseX
|
||||||
TileXY2LatLon(@MarkerCoords, @PBMap\Marker()\GeographicCoordinates, PBMap\Zoom)
|
MarkerCoords\y + MouseY
|
||||||
|
Pixel2LatLon(@MarkerCoords, @PBMap\Marker()\GeographicCoordinates, PBMap\Zoom)
|
||||||
|
Break ;Only one marker moved at once
|
||||||
|
EndIf
|
||||||
|
Next
|
||||||
ElseIf PBMap\Mode = #MODE_DEFAULT Or PBMap\Mode = #MODE_HAND
|
ElseIf PBMap\Mode = #MODE_DEFAULT Or PBMap\Mode = #MODE_HAND
|
||||||
;New move values
|
;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
|
;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
|
||||||
@@ -1394,18 +1400,35 @@ Module PBMap
|
|||||||
PBMap\Redraw = #True
|
PBMap\Redraw = #True
|
||||||
PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
|
PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
|
||||||
PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
|
PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
|
||||||
|
Else
|
||||||
|
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)
|
||||||
|
If PBMap\Mode = #MODE_DEFAULT Or PBMap\Mode = #MODE_SELECT
|
||||||
|
;Check if mouse touch markers
|
||||||
|
ForEach PBMap\Marker()
|
||||||
|
LatLon2Pixel(@PBMap\Marker()\GeographicCoordinates, @MarkerCoords, PBMap\Zoom)
|
||||||
|
If Distance(MarkerCoords\x, MarkerCoords\y, MouseX, MouseY) < 8
|
||||||
|
PBMap\Marker()\Selected = #True
|
||||||
|
Else
|
||||||
|
PBMap\Marker()\Selected = #False
|
||||||
|
EndIf
|
||||||
|
Next
|
||||||
|
EndIf
|
||||||
|
PBMap\Redraw = #True
|
||||||
EndIf
|
EndIf
|
||||||
Case #PB_EventType_LeftButtonUp
|
Case #PB_EventType_LeftButtonUp
|
||||||
PBMap\MoveStartingPoint\x = - 1
|
PBMap\MoveStartingPoint\x = - 1
|
||||||
If PBMap\EditMarkerIndex > -1
|
If PBMap\EditMarker
|
||||||
PBMap\EditMarkerIndex = -1
|
PBMap\EditMarker = #False
|
||||||
Else ;Move Map
|
;Deselect markers
|
||||||
; PBMap\Drawing\TileCoordinates\x = PBMap\PixelCoordinates\x / PBMap\TileSize
|
ForEach PBMap\Marker()
|
||||||
; PBMap\Drawing\TileCoordinates\y = PBMap\PixelCoordinates\y / PBMap\TileSize
|
PBMap\Marker()\Selected = #False
|
||||||
; MyDebug("PBMap\Drawing\TileCoordinates\x " + Str(PBMap\Drawing\TileCoordinates\x) + " ; PBMap\Drawing\TileCoordinates\y " + Str(PBMap\Drawing\TileCoordinates\y) )
|
Next
|
||||||
; TileXY2LatLon(@PBMap\Drawing\TileCoordinates, @PBMap\GeographicCoordinates, PBMap\Zoom)
|
|
||||||
PBMap\Redraw = #True
|
|
||||||
EndIf
|
EndIf
|
||||||
|
PBMap\Redraw = #True
|
||||||
Case #PB_MAP_REDRAW
|
Case #PB_MAP_REDRAW
|
||||||
Debug "Redraw"
|
Debug "Redraw"
|
||||||
PBMap\Redraw = #True
|
PBMap\Redraw = #True
|
||||||
@@ -1484,16 +1507,21 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
ProcedureReturn 0
|
ProcedureReturn 0
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure MyMarker(x.i, y.i)
|
Procedure MyMarker(x.i, y.i, Selected = #False)
|
||||||
Protected color.l
|
Protected color = RGBA(0, 255, 0, 255)
|
||||||
color=RGBA(0, 255, 0, 255)
|
|
||||||
VectorSourceColor(color)
|
|
||||||
MovePathCursor(x, y)
|
MovePathCursor(x, y)
|
||||||
AddPathLine(-16,-32,#PB_Path_Relative)
|
AddPathLine(-16,-32,#PB_Path_Relative)
|
||||||
AddPathCircle(16,0,16,180,0,#PB_Path_Relative)
|
AddPathCircle(16,0,16,180,0,#PB_Path_Relative)
|
||||||
AddPathLine(-16,32,#PB_Path_Relative)
|
AddPathLine(-16,32,#PB_Path_Relative)
|
||||||
VectorSourceColor(color)
|
VectorSourceColor(color)
|
||||||
FillPath(#PB_Path_Preserve):VectorSourceColor(RGBA(0, 0, 0, 255)):StrokePath(1)
|
FillPath(#PB_Path_Preserve)
|
||||||
|
If Selected
|
||||||
|
VectorSourceColor(RGBA($FF, $FF, 0, $FF))
|
||||||
|
StrokePath(2)
|
||||||
|
Else
|
||||||
|
VectorSourceColor(RGBA(0, 0, 0, 255))
|
||||||
|
StrokePath(1)
|
||||||
|
EndIf
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure MainPointer(x.i, y.i)
|
Procedure MainPointer(x.i, y.i)
|
||||||
@@ -1559,7 +1587,7 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
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_NAUTICAL) ; To change the scale unit
|
PBMAP::SetMapScaleUnit(PBMAP::#SCALE_NAUTICAL) ; To change the scale unit
|
||||||
PBMap::AddMarker(49.0446828398, 2.0349812508, -1, @MyMarker()) ; To add a marker
|
PBMap::AddMarker(49.0446828398, 2.0349812508, -1, @MyMarker()) ; To add a marker with a customised GFX
|
||||||
|
|
||||||
Repeat
|
Repeat
|
||||||
Event = WaitWindowEvent()
|
Event = WaitWindowEvent()
|
||||||
@@ -1608,8 +1636,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
|
|
||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
; IDE Options = PureBasic 5.50 (Windows - x64)
|
; IDE Options = PureBasic 5.50 (Windows - x64)
|
||||||
; CursorPosition = 134
|
; CursorPosition = 438
|
||||||
; FirstLine = 113
|
; FirstLine = 422
|
||||||
; Folding = ------------
|
; Folding = ------------
|
||||||
; EnableThread
|
; EnableThread
|
||||||
; EnableXP
|
; EnableXP
|
||||||
|
Reference in New Issue
Block a user