Share My Creation Openstreetmap Tilemapviewer

Hello!

That is my first try to develope a viewer to show the tiles of openstreetmaps. I hope that there are others, who can support this project.
I have tested it on my HTC HD2 with WVGA (480x800) and 1Ghz-chip. It runs fast enough, but I don't know, how it works on slower devices or different screensolutions.
In the first version, the map viewer has the following features:

- works with offline maptiles, which I have dowloaded with the PDATilemanager of corwin42, written in basic4ppc: AmberHome
- shows the map over the whole screen
- works in vertical and horizontal mode
- let scroll the map with the finger
- scrolls the map with navigation-buttons
- supports different zoomlevels
- set the map to the startposition

The next steps, I want to develope are:

- load maptiles from the tileserver, if they are not on the device
- shows an centered icon on a gps-position (latitude and longitude)

I think, that the code could be optimized, but i'm still working. The only problem, which I have yet is, that the application will be stopped from the android-os, if it is activated again or the device will be rotate. Perhaps, someone can find the mistake.....

To test the app, you have to download the maptiles which you want to have and save them in the root of the external-sdcard under "/osm/..". In Sub Init, you can set the zoomlevel and the starttiles:

B4X:
Sub Init
   Zoomlevel=15
   Label2.Text=Zoomlevel
   
   'StartTiles are the left and top-side of the moving map'
   StartTileX=16929
   StartTileY=10969
...
...


I will now try to load the mapiles from a tile-server. If there is someone who had an example to load a map tile from

B4X:
'URLs (Examples)
'OSM Mapnik     http://tile.openstreetmap.org/12/2047/1362.png
'OSM Osmarender/Tiles@Home    http://tah.openstreetmap.org/Tiles/tile/12/2047/1362.png
'OSM Cycle Map     http://andy.sandbox.cloudmade.com/tiles/cycle/12/2047/1362.png

it's easier for me, because i haven't worked with the http-lib until yet.

rgds
 

Attachments

  • MapViewer1.zip
    287.8 KB · Views: 1,726

klaus

Expert
Licensed User
Longtime User
Here you are.
I used directly TanD(lat) instead of Tan(lat*cPI/180)
B4X:
[SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff]Sub [/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Process_Globals[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]'These global variables will be declared once when the application starts.[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]'These variables can be accessed from all modules.[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OSMtileX, OldOSMtileX, OSMtileY, OldOSMtileY, OSMZoom [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]Int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT] [/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] TileSize [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]Double[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] PositionOnTileX, PositionOnTileY [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]Int[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] lat, lon [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b][FONT=Courier New][SIZE=2][COLOR=#008b8b]Double[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
and
B4X:
[SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff]Sub [/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]CalculateTileXY()[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]' // Save old calculated Tile X&Y, this way we can decide If we need To load new Tiles from the Web[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OldOSMtileX=OSMtileX[/SIZE][/FONT]
[SIZE=2][FONT=Courier New] OldOSMtileY=OSMtileY[/FONT][/SIZE]
 
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]' // calculate center tile[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OSMtileX=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Floor[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]((lon+[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]180[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]360[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]*[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Power[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],OSMZoom))[/SIZE][/FONT]
[SIZE=2][FONT=Courier New] OSMtileY=[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Floor[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]-[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Logarithm[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]TanD[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](lat) + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]CosD[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](lat),[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]cE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]cPI[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] *[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Power[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],OSMZoom))[/SIZE][/FONT]
 
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]' // calculate the position ON the tile itself - (due To variable "TileSize" this Is ready For a yet To be done new smooth zoom)[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] PositionOnTileX=[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Floor[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]((((lon+[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]180[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]360[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]*[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Power[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],OSMZoom))-OSMtileX) * TileSize)[/SIZE][/FONT]
[SIZE=2][FONT=Courier New] PositionOnTileY=[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Floor[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](((([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]-[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Logarithm[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]TanD[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](lat) + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]CosD[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](lat),[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]cE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]cPI[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])/[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] *[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Power[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],OSMZoom))-OSMtileY) * TileSize)[/SIZE][/FONT]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]

Best regards.
 

ZJP

Active Member
Licensed User
Longtime User
:sign0060:
Thank you guys. It works. The next stage: Place a marker at the location-based position.

JP
 

Cor

Active Member
Licensed User
Longtime User
program crashes when scrolling

HTC Magic 2.2

is there a new version available?
 

ZJP

Active Member
Licensed User
Longtime User
Hi,

I work from version 1. Version 2 has an issue with downloading tiles. For now, no crash. Just a computational problem. :)

JP
 

DitchParrot

Member
Licensed User
Longtime User
Just to complete the set...

I have been working with version 3 (posted on 1/18). I have also noticed some crashes. If you move the map around at start up (finger drag or buttons) it will avoid a crash. You have to move the map again if the orientation of the device loads an alternate view.

It looks like the Center button code may have a mistype. I believe the CenterX and CenterY variables should be lowercase (i.e. centerX, centerY).

B4X:
'Center map'
Sub CenterMap_click
   TileX=StartTileX   
   TileY=StartTileY
   InitMap
   ImageX=CenterX      
   ImageY=CenterY
   DrawMap
End Sub
 
Last edited:

DitchParrot

Member
Licensed User
Longtime User
centerX CenterY variables

I was not aware of the b4a ignoring the case, so I don't think there is a bug that needs to be reported. I based my comments on the fact that the variables appeared in lowercase through out the code with the exception of that one place.
 

ZJP

Active Member
Licensed User
Longtime User
I now use OsmAndMapCreator for creating maps.
I modify the source code of the application to use the data generated with this program. These data are shared with OsmAnd.

OsmAndMapCreator can generate the following tiles : Mapnik, Osmarender, Google Maps / Satellite / Terrain CloudMade, Cyclemap, OpenPisteMap, MapSurfer.Net, Microsoft Maps / Earth / Hybrid
This program is very user friendly. Just select the area to capture with the mouse.

The map creator : OsmAndMapCreator : OsmAndMapCreator-0.5.1beta-b2.zip - osmand - + OsmAndMapCreator 0.5.1 beta version (required java 1.6) - Project Hosting on Google Code

osmand - Project Hosting on Google Code
OsmAnd - OpenStreetMap Wiki

B4X:
'Load new tile'
Sub LoadTile(z,x,y)
   If File.Exists(File.DirRootExternal, "/osmand/tiles/Mapnik/" & z & "/" & x & "/" & y & ".png")=True Then
      BitmapTile.Initialize(File.DirRootExternal, "/osmand/tiles/Mapnik/" & z & "/" & x & "/" & y & ".png")
   Else
      'Here is it possible to load a new maptile from the tileserver'
      BitmapTile.Initialize(File.DirAssets , "Dummy.png")
   End If
End Sub
 

schimanski

Well-Known Member
Licensed User
Longtime User
Hello ZJP, I have tested the OsmAndMapCreator and works fine and is very useful for the project. I didn't got time the last two weeks, but I will try to work with the map viewer the next week. Do you have a version with the implemented code of klaus, which can be posted? If not, i think I start with it first...

Rgds
 

ZJP

Active Member
Licensed User
Longtime User
:)
B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
    Dim OSMtileX, OldOSMtileX, OSMtileY, OldOSMtileY, OSMZoom As Int 
    Dim TileSize As Double
    Dim PositionOnTileX, PositionOnTileY As Int
    Dim lat, lon As Double

   Dim GPS1 As GPS

End Sub

Sub Globals
   Dim SrcRect, DestRect As Rect
   Dim BitmapTile, BitmapMap As Bitmap
   Dim CanvasTile, CanvasMap As Canvas 
   Dim ButtonLeft, ButtonRight, ButtonUp, ButtonDown As Button 
   Dim sx, sy, ImageX, ImageY, ImageWidth, ImageHeight   As Int
   Dim label1, label2 As Label 
   
   Dim StartTileX, StartTileY, OSMZoom, TileX, TileY As Int
   centerX=512-(activity.Width/2)                        
   centery=512-(activity.Height/2)
   'centerX=(activity.Width/2)                        
   'centery=(activity.Height/2)

   Dim DestRectNew, DestRectTest As Rect  
   Dim DestRectFertig, SrcRectFertig As Rect 
   Dim BitmapMapNew As Bitmap 
   Dim CanvasMapNew As Canvas
   Dim GesamtRect As Rect 
   
End Sub

Sub Activity_Create(FirstTime As Boolean)

   If FirstTime Then
      GPS1.Initialize("GPS")
   End If

   Activity.LoadLayout("mapviewer320x480.bal")
   Init
   InitMap   
End Sub

Sub Activity_Resume
   If GPS1.GPSEnabled = False Then
      ToastMessageShow("Please enable the GPS device.", True)
      StartActivity(GPS1.LocationSettingsIntent) 'Will open the relevant settings screen.
   Else
      GPS1.Start(0, 0) 'Listen to GPS with no filters.
   End If

End Sub

Sub Activity_Pause (UserClosed As Boolean)
   GPS1.Stop
End Sub

Sub GPS_LocationChanged (Location1 As Location)
Return
   lat =  Location1.Latitude
   lon =  Location1.Longitude

   Label1.Text = lat
   Label2.Text = lon

   CalculateTileXY

   DrawMap

End Sub

Sub GPS_UserEnabled (Enabled As Boolean)
   ToastMessageShow("GPS device enabled = " & Enabled, True)
End Sub

Sub GPS_GpsStatus (Satellites As List)
   Label2.Text = Satellites.Size
End Sub


'I N I T'
Sub Init
   TileSize=256
   OSMZoom=13
   
   lon = 2.294634
   lat = 48.857936

   CalculateTileXY   

   TileX=StartTileX
   TileY=StartTileY

   ImageX=centerx
   ImageY=centery
   
   ImageWidth=activity.Width 
   ImageHeight=activity.Height 

   BitmapMap.InitializeMutable(256*4,256*4)   'Moving map = 4 x 4 = 16 Tiles
   BitmapMapNew.InitializeMutable(256*4,256*4)   'New map = 4 x 4 Tiles
   CanvasTile.Initialize(Activity)            
   CanvasMap.Initialize2(BitmapMap)         
   
   'New'
   CanvasMapNew.Initialize2(BitmapMapNew)
   GesamtRect.Initialize(0,0,1024,1024)

End Sub

Sub CalculateTileXY()

   ' // calculate center tile
    OSMtileX=Floor((lon+180)/360*Power(2,OSMZoom))
    OSMtileY=Floor((1-Logarithm(TanD(lat) + 1/CosD(lat),cE)/cPI)/2 *Power(2,OSMZoom))
 
   ' // calculate the position ON the tile itself - (due To variable "TileSize" this Is ready For a yet To be done new smooth zoom)
    PositionOnTileX=Floor((((lon+180)/360*Power(2,OSMZoom))-OSMtileX) * TileSize)
    PositionOnTileY=Floor((((1-Logarithm(TanD(lat) + 1/CosD(lat),cE)/cPI)/2 *Power(2,OSMZoom))-OSMtileY) * TileSize)

   StartTileX = OSMtileX-1
   StartTileY = OSMtileY-1

End Sub

'Load new tile'
Sub LoadTile(z,x,y)
' This is great. Common data with Osmand. http://code.google.com/p/osmand/
   If File.Exists(File.DirRootExternal, "/osmand/tiles/Mapnik/" & z & "/" & x & "/" & y & ".png.tile")=True Then
      BitmapTile.Initialize(File.DirRootExternal, "/osmand/tiles/Mapnik/" & z & "/" & x & "/" & y & ".png.tile")
   Else
      'Here is it possible to load a new maptile from the tileserver'
      BitmapTile.Initialize(File.DirAssets , "Dummy.png")
   End If
End Sub

'Add Tiles to moving map'
Sub InitMap
   For y=0 To 3 
      For x=0 To 3 
         LoadTile(OSMZoom, TileX+x, TileY+y)
         DestRect.Initialize(x*256,y*256, (x*256)+256,(y*256)+256)
         CanvasMap.DrawBitmap(BitmapTile,Null,DestRect)
      Next
   Next
   DestRect.Initialize(0,0,activity.Width,activity.Height)      'Show the map on the whole screen'
   DrawMap
End Sub

'Draw map'
Sub DrawMap
   CalculateMAP
   CanvasTile.Initialize(Activity)
   SrcRect.Initialize(ImageX,ImageY, ImageX+ImageWidth,ImageY+ImageHeight)   
   CanvasTile.DrawBitmap(BitmapMap,SrcRect,DestRect)

   'Marker
   If TileX=StartTileX+1 AND TileY=StartTileY+1 Then
      CanvasMap.DrawCircle(PositionOnTileX, PositionOnTileY, 8dip, Colors.blue, False, 4dip)
   End If

End Sub

'checks, if there are new tiles needed'
Sub CalculateMAP
   If ImageX<=0   Then Left_Tiles   'left'
   If ImageX>=288 Then Right_Tiles   'right'
   If ImageY<=0   Then Top_Tiles   'top'
   If ImageY>=288 Then Bottom_Tiles'bottom'
End Sub

'Draw Tilerows'
Sub Left_Tiles
   For Y=0 To 3
      LoadTile(OSMZoom, TileX-1, TileY+y)
      DestRectNew.Initialize(0,y*256,256,(y*256)+256)         'Add Tiles left side'
      CanvasMapNew.DrawBitmap(BitmapTile,Null,DestRectNew)
   Next
   ImageX=ImageX+256
   sx=sx+256
      
   SrcRectFertig.Initialize(0,0,768,1024)
   DestRectFertig.Initialize(256,0,1024,1024)
   Karte_zusammensetzen
   TileX=TileX-1
End Sub

Sub Right_Tiles
   For Y=0 To 3
      LoadTile(OSMZoom, TileX+4, TileY+y)
      DestRectNew.Initialize(768,y*256,1024,(y*256)+256)      'Add Tils right side'
      CanvasMapNew.DrawBitmap(BitmapTile,Null,DestRectNew)
   Next
   ImageX=ImageX-256
   sx=sx-256
      
   SrcRectFertig.Initialize(256,0,1024,1024)
   DestRectFertig.Initialize(0,0,768,1024)
   Karte_zusammensetzen
   TileX=TileX+1
End Sub

Sub Top_Tiles
   For x=0 To 3
      LoadTile(OSMZoom, TileX+x, TileY-1)
      DestRectNew.Initialize(x*256,0,(x*256)+256,256)         'Add Tiles upper side'
      CanvasMapNew.DrawBitmap(BitmapTile,Null,DestRectNew)
   Next
   ImageY=ImageY+256
   sy=sy+256
      
   SrcRectFertig.Initialize(0,0,1024,768)
   DestRectFertig.Initialize(0,256,1024,1024)
   Karte_zusammensetzen
   TileY=TileY-1
End Sub

Sub Bottom_Tiles
   For x=0 To 3
      LoadTile(OSMZoom, TileX+x, TileY+4)
      DestRectNew.Initialize(x*256,768,(x*256)+256,1024)      'Add Tiles bottom side'
      CanvasMapNew.DrawBitmap(BitmapTile,Null,DestRectNew)
   Next
   ImageY=ImageY-256
   sy=sy-256
      
   SrcRectFertig.Initialize(0,256,1024,1024)
   DestRectFertig.Initialize(0,0,1024,768)
   Karte_zusammensetzen
   TileY=TileY+1
End Sub

'Draw map out of the new tiles (4 tiles) and the 12 old tiles'
Sub Karte_zusammensetzen
   CanvasMapNew.DrawBitmap(BitmapMap,SrcRectFertig,DestRectFertig)   'save tilesrow 2,3,4'
   CanvasMap.DrawBitmap(BitmapMapNew,Null,GesamtRect)   'draw new map to the main map'
End Sub

'N A V I G A T I O N - B u t t o n s'
'Move map with arrow-buttons'
Sub ButtonLeft_click
   ImageX=ImageX+15
   DrawMap
End Sub

Sub ButtonRight_click
   ImageX=ImageX-15
   DrawMap
End Sub

Sub ButtonUp_click
   ImageY=ImageY+15
   DrawMap
End Sub

Sub ButtonDown_click
   ImageY=ImageY-15
   DrawMap
End Sub

'Center map'
Sub CenterMap_click
   TileX=StartTileX   
   TileY=StartTileY
'   InitMap
   'ImageX=CenterX      
   'ImageY=CenterY
   DrawMap
End Sub

'Move map with finger on touchscreen'
Sub Activity_Touch (Action As Int, X As Float, Y As Float)
   
   If action=0 Then   'MouseDown'
      sx = X + ImageX
      sy = Y + ImageY
   End If
   
   If action=2 Then   'MouseMove'
      ImageX = sx - X
      ImageY = sy - Y
      DrawMap
   End If
   
   If action=1 Then   'MouseUp'
      DrawMap
   End If
End Sub

'change OSMZoom'
Sub ZoomIn_Click
'   If OSMZoom<16 Then
'      OSMZoom=OSMZoom+1
'      TileX=(TileX*2)+1
'      TileY=(TileY*2)+1
'      StartTileX=(StartTileX*2)+1
'      StartTileY=(StartTileY*2)+1
'   InitMap
'   End If
End Sub

Sub ZoomOut_Click
'   If OSMZoom>11 Then
'      OSMZoom=OSMZoom-1      
'      TileX=Round((TileX/2)-1)
'      TileY=Round((TileY/2)-1)
'      StartTileX=Round(StartTileX/2)-1      
'      StartTileY=Round(StartTileY/2)-1
'   InitMap
'   End If
End Sub
 
Last edited:

schimanski

Well-Known Member
Licensed User
Longtime User
New Version of OSM-TileMapViewer

Hello! Here is my new Version of the OSM-TilemapViewer. Because of the problems with the online-maps, it is only a offline-mapviewer, but with some interesting features. Thanks ZJP and Klaus for the code, which I have used in the current version:

I have tested it on my samsung galaxy tab and it runs very fine:sign0060:. Because of the high resolution of the tab with 600x1024, I have grown up the tile-field. The map is now 5x5 Tiles. Please call back for devices with lower resolutions...

The new features are:

- center the map to the given gps-position and scroll it around the center of the screen
- an arrow shows the driving-direction
- zoom in and zoom out by centering the gps-position
- scrolling the map by finger or navigation-buttons, and center the given gps-position by using the c-button
- Please use a network-connection for the reverse geocoding function: Every 3 seconds, the street and the village is updating in the panel at the bottom of the screen. By clicking the panel, a messagebox with some informations about the Position will be shown.

:sign0013: for the most comments in german....

I have download the maptiles to test it with the OSMandmapcreator (look above). Please adapt the path for the tiles (I have used Osmarender)

I think I will try some more features in future:

- online-maps
- show more markers in the map
- create a nightview, if it is possible
- calculate a position in the map to the lat/lon (the reverse of the sub CalculateTileXY) :sign0085:

Best regards...
 

Attachments

  • MapViewer4.zip
    48.8 KB · Views: 563
Last edited:

Cor

Active Member
Licensed User
Longtime User
Hello,

I want to help for the online maps,
don't know what the problem right now is, can you update me?

Do you have some startcode(online maps) for the latest version?

my wish list:

1. add reference layer ( acad dxf) or shape files (.shp)
2. add markers
3. change marker color
 

Cor

Active Member
Licensed User
Longtime User
from android OSMAnd
when i download for offline maps (Netherlands)

i got directory \osmand\tiles\Mapnik\14\8840\5427.png.tile
\xx\xxxxx\xxxx.png.tile

how to handle this, or what must i do for the correct tiles download
 

schimanski

Well-Known Member
Licensed User
Longtime User
Hello Cor. The path and the filesnames of osmandmapcreator can be used in the mapviewer without problems. The tiles with the ending png.tiles are normal .png files. You only have to rename the folder osmarender, when you don't get osmarender tiles. If you get mapnik, adapt the path in the mapviewer to mapnik, like your last post.

Thanks for your help. I will post the last onlineversion later. The online version downloads the right tiles and put it to the right directory, thats fine. But by scrolling with the fingers, some tiles are set to a wrong position. I think, that the reason for that is, that the map scrolls to fast. Until some tiles are loaded, they ae no longer needed. By scrolling with the navigation buttons, the map loads correct.

I call back with the last online version...
 
Last edited:

Cor

Active Member
Licensed User
Longtime User
When i try to download with osmand on my device for the Netherlands

i get input/output error/ at the end of the download

Is there a way to extract the obf file ( to png files) which I can download from a site?
 

schimanski

Well-Known Member
Licensed User
Longtime User
Hello Cor!

I don't know the reason for the input/output - error and I don't know, which format the .obf-file is. Normaly, the osmandmapcreator downloads the tiles as .png.tile.

If this doesn't run, you can use the link to the PDATileManager from corwin42 (see above).
 

schimanski

Well-Known Member
Licensed User
Longtime User
New Version of OSM-TileMapViewer

I have mad a new OSM-TileMapViewer with the following features:

Old featuers:
- center the map to the given gps-position (= C_Ziel) and scroll it around the center of the screen
- an arrow shows the driving-direction
- zoom in and zoom out by centering the gps-position
- scrolling the map by finger and center the given gps-position by using the c-button
- Please use a network-connection for the reverse geocoding function: Every 3 seconds, the street and the village is updating in the panel at the bottom of the screen. By clicking the panel, a messagebox with some informations about the Position will be shown.

New features:

- You can now show two dynamic icons in the map. C_Ziel is the gps-position, which is shown in the middle of the map and scrolls the map, if it is needed. M_Ziel is a secondary icon, which 'drives through the map', when the zoomlevel is little enough. So it is possible for example, to show gps-data, which you get from a server and your own gps-position.
- Now you can draw markers with sperate names and colors in the map. Under

B4X:
'Marker initialisieren'
Sub Init_Marker  
   'MarkerListe.AddAll(Array As String(Bezeichnung, Latitude, Longitude, Farbe(Rot,Grün,Blau))
   MarkerListe.AddAll(Array As String("Marker 1","51.0","6.0","128","0","0"))
   MarkerListe.AddAll(Array As String("Marker 2","51.1","6.0","0","128","0"))
   MarkerListe.AddAll(Array As String("Marker 3","51.0","6.1","0","0","128"))
   MarkerListe.AddAll(Array As String("Marker 4","51.1","6.1","128","0","0"))
End Sub

you can init your markers. I have tested it with up to 40 markers and on my galaxy tab, there is no different to the speed. While the positions of the markers are calculated new every second, it is also possible to change the positions of the markers, so that all markers could be used as dynamic icons (For example "Flottenmanagemet").
I think, when you use more than 100 markers, it is better not to calculate the positions of the markers every second. You can than calculte it once at the beginning and saves the positions in variables.

- With the button T/N, you can change from day to night vision and with RGC on/off, the Reverse Geocoding could set on and off.


Under Google Online Mapviewer, i have made a short online mapviewer for google maps. You can show your gps-position in the middle of the map and it is possible to change between four different maptypes. It is only a try with a small and simple code, perhaps there is someone, who can use it.

The only problem is, that google blocks your IP, after more than 1000 downloads in 24 hours. I have reached this by my tests and it is very :BangHead:.

Perhaps, someone has another link to satellite and hybrid maps, which are not from google.....
 

Attachments

  • Mapviewer5.zip
    52.9 KB · Views: 576
  • Google Online Mapviewer.zip
    5.6 KB · Views: 618

CidTek

Active Member
Licensed User
Longtime User
Under Google Online Mapviewer, i have made a short online mapviewer for google maps. You can show your gps-position in the middle of the map and it is possible to change between four different maptypes. It is only a try with a small and simple code, perhaps there is someone, who can use it.

The only problem is, that google blocks your IP, after more than 1000 downloads in 24 hours. I have reached this by my tests and it is very :BangHead:.

Perhaps, someone has another link to satellite and hybrid maps, which are not from google.....

I took a quick look at the code in the Google MapViewer and am wondering why you use a timer instead of setting GPS filters. With Filters for instance you can avoid hitting the Google site unless your GPS moves a significant distance.

BTW, that is an excellent upgrade to just receiving a static map.
 

klaus

Expert
Licensed User
Longtime User
Hi schimanski,

Attached you find Version 5.1 with the two routines we spoke about in PM's and some other small changes.
Please test the program to make shure that I didn't add some 'mess'.

Best regards.
 

Attachments

  • MapViewer51.zip
    16.7 KB · Views: 698
Top