// This event called when tile texture changed.
        private void OnChangeMaterialTexture(OnlineMapsTile tile, Material material)
        {
            // Try get tile from list
            TilesetFadeExampleItem item = items.FirstOrDefault(i => i.tile == tile);

            // if there is custom data associated with 'tile', just update it
            if (item != null)
            {
                item.material = material;
                item.Update();
            }
            // else a animation data was not found in the master list but if there is custom data associated with 'tile'
            else if (tile.customData != null)
            {
                item = (TilesetFadeExampleItem) tile.customData;
                if (!item.finished)
                {
                    items.Add(item);
                    item.Update();
                }
                else material.color = TilesetFadeExampleItem.toColor;
            }
            // else if the tile has a texture and that texture is not a default texture
            else if (tile.texture != null && tile.texture != OnlineMaps.instance.defaultTileTexture)
            {
                item = new TilesetFadeExampleItem(tile, material);
                item.Update();
                items.Add(item);
            }
            // else set initial color
            else
            {
                material.color = TilesetFadeExampleItem.fromColor;
            }
        }
Exemple #2
0
    private void OnStartDownloadTileM(OnlineMapsTile tile)
    {
        if (TryLoadFromCache(tile))
        {
            if (OnLoadedFromCache != null)
            {
                OnLoadedFromCache(tile);
            }
        }
        else
        {
#pragma warning disable 618
            if (OnStartDownloadTile != null)
            {
                OnStartDownloadTile(tile);
            }
#pragma warning restore 618
            else if (OnlineMapsTileManager.OnStartDownloadTile != null)
            {
                OnlineMapsTileManager.OnStartDownloadTile(tile);
            }
            else
            {
                OnlineMapsTileManager.StartDownloadTile(tile);
            }
        }
    }
    private void LoadTile(OnlineMapsTile tile, byte[] bytes)
    {
        Texture2D texture = new Texture2D(0, 0, TextureFormat.RGB24, false);

        texture.LoadImage(bytes);
        texture.wrapMode = TextureWrapMode.Clamp;

        if (map.target == OnlineMapsTarget.texture)
        {
            tile.ApplyTexture(texture);
            map.buffer.ApplyTile(tile);
        }
        else
        {
            tile.texture = texture;
            tile.status  = OnlineMapsTileStatus.loaded;
        }

        if (map.traffic && !string.IsNullOrEmpty(tile.trafficURL))
        {
            if (!TryLoadTraffic(tile))
            {
                tile.trafficWWW             = OnlineMapsUtils.GetWWW(tile.trafficURL);
                tile.trafficWWW.customData  = tile;
                tile.trafficWWW.OnComplete += map.OnTrafficWWWComplete;
            }
        }
    }
    private bool TryLoadFromMemoryCache(OnlineMapsTile tile)
    {
        if (memoryCache == null)
        {
            return(false);
        }

        string key     = GetTileKey(tile);
        int    keyHash = key.GetHashCode();

        MemoryCacheItem item = null;

        for (int itemIndex = 0; itemIndex < countMemoryItems; itemIndex++)
        {
            if (memoryCache[itemIndex].hash == keyHash && memoryCache[itemIndex].key == key)
            {
                item      = memoryCache[itemIndex];
                item.time = DateTime.Now.Ticks;
                break;
            }
        }
        if (item == null)
        {
            return(false);
        }

        LoadTile(tile, item.bytes);
        if (OnLoadedFromMemoryCache != null)
        {
            OnLoadedFromMemoryCache(tile);
        }

        return(true);
    }
Exemple #5
0
        private void OnStartDownloadTile(OnlineMapsTile tile)
        {
            Texture tileTexture = new Texture();

            // Here your code to load tile texture from any source.

            // Apply your texture in the buffer and redraws the map.
            if (api.target == OnlineMapsTarget.texture)
            {
                // Apply tile texture
                tile.ApplyTexture(tileTexture as Texture2D);

                // Send tile to buffer
                api.buffer.ApplyTile(tile);
            }
            else
            {
                // Send tile texture
                tile.texture = tileTexture as Texture2D;

                // Change tile status
                tile.status = OnlineMapsTileStatus.loaded;
            }

            // Redraw map (using best redraw type)
            api.CheckRedrawType();
        }
    private static string GetTileKey(OnlineMapsTile tile)
    {
        StringBuilder builder = new StringBuilder();

        builder.Append(tile.mapType.fullID).Append(tile.key).Append(tile.labels).Append(tile.language);
        return(builder.ToString());
    }
Exemple #7
0
        private void OnStartDownloadTile(OnlineMapsTile tile)
        {
            Texture2D tileTexture = new Texture2D(256, 256);

            // Here your code to load tile texture from any source.

            // Apply your texture in the buffer and redraws the map.
            if (map.control.resultIsTexture)
            {
                // Apply tile texture
                (tile as OnlineMapsRasterTile).ApplyTexture(tileTexture as Texture2D);

                // Send tile to buffer
                map.buffer.ApplyTile(tile);

                // Destroy the texture, because it is no longer needed.
                OnlineMapsUtils.Destroy(tileTexture);
            }
            else
            {
                // Send tile texture
                tile.texture = tileTexture;

                // Change tile status
                tile.status = OnlineMapsTileStatus.loaded;
            }

            // Redraw map (using best redraw type)
            map.Redraw();
        }
    private void LoadTile(OnlineMapsTile tile, byte[] bytes)
    {
        Texture2D texture = new Texture2D(1, 1, TextureFormat.ARGB32, map.control.mipmapForTiles);

        texture.LoadImage(bytes);
        texture.wrapMode = TextureWrapMode.Clamp;

        if (map.control.resultIsTexture)
        {
            (tile as OnlineMapsRasterTile).ApplyTexture(texture);
            map.buffer.ApplyTile(tile);
            OnlineMapsUtils.Destroy(texture);
        }
        else
        {
            tile.texture = texture;
            tile.status  = OnlineMapsTileStatus.loaded;
        }

        OnlineMapsRasterTile rTile = tile as OnlineMapsRasterTile;

        if (map.traffic && !string.IsNullOrEmpty(rTile.trafficURL))
        {
            if (map.traffic && !string.IsNullOrEmpty(rTile.trafficURL))
            {
                rTile.trafficWWW             = new OnlineMapsWWW(rTile.trafficURL);
                rTile.trafficWWW["tile"]     = tile;
                rTile.trafficWWW.OnComplete += OnlineMapsTileManager.OnTrafficWWWComplete;
            }
        }
    }
Exemple #9
0
    private void InitTile(int zoom, OnlineMapsVector2i pos, int maxY, List <OnlineMapsTile> newBaseTiles, int y, int px)
    {
        int py = y + pos.y;

        if (py < 0 || py >= maxY)
        {
            return;
        }

        OnlineMapsTile tile;

        if (!OnlineMapsTile.GetTile(zoom, px, py, out tile))
        {
            OnlineMapsTile parent = null;

            if (!api.useCurrentZoomTiles)
            {
                int ptx = px / 2;
                int pty = py / 2;
                if (OnlineMapsTile.GetTile(zoom - 1, ptx, pty, out parent))
                {
                    parent.used = true;
                }
            }

            tile = new OnlineMapsTile(px, py, zoom, api, parent)
            {
                OnSetColor = OnTileSetColor
            };
        }

        newBaseTiles.Add(tile);
        tile.used = true;
    }
    private void LoadTile(OnlineMapsTile tile, byte[] bytes)
    {
        Texture2D texture = new Texture2D(256, 256, TextureFormat.ARGB32, map.control.mipmapForTiles);

        texture.LoadImage(bytes);
        texture.wrapMode = TextureWrapMode.Clamp;

        if (map.target == OnlineMapsTarget.texture)
        {
            tile.ApplyTexture(texture);
            map.buffer.ApplyTile(tile);
            OnlineMapsUtils.DestroyImmediate(texture);
        }
        else
        {
            tile.texture = texture;
            tile.status  = OnlineMapsTileStatus.loaded;
        }

        if (map.traffic && !string.IsNullOrEmpty(tile.trafficURL))
        {
            tile.trafficWWW             = OnlineMapsUtils.GetWWW(tile.trafficURL);
            tile.trafficWWW.customData  = tile;
            tile.trafficWWW.OnComplete += map.OnTrafficWWWComplete;
        }
    }
Exemple #11
0
 private void OnTileSetColor(OnlineMapsTile tile)
 {
     if (tile.zoom == bufferZoom)
     {
         SetBufferTile(tile);
     }
 }
Exemple #12
0
        /// <summary>
        /// Gets the URL to download the tile texture.
        /// </summary>
        /// <param name="tile">Instence of tile.</param>
        /// <returns>URL to tile texture.</returns>
        public string GetURL(OnlineMapsTile tile)
        {
            bool useLabels = hasLabels ? tile.labels : labelsEnabled;

            if (useLabels)
            {
                if (!string.IsNullOrEmpty(_urlWithLabels))
                {
                    return(GetURL(tile, _urlWithLabels, true));
                }
                if (!string.IsNullOrEmpty(provider.url))
                {
                    return(GetURL(tile, provider.url, true));
                }
                return(GetURL(tile, _urlWithoutLabels, false));
            }

            if (!string.IsNullOrEmpty(_urlWithoutLabels))
            {
                return(GetURL(tile, _urlWithoutLabels, false));
            }
            if (!string.IsNullOrEmpty(provider.url))
            {
                return(GetURL(tile, provider.url, false));
            }
            return(GetURL(tile, _urlWithLabels, true));
        }
Exemple #13
0
        private void OnStartDownloadTile(OnlineMapsTile tile)
        {
            Texture tileTexture = new Texture();

            // Here your code to load tile texture from any source.

            // Apply your texture in the buffer and redraws the map.
            if (map.target == OnlineMapsTarget.texture)
            {
                // Apply tile texture
                tile.ApplyTexture(tileTexture as Texture2D);

                // Send tile to buffer
                map.buffer.ApplyTile(tile);

                // Destroy the texture, because it is no longer needed.
                OnlineMapsUtils.DestroyImmediate(tileTexture);
            }
            else
            {
                // Send tile texture
                tile.texture = tileTexture as Texture2D;

                // Change tile status
                tile.status = OnlineMapsTileStatus.loaded;
            }

            // Redraw map (using best redraw type)
            map.CheckRedrawType();
        }
    private void StartDownloadOverlay(OnlineMapsTile tile)
    {
        if (tile.zoom < minZoom)
        {
            return;
        }
        if (overlays.ContainsKey(tile.key))
        {
            return;
        }

        string        url = string.Format(overlayURL, tile.zoom, tile.x, tile.y);
        OnlineMapsWWW www = new OnlineMapsWWW(url);

        www.OnComplete += delegate
        {
            if (tile.status == OnlineMapsTileStatus.disposed)
            {
                return;
            }

            Texture2D texture = new Texture2D(256, 256, TextureFormat.ARGB32, map.control.mipmapForTiles);
            www.LoadImageIntoTexture(texture);
            texture.wrapMode = TextureWrapMode.Clamp;
            overlays.Add(tile.key, texture);
            tile.OnDisposed += OnTileDisposed;

            if (enabled)
            {
                SetOverlay(tile as OnlineMapsRasterTile, texture);
                map.Redraw();
            }
        };
    }
    private void StartDownloadOverlay(OnlineMapsTile tile)
    {
        if (tile.zoom < minZoom)
        {
            return;
        }

        string        url = string.Format("https://maps.google.com/maps/vt?pb=!1m5!1m4!1i{0}!2i{1}!3i{2}!4i256!2m8!1e2!2ssvv!4m2!1scb_client!2sapiv3!4m2!1scc!2s*211m3*211e3*212b1*213e2*211m3*211e2*212b1*213e2!3m5!3sUS!12m1!1e40!12m1!1e18", tile.zoom, tile.x, tile.y);
        OnlineMapsWWW www = new OnlineMapsWWW(url);

        www.OnComplete += delegate
        {
            if (tile.status == OnlineMapsTileStatus.disposed)
            {
                return;
            }

            Texture2D texture = new Texture2D(256, 256, TextureFormat.ARGB32, map.control.mipmapForTiles);
            www.LoadImageIntoTexture(texture);
            texture.wrapMode = TextureWrapMode.Clamp;
            overlays.Add(tile.key, texture);
            tile.OnDisposed += OnTileDisposed;

            if (enabled)
            {
                tile.overlayFrontTexture = texture;
                map.Redraw();
            }
        };
    }
 private void OnPreloadTiles()
 {
     lock (OnlineMapsTile.lockTiles)
     {
         long start = DateTime.Now.Ticks;
         for (int i = 0; i < OnlineMapsTile.tiles.Count; i++)
         {
             OnlineMapsTile tile = OnlineMapsTile.tiles[i];
             if (tile.status != OnlineMapsTileStatus.none || tile.cacheChecked)
             {
                 continue;
             }
             if (!TryLoadFromCache(tile))
             {
                 tile.cacheChecked = true;
             }
             else if (OnLoadedFromCache != null)
             {
                 OnLoadedFromCache(tile);
             }
             if (DateTime.Now.Ticks - start > 200000)
             {
                 return;
             }
         }
     }
 }
    private void CreateTileParent(int zoom, OnlineMapsTile tile, OnlineMapsBufferZoom parentZoom,
                                  List <OnlineMapsTile> newParentTiles)
    {
        int px = tile.x / 2;
        int py = tile.y / 2;

        OnlineMapsTile parent =
            parentZoom.tiles.FirstOrDefault(t => t.x == px && t.y == py);

        if (parent == null)
        {
            parent = new OnlineMapsTile(px, py, zoom, api)
            {
                OnSetColor = OnTileSetColor
            };
            parentZoom.tiles.Add(parent);
        }

        newParentTiles.Add(parent);
        parent.used = true;
        tile.SetParent(parent);
        if (parent.hasColors && tile.status != OnlineMapsTileStatus.loaded)
        {
            parent.SetChildColor(tile);
        }
    }
Exemple #18
0
    private void OnStartDownloadTile(OnlineMapsTile tile)
    {
        int zoom = map.zoom - zoomOffset;

        if (tile.zoom < zoom || zoom < 1)
        {
            return;
        }

        int s = 1 << (tile.zoom - zoom);
        int x = tile.x / s;
        int y = tile.y / s;

        ulong key = OnlineMapsTile.GetTileKey(zoom, x, y);

        if (tiles.ContainsKey(key))
        {
            return;
        }

        Tile t = new Tile
        {
            x      = x,
            y      = y,
            zoom   = zoom,
            width  = tileWidth,
            height = tileHeight
        };

        tiles.Add(key, t);

        StartDownloadElevationTile(t);
    }
        /// <summary>
        /// This method is called when loading the tile.
        /// </summary>
        /// <param name="tile">Reference to tile</param>
        private void OnStartDownloadTile(OnlineMapsTile tile)
        {
            // Get local path.
            string path = GetTilePath(tile);

            // If the tile is cached.
            if (File.Exists(path))
            {
                // Load tile texture from cache.
                Texture2D tileTexture = new Texture2D(256, 256);
                tileTexture.LoadImage(File.ReadAllBytes(path));
                tileTexture.wrapMode = TextureWrapMode.Clamp;

                // Send texture to map.
                if (OnlineMaps.instance.target == OnlineMapsTarget.texture)
                {
                    tile.ApplyTexture(tileTexture);
                    OnlineMaps.instance.buffer.ApplyTile(tile);
                }
                else
                {
                    tile.texture = tileTexture;
                    tile.status  = OnlineMapsTileStatus.loaded;
                }

                // Redraw map.
                OnlineMaps.instance.Redraw();
            }
            else
            {
                // If the tile is not cached, download tile with a standard loader.
                OnlineMaps.instance.StartDownloadTile(tile);
            }
        }
    protected virtual void Destroy()
    {
        lock (lockTiles)
        {
            tiles.Remove(this);
        }

        if (texture != null)
        {
            OnlineMapsUtils.Destroy(texture);
        }
        if (overlayBackTexture != null)
        {
            OnlineMapsUtils.Destroy(overlayBackTexture);
        }
        if (overlayFrontTexture != null)
        {
            OnlineMapsUtils.Destroy(overlayFrontTexture);
        }

        texture             = null;
        overlayBackTexture  = null;
        overlayFrontTexture = null;
        _customFields       = null;

        _url     = null;
        data     = null;
        blockers = null;

        if (hasChilds)
        {
            foreach (OnlineMapsTile child in childs)
            {
                if (child != null)
                {
                    child.parent = null;
                }
            }
        }
        if (parent != null)
        {
            if (parent.childs != null)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (parent.childs[i] == this)
                    {
                        parent.childs[i] = null;
                        break;
                    }
                }
            }
        }
        parent    = null;
        childs    = null;
        hasChilds = false;
        hasColors = false;

        OnDisposed = null;
    }
        /// <summary>
        /// This method is called when loading the tile.
        /// </summary>
        /// <param name="tile">Reference to tile</param>
        private void OnStartDownloadTile(OnlineMapsTile tile)
        {
            // Get local path.
            string path = GetTilePath(tile);

            // If the tile is cached.
            if (File.Exists(path))
            {
                // Load tile texture from cache.
                Texture2D tileTexture = new Texture2D(256, 256);
                tileTexture.LoadImage(File.ReadAllBytes(path));
                tileTexture.wrapMode = TextureWrapMode.Clamp;

                // Send texture to map.
                if (OnlineMaps.instance.target == OnlineMapsTarget.texture)
                {
                    tile.ApplyTexture(tileTexture);
                    OnlineMaps.instance.buffer.ApplyTile(tile);
                }
                else
                {
                    tile.texture = tileTexture;
                    tile.status = OnlineMapsTileStatus.loaded;
                }

                // Redraw map.
                OnlineMaps.instance.Redraw();
            }
            else
            {
                // If the tile is not cached, download tile with a standard loader.
                OnlineMaps.instance.StartDownloadTile(tile);
            }
        }
    private static string GetTrafficKey(OnlineMapsTile tile)
    {
        StringBuilder builder = new StringBuilder();

        builder.Append("traffic").Append(tile.key);
        return(builder.ToString());
    }
Exemple #23
0
    public void GetColorsFromChilds()
    {
        if (hasColors)
        {
            return;
        }
        if (childs == null || childs.Any(c => c == null || c.status != OnlineMapsTileStatus.loaded))
        {
            return;
        }

        const int s  = OnlineMapsUtils.tileSize;
        const int hs = s / 2;

        _colors = new Color[OnlineMapsUtils.sqrTileSize];

        for (int i = 0; i < 4; i++)
        {
            int            cx   = i / 2;
            int            cy   = 1 - i % 2;
            OnlineMapsTile tile = childs[i];
            if (tile == null)
            {
                OnlineMapsUtils.ApplyColorArray(ref _colors, cx * hs, cy * hs, hs, hs, ref defaultColors, cx * hs, cy * hs);
            }
            else
            {
                OnlineMapsUtils.ApplyColorArray2(ref _colors, cx * hs, cy * hs, hs, hs, ref tile._colors);
            }
        }
        hasColors = true;
    }
 private void OnTrafficDownloaded(OnlineMapsTile tile)
 {
     if (useMemoryCache)
     {
         AddMemoryCacheTrafficItem(tile, tile.trafficWWW.bytes);
     }
 }
Exemple #25
0
    /// <summary>
    /// This method is called when loading the tile.
    /// </summary>
    /// <param name="tile">Reference to tile</param>
    private void OnStartDownloadTile(OnlineMapsTile tile)
    {
        // Get local path.
        string path = GetTilePath(tile);

        // If the tile is cached.
        if (File.Exists(path))
        {
            // Load tile texture from cache.
            Texture2D tileTexture = new Texture2D(256, 256, TextureFormat.RGB24, false);
            tileTexture.LoadImage(File.ReadAllBytes(path));
            tileTexture.wrapMode = TextureWrapMode.Clamp;

            // Send texture to map.
            if (OnlineMapsControlBase.instance.resultIsTexture)
            {
                (tile as OnlineMapsRasterTile).ApplyTexture(tileTexture);
                OnlineMaps.instance.buffer.ApplyTile(tile);
                OnlineMapsUtils.Destroy(tileTexture);
            }
            else
            {
                tile.texture = tileTexture;
                tile.status  = OnlineMapsTileStatus.loaded;
            }

            // Redraw map.
            OnlineMaps.instance.Redraw();
        }
        else
        {
            // If the tile is not cached, download tile with a standard loader.
            OnlineMapsTileManager.StartDownloadTile(tile);
        }
    }
    private bool TryLoadTraffic(OnlineMapsTile tile)
    {
        if (memoryCache == null)
        {
            return(false);
        }

        string key     = GetTrafficKey(tile);
        int    keyHash = key.GetHashCode();

        MemoryCacheItem item = null;

        for (int itemIndex = 0; itemIndex < countMemoryItems; itemIndex++)
        {
            if (memoryCache[itemIndex].hash == keyHash && memoryCache[itemIndex].key == key)
            {
                item      = memoryCache[itemIndex];
                item.time = DateTime.Now.Ticks;
                break;
            }
        }
        if (item == null)
        {
            return(false);
        }

        Texture2D trafficTexture = new Texture2D(256, 256, TextureFormat.RGB24, false);

        trafficTexture.LoadImage(item.bytes);
        trafficTexture.wrapMode = TextureWrapMode.Clamp;
        tile.trafficTexture     = trafficTexture;
        map.Redraw();

        return(true);
    }
 private void OnChangeMaterialTexture(OnlineMapsTile tile, Material material)
 {
     TilesetFadeExampleItem item = items.FirstOrDefault(i => i.tile == tile);
     if (item != null)
     {
         item.material = material;
         item.Update();
     }
     else if (tile.customData != null)
     {
         item = (TilesetFadeExampleItem) tile.customData;
         if (!item.finished)
         {
             items.Add(item);
             item.Update();
         }
         else material.color = TilesetFadeExampleItem.toColor;
     }
     else if (tile.texture != null && tile.texture != OnlineMaps.instance.defaultTileTexture)
     {
         item = new TilesetFadeExampleItem(tile, material);
         item.Update();
         items.Add(item);
     }
     else
     {
         material.color = TilesetFadeExampleItem.fromColor;
     }
 }
    private void AddMemoryCacheItem(OnlineMapsTile tile, int tileHash, string tileKey)
    {
        for (int i = 0; i < countMemoryItems; i++)
        {
            if (memoryCache[i].hash == tileHash && memoryCache[i].key == tileKey)
            {
                return;
            }
        }

        if (memoryCache == null)
        {
            memoryCache = new MemoryCacheItem[maxMemoryCacheSize * 10];
        }
        else if (memoryCache.Length == countMemoryItems)
        {
            Array.Resize(ref memoryCache, memoryCache.Length + 50);
        }

        MemoryCacheItem item = new MemoryCacheItem(tileKey, tile);

        memoryCache[countMemoryItems++] = item;
        _memoryCacheSize += item.size;
        if (memoryCacheSize > maxMemoryCacheSize * 1000000)
        {
            UnloadOldMemoryCacheItems();
        }
    }
    private bool TryLoadFromFileCache(OnlineMapsTile tile)
    {
#if ALLOW_FILECACHE
        if (fileCacheAtlas == null)
        {
            LoadFileCacheAtlas();
        }

        StringBuilder filename      = GetShortTilePath(tile);
        string        shortFilename = filename.ToString();
        if (fileCacheAtlas.Contains(shortFilename))
        {
            string fullTilePath = GetFullTilePath(shortFilename);
            if (!File.Exists(fullTilePath))
            {
                return(false);
            }

            byte[] bytes = File.ReadAllBytes(fullTilePath);
            LoadTile(tile, bytes);
            AddMemoryCacheItem(tile);
            if (OnLoadedFromFileCache != null)
            {
                OnLoadedFromFileCache(tile);
            }
            return(true);
        }
#endif
        return(false);
    }
Exemple #30
0
        public void Add(OnlineMapsCache cache, OnlineMapsTile tile, byte[] bytes)
        {
#if ALLOW_FILECACHE
            StringBuilder filename      = cache.GetShortTilePath(tile);
            string        shortFilename = filename.ToString();
            if (Contains(shortFilename))
            {
                return;
            }

            string fullFilename = cache.GetFullTilePath(shortFilename);

            OnlineMapsThreadManager.AddThreadAction(() =>
            {
                FileInfo fileInfo = new FileInfo(fullFilename);
                if (!Directory.Exists(fileInfo.DirectoryName))
                {
                    Directory.CreateDirectory(fileInfo.DirectoryName);
                }
                File.WriteAllBytes(fullFilename, bytes);
            });

            AddItem(shortFilename, bytes.Length);
            _size += bytes.Length;
#endif
        }
Exemple #31
0
 private void OnPreloadTiles()
 {
     lock (OnlineMapsTile.lockTiles)
     {
         float start = Time.realtimeSinceStartup;
         for (int i = 0; i < OnlineMapsTile.tiles.Count; i++)
         {
             OnlineMapsTile tile = OnlineMapsTile.tiles[i];
             if (tile.status != OnlineMapsTileStatus.none || tile.cacheChecked)
             {
                 continue;
             }
             if (!TryLoadFromCache(tile))
             {
                 tile.cacheChecked = true;
             }
             else if (OnLoadedFromCache != null)
             {
                 OnLoadedFromCache(tile);
             }
             if (Time.realtimeSinceStartup - start > 0.02)
             {
                 return;
             }
         }
     }
 }
Exemple #32
0
    private void OnStartDownloadTile(OnlineMapsTile tile)
    {
        // Load overlay for tile from Resources.
        //tile.overlayBackTexture = Resources.Load<Texture2D>(string.Format("OnlineMapsOverlay/{0}/{1}/{2}", tile.zoom, tile.x, tile.y));

        // Custom code to load a faction texture overlay for this tile, based on faction in power

        // Insert code to retrieve faction int (0=neutral, 1=paragon, 2=slayer, 3=hunter) from server
        // Using tile.x and tile.y as indexing keys
        int tileFaction = 0;

        //-----server code-----//
        // If we have reached the maximum zoom, get the tile's faction from the server
        if (tile.zoom == 18)
        {
            // Use tile.x and tile.y to construct the query to the dictionary
            // Server's dictionary should have ints from 0 to 3, and thousands of entries
            //create form
            var form = new WWWForm();
            form.AddField("xtile", tile.x);
            //Debug.Log("x = " + tile.x);
            form.AddField("ytile", tile.y);
            //Debug.Log("y = " + tile.y);
            //send form to returnFactionTile.php
            string url  = "http://13.84.163.243/returnFactionTile.php"; //script that handles faction tiles
            WWW    send = new WWW(url, form);
            StartCoroutine(GrabTileInfo(send));
            // Set texture based on faction in power
            tileFaction = faction_num;
        }
        // Otherwise, leave 0 and do nothing

        switch (tileFaction)
        {
        case 0:     // Neutral
            break;

        case 1:     // Paragon
            tile.overlayBackTexture = ParagonTex;
            break;

        case 2:     // Slayer
            tile.overlayBackTexture = SlayerTex;
            break;

        case 3:     // Hunter
            tile.overlayBackTexture = HunterTex;
            break;

        default:     // Should not reach, error if so
            // Don't put an overlay
            break;
        }

        tile.overlayBackAlpha = alpha;

        // Load the tile using a standard loader.
        OnlineMaps.instance.StartDownloadTile(tile);
    }
 public void ApplyTile(OnlineMapsTile tile)
 {
     if (newTiles == null) newTiles = new List<OnlineMapsTile>();
     lock (newTiles)
     {
         newTiles.Add(tile);
     }
 }
        private void OnStartDownloadTile(OnlineMapsTile tile)
        {
            // Load overlay for tile from Resources.
            tile.overlayBackTexture = Resources.Load <Texture2D>(string.Format("OnlineMapsOverlay/{0}/{1}/{2}", tile.zoom, tile.x, tile.y));

            // Load the tile using a standard loader.
            OnlineMaps.instance.StartDownloadTile(tile);
        }
    public TilesetFadeExampleItem(OnlineMapsTile tile, Material material)
    {
        this.tile = tile;
        this.material = material;

        startTicks = DateTime.Now.Ticks;

        tile.customData = this;
    }
        /// <summary>
        /// This method is called when tile is success downloaded.
        /// </summary>
        /// <param name="tile">Reference to tile.</param>
        private void OnTileDownloaded(OnlineMapsTile tile)
        {
            // Get local path.
            string path = GetTilePath(tile);

            // Cache tile.
            FileInfo fileInfo = new FileInfo(path);
            DirectoryInfo directory = fileInfo.Directory;
            if (!directory.Exists) directory.Create();

            File.WriteAllBytes(path, tile.www.bytes);
        }
 /// <summary>
 /// Gets the local path for tile.
 /// </summary>
 /// <param name="tile">Reference to tile</param>
 /// <returns>Local path for tile</returns>
 private static string GetTilePath(OnlineMapsTile tile)
 {
     string[] parts =
     {
     Application.persistentDataPath,
     "OnlineMapsTileCache",
     Enum.GetName(typeof(OnlineMapsProviderEnum), tile.provider),
     OnlineMaps.instance.type.ToString(),
     tile.zoom.ToString(),
     tile.x.ToString(),
     tile.y + ".png"
 };
     return string.Join("/", parts);
 }
        private void OnStartDownloadTile(OnlineMapsTile tile)
        {
            Texture tileTexture = new Texture();

            // Here your code to load tile texture from any source.

            // Apply your texture in the buffer and redraws the map.
            if (api.target == OnlineMapsTarget.texture)
            {
                tile.ApplyTexture(tileTexture as Texture2D);
                api.buffer.ApplyTile(tile);
            }
            else
            {
                tile.texture = tileTexture as Texture2D;
                tile.status = OnlineMapsTileStatus.loaded;
            }
            api.CheckRedrawType();
        }
    private void CreateTileParent(int zoom, OnlineMapsTile tile, OnlineMapsBufferZoom parentZoom,
        List<OnlineMapsTile> newParentTiles)
    {
        int px = tile.x / 2;
        int py = tile.y / 2;

        OnlineMapsTile parent =
            parentZoom.tiles.FirstOrDefault(t => t.x == px && t.y == py);
        if (parent == null)
        {
            parent = new OnlineMapsTile(px, py, zoom, api) {OnSetColor = OnTileSetColor};
            parentZoom.tiles.Add(parent);
        }

        newParentTiles.Add(parent);
        parent.used = true;
        tile.SetParent(parent);
        if (parent.hasColors && tile.status != OnlineMapsTileStatus.loaded) parent.SetChildColor(tile);
    }
    public void SetChildColor(OnlineMapsTile child)
    {
        if (child == null) return;

        if (api.target == OnlineMapsTarget.texture) SetChildColorTexture(child);

        if (child.hasChilds)
        {
            foreach (OnlineMapsTile tile in child.childs)
            {
                if (tile != null && tile.status != OnlineMapsTileStatus.loaded) child.SetChildColor(tile);
            }
        }
    }
    private void SetChildColorTexture(OnlineMapsTile child)
    {
        if (!hasColors) return;
        if (child.status == OnlineMapsTileStatus.loading || child.hasColors) return;

        Color[] clrs = colors;

        if (clrs == null) return;
        if (child._colors == null) child._colors = new Color[OnlineMapsUtils.sqrTileSize];

        const int s = OnlineMapsUtils.tileSize;
        const int hs = s / 2;
        int sx = (child.x % 2) * hs;
        int sy = hs - (child.y % 2) * hs;

        int childLength = child._colors.Length;
        int colorLength = clrs.Length;

        for (int py = 0; py < s; py++)
        {
            int spy = py * s;
            int hpy = (py / 2 + sy) * s;
            for (int px = 0; px < s; px++)
            {
                int i1 = spy + px;
                int i2 = hpy + px / 2 + sx;
                if (childLength <= i1 || colorLength <= i2) continue;

                child._colors[i1] = clrs[i2];
            }
        }

        child.hasColors = true;
        if (child.OnSetColor != null) child.OnSetColor(child);
    }
Exemple #42
0
    public void StartDownloadTile(OnlineMapsTile tile)
    {
        if (source != OnlineMapsSource.Online)
        {
            UnityEngine.Object tileTexture = Resources.Load(tile.resourcesPath);
            if (tileTexture != null)
            {
                if (target == OnlineMapsTarget.texture)
                {
                    tile.ApplyTexture(tileTexture as Texture2D);
                    buffer.ApplyTile(tile);
                }
                else
                {
                    tile.texture = tileTexture as Texture2D;
                    tile.status = OnlineMapsTileStatus.loaded;
                }
                CheckRedrawType();
                return;
            }

            if (source == OnlineMapsSource.Resources)
            {
                tile.status = OnlineMapsTileStatus.error;
                return;
            }
        }

#if UNITY_WEBPLAYER
        tile.www = new WWW("http://service.infinity-code.com/redirect.php?" + tile.url);
        if (!string.IsNullOrEmpty(tile.labelURL)) tile.labelWWW = new WWW("http://service.infinity-code.com/redirect.php?" + tile.labelURL);
#else
        tile.www = new WWW(tile.url);
        if (!string.IsNullOrEmpty(tile.labelURL)) tile.labelWWW = new WWW(tile.labelURL);
#endif
        tile.status = OnlineMapsTileStatus.loading;
    }
Exemple #43
0
    /// <summary>
    /// Allows you to test the connection to the Internet.
    /// </summary>
    /// <param name="callback">Function, which will return the availability of the Internet.</param>
    public void CheckServerConnection(Action<bool> callback)
    {
        OnlineMapsTile tempTile = new OnlineMapsTile(350, 819, 11, this, false);
        string url = tempTile.url;
        tempTile.Dispose();

        checkConnectioCallback = callback;

#if UNITY_WEBPLAYER
        checkConnectionWWW = new WWW("http://service.infinity-code.com/redirect.php?" + url);
#else
        checkConnectionWWW = new WWW(url);
#endif
    }
 private void SetChild(OnlineMapsTile tile)
 {
     int cx = tile.x % 2;
     int cy = tile.y % 2;
     childs[cx * 2 + cy] = tile;
     hasChilds = true;
 }
    private Rect SetBufferTile(OnlineMapsTile tile)
    {
        if (api.target == OnlineMapsTarget.tileset) return default(Rect);

        const int s = OnlineMapsUtils.tileSize;
        int i = 0;
        int px = tile.x - bufferPosition.x;
        int py = tile.y - bufferPosition.y;

        int maxX = 2 << (tile.zoom - 1);

        if (px < 0) px += maxX;
        else if (px >= maxX) px -= maxX;

        px *= s;
        py *= s;

        if (px + s < 0 || py + s < 0 || px > width || py > height) return new Rect(0, 0, 0, 0);

        Color[] colors = tile.colors;

        lock (colors)
        {
            int maxSize = width * height;

            for (int y = py + s - 1; y >= py; y--)
            {
                int bp = y * width + px;
                if (bp + s < 0 || bp >= maxSize) continue;
                int l = s;
                if (bp < 0)
                {
                    l -= bp;
                    bp = 0;
                }
                else if (bp + s > maxSize)
                {
                    l -= maxSize - (bp + s);
                    bp = maxSize - s - 1;
                }

                try
                {
                    Array.Copy(colors, i, backBuffer, bp, l);
                }
                catch
                {
                }

                i += s;
            }

            return new Rect(px, py, OnlineMapsUtils.tileSize, OnlineMapsUtils.tileSize);
        }
    }
    /// <summary>
    /// Starts dowloading of specified tile.
    /// </summary>
    /// <param name="tile">Tile to be downloaded.</param>
    public void StartDownloadTile(OnlineMapsTile tile)
    {
        if (source != OnlineMapsSource.Online)
        {
            UnityEngine.Object tileTexture = Resources.Load(tile.resourcesPath);
            if (tileTexture != null)
            {
                if (target == OnlineMapsTarget.texture)
                {
                    tile.ApplyTexture(tileTexture as Texture2D);
                    buffer.ApplyTile(tile);
                }
                else
                {
                    tile.texture = tileTexture as Texture2D;
                    tile.status = OnlineMapsTileStatus.loaded;
                }
                CheckRedrawType();
                return;
            }

            if (source == OnlineMapsSource.Resources)
            {
                tile.status = OnlineMapsTileStatus.error;
                return;
            }
        }

        tile.www = OnlineMapsUtils.GetWWW(tile.url);
        if (traffic && !string.IsNullOrEmpty(tile.trafficURL))
        {
            tile.trafficWWW = OnlineMapsUtils.GetWWW(tile.trafficURL);
        }

        tile.status = OnlineMapsTileStatus.loading;
    }
    /// <summary>
    /// Dispose of tile.
    /// </summary>
    public void Dispose()
    {
        if (status == OnlineMapsTileStatus.disposed) return;
        status = OnlineMapsTileStatus.disposed;

        if (www != null)
        {
            //www.Dispose();
            www = null;
        }
        if (trafficWWW != null)
        {
            //trafficWWW.Dispose();
            trafficWWW = null;
        }
        _colors = null;
        _url = null;
        labelData = null;
        labelColors = null;
        data = null;
        texture = null;
        trafficTexture = null;
        OnSetColor = null;
        if (hasChilds) foreach (OnlineMapsTile child in childs) if (child != null) child.parent = null;
        if (parent != null)
        {
            if (parent.childs != null)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (parent.childs[i] == this)
                    {
                        parent.childs[i] = null;
                        break;
                    }
                }
            }
            parent = null;
        }
        childs = null;
        hasChilds = false;
        hasColors = false;
    }
 public OnlineMapsTile(int x, int y, int zoom, OnlineMaps api, OnlineMapsTile parent)
     : this(x, y, zoom, api)
 {
     this.parent = parent;
     if (parent != null && parent.status == OnlineMapsTileStatus.loaded) parent.SetChildColor(this);
 }
 public void SetParent(OnlineMapsTile tile)
 {
     parent = tile;
     parent.SetChild(this);
 }
 public void Dispose()
 {
     if (status == OnlineMapsTileStatus.disposed) return;
     www = null;
     _colors = null;
     _url = null;
     OnSetColor = null;
     status = OnlineMapsTileStatus.disposed;
     if (hasChilds) foreach (OnlineMapsTile child in childs) if (child != null) child.parent = null;
     if (parent != null)
     {
         if (parent.childs != null)
         {
             for (int i = 0; i < 4; i++)
             {
                 if (parent.childs[i] == this)
                 {
                     parent.childs[i] = null;
                     break;
                 }
             }
         }
         parent = null;
     }
     childs = null;
     hasChilds = false;
     hasColors = false;
 }
    private void InitTile(int zoom, OnlineMapsBufferZoom activeZoom, OnlineMapsVector2i pos, int maxY,
        List<OnlineMapsTile> newBaseTiles,
        int y, IEnumerable<OnlineMapsTile> ts, int px)
    {
        int py = y + pos.y;
        if (py < 0 || py >= maxY) return;

        OnlineMapsTile tile = null;

        foreach (OnlineMapsTile t in ts)
        {
            if (t.x == px && t.y == py)
            {
                tile = t;
                break;
            }
        }

        if (tile == null)
        {
            OnlineMapsTile parent = null;

            if (!api.useCurrentZoomTiles && zooms.ContainsKey(zoom - 1))
            {
                int ptx = px / 2;
                int pty = py / 2;
                foreach (OnlineMapsTile t in zooms[zoom - 1].tiles)
                {
                    if (t.x == ptx && t.y == pty)
                    {
                        parent = t;
                        parent.used = true;
                        break;
                    }
                }
            }

            tile = new OnlineMapsTile(px, py, zoom, api, parent) { OnSetColor = OnTileSetColor };
            activeZoom.tiles.Add(tile);
        }
        newBaseTiles.Add(tile);
        tile.used = true;
        if (api.target == OnlineMapsTarget.texture) SetBufferTile(tile);
    }
    private void InitTile(int zoom, OnlineMapsBufferZoom activeZoom, OnlineMapsVector2i pos, int maxY,
        List<OnlineMapsTile> newBaseTiles,
        int y, List<OnlineMapsTile> ts, int px)
    {
        int py = y + pos.y;
        if (py < 0 || py >= maxY) return;
        OnlineMapsTile tile = ts.FirstOrDefault(t => t.x == px && t.y == py);
        if (tile == null)
        {
            OnlineMapsTile parent = OnlineMapsTile.tiles.FirstOrDefault(
                t => t.zoom == zoom - 1 && t.x == px / 2 && t.y == py / 2);

            tile = new OnlineMapsTile(px, py, zoom, api, parent) {OnSetColor = OnTileSetColor};
            activeZoom.tiles.Add(tile);
        }
        newBaseTiles.Add(tile);
        tile.used = true;
        SetBufferTile(tile);
    }
 private void OnTileSetColor(OnlineMapsTile tile)
 {
     if (tile.zoom == bufferZoom) SetBufferTile(tile);
 }
 /// <summary>
 /// This method is called when tile is success downloaded.
 /// </summary>
 /// <param name="tile">Reference to tile.</param>
 private void OnTileDownloaded(OnlineMapsTile tile)
 {
     // Increases counter of downloaded data.
     totalTileTraffic += tile.www.bytesDownloaded;
 }
    /// <summary>
    /// Allows you to test the connection to the Internet.
    /// </summary>
    /// <param name="callback">Function, which will return the availability of the Internet.</param>
    public void CheckServerConnection(Action<bool> callback)
    {
        OnlineMapsTile tempTile = new OnlineMapsTile(350, 819, 11, this, false);
        string url = tempTile.url;
        tempTile.Dispose();

        checkConnectioCallback = callback;
        checkConnectionWWW = OnlineMapsUtils.GetWWW(url);
    }
    public void SetChildColor(OnlineMapsTile child)
    {
        if (child == null) return;
        if (colors == null) _colors = new Color[OnlineMapsUtils.sqrTileSize];
        if (child._colors == null) child._colors = new Color[OnlineMapsUtils.sqrTileSize];

        const int s = OnlineMapsUtils.tileSize;
        const int hs = s / 2;
        int sx = (child.x % 2) * hs;
        int sy = hs - (child.y % 2) * hs;

        for (int py = 0; py < s; py++)
        {
            int spy = py * s;
            int hpy = (py / 2 + sy) * s;
            for (int px = 0; px < s; px++)
            {
                try
                {
                    child._colors[spy + px] = _colors[hpy + px / 2 + sx];
                }
                catch
                {
                }
            }
        }

        child.hasColors = true;
        if (child.OnSetColor != null) child.OnSetColor(child);

        if (child.hasChilds)
        {
            foreach (OnlineMapsTile tile in child.childs)
                if (tile != null && (tile.status != OnlineMapsTileStatus.loaded)) child.SetChildColor(tile);
        }
    }