OpenStreetMap embedded in your application

Share your advanced PureBasic knowledge/code with the community.
kandl
User
User
Posts: 11
Joined: Sat Apr 11, 2009 6:54 am

Re: OpenStreetMap embedded in your application

Post by kandl »

http://rapidshare.com/files/416374955/OSM2_win32.zip (updated 12:23 AM 9/1/2010)

as the name implies, only works on win32 atm (PB 4.50 x86)

itc.pb - thread and inter-thread comm
curl.pb - uses dll instead of lib. incomplete import list, only loaded functions that i might use

sqlite db file is stored in %appdata%\osm by default

middle click-drag to pan
left double click to center
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: OpenStreetMap embedded in your application

Post by citystate »

rapidshare claims that only 10 downloads are allowed - any chance of re-uploading this?
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
kandl
User
User
Posts: 11
Joined: Sat Apr 11, 2009 6:54 am

Re: OpenStreetMap embedded in your application

Post by kandl »

OSM2.1_win32.zip

http://www.sendspace.com/file/r5eavm (10:18 AM 9/8/2010)


OSM2_win32.zip

http://www.megaupload.com/?d=FRVTYBQE (8:21 PM 9/6/2010)
http://www.sendspace.com/file/pcootd (11:47 AM 9/7/2010)
metalos
User
User
Posts: 29
Joined: Thu Apr 19, 2012 8:32 am

Re: OpenStreetMap embedded in your application

Post by metalos »

To try to run this code on Mac OS X RW_LibCurl.Inc.pb I modified the file.

I already changed the CompilerCase to make MacOS and before each "SymbolName 'I added a" _ ".

Here is the modified code:

Code: Select all

XIncludeFile "RW_LibCurl_Res.pb"

Macro DQuote
  "
EndMacro
CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_MacOS
    Macro SymbolName(Val)
      DQuote#Val#DQuote
    EndMacro
    #LibCurl_ImportLib = "/usr/lib/libcurl.3.dylib"
    #LibCurl_SeparatorDir = "/"
  CompilerCase #PB_OS_Windows
    Macro SymbolName(Val)
      DQuote _#Val#DQuote
    EndMacro
    #LibCurl_ImportLib = "LibCurl.lib"
    #LibCurl_SeparatorDir = "\"
CompilerEndSelect

;- Imports
ImportC #LibCurl_ImportLib
  curl_easy_cleanup(handle.l) As SymbolName(_curl_easy_cleanup)
  curl_easy_duphandle(handle.l) As SymbolName(_curl_easy_duphandle)
  curl_easy_getinfo(curl.l, info_type.l, info.l) As SymbolName(_curl_easy_getinfo)
  curl_easy_init() As SymbolName(_curl_easy_init)
  curl_easy_perform(handle.l) As SymbolName(_curl_easy_perform)
  curl_easy_recv(*curl, *buffer, buflen.l,*n) As SymbolName(_curl_easy_recv)
  curl_easy_reset(handle.l) As SymbolName(_curl_easy_reset)
  curl_easy_send(*curl, *buffer, buflen.l, *n) As SymbolName(_curl_easy_send)
  curl_easy_setopt(handle.l, option.l, parameter.l) As SymbolName(_curl_easy_setopt)
  curl_easy_strerror(errornum.l) As SymbolName(_curl_easy_strerror)
  curl_escape(url.l, length.l) As SymbolName(_curl_escape)
  curl_formadd(firstitem.l, lastitem.l) As SymbolName(_curl_formadd)
  curl_formfree(form.l) As SymbolName(_curl_formfree)
  curl_formget(*form.curl_httppost, *arg, append) As SymbolName(_curl_formget)
  curl_free(ptr.l) As SymbolName(_curl_free)
  curl_getdate(datestring.l, now.l) As SymbolName(_curl_getdate)
  curl_getenv(name.l) As SymbolName(_curl_getenv)
  curl_global_cleanup() As SymbolName(_curl_global_cleanup)
  curl_global_init(flags.l) As SymbolName(_curl_global_init)
  curl_global_init_mem(flags.l, m.l, f.l, r.l, s.l, c.l) As SymbolName(_curl_global_init_mem)
  curl_mprintf(format.l) As SymbolName(_curl_mprintf)
  curl_mfprintf(fd.l, format.l) As SymbolName(_curl_mfprintf)
  curl_msprintf(buffer.l, format.l) As SymbolName(_curl_msprintf)
  curl_msnprintf(buffer.l, maxlength.l, format.l) As SymbolName(_curl_msnprintf)
  curl_mvprintf(format.l, args.l) As SymbolName(_curl_mvprintf)
  curl_mvfprintf(fd.l, format.l, args.l) As SymbolName(_curl_mvfprintf)
  curl_mvsprintf(buffer.l, format.l, args.l) As SymbolName(_curl_mvsprintf)
  curl_mvsnprintf(buffer.l, maxlength.l, format.l, args.l) As SymbolName(_curl_mvsnprintf)
  curl_maprintf(format.l) As SymbolName(_curl_maprintf)
  curl_mvaprintf(format.l, args.l) As SymbolName(_curl_mvaprintf)
  curl_multi_add_handle(multi_handle.l, easy_handle.l) As SymbolName(_curl_multi_add_handle)
  curl_multi_assign(*multi_handle, sockfd.l, *sockp) As SymbolName(_curl_multi_assign)
  curl_multi_cleanup(multi_handle.l) As SymbolName(_curl_multi_cleanup)
  curl_multi_fdset(multi_handle.l, read_fd_set.l, write_fd_set.l, exc_fd_set.l, max_fd.l) As SymbolName(_curl_multi_fdset)
  curl_multi_info_read(multi_handle.l, msgs_in_queue.l) As SymbolName(_curl_multi_info_read)
  curl_multi_init() As SymbolName(_curl_multi_init)
  curl_multi_perform(multi_handle.l, running_handles.l) As SymbolName(_curl_multi_perform)
  curl_multi_remove_handle(multi_handle.l, easy_handle.l) As SymbolName(_curl_multi_remove_handle)
  curl_multi_strerror(errornum.l) As SymbolName(_curl_multi_strerror)
  curl_multi_socket(*multi_handle, s.l, *running_handles) As SymbolName(_curl_multi_socket)
  curl_multi_socket_action(*multi_handle, s.l, ev_bitmask.l, *running_handles) As SymbolName(_curl_multi_socket_action)
  curl_multi_socket_all(*multi_handle, *running_handles) As SymbolName(_curl_multi_socket_all)
  curl_share_cleanup(share_handle.l) As SymbolName(_curl_share_cleanup)
  curl_share_init() As SymbolName(_curl_share_init)
  curl_share_setopt(share.l, option.l, parameter.l) As SymbolName(_curl_share_setopt)
  curl_share_strerror(errornum.l) As SymbolName(_curl_share_strerror)
  curl_slist_append(slist.l, string.p-utf8) As SymbolName(_curl_slist_append)
  curl_slist_free_all(slist.l) As SymbolName(_curl_slist_free_all)
  curl_strequal(str1.l, str2.l) As SymbolName(_curl_strequal)
  curl_strnequal(str1.l, str2.l, len.l) As SymbolName(_curl_strnequal)
  curl_unescape(url.l, length.l) As SymbolName(_curl_unescape)
  curl_version() As SymbolName(_curl_version)
  curl_version_info(type.l) As SymbolName(_curl_version_info)
EndImport;}


Procedure RW_LibCurl_InitString()
  Shared ReceivedData.s
  If ReceivedData > ""
    ReceivedData = ""
  EndIf
EndProcedure
Procedure RW_LibCurl_InitData()
  Shared *LibCurl_SharedMem
  If *LibCurl_SharedMem
    FreeMemory(*LibCurl_SharedMem)
    *LibCurl_SharedMem = 0
  EndIf
EndProcedure
ProcedureC  RW_LibCurl_WriteStrFunction(*ptr, Size, NMemB, *Stream)
  ;retreives utf-8/ascii encoded data
  Protected SizeProper.l  = Size & 255
  Protected NMemBProper.l = NMemB
  Protected MyDataS.s
  Shared ReceivedData.s
  
  MyDataS = PeekS(*ptr, SizeProper * NMemBProper)
  ReceivedData + MyDataS
  ;Debug "> " + MyDataS
  ;Debug "# " + Str(Len(MyDataS))
  ;Debug "@ " + Str(Len(ReceivedData))
  ProcedureReturn SizeProper * NMemBProper
EndProcedure
Procedure.s RW_LibCurl_GetString()
  Shared ReceivedData.s
  ProcedureReturn ReceivedData
EndProcedure
ProcedureC  RW_LibCurl_WriteDataFunction(*ptr, Size, NMemB, *Stream)
  Protected plSize.l  = Size & 255
  Protected plNmemB.l = NMemB
  Protected plMemorySize.l = plSize * plNmemB
  Protected plLibCurl_SharedMemSize.l
  
  Protected *LibCurl_TempMemory
  Protected *LibCurl_TempSharedMem
  
  Shared *LibCurl_SharedMem

  ; allocates memory for receiving data
  *LibCurl_TempMemory = AllocateMemory(plMemorySize)
  CopyMemory(*ptr, *LibCurl_TempMemory, plMemorySize)
  
  ; if memory doesn't exists
  If *LibCurl_SharedMem = 0
    *LibCurl_SharedMem = AllocateMemory(plMemorySize)
    CopyMemory(*LibCurl_TempMemory, *LibCurl_SharedMem, plMemorySize)
  Else
    ; we allocate a temporary memory zone for storing previous *LibCurl_SharedMem
    plLibCurl_SharedMemSize  = MemorySize(*LibCurl_SharedMem)
    *LibCurl_TempSharedMem = AllocateMemory(plLibCurl_SharedMemSize)
    CopyMemory(*LibCurl_SharedMem, *LibCurl_TempSharedMem, plLibCurl_SharedMemSize)
    ; we free *LibCurl_SharedMem
    FreeMemory(*LibCurl_SharedMem)
    ; we allocate *LibCurl_SharedMem wtih size of previous *LibCurl_SharedMem + new data
    *LibCurl_SharedMem = AllocateMemory(plLibCurl_SharedMemSize + plMemorySize)
    CopyMemory(*LibCurl_TempSharedMem,  *LibCurl_SharedMem,                         plLibCurl_SharedMemSize)
    CopyMemory(*LibCurl_TempMemory,     *LibCurl_SharedMem+plLibCurl_SharedMemSize, plMemorySize)
    ; we free memory
    FreeMemory(*LibCurl_TempMemory)
    FreeMemory(*LibCurl_TempSharedMem)
  EndIf
  ProcedureReturn plMemorySize
EndProcedure
Procedure RW_LibCurl_GetData()
  Shared *LibCurl_SharedMem
  Protected *LibCurl_NewMemory
  *LibCurl_NewMemory = AllocateMemory(MemorySize(*LibCurl_SharedMem))
  CopyMemory(*LibCurl_SharedMem, *LibCurl_NewMemory, MemorySize(*LibCurl_SharedMem))
  ProcedureReturn *LibCurl_NewMemory
EndProcedure
Only the compilation I get an error on loading the database sql 249 lines on the "OpenStreetMap.pb" file with this command:

Code: Select all

DatabaseUpdate(glSQLiteDB, psSQLRequest)
Compiler message: The specified # Database is not initialized.

I tested all the variables and I really do not see what that can block. For information on PB I 5.22LTS Mac OS X Mavericks.

Thank you in advance for your help.

PS: Sorry for my english because I use Google Translate.
User avatar
thyphoon
Enthusiast
Enthusiast
Posts: 345
Joined: Sat Dec 25, 2004 2:37 pm

Re: OpenStreetMap embedded in your application

Post by thyphoon »

remove curl dependancies and run with PB 4.42.

Code: Select all

;@author Progi1984
;@changelog 1.0 24/08/09 Initial release (cache, zoom, moving, layers)
;@changelog 1.1 31/08/09 ADDED : Mimize Window
;@+						 ADDED : Zoom with click on the ImageGadget
;@thanks akj (http://www.purebasic.fr/english/profile.php?mode=viewprofile&u=292) for ideas and bug reporting
;@thanks netmaestro (http://www.purebasic.fr/english/profile.php?mode=viewprofile&u=1912) for tests (Vista) and bug reporting
;@misc : Prerequisites : For Windows, http://www.microsoft.com/downloads/details.aspx?FamilyID=a5c84275-3b97-4ab7-a40d-3802b2af5fc2&displaylang=en
;@changelog by thyphoon remove curl dependencies and add latitude/longitude gadget edit

InitNetwork()
IncludePath ""

UsePNGImageDecoder()
UseSQLiteDatabase()
EnableExplicit
Enumeration
  #Window_0
  #Image_0
  #Image_1
  #Image_2
  #Image_3
  #Button_0
  #Button_1
  #Button_2
  #Button_3
  #Button_4
  #Button_5
  #Combo_0
  #Text_0
  #Text_1
  #Text_2
  #Text_3
  #Text_4
  #String_0
  #String_1
EndEnumeration
#_DQ_ = Chr(34)
Global gfLatitude.d   = 49.0422777
Global gfLongitude.d  = 2.035566
Global gfxTile.f
Global gfyTile.f
Global glZoom.l       = 17
Global glLayerCur.l   = 0
Global glSQLiteDB.l
Global gsSQLiteDBPath.s = ""
Global glGadget.l
Global glEvent.l
Global glQuit.l

Structure S_OSM_Layers
  sName.s
  sURL.s
  lZoomMin.l
  lZoomMax.l
EndStructure
#OSM_Layers_Num = 5
Global Dim OSM_Layers_Dim.S_OSM_Layers(#OSM_Layers_Num)
OSM_Layers_Dim(0)\sName     = "OSM Mapnik"
OSM_Layers_Dim(0)\sURL      = "http://tile.openstreetmap.org/"
OSM_Layers_Dim(0)\lZoomMin  = 0
OSM_Layers_Dim(0)\lZoomMax  = 18
OSM_Layers_Dim(1)\sName     = "OSM Osmarender/Tiles@Home"
OSM_Layers_Dim(1)\sURL      = "http://tah.openstreetmap.org/Tiles/tile/"
OSM_Layers_Dim(1)\lZoomMin  = 0
OSM_Layers_Dim(1)\lZoomMax  = 17
OSM_Layers_Dim(2)\sName     = "OSM Cycle Map"
OSM_Layers_Dim(2)\sURL      = "http://andy.sandbox.cloudmade.com/tiles/cycle/"
OSM_Layers_Dim(2)\lZoomMin  = 0
OSM_Layers_Dim(2)\lZoomMax  = 18
OSM_Layers_Dim(3)\sName     = "OSM Maplint"
OSM_Layers_Dim(3)\sURL      = "http://tah.openstreetmap.org/Tiles/maplint/"
OSM_Layers_Dim(3)\lZoomMin  = 12
OSM_Layers_Dim(3)\lZoomMax  = 16
OSM_Layers_Dim(4)\sName     = "NPE out-of-copyright map "
OSM_Layers_Dim(4)\sURL      = "http://richard.dev.openstreetmap.org/npe/"
OSM_Layers_Dim(4)\lZoomMin  = 13
OSM_Layers_Dim(4)\lZoomMax  = 15


Define.f pfValue

;@desc Open the main window
;@author Progi1984
Procedure WindowMain_Open()
  If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap",  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
    LoadFont(0,"Wingdings",12)
    LoadFont(1,"Arial",12,#PB_Font_Bold)
  
    ImageGadget(#Image_0, 10, 10, 256, 256, 0)
    ImageGadget(#Image_1, 266, 10, 256, 256, 0)
    ImageGadget(#Image_2, 10, 266, 256, 256, 0)
    ImageGadget(#Image_3, 266, 266, 256, 256, 0)
    
    TextGadget(#Text_0, 530, 10, 60, 15, "Layers :")
    ComboBoxGadget(#Combo_0, 550, 30, 130, 20)
      AddGadgetItem(#Combo_0, 0, OSM_Layers_Dim(0)\sName)
      AddGadgetItem(#Combo_0, 1, OSM_Layers_Dim(1)\sName)
      AddGadgetItem(#Combo_0, 2, OSM_Layers_Dim(2)\sName)
      AddGadgetItem(#Combo_0, 3, OSM_Layers_Dim(3)\sName)
      AddGadgetItem(#Combo_0, 4, OSM_Layers_Dim(4)\sName)
      SetGadgetState(#Combo_0, 0)
    TextGadget(#Text_1, 530, 50, 60, 15, "Movements :")
    ButtonGadget(#Button_0, 550, 100, 30, 30, Chr($E7))  : SetGadgetFont(#Button_0, FontID(0)) 
    ButtonGadget(#Button_1, 610, 100, 30, 30, Chr($E8))  : SetGadgetFont(#Button_1, FontID(0)) 
    ButtonGadget(#Button_2, 580, 070, 30, 30, Chr($E9))  : SetGadgetFont(#Button_2, FontID(0)) 
    ButtonGadget(#Button_3, 580, 130, 30, 30, Chr($EA))  : SetGadgetFont(#Button_3, FontID(0)) 
    TextGadget(#Text_2, 530, 160, 60, 15, "Zoom :")
    ButtonGadget(#Button_4, 550, 180, 50, 30, "+")      : SetGadgetFont(#Button_4, FontID(1)) 
    ButtonGadget(#Button_5, 600, 180, 50, 30, "-")      : SetGadgetFont(#Button_5, FontID(1)) 
    TextGadget(#Text_3, 530, 230, 60, 15, "Latitude :")
    StringGadget(#String_0, 600, 230, 90, 20, StrD(gfLatitude))
    TextGadget(#Text_4, 530, 250, 60, 15, "Longitude :")
    StringGadget(#String_1, 600, 250, 90, 20, StrD(gfLongitude))
  EndIf
EndProcedure
;@desc Permits to translate XY Coordinates to Lon/Lat Coordinates
;@author Progi1984
Procedure OSM_LatLon2XY()
  Protected n.l = Pow(2, glZoom)
  gfxTile = Int(((gfLongitude + 180) / 360) * n)
  gfyTile = Int((1-(Log(Tan(gfLatitude * #PI / 180)+(1/Cos(gfLatitude*#PI/180)))/#PI))/2*n)
EndProcedure
;@desc Permits to translate Lon/Lat Coordinates to XY Coordinates
;@author Progi1984
Procedure OSM_XY2LatLon()
  Protected n.l = Pow(2, glZoom)
  Protected pfLatitudeRad.f
  gfLongitude   = gfxTile / n * 360.0 - 180.0
  pfLatitudeRad = ATan(SinH(#PI * (1 - 2 * gfyTile / n)))
  gfLatitude    = pfLatitudeRad * 180.0 / #PI
  SetGadgetText(#String_0,StrD(gfLatitude))
  SetGadgetText(#String_1,StrD(gfLongitude))
EndProcedure
;@desc Draws 4 subtiles for the XY Coordinates
;@author Progi1984
Macro OSM_GetSquareTile()
  Debug "======"
  OSM_GetImage(0, glZoom+1,2*gfxTile  ,2*gfyTile)
  OSM_GetImage(1, glZoom+1,2*gfxTile+1,2*gfyTile)
  OSM_GetImage(2, glZoom+1,2*gfxTile  ,2*gfyTile+1)
  OSM_GetImage(3, glZoom+1,2*gfxTile+1,2*gfyTile+1)
  Debug "======"
EndMacro
Macro OSM_TestXYCoordinates(_CoordTile_, _Inc_, _Test_)
  pfValue = _CoordTile_ _Inc_ 0.5
  If pfValue _Test_ 
    _CoordTile_ = Pow(2, glZoom) - 2
  Else
    _CoordTile_ = pfValue
  EndIf
EndMacro
Procedure OSM_GetImage(Image.l, Zoom.l, XTile.l, YTile.l)
  Protected plMemory.l
  Protected psURL.s = OSM_Layers_Dim(glLayerCur)\sURL+Str(Zoom)+"/"+Str(XTile)+"/"+Str(YTile)+".png"
  Protected plImageSize.l
  Protected plImageMem.l
  Protected psSQLRequest.s
  Protected pbImageOK.b
  Protected plRes.l
  ; Test if in cache else download it
  DatabaseQuery(glSQLiteDB, "SELECT * FROM cache WHERE cache_layer="+#_DQ_+Str(glLayerCur)+#_DQ_+" AND cache_zoom="+#_DQ_+Str(Zoom)+#_DQ_+" AND cache_x="+#_DQ_+Str(XTile)+#_DQ_+" AND cache_y="+#_DQ_+Str(YTile)+#_DQ_+"")
  If FirstDatabaseRow(glSQLiteDB)
    Debug "CACHE : "+Str(glLayerCur)+"\"+Str(Zoom)+"\"+Str(XTile)+"\"+Str(Ytile)
    plImageSize = GetDatabaseLong(glSQLiteDB,6)
    If plImageSize
      plImageMem = AllocateMemory(plImageSize)
      GetDatabaseBlob(glSQLiteDB, 5, plImageMem, plImageSize)
      FinishDatabaseQuery(glSQLiteDB)
      If IsImage(Image)
        FreeImage(Image)
      EndIf
      If CatchImage(Image, plImageMem)
        SetGadgetState(#Image_0+Image, ImageID(Image))
        FreeMemory(plImageMem)
      EndIf
      pbImageOK = #True
    EndIf
  Else
    Debug DatabaseError()
  EndIf
  If pbImageOK = #False
    Debug "DOWNLOAD : "+Str(glLayerCur)+"\"+Str(Zoom)+"\"+Str(XTile)+"\"+Str(Ytile)
    plMemory = ReceiveHTTPMemory(psURL)
    If plMemory
      psSQLRequest = "INSERT INTO cache(cache_layer, cache_zoom, cache_x, cache_y, cache_image, cache_imagesize) VALUES ("
      psSQLRequest + Str(glLayerCur)+","
      psSQLRequest + Str(Zoom)+","
      psSQLRequest + Str(XTile)+","
      psSQLRequest + Str(YTile)+","
      psSQLRequest + "?,"
      psSQLRequest + Str(MemorySize(plMemory))+")"
      SetDatabaseBlob(glSQLiteDB, 0, plMemory, MemorySize(plMemory))
      plRes = DatabaseUpdate(glSQLiteDB, psSQLRequest)
      If plRes = 0
        Debug psSQLRequest
        Debug DatabaseError()
      EndIf
      If IsImage(Image)
        FreeImage(Image)
      EndIf
      If CatchImage(Image, plMemory, MemorySize(plMemory))
        SetGadgetState(#Image_0+Image, ImageID(Image))
        FreeMemory(plMemory)
      EndIf
    EndIf
  EndIf
EndProcedure
Procedure OSM_CacheInit()
  Protected psSQLRequest.s
  If gsSQLiteDBPath = ""
    gsSQLiteDBPath = GetCurrentDirectory()+"OSMCache.sqlite"
  EndIf
  If FileSize(gsSQLiteDBPath) <= 0
    If CreateFile(0, gsSQLiteDBPath)
      CloseFile(0)
    EndIf
    glSQLiteDB = OpenDatabase(#PB_Any, gsSQLiteDBPath, "", "")
    If glSQLiteDB
      psSQLRequest = "CREATE  TABLE "+#_DQ_+"main"+#_DQ_+"."+#_DQ_+"cache"+#_DQ_+" ("
      psSQLRequest + #_DQ_+"id_cache"+#_DQ_+" INTEGER PRIMARY KEY  AUTOINCREMENT  Not NULL , "
      psSQLRequest + #_DQ_+"cache_layer"+#_DQ_+" INTEGER Not NULL  Default 0, "
      psSQLRequest + #_DQ_+"cache_zoom"+#_DQ_+" INTEGER Not NULL , "
      psSQLRequest + #_DQ_+"cache_x"+#_DQ_+" INTEGER Not NULL , "
      psSQLRequest + #_DQ_+"cache_y"+#_DQ_+"  INTEGER Not NULL , "
      psSQLRequest + #_DQ_+"cache_image"+#_DQ_+" BLOB, "
      psSQLRequest + #_DQ_+"cache_imagesize"+#_DQ_+"  INTEGER Not NULL"
      psSQLRequest + ")"
      DatabaseUpdate(glSQLiteDB, psSQLRequest)
    EndIf
  Else
    glSQLiteDB = OpenDatabase(#PB_Any, gsSQLiteDBPath, "", "")
  EndIf  
EndProcedure

  WindowMain_Open()
  ; Init DB
  OSM_CacheInit()
  ; Init Map
  OSM_LatLon2XY()
  OSM_GetSquareTile()
  
  
  Repeat
    glEvent = WaitWindowEvent()
    Select glEvent
      Case #PB_Event_CloseWindow : glQuit = 1
      Case #PB_Event_Gadget ;{
        glGadget = EventGadget()
        Select glGadget
          Case #Button_0 ;{ To left
            OSM_TestXYCoordinates(gfxTile, -, < 0)
            OSM_GetSquareTile()
            OSM_XY2LatLon()
            SetGadgetText(#String_1, StrF(gfLongitude))
          ;}
          Case #Button_1 ;{ To Right
            OSM_TestXYCoordinates(gfxTile, +,> Pow(2, glZoom) - 1)
            OSM_GetSquareTile()
            OSM_XY2LatLon()
            SetGadgetText(#String_1, StrF(gfLongitude))
          ;}
          Case #Button_2 ;{ To Top
            OSM_TestXYCoordinates(gfyTile, -, < 0)
            OSM_GetSquareTile()
            OSM_XY2LatLon()
            SetGadgetText(#String_0, StrF(gfLatitude))
          ;}
          Case #Button_3 ;{ To Bottom
            OSM_TestXYCoordinates(gfyTile, +, > Pow(2, glZoom) - 1)
            OSM_GetSquareTile()
            OSM_XY2LatLon()
            SetGadgetText(#String_0, StrF(gfLatitude))
          ;}
          Case #Button_4 ;{ Zoom +
            If glZoom < OSM_Layers_Dim(glLayerCur)\lZoomMax
              glZoom + 1
              OSM_LatLon2XY()
              OSM_GetSquareTile()
            EndIf
          ;}
          Case #Button_5 ;{ Zoom -
            If glZoom > OSM_Layers_Dim(glLayerCur)\lZoomMin
              glZoom - 1
              OSM_LatLon2XY()
              OSM_GetSquareTile()
            EndIf
          ;}
          Case #Combo_0  ;{ Layers
            pfValue = GetGadgetState(#Combo_0)
            If pfValue >= 0 And pfValue < #OSM_Layers_Num And pfValue <> glLayerCur
              ; Current Layer
              glLayerCur = pfValue
              ; Zoom
              If glZoom < OSM_Layers_Dim(glLayerCur)\lZoomMin
                glZoom = OSM_Layers_Dim(glLayerCur)\lZoomMin +1
              EndIf
              If glZoom > OSM_Layers_Dim(glLayerCur)\lZoomMax
                glZoom = OSM_Layers_Dim(glLayerCur)\lZoomMax
              EndIf
              OSM_LatLon2XY()
              OSM_GetSquareTile()
            EndIf
          ;}
          Case #Image_0 ;{
            gfxTile = 2*gfxTile  
            gfyTile = 2*gfyTile
            glZoom + 1
            OSM_XY2LatLon()
            OSM_GetSquareTile()
          ;}
          Case #Image_1 ;{
            gfxTile = 2*gfxTile  +1
            gfyTile = 2*gfyTile
            glZoom + 1
            OSM_XY2LatLon()
            OSM_GetSquareTile()
          ;}
          Case #Image_2 ;{
            gfxTile = 2*gfxTile  
            gfyTile = 2*gfyTile+1
            glZoom + 1
            OSM_XY2LatLon()
            OSM_GetSquareTile()
          ;}
          Case #Image_3 ;{
            gfxTile = 2*gfxTile  +1
            gfyTile = 2*gfyTile+1
            glZoom + 1
            OSM_XY2LatLon()
            OSM_GetSquareTile()
            ;}
          Case #String_0,#String_1
            gfLatitude=ValD(GetGadgetText(#String_0))
            gfLongitude=ValD(GetGadgetText(#String_1))
             OSM_LatLon2XY()
             OSM_GetSquareTile()
 
        EndSelect
      ;}
    EndSelect
  Until glQuit = 1

Next step use canvas and scroll like google map and display target. If somebody want to help me .. i have lot of try but not success.
Post Reply