Esempio n. 1
0
        private void BuildRasterTile()
        {
            var parameters = new Tile.Parameters
            {
                Fs    = _fileSource,
                Id    = new CanonicalTileId(zoomLevel, (int)tileCoordinate.x, (int)tileCoordinate.y),
                MapId = string.IsNullOrEmpty(_styleUrl) ? "mapbox://styles/mapbox/satellite-v9" : _styleUrl
            };

            // Use RasterTile class for raster tiles. Requests mapbox.satellite mapid by default.
            var rasterTile = new RasterTile();

            rasterTile.Initialize(parameters, () =>
            {
                if (rasterTile.Error != null)
                {
                    Debug.Log(rasterTile.Error);
                    return;
                }

                var satt = new Texture2D(512, 512);
                satt.LoadImage(rasterTile.Data);

                var rend = tileObject.GetComponent <MeshRenderer>();
                rend.material.mainTexture = satt;
            });
        }
Esempio n. 2
0
 protected override void OnInitialized(Tile.Parameters parameters)
 {
     if (!string.IsNullOrEmpty(_styleUrl))
     {
         parameters.MapId = _styleUrl;
     }
     _tile.Initialize(parameters, HandleTileLoaded);
 }
    void loadMapCone()
    {
        var parameters = new Tile.Parameters();

        parameters.Fs = MapboxAccess.Instance;
        // lat long -37.8142, 144.9632
        Vector2d latlong = _map.WorldToGeoPosition(transform.position);

        //UnwrappedTileId tileId = Conversions.LatitudeLongitudeToTileId(-37.8142, 144.9632, 10);
        // Current latlong: 144.96470,-37.82177
        Debug.Log("Current latlong: " + latlong);
        UnwrappedTileId tileId = Conversions.LatitudeLongitudeToTileId(latlong.x, latlong.y, 10);

        parameters.Id    = new CanonicalTileId(tileId.Z, tileId.X, tileId.Y);
        parameters.MapId = "mapbox://styles/quangquach/cjonlkxkg3it52snz3q5yfnqd";
        var rasterTile = new RasterTile();

        Debug.Log("Start to fetch Mapbox");
        rasterTile.Initialize(parameters, (Action)(() =>
        {
            if (!rasterTile.HasError)
            {
                Debug.Log("Mapbox image loaded, saving");
                var texture = new Texture2D(0, 0);
                texture.LoadImage(rasterTile.Data);

                string filePath = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[] {
                    Application.dataPath,
                    "maptest.png"
                });

                File.WriteAllBytes(filePath, rasterTile.Data);
            }
            else
            {
                Debug.Log("Mapbox failed to load image!");
            }
        }));
    }