void GetTileRect(int zoomLevel, out int x0, out int y0, out int x1, out int y1)
 {
     if (worldArea == RestrictMode.Restricted)
     {
         Conversion.GetTileFromLatLon(zoomLevel, latMin, lonMin, out x0, out y1);
         Conversion.GetTileFromLatLon(zoomLevel, latMax, lonMax, out x1, out y0);
     }
     else
     {
         x0 = y0 = 0;
         x1 = y1 = (int)Mathf.Pow(2, zoomLevel) - 1;
     }
 }
Ejemplo n.º 2
0
        int GetTileZoomLevel()
        {
            // Get screen dimensions of central tile
            int     zoomLevel0 = 1;
            int     zoomLevel1 = TILE_MAX_ZOOM_LEVEL;
            int     zoomLevel = TILE_MIN_ZOOM_LEVEL;
            Vector2 latLon = Conversion.GetLatLonFromSpherePoint(GetCurrentMapLocation());
            int     xTile, yTile;

            currentTileSize  = _tileSize > TILE_MIN_SIZE ? _tileSize : TILE_MIN_SIZE;
            currentTileSize *= (3.0f - _tileResolutionFactor);
            float dist = 0;

            for (int i = 0; i < 5; i++)
            {
                zoomLevel = (zoomLevel0 + zoomLevel1) / 2;
                Conversion.GetTileFromLatLon(zoomLevel, latLon.x, latLon.y, out xTile, out yTile);
                Vector2 latLonTL      = Conversion.GetLatLonFromTile(xTile, yTile, zoomLevel);
                Vector2 latLonBR      = Conversion.GetLatLonFromTile(xTile + 0.99f, yTile + 0.99f, zoomLevel);
                Vector3 spherePointTL = Conversion.GetSpherePointFromLatLon(latLonTL);
                Vector3 spherePointBR = Conversion.GetSpherePointFromLatLon(latLonBR);
                Vector3 wposTL        = currentCamera.WorldToScreenPoint(transform.TransformPoint(spherePointTL));
                Vector3 wposBR        = currentCamera.WorldToScreenPoint(transform.TransformPoint(spherePointBR));
                dist = Mathf.Max(Mathf.Abs(wposBR.x - wposTL.x), Mathf.Abs(wposTL.y - wposBR.y));
                if (dist > currentTileSize)
                {
                    zoomLevel0 = zoomLevel;
                }
                else
                {
                    zoomLevel1 = zoomLevel;
                }
            }
            if (dist > currentTileSize)
            {
                zoomLevel++;
            }

            zoomLevel = Mathf.Clamp(zoomLevel, TILE_MIN_ZOOM_LEVEL, TILE_MAX_ZOOM_LEVEL);
            return(zoomLevel);
        }