public override byte[] GetTile(Capabilities capabilities, string path, GetTile getTile) { byte[] buffer = null; if (capabilities == null || string.IsNullOrWhiteSpace(path) || getTile == null) { return(buffer); } IMapLayer mapLayer = DataHelper.GetMapLayer(path); if (mapLayer != null) { LayerType layerType = capabilities.Contents?.DatasetDescriptionSummary?.FirstOrDefault(x => x.Identifier?.Value == getTile.Layer && x is LayerType) as LayerType; if (layerType != null) { BoundingBoxType boundingBoxType = layerType.BoundingBox?.Length > 0 ? layerType.BoundingBox[0] : layerType.WGS84BoundingBox?.Length > 0 ? layerType.WGS84BoundingBox[0] : null; string layerTileMatrixSetStr = layerType.TileMatrixSetLink[0].TileMatrixSet; TileMatrixSet layerTileMatrixSet = capabilities.Contents.TileMatrixSet?.FirstOrDefault(x => x.Identifier?.Value == layerTileMatrixSetStr); TileMatrix layerTileMatrix = layerTileMatrixSet.TileMatrix?.FirstOrDefault(x => x.Identifier.Value == getTile.TileMatrix); if (layerTileMatrix != null) { bool ret = WmtsHelper.ComputeTileBoundary(layerType, layerTileMatrix, getTile.TileCol, getTile.TileRow, out double tileXMin, out double tileYMin, out double tileXMax, out double tileYMax); if (ret) { Extent extent = new Extent(tileXMin, tileYMin, tileXMax, tileYMax); int tileWidth = Convert.ToInt32(layerTileMatrix.TileWidth); int tileHeight = Convert.ToInt32(layerTileMatrix.TileHeight); Rectangle rectangle = new Rectangle(0, 0, tileWidth, tileHeight); using (Bitmap bmp = GetBitmap(mapLayer, extent, rectangle)) { ImageFormat imageFormat = null; if (string.IsNullOrWhiteSpace(getTile.Format) || !getTile.Format.Contains('/')) { imageFormat = ImageFormat.Png; } else { string[] formatMimeArray = getTile.Format.Split('/'); switch (formatMimeArray[1]) { case "jpg": imageFormat = ImageFormat.Jpeg; break; default: imageFormat = ImageFormat.Png; break; } } buffer = GetBitmapBuffer(bmp, imageFormat); } } } } mapLayer.Dispose(); } return(buffer); }
public override void OnClick() { const string url = "https://bertt.github.io/wmts/capabilities/nokia.xml"; var wmtsLayer = WmtsHelper.GetWmtsLayer(_application, "png", url, "Nokia streets", "nokia-streets"); var mxdoc = (IMxDocument)_application.Document; var map = mxdoc.FocusMap; ((IMapLayers)map).InsertLayer(wmtsLayer, true, 0); }
public override void OnClick() { var mxdoc = (IMxDocument)_application.Document; var tileSource = KnownTileSources.Create(KnownTileSource.BingHybrid); var wmtsLayer = WmtsHelper.GetWmtsLayer(_application, tileSource, "Bing Hybrid"); var map = mxdoc.FocusMap; ((IMapLayers)map).InsertLayer(wmtsLayer, true, 0); }
static void Test() { double originX = 35383146.5; double originY = 3395525.5; double semimajor = 6378140.0; int level = 18; double x = 35405935.91222596; double y = 3366208.718846301; double falseEasting = 35500000.0; double falseNorthing = 0; var ret = WmtsHelper.GetTileIndexByProjection(originX, originY, semimajor, level, x, y, out int col, out int row, falseEasting, falseNorthing); }
public override void OnClick() { try { const string url = "https://bertt.github.io/wmts/capabilities/osm.xml"; var wmtsLayer = WmtsHelper.GetWmtsLayer(_application, "png", url, "OpenStreetMap.FR", "osm-openstreetmap.fr"); var mxdoc = (IMxDocument)_application.Document; var map = mxdoc.FocusMap; ((IMapLayers)map).InsertLayer(wmtsLayer, true, 0); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public override void OnClick() { try { const string url = "https://bertt.github.io/wmts/capabilities/thunderforest.xml"; var wmtsLayer = WmtsHelper.GetWmtsLayer(_application, "png", url, "Landscape", "thunderforest-landscape"); var mxdoc = (IMxDocument)_application.Document; var map = mxdoc.FocusMap; ((IMapLayers)map).InsertLayer(wmtsLayer, true, 0); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void AddStravaLayer(StravaColor stravaColor, StravaActivityType stravaActivityType) { const string url = "http://bertt.github.io/wmts/capabilities/strava2017.xml"; var wmtsLayer = WmtsHelper.GetWmtsLayer(_application, "png", url, $"Strava 2017 - {stravaActivityType.ToString()}", "strava-riding"); var prov = (HttpTileProvider)wmtsLayer.TileSource.Provider; foreach (var resourceUrl in ((WmtsRequest)prov.Request)._resourceUrls) { var template = resourceUrl.Template; template = template.Replace("{color}", stravaColor.ToString()); template = template.Replace("{activity_type}", stravaActivityType.ToString()); resourceUrl.Template = template; } var schema = (WmtsTileSchema)wmtsLayer.TileSource.Schema; schema.Layer = $"strava-{stravaColor.ToString()}-{stravaActivityType.ToString()}"; wmtsLayer.TileSource.Schema = schema; var mxdoc = (IMxDocument)_application.Document; var map = mxdoc.FocusMap; ((IMapLayers)map).InsertLayer(wmtsLayer, true, 0); }