-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to load overlay layer using "set_overlay_tile_server" #117
Comments
Hi @hanselmoovita sorry for late answer. You are probably having an exception raising in the try block at line 494 of the map_widget.py file that results in one of the except blocks which is returning self.empty_tile_image. |
Can I clarify with you, if I would like to apply overlay layer on top of Main Tile layer, is this the correct way to do it? See screenshot below, right window for highlighted portion: The current problem I faced is that when I added this line, the tkinter application goes blank when I made the selection with overlay (ie: Google satellite) For this scenario, I have not made modifications to map_widget.py I have tried to modify the definition for but have not been successful either For your kind advice please |
Yes, you are doing right in setting the overlay_tile_server. The problem I think you are facing is in the block I mentioned in my previous answer. I suggest you to execute the code in debug mode or trivially to temporarily remove the try except block at line 494 in map_widget.py to see what exception is raised. I'm talking about this piece of code try:
url = self.tile_server.replace("{x}", str(x)).replace("{y}", str(y)).replace("{z}", str(zoom))
image = Image.open(requests.get(url, stream=True, headers={"User-Agent": "TkinterMapView"}).raw)
if self.overlay_tile_server is not None:
url = self.overlay_tile_server.replace("{x}", str(x)).replace("{y}", str(y)).replace("{z}", str(zoom))
image_overlay = Image.open(requests.get(url, stream=True, headers={"User-Agent": "TkinterMapView"}).raw)
image = image.convert("RGBA")
image_overlay = image_overlay.convert("RGBA")
if image_overlay.size is not (self.tile_size, self.tile_size):
image_overlay = image_overlay.resize((self.tile_size, self.tile_size), Image.ANTIALIAS)
image.paste(image_overlay, (0, 0), image_overlay)
if self.running:
image_tk = ImageTk.PhotoImage(image)
else:
return self.empty_tile_image
self.tile_image_cache[f"{zoom}{x}{y}"] = image_tk
return image_tk
except PIL.UnidentifiedImageError: # image does not exist for given coordinates
self.tile_image_cache[f"{zoom}{x}{y}"] = self.empty_tile_image
return self.empty_tile_image
except requests.exceptions.ConnectionError:
return self.empty_tile_image
except Exception:
return self.empty_tile_image Keep me updated once you have tried! |
I've removed the entire try-except code block starting from line 494 in map_widget.py, and when the app is launched, the default selection OpenStreetMap shows a blank grey screen, and many exception errors were returned in the debugger in one go: No other modifications were made other than the one you've suggested above. The full log of exception errors are found below: |
Hi @hanselmoovita, sorry, I did not explain myself well. You do not have to completely remove the try catch block, but only to remove the try, leaving the block of code inside it, and all the catches. So this code: try:
url = self.tile_server.replace("{x}", str(x)).replace("{y}", str(y)).replace("{z}", str(zoom))
image = Image.open(requests.get(url, stream=True, headers={"User-Agent": "TkinterMapView"}).raw)
if self.overlay_tile_server is not None:
url = self.overlay_tile_server.replace("{x}", str(x)).replace("{y}", str(y)).replace("{z}", str(zoom))
image_overlay = Image.open(requests.get(url, stream=True, headers={"User-Agent": "TkinterMapView"}).raw)
image = image.convert("RGBA")
image_overlay = image_overlay.convert("RGBA")
if image_overlay.size is not (self.tile_size, self.tile_size):
image_overlay = image_overlay.resize((self.tile_size, self.tile_size), Image.ANTIALIAS)
image.paste(image_overlay, (0, 0), image_overlay)
if self.running:
image_tk = ImageTk.PhotoImage(image)
else:
return self.empty_tile_image
self.tile_image_cache[f"{zoom}{x}{y}"] = image_tk
return image_tk
except PIL.UnidentifiedImageError: # image does not exist for given coordinates
self.tile_image_cache[f"{zoom}{x}{y}"] = self.empty_tile_image
return self.empty_tile_image
except requests.exceptions.ConnectionError:
return self.empty_tile_image
except Exception:
return self.empty_tile_image will be: url = self.tile_server.replace("{x}", str(x)).replace("{y}", str(y)).replace("{z}", str(zoom))
image = Image.open(requests.get(url, stream=True, headers={"User-Agent": "TkinterMapView"}).raw)
if self.overlay_tile_server is not None:
url = self.overlay_tile_server.replace("{x}", str(x)).replace("{y}", str(y)).replace("{z}", str(zoom))
image_overlay = Image.open(requests.get(url, stream=True, headers={"User-Agent": "TkinterMapView"}).raw)
image = image.convert("RGBA")
image_overlay = image_overlay.convert("RGBA")
if image_overlay.size is not (self.tile_size, self.tile_size):
image_overlay = image_overlay.resize((self.tile_size, self.tile_size), Image.ANTIALIAS)
image.paste(image_overlay, (0, 0), image_overlay)
if self.running:
image_tk = ImageTk.PhotoImage(image)
else:
return self.empty_tile_image
self.tile_image_cache[f"{zoom}{x}{y}"] = image_tk
return image_tk Obviously, this operation only aimes at understanding the error that is causing the display of blank images, indeed using the try catch, the error is never shown in the console. Morever, even if this approach works, the best way to do this would be to use the debugger and not to modify the code. Let me know! |
Hi, The change is able to work based on the modification to if-else conditional as you have suggested: For the above test, I used OpenStreetMap as base layer with Railway lines as overlay. Please note that the Antialias class seems to have been removed, I have replaced it with LANCZOS as per: https://stackoverflow.com/questions/76616042/attributeerror-module-pil-image-has-no-attribute-antialias Do note that there are warning issued: /usr/lib/python3/dist-packages/requests/init.py:89: RequestsDependencyWarning: urllib3 (2.1.0) or chardet (3.0.4) doesn't match a supported version! |
However, can I also ask, if Tkintermapview is able to support Openstreetmap/Google maps as base layer, with local map tiles as overlay layer? With the latest update to implementation, only the map tile layer (overlay) is loaded, and the base layer with Openstreetmap doesn't load: Conditions to which this issue is attempted:
The intended implementation is to look like this: How do you suggest map_widget.py maybe further modified to support this implementation? |
Hi @hanselmoovita, cool! Removing the try revealed that the error that was causing the blank image to be returned in one of those catch blocks was related to that Image.LANCZOS. So now you can actually reintroduce the try and bring back the code to its original version, obviously keeping the fix of the LANCZOS. Concerning your second question, this is surely possible, but it is necessary to change something in the request_image method. Are you using a db created with the offline_loading.py file to load offline the overlays? |
Hi @LorenzoMattia Yes, if I revert the code back to its original version, and keeping the fix for LANCZOS, the crash issue disappears. No....I did not create db using offline_loading.py; I set up a local HTTP server by opening an Ubuntu terminal, screenshot shown below. 0 to 19 indicates the zoom level: While I am able to load the local tiles using set_tile_server as the sole layer, I am not able to display the local tiles if it is an overlay layer, with OSM as base layer with the original mplementation (only change applied is changing line 504 ANTIALIAS-->LANCZOS): Would like to ask how def set_overlay_tile_server (or any other related functions) can be modified to support image tile overlay..... |
Hi @hanselmoovita, first of all I want to clarify that in my answer I am supposing your self.database_path to be unspecified (None). Starting from this assumption, what I can tell you is that problems are probably again in that try catch block. So, I would suggest you again to remove that try, as you already did to discover the LANCZOS problem, and see what is the error that is causing this problem. Indeed, that part of code should actually work, and the behavior you are obtaining is really strange. Lastly, just to be sure, are your overlay images .png with no bacground? Keep me updated! |
Hi @LorenzoMattia I have once again attempted to replace the try-except block with the if-else block at Line 494 which you have suggested. For this scenario, selecting option with the OSM base layer + overlay doesn't work either. Additionally, I noticed the following issues:
Scenario illustrated in screenshot below: The overlay_images.png have no background; the background intended to be used would be either OSM or Google streetmap. If you would like to have a copy of the overlay images, you can email me at hansel.chan@moovita.com Hope to hear from you again, wishing you a Merry Christmas! |
Hi @hanselmoovita, thank you and I hope you had a really Merry Christmas! Answering to your points:
Hoping to be helpful, let me know! |
@LorenzoMattia Good day, I am happy to share my code with you, is it possible you send me a private message at hansel.chan@moovita.com so that I can share it with you? Wishing you a Happy New Year |
Example used: map_with_customtkinter.py
I added a 4th option to include overlay option for "Railway". Modifications made were:
In self.map_option_menu:
self.map_option_menu = customtkinter.CTkOptionMenu(self.frame_left, values=["OpenStreetMap", "Google normal", "Google satellite", "railway"]
In def change map:
elif new_map == "railway":
self.map_widget.set_overlay_tile_server("http://a.tiles.openrailwaymap.org/standard/{z}/{x}/{y}.png") # railway infrastructure
However, upon running the program and selecting the "railway" option for Tile Server, the TkinterMapView returned blank map:
I used the suggested API link given under "Use other tile servers" in your Readme.
May I ask for help to fix or advice on this issue
The text was updated successfully, but these errors were encountered: