92 Commits

Author SHA1 Message Date
djes
a32fd4d093 Merge pull request #20 from djes/thyphoon
Thyphoon desktop centering fixes
2021-09-01 10:09:05 +02:00
djes
873f25d0fe Merge branch 'master' into thyphoon 2021-09-01 10:08:26 +02:00
b108b8b385 DPI Aware
Add compatible with DPI Scaling (4k screen)
2021-08-22 14:48:55 +02:00
djes
7049aa5738 Merge pull request #19 from djes/djes
Demo separated from module
2021-01-17 11:35:17 +01:00
djes
00d7cdceb7 Demo separated from module 2021-01-17 11:30:57 +01:00
djes
878c6a0408 Merge pull request #18 from djes/djes
Faulty PNG tiles fixes
2019-07-19 13:46:13 +02:00
djes
bbd1d75c02 Update PBMap.pb 2019-07-19 13:42:09 +02:00
djes
297fe00f57 PNG checking
Thanks to idle !
2019-07-19 11:15:29 +02:00
djes
10e88b685a pngcheck comment 2019-07-18 22:07:23 +02:00
djes
a909362ee2 Update PBMap.pb 2019-07-18 21:39:34 +02:00
djes
705be8f877 Incomplete image file download automatic deletion
Little update to delete incomplete (eventually malformed) image file
2019-07-18 20:56:33 +02:00
djes
741aa2afb1 Update README.md 2019-07-18 16:39:41 +02:00
djes
86acc0be60 Update README.md 2019-07-18 16:39:22 +02:00
djes
ff6a10feb4 Update README.md 2019-07-18 16:38:22 +02:00
djes
629c469a6b Code cleanup
Misc internal fixes, especially in GetImageThread()
2019-07-18 16:24:12 +02:00
djes
be8f378bbc Merge branch 'djes' of https://github.com/djes/PBMap into djes 2019-07-18 15:18:34 +02:00
djes
55930e68b1 Bug tracking
Some bugs removed and OnError() coded added (thanks to falsam)
Spotted png image library bug, reported on PB forum.
2019-07-18 15:04:43 +02:00
djes
b09559c5ee Pixel2Lon()/Pixel2Lat() correction and GetCanvasPixelLon()/Lat() functions 2018-09-03 14:46:24 +02:00
djes
7b17b7166e UTF8 2018-06-11 23:39:02 +02:00
djes
7970758114 UTF8 source 2018-06-11 23:36:47 +02:00
djes
c13ff4fc92 Merge branch 'djes' of https://github.com/djes/PBMap into djes 2018-06-11 23:24:00 +02:00
djes
864d1e33f5 Optimisation
Little optimisation by Michael Vogel, see https://www.purebasic.fr/english/viewtopic.php?p=523247#p523247
2018-06-11 23:23:48 +02:00
djes
848b817403 Merge pull request #17 from djes/djes
Major update
2018-06-11 23:07:27 +02:00
djes
28c85648ca Merge branch 'master' into djes 2018-06-11 23:06:55 +02:00
djes
55bc5c8f78 Debug mode corrected
Active Window wasn't anymore when console opened
2018-03-17 14:36:44 +01:00
djes
648c9c9a4a Multiple PBMaps WIP
PBMap is now able to handle multiple maps.

Warning : it breaks compatibility with older codes !
InitPBMap() and Quit() are no longer used, only MapGadget() and FreeMapGadget() as in standard PureBASIC gadgets.
All functions should now include the MapGadget id as first parameter.

Now included, the André Beer demo.
2018-03-03 19:26:28 +01:00
djes
1c7b161a87 Multiple PBMaps WIP 2018-03-02 21:55:38 +01:00
djes
12723fab31 Multiple MapGadget bugfix 2018-03-02 19:42:22 +01:00
djes
dfcf0e9f5e Multiple PBMap handling
The internal pbmap structure was unique and shared. Now it is dynamically allocated and returned by the InitPBMap() function. It allows to have multiple PBMap in the same window. Switch is done by the new SelectPBMap() function. Quit() function must be called for each PBMap.
2018-03-01 09:33:52 +01:00
djes
ba26af24e1 GetImageThread() not anymore mutex excluded
Andre and DarkSoul bug tracking. This mutex doesn't seem to have any real utility in this function, as the memory management is already protected by mutex outside, and the tile data has been copied to a private memory area.
2018-02-25 19:32:34 +01:00
djes
a90b44eb6b Two new callbacks to alter tile rendering, and to work on tile file after loading
Prototype.i ProtoDrawTile(x.i, y.i, image.i, alpha.d = 1)
  Prototype.s ProtoModifyTileFile(Filename.s, OriginalURL.s)
2017-07-04 16:50:18 +02:00
djes
afc271278a CallBackDrawTile + misc cleaning + useragent
Allows a customised tile drawing
2017-07-04 12:20:07 +02:00
djes
8300e02bba Merging typhoon and djes branches 2017-07-04 09:21:00 +02:00
djes
a98f658287 Merge branch 'thyphoon' into djes 2017-07-04 09:19:30 +02:00
djes
e87435c892 Cache file delete if size = 0 2017-07-04 08:52:01 +02:00
60647f4928 Change some SetCallBackMarker Fonctionnality
replace CallFunctionFast(PBMap\CallBackMarker,  @PBMap\Markers()\GeographicCoordinates) by               CallFunctionFast(PBMap\CallBackMarker,  @PBMap\Markers()) To use Marker identifier if necessary

move "Marker" and "GeographicCoordinates" from Module to DeclareModule. I need it's public to read easly data send to callback function.
2017-07-03 23:41:25 +02:00
djes
eb8e73a245 Updating from yves86 branch 2017-07-03 12:32:00 +02:00
djes
95d78f0590 Header 2017-06-15 17:21:52 +02:00
djes
596733f49b Header slight modifications 2017-06-15 17:19:59 +02:00
djes
13798f2517 Merge pull request #16 from djes/Yves86
(djes) implemented the new functions by Yves86
2017-06-15 17:13:23 +02:00
djes
552763d346 (djes) implemented the new functions by Yves86 2017-06-15 17:08:14 +02:00
djes
0319c8b5a4 Merge pull request #15 from djes/djes
Rewrite of cache mechanism
2017-06-15 16:42:15 +02:00
djes
4183dcd59b Create README.md 2017-06-15 15:32:33 +02:00
djes
d3e277937e Old files cleaning bug fixed 2017-06-15 15:30:19 +02:00
djes
e67076802b Latest strange image drawing bugs killed 2017-06-15 15:15:02 +02:00
djes
55bbe10378 Better thread/download management 2017-06-15 12:24:23 +02:00
djes
b11176a46f Ensures that there's no loading threads while cleaning
Should be changed, as the feeling is less good, memory consumption could get huge, and unuseful threads may continue instead of being stopped.
2017-06-14 10:58:48 +02:00
djes
7d351f4f92 Threads and cache cleaning now mutually excluded 2017-06-14 10:39:03 +02:00
djes
da8c3e9001 semaphores test 2017-06-13 21:04:59 +02:00
djes
61503c3e98 Several bugfix 2017-06-12 20:37:08 +02:00
djes
bb405afca9 Download slots bugfix 2017-06-12 12:32:51 +02:00
djes
1b903ffdc6 One more lil bugfix 2017-06-09 16:58:58 +02:00
djes
bbb66d20b6 Little bugfix 2017-06-09 16:08:39 +02:00
djes
530273a934 Added download slots and automatic download cancellation after a delay 2017-06-09 15:16:08 +02:00
djes
1de62dfb16 Caching mechanism enhanced + better downloading wip 2017-06-09 13:49:29 +02:00
djes
bbf5be2efd New cache mechanism and thread overload fixed 2017-06-08 15:02:34 +02:00
djes
c862f9099e Overload bugfix in progress
When several threads are launched and the web server doesn't respond, a form of overload appears.
2017-06-08 12:27:56 +02:00
djes
4cb1f57bbc Cache bugfix in progress
And better web loading by thread limit
2017-06-07 17:15:04 +02:00
djes
ff72bc8f07 Merge pull request #14 from djes/djes
Revert "Little tile loading bugfix"
2017-06-06 16:58:14 +02:00
djes
280e4faba6 Revert "Little tile loading bugfix"
This reverts commit 74fe157b47.
2017-06-06 16:45:45 +02:00
djes
a42058d78e Merge pull request #13 from djes/djes
Layer alpha, save GPX, geoserver support, bugfixes
2017-06-02 13:47:59 +02:00
djes
74fe157b47 Little tile loading bugfix 2017-06-02 12:53:29 +02:00
djes
246d56a008 Revert "Little tile loading bugfix"
This reverts commit aef23aa03b.
2017-06-02 12:51:38 +02:00
djes
aef23aa03b Little tile loading bugfix 2017-06-02 12:50:54 +02:00
djes
c1a650bce5 Geoserver layers support
Basic geoserver support (google maps services only by now)
2017-04-03 11:32:08 +02:00
djes
d5cd0cd6f3 Basic save GPX file function 2017-03-29 16:46:55 +02:00
djes
544750f74e Layer alpha
and some cleaning as usual
2017-03-29 12:15:33 +02:00
djes
74b2f52304 Merge pull request #12 from djes/djes
Tile file lifetime management
2017-03-24 17:36:25 +01:00
djes
7746b88731 Tile file lifetime management 2017-03-21 18:01:21 +01:00
djes
faf21269dc Merge pull request #11 from djes/djes
Important fix on tile loading.
2017-03-20 17:42:50 +01:00
djes
6e295ee658 Merge remote-tracking branch 'refs/remotes/origin/master' into djes 2017-03-20 12:39:53 +01:00
djes
ae1c031ea0 Options improvements 2017-03-20 12:38:40 +01:00
djes
6bdb4880b6 Not threadable HTTPProxy
bugfixing, plus the not threadable httpproxy() fix
2017-03-20 11:48:40 +01:00
djes
e55c4851ed Merge remote-tracking branch 'origin/djes' into djes
# Conflicts:
#	PBMap.pb
2017-03-20 10:25:50 +01:00
djes
a2ffb7b4de Merge pull request #10 from djes/djes
"here" support
2017-03-19 13:20:55 +01:00
djes
f2cb4f08e9 Latest HERE and proxy fixes 2017-03-15 20:17:27 +01:00
djes
799e61ce4e Here update with options
and new layer system based on map and list
2017-03-15 19:47:45 +01:00
djes
2346bf3b33 "HERE" addons and layer modifications
Layers are now map and list based to facilitate ordering and deletion
2017-03-15 18:17:51 +01:00
djes
c1b55ef8c3 "HERE" update 2017-03-15 15:33:37 +01:00
djes
0c1287e66f Dragging release bug fixed + here wip 2017-03-15 12:47:33 +01:00
djes
8cb400f1a9 Code makeup 2017-03-03 17:23:42 +01:00
djes
528279e85c Merge remote-tracking branch 'refs/remotes/origin/master' into djes 2017-03-01 16:38:24 +01:00
djes
825be77b4e To correct sync problem 2017-03-01 16:12:58 +01:00
djes
f75f93a46c Merge remote-tracking branch 'refs/remotes/origin/master' into thyphoon
# Conflicts:
#	README.md
2017-03-01 16:09:58 +01:00
djes
2535b685dd Readme change 2017-03-01 16:07:20 +01:00
djes
1cc8748ddc do not ignore png 2017-03-01 16:04:22 +01:00
djes
657a0f9c5f Merge remote-tracking branch 'refs/remotes/origin/master' into thyphoon
# Conflicts:
#	PBMap.pb
#	screenshot.png
2017-03-01 15:38:17 +01:00
djes
fb5dc89363 Merge pull request #9 from djes/MasterRevision
Major revision
2017-03-01 15:31:14 +01:00
djes
4f8ad1af73 Merge remote-tracking branch 'refs/remotes/origin/master' into thyphoon
# Conflicts:
#	PBMap.pb
2017-03-01 14:29:46 +01:00
djes
8128748f6e Merge remote-tracking branch 'refs/remotes/origin/master' into djes 2017-03-01 14:25:25 +01:00
5587e1cc11 Add "CleanCache" to SetOption
- Add "CleanCache" to SetOption
- Some minor change to proxy http download
2017-02-28 10:22:26 +01:00
cdd8ba1074 remove curl Dependencies
Use PB command only with Proxy Support
2017-02-21 15:42:29 +01:00
5 changed files with 3305 additions and 2039 deletions

4
.gitignore vendored
View File

@@ -1 +1,3 @@
PBMap.pb.bak
PBMap.pb.bak
*.exe

380
Demo.pb Normal file
View File

@@ -0,0 +1,380 @@
; ********************************************************************
; Program: PBMap example
; Author: djes
; Date: Jan, 2021
; License: PBMap : Free, unrestricted, credit
; appreciated but not required.
; OSM : see http://www.openstreetmap.org/copyright
; Note: Please share improvement !
; Thanks: Progi1984, falsam
; ********************************************************************
;
; Track bugs with the following options with debugger enabled
; PBMap::SetOption(#Map, "ShowDebugInfos", "1")
; PBMap::SetDebugLevel(5)
; PBMap::SetOption(#Map, "Verbose", "1")
;
; or with the OnError() PB capabilities :
;
; CompilerIf #PB_Compiler_LineNumbering = #False
; MessageRequester("Warning !", "You must enable 'OnError lines support' in compiler options", #PB_MessageRequester_Ok )
; End
; CompilerEndIf
;
; Declare ErrorHandler()
;
; OnErrorCall(@ErrorHandler())
;
; Procedure ErrorHandler()
; MessageRequester("Ooops", "The following error happened : " + ErrorMessage(ErrorCode()) + #CRLF$ +"line : " + Str(ErrorLine()))
; EndProcedure
;
; ********************************************************************
XIncludeFile "PBMap.pb"
InitNetwork()
CompilerIf #PB_Compiler_Thread = #False
MessageRequester("Warning !", "You must enable 'Create ThreadSafe Executable' in compiler options", #PB_MessageRequester_Ok )
End
CompilerEndIf
EnableExplicit
Enumeration
#Window_0
#Map
#Gdt_Left
#Gdt_Right
#Gdt_Up
#Gdt_Down
; #Gdt_RotateLeft
; #Gdt_RotateRight
#Button_4
#Button_5
#Combo_0
#Text_0
#Text_1
#Text_2
#Text_3
#Text_4
#StringLatitude
#StringLongitude
#Gdt_LoadGpx
#Gdt_SaveGpx
#Gdt_AddMarker
#Gdt_AddOpenseaMap
#Gdt_AddHereMap
#Gdt_AddGeoServerMap
#Gdt_Degrees
#Gdt_EditMode
#Gdt_ClearDiskCache
#TextGeoLocationQuery
#StringGeoLocationQuery
EndEnumeration
; Menu events
Enumeration
#MenuEventLonLatStringEnter
#MenuEventGeoLocationStringEnter
EndEnumeration
Structure Location
Longitude.d
Latitude.d
EndStructure
Procedure UpdateLocation(*Location.Location)
SetGadgetText(#StringLatitude, StrD(*Location\Latitude))
SetGadgetText(#StringLongitude, StrD(*Location\Longitude))
ProcedureReturn 0
EndProcedure
; This callback demonstration procedure will receive relative coords from canvas
Procedure MyMarker(x.i, y.i, Focus = #False, Selected = #False)
Protected color = RGBA(0, 255, 0, 255)
MovePathCursor(x, y)
AddPathLine(-16,-32,#PB_Path_Relative)
AddPathCircle(16,0,16,180,0,#PB_Path_Relative)
AddPathLine(-16,32,#PB_Path_Relative)
VectorSourceColor(color)
FillPath(#PB_Path_Preserve)
If Focus
VectorSourceColor(RGBA($FF, $FF, 0, $FF))
StrokePath(2)
ElseIf Selected
VectorSourceColor(RGBA($FF, $FF, 0, $FF))
StrokePath(3)
Else
VectorSourceColor(RGBA(0, 0, 0, 255))
StrokePath(1)
EndIf
EndProcedure
Procedure MarkerMoveCallBack(*Marker.PBMap::Marker)
Debug "Identifier : " + *Marker\Identifier + "(" + StrD(*Marker\GeographicCoordinates\Latitude) + ", " + StrD(*Marker\GeographicCoordinates\Longitude) + ")"
EndProcedure
; Example of a custom procedure to alter tile rendering
Procedure DrawTileCallBack(x.i, y.i, image.i, alpha.d)
MovePathCursor(x, y)
DrawVectorImage(ImageID(image), 255 * alpha)
EndProcedure
; Example of a custom procedure to alter tile file just after loading
Procedure.s ModifyTileFileCallback(CacheFile.s, OrgURL.s)
Protected ImgNB = LoadImage(#PB_Any, CacheFile)
If ImgNB
StartDrawing(ImageOutput(ImgNB))
DrawText(0, 0,"PUREBASIC", RGB(255, 255, 0))
StopDrawing()
;*** Could be used to create new files
; Cachefile = ReplaceString(Cachefile, ".png", "_PB.png")
;***
If SaveImage(ImgNB, CacheFile, #PB_ImagePlugin_PNG, 0, 32) ;Warning, the 32 is mandatory as some tiles aren't correctly rendered
; Send back the new name (not functional by now)
ProcedureReturn CacheFile
EndIf
EndIf
EndProcedure
Procedure MainPointer(x.i, y.i)
VectorSourceColor(RGBA(255, 255,255, 255)) : AddPathCircle(x, y,32) : StrokePath(1)
VectorSourceColor(RGBA(0, 0, 0, 255)) : AddPathCircle(x, y, 29):StrokePath(2)
EndProcedure
Procedure ResizeAll()
ResizeGadget(#Map, 10, 10, WindowWidth(#Window_0)-198, WindowHeight(#Window_0)-59)
ResizeGadget(#Text_1, WindowWidth(#Window_0)-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_Left, WindowWidth(#Window_0) - 150, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_Right, WindowWidth(#Window_0) - 90, #PB_Ignore, #PB_Ignore, #PB_Ignore)
; ResizeGadget(#Gdt_RotateLeft, WindowWidth(#Window_0) - 150, #PB_Ignore, #PB_Ignore, #PB_Ignore)
; ResizeGadget(#Gdt_RotateRight, WindowWidth(#Window_0) - 90, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_Up, WindowWidth(#Window_0) - 120, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_Down, WindowWidth(#Window_0) - 120, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Text_2, WindowWidth(#Window_0)-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Button_4, WindowWidth(#Window_0)-150, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Button_5, WindowWidth(#Window_0)-100, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Text_3, WindowWidth(#Window_0)-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#StringLatitude, WindowWidth(#Window_0)-120, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#StringLongitude, WindowWidth(#Window_0)-120, #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_LoadGpx, WindowWidth(#Window_0)-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_SaveGpx, WindowWidth(#Window_0)-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_AddOpenseaMap, WindowWidth(#Window_0)-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_AddHereMap, WindowWidth(#Window_0)-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_AddGeoServerMap, WindowWidth(#Window_0)-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_Degrees, WindowWidth(#Window_0)-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_EditMode, WindowWidth(#Window_0)-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_ClearDiskCache, WindowWidth(#Window_0)-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#TextGeoLocationQuery, WindowWidth(#Window_0)-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#StringGeoLocationQuery, WindowWidth(#Window_0)-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
PBMap::Refresh(#Map)
EndProcedure
;- MAIN TEST
If OpenWindow(#Window_0, 260, 225, 700, 571, "PBMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
LoadFont(0, "Arial", 12)
LoadFont(1, "Arial", 12, #PB_Font_Bold)
LoadFont(2, "Arial", 8)
TextGadget(#Text_1, 530, 10, 60, 15, "Movements")
; ButtonGadget(#Gdt_RotateLeft, 550, 070, 30, 30, "LRot") : SetGadgetFont(#Gdt_RotateLeft, FontID(2))
; ButtonGadget(#Gdt_RotateRight, 610, 070, 30, 30, "RRot") : SetGadgetFont(#Gdt_RotateRight, FontID(2))
ButtonGadget(#Gdt_Left, 550, 60, 30, 30, Chr($25C4)) : SetGadgetFont(#Gdt_Left, FontID(0))
ButtonGadget(#Gdt_Right, 610, 60, 30, 30, Chr($25BA)) : SetGadgetFont(#Gdt_Right, FontID(0))
ButtonGadget(#Gdt_Up, 580, 030, 30, 30, Chr($25B2)) : SetGadgetFont(#Gdt_Up, FontID(0))
ButtonGadget(#Gdt_Down, 580, 90, 30, 30, Chr($25BC)) : SetGadgetFont(#Gdt_Down, FontID(0))
TextGadget(#Text_2, 530, 120, 60, 15, "Zoom")
ButtonGadget(#Button_4, 550, 140, 50, 30, " + ") : SetGadgetFont(#Button_4, FontID(1))
ButtonGadget(#Button_5, 600, 140, 50, 30, " - ") : SetGadgetFont(#Button_5, FontID(1))
TextGadget(#Text_3, 530, 190, 50, 15, "Latitude ")
StringGadget(#StringLatitude, 580, 190, 90, 20, "")
TextGadget(#Text_4, 530, 210, 50, 15, "Longitude ")
StringGadget(#StringLongitude, 580, 210, 90, 20, "")
ButtonGadget(#Gdt_AddMarker, 530, 240, 150, 30, "Add Marker")
ButtonGadget(#Gdt_LoadGpx, 530, 270, 150, 30, "Load GPX")
ButtonGadget(#Gdt_SaveGpx, 530, 300, 150, 30, "Save GPX")
ButtonGadget(#Gdt_AddOpenseaMap, 530, 330, 150, 30, "Show/Hide OpenSeaMap", #PB_Button_Toggle)
ButtonGadget(#Gdt_AddHereMap, 530, 360, 150, 30, "Show/Hide HERE Aerial", #PB_Button_Toggle)
ButtonGadget(#Gdt_AddGeoServerMap, 530, 390, 150, 30, "Show/Hide Geoserver layer", #PB_Button_Toggle)
ButtonGadget(#Gdt_Degrees, 530, 420, 150, 30, "Show/Hide Degrees", #PB_Button_Toggle)
ButtonGadget(#Gdt_EditMode, 530, 450, 150, 30, "Edit mode ON/OFF", #PB_Button_Toggle)
ButtonGadget(#Gdt_ClearDiskCache, 530, 480, 150, 30, "Clear disk cache", #PB_Button_Toggle)
TextGadget(#TextGeoLocationQuery, 530, 515, 150, 15, "Enter an address")
StringGadget(#StringGeoLocationQuery, 530, 530, 150, 20, "")
SetActiveGadget(#StringGeoLocationQuery)
AddKeyboardShortcut(#Window_0, #PB_Shortcut_Return, #MenuEventGeoLocationStringEnter)
; *** TODO : code to remove when the SetActiveGadget(-1) will be fixed
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
Define Dummy = ButtonGadget(#PB_Any, 0, 0, 1, 1, "Dummy")
HideGadget(Dummy, 1)
CompilerElse
Define Dummy = -1
CompilerEndIf
; ***
Define Event.i, Gadget.i, Quit.b = #False
Define pfValue.d
Define Degrees = 1
Define *Track
Define *PBMap
; Our main gadget
;*PBMap = PBMap::InitPBMap(#Window_0)
PBMap::MapGadget(#Map, 10, 10, 512, 512)
PBMap::SetOption(#Map, "ShowDegrees", "1") : Degrees = 0
PBMap::SetOption(#Map, "ShowDebugInfos", "1")
PBMap::SetDebugLevel(5)
PBMap::SetOption(#Map, "Verbose", "0")
PBMap::SetOption(#Map, "ShowScale", "1")
PBMap::SetOption(#Map, "Warning", "1")
PBMap::SetOption(#Map, "ShowMarkersLegend", "1")
PBMap::SetOption(#Map, "ShowTrackKms", "1")
PBMap::SetOption(#Map, "ColourFocus", "$FFFF00AA")
PBMap::SetCallBackMainPointer(#Map, @MainPointer()) ; To change the main pointer (center of the view)
PBMap::SetCallBackLocation(#Map, @UpdateLocation()) ; To obtain realtime coordinates
PBMap::SetLocation(#Map, -36.81148, 175.08634,12) ; Change the PBMap coordinates
PBMap::SetMapScaleUnit(#Map, PBMAP::#SCALE_KM) ; To change the scale unit
PBMap::AddMarker(#Map, 49.0446828398, 2.0349812508, "", "", -1, @MyMarker()) ; To add a marker with a customised GFX
PBMap::SetCallBackMarker(#Map, @MarkerMoveCallBack())
;PBMap::SetCallBackDrawTile(@DrawTileCallBack())
;PBMap::SetCallBackModifyTileFile(@ModifyTileFileCallback())
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow : Quit = 1
Case #PB_Event_Gadget ; {
Gadget = EventGadget()
Select Gadget
Case #Gdt_Up
PBMap::SetLocation(#Map, 10* 360 / Pow(2, PBMap::GetZoom(#Map) + 8), 0, 0, #PB_Relative)
Case #Gdt_Down
PBMap::SetLocation(#Map, 10* -360 / Pow(2, PBMap::GetZoom(#Map) + 8), 0, 0, #PB_Relative)
Case #Gdt_Left
PBMap::SetLocation(#Map, 0, 10* -360 / Pow(2, PBMap::GetZoom(#Map) + 8), 0, #PB_Relative)
Case #Gdt_Right
PBMap::SetLocation(#Map, 0, 10* 360 / Pow(2, PBMap::GetZoom(#Map) + 8), 0, #PB_Relative)
; Case #Gdt_RotateLeft
; PBMAP::SetAngle(-5,#PB_Relative)
; PBMap::Refresh()
; Case #Gdt_RotateRight
; PBMAP::SetAngle(5,#PB_Relative)
; PBMap::Refresh()
Case #Button_4
PBMap::SetZoom(#Map, 1)
Case #Button_5
PBMap::SetZoom(#Map, -1)
Case #Gdt_LoadGpx
*Track = PBMap::LoadGpxFile(#Map, OpenFileRequester("Choose a file to load", "", "Gpx|*.gpx", 0))
PBMap::SetTrackColour(#Map, *Track, RGBA(Random(255), Random(255), Random(255), 128))
Case #Gdt_SaveGpx
If *Track
If PBMap::SaveGpxFile(#Map, SaveFileRequester("Choose a filename", "mytrack.gpx", "Gpx|*.gpx", 0), *Track)
MessageRequester("PBMap", "Saving OK !", #PB_MessageRequester_Ok)
Else
MessageRequester("PBMap", "Problem while saving.", #PB_MessageRequester_Ok)
EndIf
Else
MessageRequester("PBMap", "No track to save.", #PB_MessageRequester_Ok)
EndIf
Case #StringLatitude, #StringLongitude
Select EventType()
Case #PB_EventType_Focus
AddKeyboardShortcut(#Window_0, #PB_Shortcut_Return, #MenuEventLonLatStringEnter)
Case #PB_EventType_LostFocus
RemoveKeyboardShortcut(#Window_0, #PB_Shortcut_Return)
EndSelect
Case #Gdt_AddMarker
PBMap::AddMarker(#Map, ValD(GetGadgetText(#StringLatitude)), ValD(GetGadgetText(#StringLongitude)), "", "Test", RGBA(Random(255), Random(255), Random(255), 255))
Case #Gdt_AddOpenseaMap
If PBMap::IsLayer(#Map, "OpenSeaMap")
PBMap::DeleteLayer(#Map, "OpenSeaMap")
SetGadgetState(#Gdt_AddOpenseaMap, 0)
Else
PBMap::AddOSMServerLayer(#Map, "OpenSeaMap", 3, "http://t1.openseamap.org/seamark/") ; Add a special osm overlay map on layer nb 3
SetGadgetState(#Gdt_AddOpenseaMap, 1)
EndIf
PBMap::Refresh(#Map)
Case #Gdt_AddHereMap
If PBMap::IsLayer(#Map, "Here")
PBMap::DeleteLayer(#Map, "Here")
SetGadgetState(#Gdt_AddHereMap, 0)
Else
If PBMap::GetOption(#Map, "appid") <> "" And PBMap::GetOption(#Map, "appcode") <> ""
PBMap::AddHereServerLayer(#Map, "Here", 2) ; Add a "HERE" overlay map on layer nb 2
PBMap::SetLayerAlpha(#Map, "Here", 0.75)
Else
MessageRequester("Info", "Don't forget to register on HERE and change the following line or edit options file")
PBMap::AddHereServerLayer(#Map, "Here", 2, "my_id", "my_code") ; Add a here overlay map on layer nb 2
EndIf
SetGadgetState(#Gdt_AddHereMap, 1)
EndIf
PBMap::Refresh(#Map)
Case #Gdt_AddGeoServerMap
If PBMap::IsLayer(#Map, "GeoServer")
PBMap::DeleteLayer(#Map, "GeoServer")
SetGadgetState(#Gdt_AddGeoServerMap, 0)
Else
PBMap::AddGeoServerLayer(#Map, "GeoServer", 3, "demolayer", "http://localhost:8080/", "geowebcache/service/gmaps", "image/png") ; Add a geoserver overlay map on layer nb 3
PBMap::SetLayerAlpha(#Map, "GeoServer", 0.75)
SetGadgetState(#Gdt_AddGeoServerMap, 1)
EndIf
PBMap::Refresh(#Map)
Case #Gdt_Degrees
Degrees = 1 - Degrees
PBMap::SetOption(#Map, "ShowDegrees", Str(Degrees))
PBMap::Refresh(#Map)
SetGadgetState(#Gdt_Degrees, Degrees)
Case #Gdt_EditMode
If PBMap::GetMode(#Map) <> PBMap::#MODE_EDIT
PBMap::SetMode(#Map, PBMap::#MODE_EDIT)
SetGadgetState(#Gdt_EditMode, 1)
Else
PBMap::SetMode(#Map, PBMap::#MODE_DEFAULT)
SetGadgetState(#Gdt_EditMode, 0)
EndIf
Case #Gdt_ClearDiskCache
PBMap::ClearDiskCache(#Map)
Case #StringGeoLocationQuery
Select EventType()
Case #PB_EventType_Focus
AddKeyboardShortcut(#Window_0, #PB_Shortcut_Return, #MenuEventGeoLocationStringEnter)
Case #PB_EventType_LostFocus
RemoveKeyboardShortcut(#Window_0, #PB_Shortcut_Return)
EndSelect
EndSelect
Case #PB_Event_SizeWindow
ResizeAll()
Case #PB_Event_Menu
; Receive "enter" key events
Select EventMenu()
Case #MenuEventGeoLocationStringEnter
If GetGadgetText(#StringGeoLocationQuery) <> ""
PBMap::NominatimGeoLocationQuery(#Map, GetGadgetText(#StringGeoLocationQuery))
PBMap::Refresh(#Map)
EndIf
; *** TODO : code to change when the SetActiveGadget(-1) will be fixed
SetActiveGadget(Dummy)
; ***
Case #MenuEventLonLatStringEnter
PBMap::SetLocation(#Map, ValD(GetGadgetText(#StringLatitude)), ValD(GetGadgetText(#StringLongitude))) ; Change the PBMap coordinates
PBMap::Refresh(#Map)
EndSelect
EndSelect
Until Quit = #True
PBMap::FreeMapGadget(#Map)
EndIf
; IDE Options = PureBasic 5.73 LTS (Windows - x64)
; CursorPosition = 7
; Folding = --
; EnableThread
; EnableXP

375
Multiple-PBMaps-Demo.pb Normal file
View File

@@ -0,0 +1,375 @@
; Based on the orginal PBMap example (delivered with the package in Feb. 2018), this is an example with
; less functionality, but with 2 different Canvas Map gadgets placed in 2 tabs of a PanelGadget...
; (for testing purposes related to my GeoWorldEditor)
;
; Author: André Beer
; Last change: 26. Feb. 2018
; Modified by djes : 01. March 2018
; Adapted to new PBMap syntax by André: 02. March 2018
;
; ****************************************************************
;
;- Example of application
;
; ****************************************************************
XIncludeFile "PBMap.pb"
CompilerIf #PB_Compiler_Thread = #False
MessageRequester("Warning !", "You must enable 'Create ThreadSafe Executable' in compiler options", #PB_MessageRequester_Ok )
End
CompilerEndIf
EnableExplicit
InitNetwork()
Enumeration
#Window_0
#Map
#Gdt_Left
#Gdt_Right
#Gdt_Up
#Gdt_Down
#Button_4
#Button_5
#Combo_0
#Text_0
#Text_1
#Text_2
#Text_3
#Text_4
#StringLatitude
#StringLongitude
#Gdt_AddMarker
#Gdt_Degrees
#Gdt_ClearDiskCache
#TextGeoLocationQuery
#StringGeoLocationQuery
; Additions for a 2nd panel:
#PanelGadget
#Map2_Canvas
#Map2_Move
#Map2_Left
#Map2_Right
#Map2_Up
#Map2_Down
#Map2_Zoom
#Map2_ZoomIn
#Map2_ZoomOut
#Map2_LatitudeText
#Map2_StringLatitude
#Map2_LongitudeText
#Map2_StringLongitude
EndEnumeration
; Menu events
Enumeration
#MenuEventLonLatStringEnter
#MenuEventGeoLocationStringEnter
EndEnumeration
Structure Location
Longitude.d
Latitude.d
EndStructure
Procedure UpdateLocation(*Location.Location)
SetGadgetText(#StringLatitude, StrD(*Location\Latitude))
SetGadgetText(#StringLongitude, StrD(*Location\Longitude))
ProcedureReturn 0
EndProcedure
; This callback demonstration procedure will receive relative coords from canvas
Procedure MyMarker(x.i, y.i, Focus = #False, Selected = #False)
Protected color = RGBA(0, 255, 0, 255)
MovePathCursor(x, y)
AddPathLine(-16,-32,#PB_Path_Relative)
AddPathCircle(16,0,16,180,0,#PB_Path_Relative)
AddPathLine(-16,32,#PB_Path_Relative)
VectorSourceColor(color)
FillPath(#PB_Path_Preserve)
If Focus
VectorSourceColor(RGBA($FF, $FF, 0, $FF))
StrokePath(2)
ElseIf Selected
VectorSourceColor(RGBA($FF, $FF, 0, $FF))
StrokePath(3)
Else
VectorSourceColor(RGBA(0, 0, 0, 255))
StrokePath(1)
EndIf
EndProcedure
Procedure MarkerMoveCallBack(*Marker.PBMap::Marker)
Debug "Identifier : " + *Marker\Identifier + "(" + StrD(*Marker\GeographicCoordinates\Latitude) + ", " + StrD(*Marker\GeographicCoordinates\Longitude) + ")"
EndProcedure
; Example of a custom procedure to alter tile rendering
Procedure DrawTileCallBack(x.i, y.i, image.i, alpha.d)
MovePathCursor(x, y)
DrawVectorImage(ImageID(image), 255 * alpha)
EndProcedure
; Example of a custom procedure to alter tile file just after loading
Procedure.s ModifyTileFileCallback(CacheFile.s, OrgURL.s)
Protected ImgNB = LoadImage(#PB_Any, CacheFile)
If ImgNB
StartDrawing(ImageOutput(ImgNB))
DrawText(0, 0,"PUREBASIC", RGB(255, 255, 0))
StopDrawing()
;*** Could be used to create new files
; Cachefile = ReplaceString(Cachefile, ".png", "_PB.png")
;***
If SaveImage(ImgNB, CacheFile, #PB_ImagePlugin_PNG, 0, 32) ;Warning, the 32 is mandatory as some tiles aren't correctly rendered
; Send back the new name (not functional by now)
ProcedureReturn CacheFile
EndIf
EndIf
EndProcedure
Procedure MainPointer(x.i, y.i)
VectorSourceColor(RGBA(255, 255,255, 255)) : AddPathCircle(x, y,32) : StrokePath(1)
VectorSourceColor(RGBA(0, 0, 0, 255)) : AddPathCircle(x, y, 29):StrokePath(2)
EndProcedure
Procedure ResizeAll()
Protected PanelTabHeight = GetGadgetAttribute(#PanelGadget, #PB_Panel_TabHeight)
ResizeGadget(#PanelGadget, #PB_Ignore, #PB_Ignore, WindowWidth(#Window_0), WindowHeight(#Window_0)-PanelTabHeight)
Protected PanelItemWidth = GetGadgetAttribute(#PanelGadget, #PB_Panel_ItemWidth)
Protected PanelItemHeight = GetGadgetAttribute(#PanelGadget, #PB_Panel_ItemHeight)
; First tab:
ResizeGadget(#Map, 10, 10, PanelItemWidth-198, PanelItemHeight-59)
ResizeGadget(#Text_1, PanelItemWidth-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_Left, PanelItemWidth-150, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_Right, PanelItemWidth-90, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_Up, PanelItemWidth-120, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_Down, PanelItemWidth-120, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Text_2, PanelItemWidth-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Button_4, PanelItemWidth-150, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Button_5, PanelItemWidth-100, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Text_3, PanelItemWidth-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#StringLatitude, PanelItemWidth-120, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#StringLongitude, PanelItemWidth-120, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Text_4, PanelItemWidth-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_AddMarker, PanelItemWidth-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_Degrees, PanelItemWidth-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Gdt_ClearDiskCache, PanelItemWidth-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#TextGeoLocationQuery, PanelItemWidth-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#StringGeoLocationQuery, PanelItemWidth-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
; Second tab:
ResizeGadget(#Map2_Canvas, 10, 10, PanelItemWidth-198, PanelItemHeight-59)
ResizeGadget(#Map2_Move, PanelItemWidth-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Map2_Left, PanelItemWidth-150, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Map2_Right, PanelItemWidth-90, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Map2_Up, PanelItemWidth-120, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Map2_Down, PanelItemWidth-120, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Map2_Zoom, PanelItemWidth-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Map2_ZoomIn, PanelItemWidth-150, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Map2_ZoomOut, PanelItemWidth-100, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Map2_LatitudeText, PanelItemWidth-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Map2_StringLatitude, PanelItemWidth-120, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Map2_LongitudeText, PanelItemWidth-170, #PB_Ignore, #PB_Ignore, #PB_Ignore)
ResizeGadget(#Map2_StringLongitude, PanelItemWidth-120, #PB_Ignore, #PB_Ignore, #PB_Ignore)
; Refresh the PBMap:
PBMap::Refresh(#Map)
PBMap::Refresh(#Map2_Canvas)
EndProcedure
;- MAIN TEST
If OpenWindow(#Window_0, 260, 225, 720, 595, "PBMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
; ***
Define Event.i, Gadget.i, Quit.b = #False
Define pfValue.d
Define Degrees = 1
Define *Track
Define a, ActivePanel
LoadFont(0, "Arial", 12)
LoadFont(1, "Arial", 12, #PB_Font_Bold)
LoadFont(2, "Arial", 8)
PanelGadget(#PanelGadget, 0, 0, 720, 595)
AddGadgetItem(#PanelGadget, 0, "Map 1")
TextGadget(#Text_1, 530, 10, 60, 15, "Movements")
ButtonGadget(#Gdt_Left, 550, 60, 30, 30, Chr($25C4)) : SetGadgetFont(#Gdt_Left, FontID(0))
ButtonGadget(#Gdt_Right, 610, 60, 30, 30, Chr($25BA)) : SetGadgetFont(#Gdt_Right, FontID(0))
ButtonGadget(#Gdt_Up, 580, 030, 30, 30, Chr($25B2)) : SetGadgetFont(#Gdt_Up, FontID(0))
ButtonGadget(#Gdt_Down, 580, 90, 30, 30, Chr($25BC)) : SetGadgetFont(#Gdt_Down, FontID(0))
TextGadget(#Text_2, 530, 120, 60, 15, "Zoom")
ButtonGadget(#Button_4, 550, 140, 50, 30, " + ") : SetGadgetFont(#Button_4, FontID(1))
ButtonGadget(#Button_5, 600, 140, 50, 30, " - ") : SetGadgetFont(#Button_5, FontID(1))
TextGadget(#Text_3, 530, 190, 50, 15, "Latitude ")
StringGadget(#StringLatitude, 580, 190, 90, 20, "")
TextGadget(#Text_4, 530, 210, 50, 15, "Longitude ")
StringGadget(#StringLongitude, 580, 210, 90, 20, "")
ButtonGadget(#Gdt_AddMarker, 530, 240, 150, 30, "Add Marker")
ButtonGadget(#Gdt_Degrees, 530, 420, 150, 30, "Show/Hide Degrees", #PB_Button_Toggle)
ButtonGadget(#Gdt_ClearDiskCache, 530, 480, 150, 30, "Clear disk cache", #PB_Button_Toggle)
TextGadget(#TextGeoLocationQuery, 530, 515, 150, 15, "Enter an address")
StringGadget(#StringGeoLocationQuery, 530, 530, 150, 20, "")
SetActiveGadget(#StringGeoLocationQuery)
; Our main gadget
PBMap::MapGadget(#Map, 10, 10, 512, 512, 1, #Window_0)
PBMap::SetOption(#Map, "ShowDegrees", "1") : Degrees = 0
PBMap::SetOption(#Map, "ShowDebugInfos", "1")
PBMap::SetDebugLevel(5)
PBMap::SetOption(#Map, "Verbose", "1")
PBMap::SetOption(#Map, "ShowScale", "1")
PBMap::SetOption(#Map, "Warning", "1")
PBMap::SetOption(#Map, "ShowMarkersLegend", "1")
PBMap::SetOption(#Map, "ShowTrackKms", "1")
PBMap::SetOption(#Map, "ColourFocus", "$FFFF00AA")
PBMap::SetCallBackMainPointer(#Map, @MainPointer()) ; To change the main pointer (center of the view)
PBMap::SetCallBackLocation(#Map, @UpdateLocation()) ; To obtain realtime coordinates
PBMap::SetLocation(#Map, -36.81148, 175.08634,12) ; Change the PBMap coordinates
PBMAP::SetMapScaleUnit(#Map, PBMAP::#SCALE_KM) ; To change the scale unit
PBMap::AddMarker(#Map, 49.0446828398, 2.0349812508, "", "", -1, @MyMarker()) ; To add a marker with a customised GFX
PBMap::SetCallBackMarker(#Map, @MarkerMoveCallBack())
PBMap::SetCallBackDrawTile(#Map, @DrawTileCallBack())
PBMap::SetCallBackModifyTileFile(#Map, @ModifyTileFileCallback())
AddGadgetItem(#PanelGadget, 1, "Map 2")
TextGadget(#Map2_Move, 530, 10, 60, 15, "Movements")
ButtonGadget(#Map2_Left, 550, 60, 30, 30, Chr($25C4)) : SetGadgetFont(#Gdt_Left, FontID(0))
ButtonGadget(#Map2_Right, 610, 60, 30, 30, Chr($25BA)) : SetGadgetFont(#Gdt_Right, FontID(0))
ButtonGadget(#Map2_Up, 580, 030, 30, 30, Chr($25B2)) : SetGadgetFont(#Gdt_Up, FontID(0))
ButtonGadget(#Map2_Down, 580, 90, 30, 30, Chr($25BC)) : SetGadgetFont(#Gdt_Down, FontID(0))
TextGadget(#Map2_Zoom, 530, 120, 60, 15, "Zoom")
ButtonGadget(#Map2_ZoomIn, 550, 140, 50, 30, " + ") : SetGadgetFont(#Button_4, FontID(1))
ButtonGadget(#Map2_ZoomOut, 600, 140, 50, 30, " - ") : SetGadgetFont(#Button_5, FontID(1))
TextGadget(#Map2_LatitudeText, 530, 190, 50, 15, "Latitude ")
StringGadget(#Map2_StringLatitude, 580, 190, 90, 20, "")
TextGadget(#Map2_LongitudeText, 530, 210, 50, 15, "Longitude ")
StringGadget(#Map2_StringLongitude, 580, 210, 90, 20, "")
; Our second map:
PBMap::MapGadget(#Map2_Canvas, 10, 10, 512, 512, 1, #Window_0)
PBMap::SetOption(#Map2_Canvas, "ShowDegrees", "1") : Degrees = 0
PBMap::SetOption(#Map2_Canvas, "ShowDebugInfos", "1")
PBMap::SetDebugLevel(5)
PBMap::SetOption(#Map2_Canvas, "Verbose", "1")
PBMap::SetOption(#Map2_Canvas, "ShowScale", "1")
PBMap::SetOption(#Map2_Canvas, "Warning", "1")
PBMap::SetOption(#Map2_Canvas, "ShowMarkersLegend", "1")
PBMap::SetOption(#Map2_Canvas, "ShowTrackKms", "1")
PBMap::SetOption(#Map2_Canvas, "ColourFocus", "$FFFF00AA")
PBMap::SetCallBackMainPointer(#Map2_Canvas, @MainPointer()) ; To change the main pointer (center of the view)
PBMap::SetCallBackLocation(#Map2_Canvas, @UpdateLocation()) ; To obtain realtime coordinates
PBMap::SetLocation(#Map2_Canvas, 6.81148, 15.08634,12) ; Change the PBMap coordinates
PBMAP::SetMapScaleUnit(#Map2_Canvas, PBMAP::#SCALE_KM) ; To change the scale unit
PBMap::AddMarker(#Map2_Canvas, 49.0446828398, 2.0349812508)
CloseGadgetList()
ActivePanel = 2 ; Set the current active panel (1 = Map1, 2 = Map2)
SetGadgetState(#PanelGadget, 1)
AddKeyboardShortcut(#Window_0, #PB_Shortcut_Return, #MenuEventGeoLocationStringEnter)
; *** TODO : code to remove when the SetActiveGadget(-1) will be fixed
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
Define Dummy = ButtonGadget(#PB_Any, 0, 0, 1, 1, "Dummy")
HideGadget(Dummy, 1)
CompilerElse
Define Dummy = -1
CompilerEndIf
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow : Quit = 1
Case #PB_Event_Gadget ; {
Gadget = EventGadget()
Select Gadget
Case #PanelGadget
Select EventType()
Case #PB_EventType_Change
a = GetGadgetState(#PanelGadget)
If a <> ActivePanel
ActivePanel = a
If ActivePanel = 0
; ....
Else
; ....
EndIf
EndIf
EndSelect
Case #Gdt_Up
PBMap::SetLocation(#Map, 10* 360 / Pow(2, PBMap::GetZoom(#Map) + 8), 0, 0, #PB_Relative)
Case #Map2_Up
PBMap::SetLocation(#Map2_Canvas, 10* 360 / Pow(2, PBMap::GetZoom(#Map2_Canvas) + 8), 0, 0, #PB_Relative)
Case #Gdt_Down
PBMap::SetLocation(#Map, 10* -360 / Pow(2, PBMap::GetZoom(#Map) + 8), 0, 0, #PB_Relative)
Case #Map2_Down
PBMap::SetLocation(#Map2_Canvas, 10* -360 / Pow(2, PBMap::GetZoom(#Map2_Canvas) + 8), 0, 0, #PB_Relative)
Case #Gdt_Left
PBMap::SetLocation(#Map, 0, 10* -360 / Pow(2, PBMap::GetZoom(#Map) + 8), 0, #PB_Relative)
Case #Map2_Left
PBMap::SetLocation(#Map2_Canvas, 0, 10* -360 / Pow(2, PBMap::GetZoom(#Map2_Canvas) + 8), 0, #PB_Relative)
Case #Gdt_Right
PBMap::SetLocation(#Map, 0, 10* 360 / Pow(2, PBMap::GetZoom(#Map) + 8), 0, #PB_Relative)
Case #Map2_Right
PBMap::SetLocation(#Map2_Canvas, 0, 10* 360 / Pow(2, PBMap::GetZoom(#Map2_Canvas) + 8), 0, #PB_Relative)
Case #Button_4
PBMap::SetZoom(#Map, 1)
Case #Map2_ZoomIn
PBMap::SetZoom(#Map2_Canvas, 1)
Case #Button_5
PBMap::SetZoom(#Map, - 1)
Case #Map2_ZoomOut
PBMap::SetZoom(#Map2_Canvas, - 1)
Case #StringLatitude, #StringLongitude, #Map2_StringLatitude, #Map2_StringLongitude
Select EventType()
Case #PB_EventType_Focus
AddKeyboardShortcut(#Window_0, #PB_Shortcut_Return, #MenuEventLonLatStringEnter)
Case #PB_EventType_LostFocus
RemoveKeyboardShortcut(#Window_0, #PB_Shortcut_Return)
EndSelect
Case #Gdt_AddMarker
PBMap::AddMarker(#Map, ValD(GetGadgetText(#StringLatitude)), ValD(GetGadgetText(#StringLongitude)), "", "Test", RGBA(Random(255), Random(255), Random(255), 255))
Case #Gdt_Degrees
Degrees = 1 - Degrees
PBMap::SetOption(#Map, "ShowDegrees", Str(Degrees))
PBMap::Refresh(#Map)
SetGadgetState(#Gdt_Degrees, Degrees)
Case #Gdt_ClearDiskCache
PBMap::ClearDiskCache(#Map)
Case #StringGeoLocationQuery
Select EventType()
Case #PB_EventType_Focus
AddKeyboardShortcut(#Window_0, #PB_Shortcut_Return, #MenuEventGeoLocationStringEnter)
Case #PB_EventType_LostFocus
RemoveKeyboardShortcut(#Window_0, #PB_Shortcut_Return)
EndSelect
EndSelect
Case #PB_Event_SizeWindow
ResizeAll()
Case #PB_Event_Menu
; Receive "enter" key events
Select EventMenu()
Case #MenuEventGeoLocationStringEnter
If GetGadgetText(#StringGeoLocationQuery) <> ""
PBMap::NominatimGeoLocationQuery(#Map, GetGadgetText(#StringGeoLocationQuery))
PBMap::Refresh(#Map)
EndIf
; *** TODO : code to change when the SetActiveGadget(-1) will be fixed
SetActiveGadget(Dummy)
; ***
Case #MenuEventLonLatStringEnter
PBMap::SetLocation(#Map, ValD(GetGadgetText(#StringLatitude)), ValD(GetGadgetText(#StringLongitude))) ; Change the PBMap coordinates
PBMap::Refresh(#Map)
EndSelect
EndSelect
Until Quit = #True
PBMap::FreeMapGadget(#Map)
PBMap::FreeMapGadget(#Map2_Canvas)
EndIf
; IDE Options = PureBasic 5.73 LTS (Windows - x64)
; CursorPosition = 21
; Folding = --
; EnableThread
; EnableXP
; CompileSourceDirectory

4561
PBMap.pb

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,17 @@
# PBMap # PBMap 0.91
Purebasic open source tiled map software. Open source tiled map software.
Created to develop and test tiles applications in PureBasic.
This code is free ! Module to develop tiled map applications in PureBasic, like like OpenStreetMap(c), Google Maps(c), Here(c), ...
Officials forums topics here :
Functional example based on OpenStreetMap(c) services
OSM copyright : http://www.openstreetmap.org/copyright
This code is free, but any user should mention the origin of this code.
Official forums topics :
http://www.purebasic.fr/english/viewtopic.php?f=27&t=66320 (english) http://www.purebasic.fr/english/viewtopic.php?f=27&t=66320 (english)
http://www.purebasic.fr/french/viewtopic.php?f=3&t=16160 (french) http://www.purebasic.fr/french/viewtopic.php?f=3&t=16160 (french)
@@ -12,4 +19,11 @@ Contributors :
Thyphoon Thyphoon
djes djes
Idle Idle
Thanks to :
Progi1984 Progi1984
yves86
André
falsam
Special thanks to Fred and Fantaisie Software's team