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; }); }
public void GetAreasGeoTiffNullImage() { Number number = new Number(0, 0, 0); ITile tile = new RasterTile(number, Cs4326, tmsCompatible: true); Assert.Throws <ArgumentNullException>(() => Area.GetAreas(null, tile)); }
private void OnImageReceived(CustomTile tile, RasterTile rasterTile) { if (tile == null) { return; } TilesWaitingResponse.Remove(tile); var raster = new Texture2D(512, 512, TextureFormat.RGB24, false) { wrapMode = TextureWrapMode.Clamp }; raster.LoadImage(rasterTile.Data); raster.Compress(true); _textures[tile.TextureIndex] = raster; _combineInstances[tile.TextureIndex] = new CombineInstance { mesh = tile.QuadMesh, transform = tile.Transform.parent.localToWorldMatrix * tile.Transform.localToWorldMatrix }; tile.ClearMesh(); if (++_counter == ManhattanTileProvider.Tiles.Count) { OnComplete(); } }
public RasterTileRegion(RasterTile tile, int west, int south, int east, int north) { _tile = tile; _west = west; _south = south; _east = east; _north = north; }
private void OnImageRecieved(UnityTile tile, RasterTile rasterTile) { if (tile != null) { Progress--; tile.SetRasterData(rasterTile.Data, _properties.rasterOptions.useMipMap, _properties.rasterOptions.useCompression); tile.RasterDataState = TilePropertyState.Loaded; } }
private void OnImageRecieved(UnityTile tile, RasterTile rasterTile) { if (tile != null) { if (tile.RasterDataState != TilePropertyState.Unregistered) { _tilesWaitingResponse.Remove(tile); tile.SetRasterData(rasterTile.Data, _properties.rasterOptions.useMipMap, _properties.rasterOptions.useCompression); } } }
//merge this with OnErrorOccurred? protected virtual void OnDataError(UnityTile tile, RasterTile rasterTile, TileErrorEventArgs e) { if (tile != null) { if (tile.RasterDataState != TilePropertyState.Unregistered) { tile.RasterDataState = TilePropertyState.Error; _tilesWaitingResponse.Remove(tile); OnErrorOccurred(e); } } }
Drawable IDrawableTileSource.GetDrawable(TileInfo ti) { // Check Schema for TileInfo var tileInfo = Schema.YAxis == YAxis.OSM ? ti.ToTMS() : ti; try { var bytes = Source.GetTile(tileInfo); var image = SKImage.FromEncodedData(bytes); var result = new RasterTile(TileSize, image, Style.Paints.FirstOrDefault <IVectorPaint>()); return(result); } catch (Exception e) { return(null); } }
public void GetAreasGeoTiffNormal() { using IGeoTiff image = new Raster(_in4326, Cs4326); using ITile tile = new RasterTile(Locations.TokyoGeodeticTmsNumber, image.GeoCoordinateSystem, tmsCompatible: true); PixelCoordinate expectedReadCoord = new PixelCoordinate(0.0, 218.0); PixelCoordinate expectedWriteCoord = new PixelCoordinate(5.6875, 0.0); Size expectedReadSize = new Size(4473, 3293); Size expectedWriteSize = new Size(140, 102); Area calcReadArea = null; Area calcWriteArea = null; Assert.DoesNotThrow(() => (calcReadArea, calcWriteArea) = Area.GetAreas(image, tile)); Assert.True(calcReadArea.OriginCoordinate == expectedReadCoord && calcReadArea.Size == expectedReadSize); Assert.True(calcWriteArea.OriginCoordinate == expectedWriteCoord && calcWriteArea.Size == expectedWriteSize); }
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!"); } })); }
//tile here should be totally optional and used only not to have keep a dictionary in terrain factory base public override void FetchData(DataFetcherParameters parameters, bool useMapBox = true) { if (CoroutineParent == null) { CoroutineParent = new GameObject(); CoroutineParent.name = "CoroutineParent"; } var imageDataParameters = parameters as ImageDataFetcherParameters; if (imageDataParameters == null) { return; } RasterTile rasterTile; if (imageDataParameters.mapid.StartsWith("mapbox://", StringComparison.Ordinal)) { rasterTile = imageDataParameters.useRetina ? new RetinaRasterTile() : new RasterTile(); } else { rasterTile = imageDataParameters.useRetina ? new ClassicRetinaRasterTile() : new ClassicRasterTile(); } if (imageDataParameters.tile != null) { imageDataParameters.tile.AddTile(rasterTile); } TileInitializer(rasterTile, _fileSource, imageDataParameters.tile, imageDataParameters.mapid); bool useMaplarge = false; //!useMapBox; if (useMapBox) { RasterTile elevationTile = imageDataParameters.useRetina ? new ClassicRetinaRasterTile() : new ClassicRasterTile(); RasterTile porosityTile = imageDataParameters.useRetina ? new ClassicRetinaRasterTile() : new ClassicRasterTile(); RasterTile thicknessTile = imageDataParameters.useRetina ? new ClassicRetinaRasterTile() : new ClassicRasterTile(); RasterTile TOCTile = imageDataParameters.useRetina ? new ClassicRetinaRasterTile() : new ClassicRasterTile(); RasterTile vShaleTile = imageDataParameters.useRetina ? new ClassicRetinaRasterTile() : new ClassicRasterTile(); TileInitializer(elevationTile, _fileSource, imageDataParameters.tile, "victer.0fd7kryp", Layers.Elevation, true); TileInitializer(porosityTile, _fileSource, imageDataParameters.tile, "victer.2w2lzfug", Layers.Porosity, true); TileInitializer(thicknessTile, _fileSource, imageDataParameters.tile, "victer.3totsqo7", Layers.Thickness, true); TileInitializer(TOCTile, _fileSource, imageDataParameters.tile, "victer.3df23l89", Layers.TOC, true); TileInitializer(vShaleTile, _fileSource, imageDataParameters.tile, "victer.cejjf2l8", Layers.VShale, true); } else if (useMaplarge) { CanonicalTileId tID = imageDataParameters.tile.CanonicalTileId; GameObject temp = new GameObject(); temp.name = "Temp_" + tID; temp.transform.SetParent(CoroutineParent.transform); MonoCoroutine mc = temp.AddComponent <MonoCoroutine>(); string url = enlargeURL.Replace("${X}", tID.X.ToString()) .Replace("${Y}", tID.Y.ToString()) .Replace("${Z}", tID.Z.ToString()); mc.GetGZipExternalMapData(url, InvokeCallback); void InvokeCallback(byte[] data) { LayerRawDataRecieved(imageDataParameters.tile, data, Layers.VShale); } } else { CanonicalTileId tID = imageDataParameters.tile.CanonicalTileId; foreach (Layers layer in (Layers[])Enum.GetValues(typeof(Layers))) { GameObject temp = new GameObject(); temp.name = "Temp_" + layer + "_" + tID; temp.transform.SetParent(CoroutineParent.transform); MonoCoroutine mc = temp.AddComponent <MonoCoroutine>(); string hash; switch (layer) { case Layers.Elevation: hash = ElevationHash; break; case Layers.Porosity: hash = PorosityHash; break; case Layers.Thickness: hash = ThicknessHash; break; case Layers.TOC: hash = TOCHash; break; case Layers.VShale: hash = VShaleHash; break; default: return; } string address = @"https://energy.maplarge.com/Api/ProcessDirect?request={""action"":""tile/getmultitile"",""hash"":" + hash + "}&uParams=x:" + tID.X + ";y:" + tID.Y + ";z:" + tID.Z + ";w:1;h:1;layeronly:true;debug:false"; mc.GetExternalMapData(address, InvokeCallback); void InvokeCallback(byte[] data) { LayerRawDataRecieved(imageDataParameters.tile, data, layer); } } } void TileInitializer(RasterTile tile, IFileSource fileSource, UnityTile uTile, string mapId, Layers layer = Layers.Elevation, bool useLayer = false) { tile.Initialize(fileSource, uTile.CanonicalTileId, mapId, () => { if (uTile.CanonicalTileId != tile.Id) { //this means tile object is recycled and reused. Returned data doesn't belong to this tile but probably the previous one. So we're trashing it. return; } if (tile.HasError) { FetchingError(uTile, tile, new TileErrorEventArgs(uTile.CanonicalTileId, tile.GetType(), uTile, tile.Exceptions)); } else { if (useLayer) { LayerDataRecieved(uTile, tile, layer); } else { DataRecieved(uTile, tile); } } }); } }
void Awake() { _tile = new RasterTile(); _renderer = GetComponent <Renderer>(); _material = _renderer.material; }