private Feature ToFeature(TileInfo tileInfo) { byte[] tileData = _tileSource.GetTile(tileInfo); return(new Feature { Geometry = ToGeometry(tileInfo, tileData) }); }
private IFeature ToFeature(TileInfo tileInfo) { var tileData = _source.GetTile(tileInfo); return(new Feature { Geometry = ToGeometry(tileInfo, tileData) }); }
private RasterFeature?ToFeature(TileInfo tileInfo) { var tileData = _tileSource.GetTile(tileInfo); var mRaster = ToRaster(tileInfo, tileData); if (mRaster != null) { return(new RasterFeature(mRaster)); } return(null); }
/// <summary> /// Renders the layer /// </summary> /// <param name="g">Graphics object reference</param> /// <param name="map">Map which is rendered</param> public override void OnRender(System.Drawing.Graphics g, IMap map) { MapTransform mapTransform = new MapTransform(new PointF((float)Map.Center.X, (float)Map.Center.Y), (float)Map.PixelSize, Map.Image.Width, Map.Image.Height); _tileSource = KnownTileSources.Create(KnownTileSource.BingHybrid, BingApiKey); string level = BruTile.Utilities.GetNearestLevel(_tileSource.Schema.Resolutions, Map.PixelSize); IEnumerable <TileInfo> tileInfos = Schema.GetTileInfos(mapTransform.Extent, level); //new BingRequest(BingRequest.UrlBing, string.Empty, BingMapType.Hybrid); using (var graphics = Graphics.FromImage(Image)) { // log.DebugFormat("Downloading tiles:"); foreach (var tileInfo in tileInfos) { var bytes = cache.Find(tileInfo.Index); if (bytes == default(byte[])) { try { // log.DebugFormat("row: {0}, column: {1}, level: {2}", tileInfo.Index.Row, tileInfo.Index.Col, tileInfo.Index.Level); bytes = _tileSource.GetTile(tileInfo); cache.Add(tileInfo.Index, bytes); } catch (WebException e) { log.Error("Can't fetch tiles from the server", e); } } else { //log.DebugFormat("row: {0}, column: {1}, level: {2} (cached)", tileInfo.Index.Row, tileInfo.Index.Col, tileInfo.Index.Level); } if (bytes == null) { continue; } using (var bitmap = new Bitmap(new MemoryStream(bytes))) { var rectangle = mapTransform.WorldToMap(tileInfo.Extent.MinX, tileInfo.Extent.MinY, tileInfo.Extent.MaxX, tileInfo.Extent.MaxY); DrawTile(Schema, level, graphics, bitmap, rectangle); } } } }
private static List <RasterFeature> TileIndexToFeatures(TileIndex[] tileIndexes, ITileSource tileSource) { var features = new List <RasterFeature>(); foreach (var tileIndex in tileIndexes) { var tileInfo = new TileInfo { Index = tileIndex, Extent = TileTransform.TileToWorld( new TileRange(tileIndex.Col, tileIndex.Row), tileIndex.Level, tileSource.Schema) }; var raster = new MRaster(tileSource.GetTile(tileInfo), tileInfo.Extent.ToMRect()); features.Add(new RasterFeature(raster)); } return(features); }
private RasterFeature TileToFeature(ITileSource tileProvider, TileInfo tileInfo) { var tile = tileProvider.GetTile(tileInfo); // A tile layer can return a null value. This indicates the tile is not // present in the source, permanently. If this is the case no further // requests should be done. To avoid further fetches a feature should // be returned with the Geometry set to null. If a null Feature is returned // this equates to having no tile at all and attempts to fetch the tile will // continue. TileLayer.ToGeometry() follows the same implementations. // // Note, the fact that we have to define this complex method on the outside // indicates a design flaw. if (tile == null) { return(new RasterFeature((MRaster?)null)); } return(new RasterFeature(new MRaster(tile, tileInfo.Extent.ToMRect()))); }
private static List<IFeature> TileIndexToFeatures(TileIndex[] tileIndexes, ITileSource tileSource) { var features = new List<IFeature>(); foreach (var tileIndex in tileIndexes) { var tileInfo = new TileInfo { Index = tileIndex, Extent = TileTransform.TileToWorld( new TileRange(tileIndex.Col, tileIndex.Row), tileIndex.Level, tileSource.Schema) }; var feature = new Feature { Geometry = new Raster(new MemoryStream( tileSource.GetTile(tileInfo)), tileInfo.Extent.ToBoundingBox()) }; features.Add(feature); } return features; }
/// <summary> /// Save a given map tile to an Mbtiles file /// </summary> /// <param name="tileSource"></param> /// <param name="tileInfo"></param> /// <param name="dbpath"></param> /// <param name="layer"></param> public static void saveTile(ITileSource tileSource, TileInfo tileInfo, string dbpath, BioDivCollectorXamarin.Models.DatabaseModel.Layer layer) { if (!Mbtiles.TileExists(tileInfo, dbpath)) { try { var tile = tileSource.GetTile(tileInfo); Mbtiles.PopulateMbtilesWith(tile, tileInfo, dbpath); } catch (Exception e) { Console.WriteLine(e); } finally { MessagingCenter.Send <Application>(App.Current, "TileSavedInternal"); } } else { MessagingCenter.Send <Application>(App.Current, "TileSavedInternal"); } }
private static List <IFeature> TileIndexToFeatures(TileIndex[] tileIndexes, ITileSource tileSource) { var features = new List <IFeature>(); foreach (var tileIndex in tileIndexes) { var tileInfo = new TileInfo { Index = tileIndex, Extent = TileTransform.TileToWorld( new TileRange(tileIndex.Col, tileIndex.Row), tileIndex.Level, tileSource.Schema) }; var feature = new Feature { Geometry = new Raster(new MemoryStream( tileSource.GetTile(tileInfo)), tileInfo.Extent.ToBoundingBox()) }; features.Add(feature); } return(features); }
private Feature TileToFeature(ITileSource tileProvider, TileInfo tileInfo) { var tile = tileProvider.GetTile(tileInfo); return(new Feature()); }
private void Process(ITileSource source, Extent extent, out Dictionary <BruTile.TileInfo, byte[]> tiles, //IRequest request = null, string levelId = null) { int levelId_int = -1; if (!string.IsNullOrEmpty(levelId)) { if (!int.TryParse(levelId, out levelId_int)) { Debug.LogErrorFormat("Could not parse levelId {0}", levelId); } } IEnumerable <TileInfo> tileInfos = null; if (extent == null) { extent = new BruTile.Extent(-20037508, -20037508, 20037508, 20037508); } if (levelId_int != -1) { tileInfos = source.Schema.GetTileInfos(extent, levelId); } else { const int screenWidthInPixels = 400; // The width of the map on screen in pixels var unitsPerPixel = extent.Width / screenWidthInPixels; tileInfos = source.Schema.GetTileInfos(extent, unitsPerPixel); } tiles = new Dictionary <BruTile.TileInfo, byte[]>(); //var tileUris = new Dictionary<BruTile.TileInfo, Uri>(); int count = 0; foreach (var tileInfo in tileInfos) { try { tiles[tileInfo] = source.GetTile(tileInfo); //if (request != null) // tileUris[tileInfo] = request.GetUri(tileInfo); } catch (HttpRequestException e) { Debug.LogException(e); } ++count; } //int i = 0; //foreach (var kvp in tiles) //{ // var tileInfo = kvp.Key; // var bytes = kvp.Value; // if (bytes == null) // continue; // //int width = source.Schema.GetTileWidth(tileInfo.Index.Level); // //int height = source.Schema.GetTileHeight(tileInfo.Index.Level); // ++i; //} if (VerboseLogging) { PrintTiles(ref tiles); } }
private Texture2D[] Process(ITileSource source, //IRequest request = null, string levelId = null) { int levelId_int = -1; if (!string.IsNullOrEmpty(levelId)) { if (!int.TryParse(levelId, out levelId_int)) { Debug.LogErrorFormat("Could not parse levelId {0}", levelId); } } IEnumerable <TileInfo> tileInfos = null; var extent = new BruTile.Extent(-20037508, -20037508, 20037508, 20037508); if (levelId_int != -1) { tileInfos = source.Schema.GetTileInfos(extent, levelId); } else { const int screenWidthInPixels = 400; // The width of the map on screen in pixels var unitsPerPixel = extent.Width / screenWidthInPixels; tileInfos = source.Schema.GetTileInfos(extent, unitsPerPixel); } var tiles = new Dictionary <BruTile.TileInfo, byte[]>(); var tileUris = new Dictionary <BruTile.TileInfo, Uri>(); int count = 0; foreach (var tileInfo in tileInfos) { try { tiles[tileInfo] = source.GetTile(tileInfo); //if (request != null) // tileUris[tileInfo] = request.GetUri(tileInfo); } catch (HttpRequestException e) { Debug.LogException(e); } ++count; } var textureTest = new Texture2D[count]; int i = 0; foreach (var kvp in tiles) { var tileInfo = kvp.Key; var bytes = kvp.Value; if (bytes == null) { continue; } int width = source.Schema.GetTileWidth(tileInfo.Index.Level); int height = source.Schema.GetTileHeight(tileInfo.Index.Level); if (source.Schema.Format.ToLower().EndsWith("png")) { textureTest[i] = Load_PNG_or_JPG(width, height, bytes); } else if (source.Schema.Format.ToLower().EndsWith("jpg") || source.Schema.Format.ToLower().EndsWith("jpeg")) { textureTest[i] = Load_PNG_or_JPG(width, height, bytes); } ++i; } if (VerboseLogging) { PrintTiles(ref tiles); } return(textureTest); }