TomSchimansky / TkinterMapView

A python Tkinter widget to display tile based maps like OpenStreetMap or Google Satellite Images.
Creative Commons Zero v1.0 Universal
596 stars 88 forks source link

Downloading offline tiles #89

Open always1hungry1 opened 1 year ago

always1hungry1 commented 1 year ago

First of all, I want to express great gratitude to TomSchimansky, who made this code. Thanks to you, I am inspired to work. The main problem is how to change tile server for downloading. I changed in offline_loading.py tile_server from https://a.tile.openstreetmap.org/{z}/{x}/{y}.png to https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga. After run the code I get message that work is done. But when I want to use offline_tile to display in tkinter, its empty. But If I use default code, its work fine. Can someone help me with this problem. P/s Sorry for my English and coding level. I am a new to this field. Thanks for your time

tanmayyb commented 1 year ago

Same issue. The database seems to be downloading files from the satellite alright,; but the loader(def request_image) in tkintermapview/map_widget.py does not seem to load map tile, it returns an empty tile to the map. If someone has some time pleassseee help resolve this bug.

tanmayyb commented 1 year ago

Okay I resolved it. The database(.db) uses SQLite, and the satellite imagery tiles downloaded from google are saved the same way as the osm ones due to the parsing method of the OfflineLoader i.e. the zoom, x and y columns are preserved the same way for the google maps as for the osm ones.

But the server column/table attribute contains a string like: http://mt0.google.com/vt/lyrs=y&hl=en&x={x}&y={y}&z={z}&s=Ga Which causes a problem for the map_widget.py in loading the tiles (the widget returns empty tiles).

An easy fix is to edit the downloaded google satellite imagery database's server attribute and replace the previous string with the default osm one: https://a.tile.openstreetmap.org/{z}/{x}/{y}.png This should let you load google satellite imagery in tkinter mapview. TLDR: the downloaded database downloads the files correctly but the server string column has to replaced with default osm tileserver string to make it work with tkintermapview. Hope this helps.

Painkiller675 commented 1 year ago

tanmayyb I downloaded .db I opened it in DB Browser What should I do then?? I didn't get it sorry

Burak111 commented 11 months ago

tanmayyb I downloaded .db I opened it in DB Browser What should I do then?? I didn't get it sorry

It took me time to understand problem. I haven't solve the problem in python script. However, quick fix for downloaded maps is possible.

  1. Install a program that you can edit the ".db" files. I used SQLiteStudio but it doesn't matter.
  2. ".db" files has 3 tables in it (sections, server, and tiles). Go to tiles and remove FOREIGN key set for the server. Go to sections and remove FOREIGN key set for the server. Finally you can edit url's and server.
  3. Set (UPDATE) url and servers to https://a.tile.openstreetmap.org/{z}/{x}/{y}.png.
  4. Save the .db file.

Now you should run and test with map_with_offline_tiles.py. If you haven't download all map for all zoom levels you might not see map directly. Try zooming in and out.

A better solution would be editing the request_image function in the map_widget.py. It is not so complicated. However, I didn't test it!.

tanmayyb commented 9 months ago

Yes exactly @Burak111 . Sorry I don't know how I missed @Painkiller675's comment.

atulsdharan commented 5 months ago

hi i am new to sql database editing. i followed the steps using DB Browser for SQL lite however i could not resolve the issue. when i use the exact code made by TomSchimansky to load offline maps and to display the map in a map_widget, im getting a blank map. When im running load_offline_tiles.py , it shows that the tiles have been successfuly downloaded. a picture is attached (I have changed the lat long selection values)

mapview

however later when i try the map_with_offline_tiles.py i get a blank box with just white colour no matter which tile server i select .

I tried to carry out the instructions by @tanmayyb and @Burak111 but could not succeed. How to remove the foreign key ? im new to sql , it would be very helpful if any of you can help me to use sattellite image tiles

mannetu commented 5 months ago

Hi all, could this issue be related to #68? There is a typo in offline_loading.py. My PR was not merged.

Burak111 commented 5 months ago

@atulsdharan have you edit line 18 in load_tiles.py. You should edit it to download satellite database. Zoom levels can be configured too.

AzzamALMEKHLAFI commented 2 months ago

I did all the solutions you mentioned, but unfortunately the map did not work for me and came back empty. I deleted the foreign key from the section table and from Tiles table. Then I modified the URL link to "https://a.tile.openstreetmap.org/{z}/{x}/{y}.png". I change the 138 row as @mannetu is said. If you solve the problem, I would like to share the solution. I will be grateful to you. @Burak111 @tanmayyb @Burak111