Topic: Preload tiles around a marker
Hey there !
Is it somehow possible to preload tiles around a marker ? Is there already a script for that or do i Need to Code such a System on my own ? ^^
You are not logged in. Please login or register.
Infinity Code Forum → Online Maps Help → Preload tiles around a marker
Hey there !
Is it somehow possible to preload tiles around a marker ? Is there already a script for that or do i Need to Code such a System on my own ? ^^
Hello.
We've added quite good way to do it.
Example (for Online Maps v2.5.14+):
using System.Collections.Generic;
using UnityEngine;
public class PreloadTilesAroundMarker:MonoBehaviour
{
public int countTilesX = 3;
public int countTilesY = 3;
public int zoomOffset = 2;
private Dictionary<ulong, OnlineMapsTile> tiles;
private OnlineMapsMarker marker;
private OnlineMaps map;
private void OnGUI()
{
if (GUILayout.Button("Preload"))
{
StartPreloading();
}
}
private void Start()
{
map = OnlineMaps.instance;
marker = map.AddMarker(map.position);
tiles = new Dictionary<ulong, OnlineMapsTile>();
}
private void StartPreloading()
{
foreach (KeyValuePair<ulong, OnlineMapsTile> pair in tiles)
{
pair.Value.Unblock(this);
}
tiles.Clear();
double lng, lat;
marker.GetPosition(out lng, out lat);
int zoom = map.zoom - zoomOffset;
if (zoom < 3) zoom = 3;
double tx, ty;
map.projection.CoordinatesToTile(lng, lat, zoom, out tx, out ty);
int itx = (int) tx;
int ity = (int) ty;
int sx = itx - (countTilesX - 1) / 2;
int sy = ity - (countTilesY - 1) / 2;
int max = 1 << zoom;
for (int x = sx; x < sx + countTilesX; x++)
{
itx = x;
if (itx < 0) itx += max;
else if (itx >= max) itx -= max;
for (int y = sy; y < sy + countTilesY; y++)
{
if (y < 0 || y > max) continue;
ulong key = OnlineMapsTile.GetTileKey(zoom, itx, y);
OnlineMapsTile parentTile = OnlineMapsTile.GetTile(zoom - 1, itx / 2, y / 2);
OnlineMapsTile tile = new OnlineMapsTile(itx, y, zoom, map, parentTile);
tile.Block(this);
tiles[key] = tile;
}
}
}
}
The new version will be available soon.
Great ! Thanks never saw such a fast support
Infinity Code Forum → Online Maps Help → Preload tiles around a marker
Powered by PunBB, supported by Informer Technologies, Inc.