Cleanup + layer update
This commit is contained in:
208
PBMap.pb
208
PBMap.pb
@@ -37,7 +37,8 @@ DeclareModule PBMap
|
|||||||
#SCALE_KM = 0
|
#SCALE_KM = 0
|
||||||
|
|
||||||
Declare InitPBMap(window)
|
Declare InitPBMap(window)
|
||||||
Declare SetMapServer(ServerURL.s = "http://tile.openstreetmap.org/", TileSize = 256, ZoomMin = 0, ZoomMax = 18)
|
Declare.i AddMapServerLayer(LayerName.s, Order.i, ServerURL.s = "http://tile.openstreetmap.org/", TileSize = 256, ZoomMin = 0, ZoomMax = 18)
|
||||||
|
Declare DeleteLayer(Nb.i)
|
||||||
Declare MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i)
|
Declare MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i)
|
||||||
Declare SetLocation(latitude.d, longitude.d, zoom = 15, mode.i = #PB_Absolute)
|
Declare SetLocation(latitude.d, longitude.d, zoom = 15, mode.i = #PB_Absolute)
|
||||||
Declare Drawing()
|
Declare Drawing()
|
||||||
@@ -86,10 +87,10 @@ Module PBMap
|
|||||||
CacheFile.s
|
CacheFile.s
|
||||||
GetImageThread.i
|
GetImageThread.i
|
||||||
RetryNb.i
|
RetryNb.i
|
||||||
Layer.i
|
ServerURL.s
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Structure TileBounds
|
Structure TileBounds
|
||||||
NorthWest.Coordinates
|
NorthWest.Coordinates
|
||||||
SouthEast.Coordinates
|
SouthEast.Coordinates
|
||||||
EndStructure
|
EndStructure
|
||||||
@@ -127,56 +128,61 @@ Module PBMap
|
|||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Structure Marker
|
Structure Marker
|
||||||
GeographicCoordinates.GeographicCoordinates ; Marker latitude and longitude
|
GeographicCoordinates.GeographicCoordinates ; Marker latitude and longitude
|
||||||
color.l ; Marker color
|
color.l ; Marker color
|
||||||
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
|
||||||
|
|
||||||
Structure Option
|
Structure Option
|
||||||
WheelMouseRelative.i
|
WheelMouseRelative.i
|
||||||
ScaleUnit.i ; Scale unit to use for measurements
|
ScaleUnit.i ; Scale unit to use for measurements
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
|
Structure Layer
|
||||||
|
Order.i ; Layer nb
|
||||||
|
Name.s
|
||||||
|
ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/
|
||||||
|
EndStructure
|
||||||
|
|
||||||
;-PBMap Structure
|
;-PBMap Structure
|
||||||
Structure PBMap
|
Structure PBMap
|
||||||
Window.i ; Parent Window
|
Window.i ; Parent Window
|
||||||
Gadget.i ; Canvas Gadget Id
|
Gadget.i ; Canvas Gadget Id
|
||||||
Font.i ; Font to uses when write on the map
|
Font.i ; Font to uses when write on the map
|
||||||
Timer.i
|
Timer.i
|
||||||
GeographicCoordinates.GeographicCoordinates ; Latitude and Longitude from focus point
|
GeographicCoordinates.GeographicCoordinates ; Latitude and Longitude from focus point
|
||||||
Drawing.DrawingParameters ; Drawing parameters based on focus point
|
Drawing.DrawingParameters ; Drawing parameters based on focus point
|
||||||
;
|
;
|
||||||
CallBackLocation.i ; @Procedure(latitude.d,lontitude.d)
|
CallBackLocation.i ; @Procedure(latitude.d,lontitude.d)
|
||||||
CallBackMainPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib)
|
CallBackMainPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib)
|
||||||
;
|
;
|
||||||
PixelCoordinates.PixelCoordinates ; Actual focus point coords in pixels (global)
|
PixelCoordinates.PixelCoordinates ; Actual focus point coords in pixels (global)
|
||||||
MoveStartingPoint.PixelCoordinates ; Start mouse position coords when dragging the map
|
MoveStartingPoint.PixelCoordinates ; Start mouse position coords when dragging the map
|
||||||
;
|
;
|
||||||
Array ServerURL.s(0) ; Web URL ex: http://tile.openstreetmap.org/
|
List Layers.Layer()
|
||||||
NumberOfMapLayers.i ; The number of map tile layers;
|
|
||||||
|
|
||||||
ZoomMin.i ; Min Zoom supported by server
|
ZoomMin.i ; Min Zoom supported by server
|
||||||
ZoomMax.i ; Max Zoom supported by server
|
ZoomMax.i ; Max Zoom supported by server
|
||||||
Zoom.i ; Current zoom
|
Zoom.i ; Current zoom
|
||||||
TileSize.i ; Tile size downloaded on the server ex : 256
|
TileSize.i ; Tile size downloaded on the server ex : 256
|
||||||
;
|
;
|
||||||
HDDCachePath.S ; Path where to load and save tiles downloaded from server
|
HDDCachePath.S ; Path where to load and save tiles downloaded from server
|
||||||
MemCache.TileMemCach ; Images in memory cache
|
MemCache.TileMemCach ; Images in memory cache
|
||||||
;
|
;
|
||||||
Redraw.i
|
Redraw.i
|
||||||
Moving.i
|
Moving.i
|
||||||
Dirty.i ; To signal that drawing need a refresh
|
Dirty.i ; To signal that drawing need a refresh
|
||||||
;
|
;
|
||||||
MainDrawingThread.i
|
MainDrawingThread.i
|
||||||
TileThreadMutex.i; ;Mutex to protect resources
|
TileThreadMutex.i; ;Mutex to protect resources
|
||||||
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
|
EditMarkerIndex.l
|
||||||
|
|
||||||
ImgLoading.i ;Image Loading Tile
|
ImgLoading.i ;Image Loading Tile
|
||||||
ImgNothing.i ;Image Nothing Tile
|
ImgNothing.i ;Image Nothing Tile
|
||||||
|
|
||||||
Options.option ;
|
Options.option ;
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
#PB_MAP_REDRAW = #PB_EventType_FirstCustomValue + 1
|
#PB_MAP_REDRAW = #PB_EventType_FirstCustomValue + 1
|
||||||
@@ -306,8 +312,7 @@ Module PBMap
|
|||||||
PBMap\Window = Window
|
PBMap\Window = Window
|
||||||
PBMap\Timer = 1
|
PBMap\Timer = 1
|
||||||
PBMap\Options\WheelMouseRelative = #True
|
PBMap\Options\WheelMouseRelative = #True
|
||||||
SetMapServer("http://tile.openstreetmap.org/")
|
AddMapServerLayer("OSM", 1, "http://tile.openstreetmap.org/")
|
||||||
|
|
||||||
;-Preferences
|
;-Preferences
|
||||||
;Use this to create and customize your preferences file for the first time
|
;Use this to create and customize your preferences file for the first time
|
||||||
; CreatePreferences(GetHomeDirectory() + "PBMap.prefs")
|
; CreatePreferences(GetHomeDirectory() + "PBMap.prefs")
|
||||||
@@ -336,13 +341,24 @@ Module PBMap
|
|||||||
TechnicalImagesCreation()
|
TechnicalImagesCreation()
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure SetMapServer(ServerURL.s = "http://tile.openstreetmap.org/", TileSize = 256, ZoomMin = 0, ZoomMax = 18)
|
Procedure.i AddMapServerLayer(LayerName.s, Order.i, ServerURL.s = "http://tile.openstreetmap.org/", TileSize = 256, ZoomMin = 0, ZoomMax = 18)
|
||||||
PBMAP\NumberOfMapLayers + 1
|
Protected *Ptr = AddElement(PBMap\Layers())
|
||||||
ReDim PBMap\ServerURL(PBMAP\NumberOfMapLayers)
|
If *Ptr
|
||||||
PBMap\ServerURL(PBMAP\NumberOfMapLayers-1) = ServerURL
|
PBMap\Layers()\Name = LayerName
|
||||||
PBMap\ZoomMin = ZoomMin
|
PBMap\Layers()\Order = Order
|
||||||
PBMap\ZoomMax = ZoomMax
|
PBMap\Layers()\ServerURL = ServerURL
|
||||||
PBMap\TileSize = TileSize
|
SortStructuredList(PBMap\Layers(), #PB_Sort_Ascending, OffsetOf(Layer\Order),TypeOf(Layer\Order))
|
||||||
|
ProcedureReturn *Ptr
|
||||||
|
Else
|
||||||
|
ProcedureReturn #False
|
||||||
|
EndIf
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure DeleteLayer(*Ptr)
|
||||||
|
ChangeCurrentElement(PBMap\Layers(), *Ptr)
|
||||||
|
DeleteElement(PBMap\Layers())
|
||||||
|
FirstElement(PBMap\Layers())
|
||||||
|
SortStructuredList(PBMap\Layers(), #PB_Sort_Ascending, OffsetOf(Layer\Order),TypeOf(Layer\Order))
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure Quit()
|
Procedure Quit()
|
||||||
@@ -395,8 +411,8 @@ Module PBMap
|
|||||||
MyDebug("Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude), 5)
|
MyDebug("Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude), 5)
|
||||||
MyDebug("Coords X : " + Str(*Coords\x) + " ; Y : " + Str(*Coords\y), 5)
|
MyDebug("Coords X : " + Str(*Coords\x) + " ; Y : " + Str(*Coords\y), 5)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
;*** Converts tile.decimal to coords
|
;*** Converts tile.decimal to coords
|
||||||
;Warning, structures used in parameters are not tested
|
;Warning, structures used in parameters are not tested
|
||||||
Procedure TileXY2LatLon(*Coords.Coordinates, *Location.GeographicCoordinates, Zoom)
|
Procedure TileXY2LatLon(*Coords.Coordinates, *Location.GeographicCoordinates, Zoom)
|
||||||
Protected n.d = Pow(2.0, Zoom)
|
Protected n.d = Pow(2.0, Zoom)
|
||||||
@@ -436,8 +452,8 @@ Module PBMap
|
|||||||
;Debug "c2"
|
;Debug "c2"
|
||||||
*Pixel\x = cx + (px - dpx - tilemax)
|
*Pixel\x = cx + (px - dpx - tilemax)
|
||||||
ElseIf px - dpx < 0
|
ElseIf px - dpx < 0
|
||||||
;Debug "c3"
|
;Debug "c3"
|
||||||
*Pixel\x = cx - (dpx - px)
|
*Pixel\x = cx - (dpx - px)
|
||||||
Else
|
Else
|
||||||
;Debug "c0"
|
;Debug "c0"
|
||||||
*Pixel\x = cx + (px - dpx)
|
*Pixel\x = cx + (px - dpx)
|
||||||
@@ -445,7 +461,7 @@ Module PBMap
|
|||||||
*Pixel\y = PBMap\Drawing\CenterY + (py - PBMap\PixelCoordinates\y)
|
*Pixel\y = PBMap\Drawing\CenterY + (py - PBMap\PixelCoordinates\y)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; HaversineAlgorithm
|
; HaversineAlgorithm
|
||||||
; http://andrew.hedges.name/experiments/haversine/
|
; http://andrew.hedges.name/experiments/haversine/
|
||||||
@@ -465,7 +481,7 @@ Module PBMap
|
|||||||
ProcedureReturn (1000 * HaversineInKM(@*posA,@*posB));
|
ProcedureReturn (1000 * HaversineInKM(@*posA,@*posB));
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure GetPixelCoordFromLocation(*Location.GeographicCoordinates, *Pixel.PixelCoordinates, Zoom) ; TODO to Optimize
|
Procedure GetPixelCoordFromLocation(*Location.GeographicCoordinates, *Pixel.PixelCoordinates, Zoom) ; TODO to Optimize
|
||||||
Protected mapWidth.l = Pow(2, Zoom + 8)
|
Protected mapWidth.l = Pow(2, Zoom + 8)
|
||||||
Protected mapHeight.l = Pow(2, Zoom + 8)
|
Protected mapHeight.l = Pow(2, Zoom + 8)
|
||||||
Protected x1.l,y1.l
|
Protected x1.l,y1.l
|
||||||
@@ -475,20 +491,20 @@ Module PBMap
|
|||||||
Protected latRad.d = *Location\Latitude*#PI/180;
|
Protected latRad.d = *Location\Latitude*#PI/180;
|
||||||
Protected mercN.d = Log(Tan((#PI/4)+(latRad/2)));
|
Protected mercN.d = Log(Tan((#PI/4)+(latRad/2)));
|
||||||
y1 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)) ;
|
y1 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)) ;
|
||||||
; Debug "location"
|
; Debug "location"
|
||||||
; Debug x1
|
; Debug x1
|
||||||
; Debug y1
|
; Debug y1
|
||||||
Protected x2.l, y2.l
|
Protected x2.l, y2.l
|
||||||
; get x value
|
; get x value
|
||||||
x2 = (PBMap\GeographicCoordinates\Longitude+180)*(mapWidth/360)
|
x2 = (PBMap\GeographicCoordinates\Longitude+180)*(mapWidth/360)
|
||||||
; convert from degrees To radians
|
; convert from degrees To radians
|
||||||
latRad = PBMap\GeographicCoordinates\Latitude*#PI/180;
|
latRad = PBMap\GeographicCoordinates\Latitude*#PI/180;
|
||||||
; get y value
|
; get y value
|
||||||
mercN = Log(Tan((#PI/4)+(latRad/2)))
|
mercN = Log(Tan((#PI/4)+(latRad/2)))
|
||||||
y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI));
|
y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI));
|
||||||
; Debug "GeographicCoordinates"
|
; Debug "GeographicCoordinates"
|
||||||
; Debug x1
|
; Debug x1
|
||||||
; Debug y1
|
; Debug y1
|
||||||
*Pixel\x=GadgetWidth(PBMap\Gadget)/2 - (x2-x1)
|
*Pixel\x=GadgetWidth(PBMap\Gadget)/2 - (x2-x1)
|
||||||
*Pixel\y=GadgetHeight(PBMap\Gadget)/2 - (y2-y1)
|
*Pixel\y=GadgetHeight(PBMap\Gadget)/2 - (y2-y1)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
@@ -546,11 +562,10 @@ Module PBMap
|
|||||||
ProcedureReturn -1
|
ProcedureReturn -1
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.i GetTileFromWeb(Zoom.i, XTile.i, YTile.i, CacheFile.s, Layer.i)
|
Procedure.i GetTileFromWeb(TileURL.s, CacheFile.s)
|
||||||
Protected *Buffer
|
Protected *Buffer
|
||||||
Protected nImage.i = -1
|
Protected nImage.i = -1
|
||||||
Protected FileSize.i, timg
|
Protected FileSize.i, timg
|
||||||
Protected TileURL.s = PBMap\ServerURL(Layer) + Str(Zoom) + "/" + Str(XTile) + "/" + Str(YTile) + ".png"
|
|
||||||
If Proxy
|
If Proxy
|
||||||
FileSize = CurlReceiveHTTPToFile(TileURL, CacheFile, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$)
|
FileSize = CurlReceiveHTTPToFile(TileURL, CacheFile, ProxyURL$, ProxyPort$, ProxyUser$, ProxyPassword$)
|
||||||
If FileSize > 0
|
If FileSize > 0
|
||||||
@@ -595,8 +610,9 @@ Module PBMap
|
|||||||
|
|
||||||
Procedure GetImageThread(*Tile.Tile)
|
Procedure GetImageThread(*Tile.Tile)
|
||||||
Protected nImage.i = -1
|
Protected nImage.i = -1
|
||||||
|
Protected TileURL.s = *Tile\ServerURL + Str(*Tile\PBMapZoom) + "/" + Str(*Tile\PBMapTileX) + "/" + Str(*Tile\PBMapTileY) + ".png"
|
||||||
Repeat
|
Repeat
|
||||||
nImage = GetTileFromWeb(*Tile\PBMapZoom, *Tile\PBMapTileX, *Tile\PBMapTileY, *Tile\CacheFile, *Tile\Layer)
|
nImage = GetTileFromWeb(TileURL, *Tile\CacheFile)
|
||||||
If nImage <> -1
|
If nImage <> -1
|
||||||
MyDebug("Image key : " + *Tile\key + " web image loaded", 3)
|
MyDebug("Image key : " + *Tile\key + " web image loaded", 3)
|
||||||
*Tile\RetryNb = 0
|
*Tile\RetryNb = 0
|
||||||
@@ -611,7 +627,7 @@ Module PBMap
|
|||||||
PostEvent(#PB_Event_Gadget, PBMap\Window, PBmap\Gadget, #PB_MAP_TILE_CLEANUP, *Tile) ;To free memory outside the thread
|
PostEvent(#PB_Event_Gadget, PBMap\Window, PBmap\Gadget, #PB_MAP_TILE_CLEANUP, *Tile) ;To free memory outside the thread
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.i GetTile(key.s, CacheFile.s, px.i, py.i, tilex.i, tiley.i, Layer.i)
|
Procedure.i GetTile(key.s, CacheFile.s, px.i, py.i, tilex.i, tiley.i, ServerURL.s)
|
||||||
Protected timg = -1
|
Protected timg = -1
|
||||||
If FindMapElement(PBMap\MemCache\Images(), key)
|
If FindMapElement(PBMap\MemCache\Images(), key)
|
||||||
MyDebug("Key : " + key + " found in memory cache!", 3)
|
MyDebug("Key : " + key + " found in memory cache!", 3)
|
||||||
@@ -647,7 +663,7 @@ Module PBMap
|
|||||||
\PBMapZoom = PBMap\Zoom
|
\PBMapZoom = PBMap\Zoom
|
||||||
\key = key
|
\key = key
|
||||||
\CacheFile = CacheFile
|
\CacheFile = CacheFile
|
||||||
\Layer = Layer
|
\ServerURL = ServerURL
|
||||||
\RetryNb = 5
|
\RetryNb = 5
|
||||||
\nImage = -1
|
\nImage = -1
|
||||||
MyDebug(" Creating get image thread nb " + Str(\GetImageThread) + " to get " + CacheFile, 3)
|
MyDebug(" Creating get image thread nb " + Str(\GetImageThread) + " to get " + CacheFile, 3)
|
||||||
@@ -660,7 +676,7 @@ Module PBMap
|
|||||||
ProcedureReturn timg
|
ProcedureReturn timg
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure DrawTiles(*Drawing.DrawingParameters, Layer.i, alpha.i=255)
|
Procedure DrawTiles(*Drawing.DrawingParameters, Layer, alpha.i=255)
|
||||||
;DisableDebugger
|
;DisableDebugger
|
||||||
Protected x.i, y.i,kq.q
|
Protected x.i, y.i,kq.q
|
||||||
Protected tx = Int(*Drawing\TileCoordinates\x) ;Don't forget the Int() !
|
Protected tx = Int(*Drawing\TileCoordinates\x) ;Don't forget the Int() !
|
||||||
@@ -669,6 +685,7 @@ Module PBMap
|
|||||||
Protected ny = *Drawing\CenterY / PBMap\TileSize
|
Protected ny = *Drawing\CenterY / PBMap\TileSize
|
||||||
Protected px, py, img, tilex,tiley, key.s, CacheFile.s
|
Protected px, py, img, tilex,tiley, key.s, CacheFile.s
|
||||||
Protected tilemax = 1<<PBMap\Zoom
|
Protected tilemax = 1<<PBMap\Zoom
|
||||||
|
SelectElement(PBMap\Layers(), Layer)
|
||||||
MyDebug("Drawing tiles")
|
MyDebug("Drawing tiles")
|
||||||
For y = - ny - 1 To ny + 1
|
For y = - ny - 1 To ny + 1
|
||||||
For x = - nx - 1 To nx + 1
|
For x = - nx - 1 To nx + 1
|
||||||
@@ -680,11 +697,10 @@ Module PBMap
|
|||||||
EndIf
|
EndIf
|
||||||
tiley = ty + y
|
tiley = ty + y
|
||||||
If tiley >= 0 And tiley < tilemax
|
If tiley >= 0 And tiley < tilemax
|
||||||
kq = Layer | (pbmap\zoom << 8) | (tilex << 16) | (tiley << 36)
|
kq = (PBMap\zoom << 8) | (tilex << 16) | (tiley << 36)
|
||||||
key = Str(kq)
|
key = PBMap\Layers()\Name + Str(kq)
|
||||||
CacheFile = PBMap\HDDCachePath + key + ".png"
|
CacheFile = PBMap\HDDCachePath + key + ".png"
|
||||||
|
img = GetTile(key, CacheFile, px, py, tilex, tiley, PBMap\Layers()\ServerURL)
|
||||||
img = GetTile(key, CacheFile, px, py, tilex, tiley, Layer)
|
|
||||||
If img <> -1
|
If img <> -1
|
||||||
MovePathCursor(px, py)
|
MovePathCursor(px, py)
|
||||||
DrawVectorImage(ImageID(img), alpha)
|
DrawVectorImage(ImageID(img), alpha)
|
||||||
@@ -693,7 +709,7 @@ Module PBMap
|
|||||||
DrawVectorImage(ImageID(PBMap\ImgLoading), alpha)
|
DrawVectorImage(ImageID(PBMap\ImgLoading), alpha)
|
||||||
EndIf
|
EndIf
|
||||||
Else
|
Else
|
||||||
If Layer = 0
|
If PBMap\Layers()\Name = ""
|
||||||
MovePathCursor(px, py)
|
MovePathCursor(px, py)
|
||||||
DrawVectorImage(ImageID(PBMap\ImgNothing))
|
DrawVectorImage(ImageID(PBMap\ImgNothing))
|
||||||
EndIf
|
EndIf
|
||||||
@@ -768,7 +784,7 @@ Module PBMap
|
|||||||
AddPathLine(x+128,y+12)
|
AddPathLine(x+128,y+12)
|
||||||
StrokePath(1)
|
StrokePath(1)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure DrawDegrees(*Drawing.DrawingParameters, alpha=192)
|
Procedure DrawDegrees(*Drawing.DrawingParameters, alpha=192)
|
||||||
Protected tx, ty, nx,ny,nx1,ny1,x,y,n,cx,dperpixel.d
|
Protected tx, ty, nx,ny,nx1,ny1,x,y,n,cx,dperpixel.d
|
||||||
Protected pos1.PixelCoordinates,pos2.PixelCoordinates,Degrees1.GeographicCoordinates,degrees2.GeographicCoordinates
|
Protected pos1.PixelCoordinates,pos2.PixelCoordinates,Degrees1.GeographicCoordinates,degrees2.GeographicCoordinates
|
||||||
@@ -781,7 +797,7 @@ Module PBMap
|
|||||||
*Drawing\Bounds\NorthWest\y = ty-ny-1
|
*Drawing\Bounds\NorthWest\y = ty-ny-1
|
||||||
*Drawing\Bounds\SouthEast\x = tx+nx+2
|
*Drawing\Bounds\SouthEast\x = tx+nx+2
|
||||||
*Drawing\Bounds\SouthEast\y = ty+ny+2
|
*Drawing\Bounds\SouthEast\y = ty+ny+2
|
||||||
; Debug "------------------"
|
; Debug "------------------"
|
||||||
TileXY2LatLon(*Drawing\Bounds\NorthWest, @Degrees1, PBMap\Zoom)
|
TileXY2LatLon(*Drawing\Bounds\NorthWest, @Degrees1, PBMap\Zoom)
|
||||||
TileXY2LatLon(*Drawing\Bounds\SouthEast, @Degrees2, PBMap\Zoom)
|
TileXY2LatLon(*Drawing\Bounds\SouthEast, @Degrees2, PBMap\Zoom)
|
||||||
;ensure we stay positive for the drawing
|
;ensure we stay positive for the drawing
|
||||||
@@ -793,7 +809,7 @@ Module PBMap
|
|||||||
Degrees1\Latitude = ny
|
Degrees1\Latitude = ny
|
||||||
Degrees2\Longitude = nx1
|
Degrees2\Longitude = nx1
|
||||||
Degrees2\Latitude = ny1
|
Degrees2\Latitude = ny1
|
||||||
; Debug "NW : " + StrD(Degrees1\Longitude) + " ; NE : " + StrD(Degrees2\Longitude)
|
; Debug "NW : " + StrD(Degrees1\Longitude) + " ; NE : " + StrD(Degrees2\Longitude)
|
||||||
LatLon2PixelRel(@Degrees1, @pos1, PBMap\Zoom)
|
LatLon2PixelRel(@Degrees1, @pos1, PBMap\Zoom)
|
||||||
LatLon2PixelRel(@Degrees2, @pos2, PBMap\Zoom)
|
LatLon2PixelRel(@Degrees2, @pos2, PBMap\Zoom)
|
||||||
VectorFont(FontID(PBMap\Font), 10)
|
VectorFont(FontID(PBMap\Font), 10)
|
||||||
@@ -886,7 +902,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)
|
||||||
VectorSourceColor(color)
|
VectorSourceColor(color)
|
||||||
MovePathCursor(x, y)
|
MovePathCursor(x, y)
|
||||||
AddPathLine(-8, -16, #PB_Path_Relative)
|
AddPathLine(-8, -16, #PB_Path_Relative)
|
||||||
@@ -909,7 +925,7 @@ Module PBMap
|
|||||||
PBMap\Marker()\CallBackPointer = CallBackPointer
|
PBMap\Marker()\CallBackPointer = CallBackPointer
|
||||||
PBMap\Redraw = #True
|
PBMap\Redraw = #True
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; Draw all markers on the screen !
|
; Draw all markers on the screen !
|
||||||
Procedure DrawMarkers(*Drawing.DrawingParameters)
|
Procedure DrawMarkers(*Drawing.DrawingParameters)
|
||||||
Protected Pixel.PixelCoordinates
|
Protected Pixel.PixelCoordinates
|
||||||
@@ -948,8 +964,8 @@ Module PBMap
|
|||||||
StartVectorDrawing(CanvasVectorOutput(PBMap\Gadget))
|
StartVectorDrawing(CanvasVectorOutput(PBMap\Gadget))
|
||||||
;TODO add in layers of tiles ;this way we can cache them as 0 base 1.n layers
|
;TODO add in layers of tiles ;this way we can cache them as 0 base 1.n layers
|
||||||
;such as for openseamap tiles which are overlaid. not that efficent from here though.
|
;such as for openseamap tiles which are overlaid. not that efficent from here though.
|
||||||
For a = 0 To PBMap\NumberOfMapLayers - 1
|
ForEach PBMap\Layers()
|
||||||
DrawTiles(*Drawing, a)
|
DrawTiles(*Drawing, ListIndex(PBMap\Layers()))
|
||||||
Next
|
Next
|
||||||
DrawTrack(*Drawing)
|
DrawTrack(*Drawing)
|
||||||
DrawMarkers(*Drawing)
|
DrawMarkers(*Drawing)
|
||||||
@@ -1156,12 +1172,12 @@ Module PBMap
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.d GetLatitude()
|
Procedure.d GetLatitude()
|
||||||
; ProcedureReturn 0-(90-Mod((PBMap\GeographicCoordinates\Latitude+90),180))
|
; ProcedureReturn 0-(90-Mod((PBMap\GeographicCoordinates\Latitude+90),180))
|
||||||
ProcedureReturn PBMap\GeographicCoordinates\Latitude
|
ProcedureReturn PBMap\GeographicCoordinates\Latitude
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.d GetLongitude()
|
Procedure.d GetLongitude()
|
||||||
; ProcedureReturn 0-(180-Mod((PBMap\GeographicCoordinates\Longitude+180),360))
|
; ProcedureReturn 0-(180-Mod((PBMap\GeographicCoordinates\Longitude+180),360))
|
||||||
ProcedureReturn PBMap\GeographicCoordinates\Longitude
|
ProcedureReturn PBMap\GeographicCoordinates\Longitude
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
@@ -1221,7 +1237,7 @@ Module PBMap
|
|||||||
Else
|
Else
|
||||||
;New move values
|
;New move values
|
||||||
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
|
||||||
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
|
||||||
@@ -1240,10 +1256,10 @@ Module PBMap
|
|||||||
If PBMap\EditMarkerIndex > -1
|
If PBMap\EditMarkerIndex > -1
|
||||||
PBMap\EditMarkerIndex = -1
|
PBMap\EditMarkerIndex = -1
|
||||||
Else ;Move Map
|
Else ;Move Map
|
||||||
; PBMap\Drawing\TileCoordinates\x = PBMap\PixelCoordinates\x / PBMap\TileSize
|
; PBMap\Drawing\TileCoordinates\x = PBMap\PixelCoordinates\x / PBMap\TileSize
|
||||||
; PBMap\Drawing\TileCoordinates\y = PBMap\PixelCoordinates\y / PBMap\TileSize
|
; PBMap\Drawing\TileCoordinates\y = PBMap\PixelCoordinates\y / PBMap\TileSize
|
||||||
; MyDebug("PBMap\Drawing\TileCoordinates\x " + Str(PBMap\Drawing\TileCoordinates\x) + " ; PBMap\Drawing\TileCoordinates\y " + Str(PBMap\Drawing\TileCoordinates\y) )
|
; MyDebug("PBMap\Drawing\TileCoordinates\x " + Str(PBMap\Drawing\TileCoordinates\x) + " ; PBMap\Drawing\TileCoordinates\y " + Str(PBMap\Drawing\TileCoordinates\y) )
|
||||||
; TileXY2LatLon(@PBMap\Drawing\TileCoordinates, @PBMap\GeographicCoordinates, PBMap\Zoom)
|
; TileXY2LatLon(@PBMap\Drawing\TileCoordinates, @PBMap\GeographicCoordinates, PBMap\Zoom)
|
||||||
PBMap\Redraw = #True
|
PBMap\Redraw = #True
|
||||||
EndIf
|
EndIf
|
||||||
Case #PB_MAP_REDRAW
|
Case #PB_MAP_REDRAW
|
||||||
@@ -1308,6 +1324,7 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
#String_1
|
#String_1
|
||||||
#Gdt_LoadGpx
|
#Gdt_LoadGpx
|
||||||
#Gdt_AddMarker
|
#Gdt_AddMarker
|
||||||
|
#Gdt_AddOpenseaMap
|
||||||
EndEnumeration
|
EndEnumeration
|
||||||
|
|
||||||
Structure Location
|
Structure Location
|
||||||
@@ -1316,8 +1333,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Procedure UpdateLocation(*Location.Location)
|
Procedure UpdateLocation(*Location.Location)
|
||||||
; SetGadgetText(#String_0, StrD(0-(90-Mod((*Location\Latitude+90),180))))
|
; SetGadgetText(#String_0, StrD(0-(90-Mod((*Location\Latitude+90),180))))
|
||||||
; SetGadgetText(#String_1, StrD(0-(180-Mod((*Location\Longitude+180),360))))
|
; SetGadgetText(#String_1, StrD(0-(180-Mod((*Location\Longitude+180),360))))
|
||||||
SetGadgetText(#String_0, StrD(*Location\Latitude))
|
SetGadgetText(#String_0, StrD(*Location\Latitude))
|
||||||
SetGadgetText(#String_1, StrD(*Location\Longitude))
|
SetGadgetText(#String_1, StrD(*Location\Longitude))
|
||||||
ProcedureReturn 0
|
ProcedureReturn 0
|
||||||
@@ -1356,6 +1373,7 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
ResizeGadget(#Text_4,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
ResizeGadget(#Text_4,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||||
ResizeGadget(#Gdt_AddMarker,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
ResizeGadget(#Gdt_AddMarker,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||||
ResizeGadget(#Gdt_LoadGpx,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
ResizeGadget(#Gdt_LoadGpx,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||||
|
ResizeGadget(#Gdt_AddOpenseaMap,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
|
||||||
PBMap::Refresh()
|
PBMap::Refresh()
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
@@ -1378,10 +1396,12 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
TextGadget(#Text_4, 530, 250, 60, 15, "Longitude : ")
|
TextGadget(#Text_4, 530, 250, 60, 15, "Longitude : ")
|
||||||
StringGadget(#String_1, 600, 250, 90, 20, "")
|
StringGadget(#String_1, 600, 250, 90, 20, "")
|
||||||
ButtonGadget(#Gdt_AddMarker, 530, 280, 150, 30, "Add Marker")
|
ButtonGadget(#Gdt_AddMarker, 530, 280, 150, 30, "Add Marker")
|
||||||
ButtonGadget(#Gdt_LoadGpx, 530, 310, 150, 30, "Load GPX")
|
ButtonGadget(#Gdt_LoadGpx, 530, 310, 150, 30, "Load GPX")
|
||||||
|
ButtonGadget(#Gdt_AddOpenseaMap, 530, 340, 150, 30, "OpenSeaMap")
|
||||||
|
|
||||||
Define Event.i, Gadget.i, Quit.b = #False
|
Define Event.i, Gadget.i, Quit.b = #False
|
||||||
Define pfValue.d
|
Define pfValue.d
|
||||||
|
Define OpenSeaMap = 0
|
||||||
|
|
||||||
;Our main gadget
|
;Our main gadget
|
||||||
PBMap::InitPBMap(#Window_0)
|
PBMap::InitPBMap(#Window_0)
|
||||||
@@ -1390,7 +1410,6 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
PBMap::SetCallBackLocation(@UpdateLocation())
|
PBMap::SetCallBackLocation(@UpdateLocation())
|
||||||
PBMap::SetLocation(-36.81148, 175.08634,12)
|
PBMap::SetLocation(-36.81148, 175.08634,12)
|
||||||
;PBMap::SetLocation(0, 0)
|
;PBMap::SetLocation(0, 0)
|
||||||
PBMap::SetMapServer("http://t1.openseamap.org/seamark/") ;add a special osm overlay map
|
|
||||||
PBMAP::SetMapScaleUnit(PBMAP::#SCALE_NAUTICAL)
|
PBMAP::SetMapScaleUnit(PBMAP::#SCALE_NAUTICAL)
|
||||||
PBMap::AddMarker(49.0446828398, 2.0349812508, -1, @MyMarker())
|
PBMap::AddMarker(49.0446828398, 2.0349812508, -1, @MyMarker())
|
||||||
|
|
||||||
@@ -1417,7 +1436,15 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
PBMap::LoadGpxFile(OpenFileRequester("Choose a file to load", "", "*.gpx", 0))
|
PBMap::LoadGpxFile(OpenFileRequester("Choose a file to load", "", "*.gpx", 0))
|
||||||
PBMap::ZoomToArea() ; <-To center the view, and zoom on the tracks
|
PBMap::ZoomToArea() ; <-To center the view, and zoom on the tracks
|
||||||
Case #Gdt_AddMarker
|
Case #Gdt_AddMarker
|
||||||
PBMap:: AddMarker(ValD(GetGadgetText(#String_0)), ValD(GetGadgetText(#String_1)), RGBA(Random(255), Random(255), Random(255), 255), @MyMarker())
|
PBMap::AddMarker(ValD(GetGadgetText(#String_0)), ValD(GetGadgetText(#String_1)), RGBA(Random(255), Random(255), Random(255), 255), @MyMarker())
|
||||||
|
Case #Gdt_AddOpenseaMap
|
||||||
|
If OpenSeaMap = 0
|
||||||
|
OpenSeaMap = PBMap::AddMapServerLayer("OpenSeaMap", 2, "http://t1.openseamap.org/seamark/") ;add a special osm overlay map
|
||||||
|
Else
|
||||||
|
PBMap::DeleteLayer(OpenSeaMap)
|
||||||
|
OpenSeaMap = 0
|
||||||
|
EndIf
|
||||||
|
PBMAP::Refresh()
|
||||||
EndSelect
|
EndSelect
|
||||||
Case #PB_Event_SizeWindow
|
Case #PB_Event_SizeWindow
|
||||||
ResizeAll()
|
ResizeAll()
|
||||||
@@ -1426,10 +1453,11 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
|
|
||||||
PBMap::Quit()
|
PBMap::Quit()
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
; IDE Options = PureBasic 5.50 (Windows - x64)
|
; IDE Options = PureBasic 5.50 (Windows - x64)
|
||||||
; CursorPosition = 8
|
; CursorPosition = 310
|
||||||
|
; FirstLine = 291
|
||||||
; Folding = -----------
|
; Folding = -----------
|
||||||
; EnableThread
|
; EnableThread
|
||||||
; EnableXP
|
; EnableXP
|
||||||
|
Reference in New Issue
Block a user