1 (edited by lefantan 2020-07-20 16:51:46)

Topic: Reloading Tiles manually

Hi, I'm currently overlaying tiles from a custom source(mbtiles) by intercepting the tiles download and then attaching a custom texture2d to the tiles.overlayTexture property.

However, the texture2d I'm attaching will change during runtime through a public function, I'm wondering which built-in function or ways can I use to redraw the tiles with the updated texture2d. I've tried using ClearAllCachce() and maps.Redraw but it doesn't seem to work. Right now in order for it to work, I have to zoom in and out in order to see the new tile texture.

Thank you!

Re: Reloading Tiles manually

Hello.

It depends on what you mean by "will change during runtime".
If this means changing via SetPixels, then the texture will be automatically changed when you use Apply.
If this means that you are loading another texture, then you need to destroy the texture in overlayTexture (to avoid a memory leak), and set a new value for overlayTexture.
In addition, Online Maps does not cache overlay, and ClearAllCache only affects the cache entries, and does not affect the tiles used.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Reloading Tiles manually

Alex Vertax wrote:

Hello.

It depends on what you mean by "will change during runtime".
If this means changing via SetPixels, then the texture will be automatically changed when you use Apply.
If this means that you are loading another texture, then you need to destroy the texture in overlayTexture (to avoid a memory leak), and set a new value for overlayTexture.
In addition, Online Maps does not cache overlay, and ClearAllCache only affects the cache entries, and does not affect the tiles used.

Hey Alex, thank you for replying. I've done all the tile intercepting and I currently update the texture by loading a new one that I generated myself and setting it to overlayTexture. However, a new texture will be generated during runtime but I'm not quite sure how to display the new texture. (Is there another way to invoke the OnlineMapsTileManager.OnStartDownloadTile action) ?

Re: Reloading Tiles manually

Why would you want to call OnStartDownloadTile? To get a tile?
Just use OnlineMapsTileManager.GetTile.
http://infinity-code.com/doxygen/online … 2ecfc67393

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Reloading Tiles manually

Alex Vertax wrote:

Why would you want to call OnStartDownloadTile? To get a tile?
Just use OnlineMapsTileManager.GetTile.
http://infinity-code.com/doxygen/online … 2ecfc67393

I thought to call OnStartDownTile because the action provides the tiles along with the info I needed to generate the texture and overlay it on the tile during runtime.

I've attached the script for example. In simpler terms, I want to be able to call LoadMBTiles during runtime which updates the texture. is there a way for me to get an array of OnlineMapTile Tile that the map currently display in order to pass into LoadMBTiles?

Post's attachments

Attachment icon OverlayManager.cs 5.1 kb, 86 downloads since 2020-07-21 

Re: Reloading Tiles manually

Use OnlineMapsTileManager.tiles to get all the tiles the map uses.
Iterate all the tiles in the list and pass to LoadTileFromMB.
In addition, you can check the status of a tile, and only apply overlay to loading (because you are generating overlay before loading) and loaded tiles.

Tip: in your case, it is better to use OnlineMapsTileManager.OnTileLoaded instead of OnStartDownTile. This will speed up the initial loading of tiles a little, and you will not generate overlay if loading fails.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Reloading Tiles manually

Alex Vertax wrote:

Use OnlineMapsTileManager.tiles to get all the tiles the map uses.
Iterate all the tiles in the list and pass to LoadTileFromMB.
In addition, you can check the status of a tile, and only apply overlay to loading (because you are generating overlay before loading) and loaded tiles.

Tip: in your case, it is better to use OnlineMapsTileManager.OnTileLoaded instead of OnStartDownTile. This will speed up the initial loading of tiles a little, and you will not generate overlay if loading fails.


Hey, thank you for responding, it is working now. However, I do see a hit in performance when turning on and off layers as the code is currently redrawing all tiles texture whenever a layer is toggled. I do wonder if there is a way to overlay multiple Texture2d instead of just assigning the one texture to tile.overlayBackTexture. If not, then I might have to tinker with the shader script to support more overlay textures?
Thanks!

Re: Reloading Tiles manually

This is to be expected since you are drawing overlays for tens and hundreds (if you are using high settings) of tiles at the same time. Even if you have highly optimized code to draw overlays, the total is a lot of time.

Out of the box, the tile has three layers for overlays, but using all of them or creating additional layers is a very bad idea.
This will greatly increase memory usage and slow down the application because you will need to generate, store and process all layers.

The correct way to do this is to limit the number of overlays generated per frame.
For example, you give 50 milliseconds per frame to generate overlays, and transfer all generations over this time to the next frames.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

9 (edited by lefantan 2020-07-29 22:04:49)

Re: Reloading Tiles manually

Alex Vertax wrote:

This is to be expected since you are drawing overlays for tens and hundreds (if you are using high settings) of tiles at the same time. Even if you have highly optimized code to draw overlays, the total is a lot of time.

Out of the box, the tile has three layers for overlays, but using all of them or creating additional layers is a very bad idea.
This will greatly increase memory usage and slow down the application because you will need to generate, store and process all layers.

The correct way to do this is to limit the number of overlays generated per frame.
For example, you give 50 milliseconds per frame to generate overlays, and transfer all generations over this time to the next frames.

I see, thanks for the suggestions. I do wonder if there is a way to turn overlay on and off immediately, i asked if creating additional layers is possible because having additional layer means that I can switch overlays on and off immediately by just changing the alpha value of a particular layer. Right now, turning on/off an overlay causes the re-generation of texture which takes time and therefore not instant.