protected virtual TileDataSource CreateTileDataSource() { TileDataSource vectorTileDataSource = new CartoOnlineTileDataSource("nutiteq.osm"); // We don't use vectorTileDataSource directly (this would be also option), // but via caching to cache data locally persistently/non-persistently // Note that persistent cache requires WRITE_EXTERNAL_STORAGE permission TileDataSource cacheDataSource = vectorTileDataSource; if (persistentTileCache) { string cacheFile = GetExternalFilesDir(null) + "/mapcache.db"; cacheDataSource = new PersistentCacheTileDataSource(vectorTileDataSource, cacheFile); } else { cacheDataSource = new MemoryCacheTileDataSource(vectorTileDataSource); } return(cacheDataSource); }
void UpdateBaseLayer(Section section, string selection) { if (section.Type != SectionType.Language) { currentOSM = section.OSM.Value; currentSelection = selection; } if (section.Type == SectionType.Vector) { if (currentOSM == "nutiteq.osm") { // Nutiteq styles are bundled with the SDK, we can initialize them via constuctor if (currentSelection == "default") { currentLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDefault); } else if (currentSelection == "gray") { currentLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleGray); } else { currentLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDark); } } else if (currentOSM == "mapzen.osm") { // Mapzen styles are all bundled in one .zip file. // Selection contains both the style name and file name (cf. Sections.cs in Shared) string fileName = currentSelection.Split(':')[0]; string styleName = currentSelection.Split(':')[1]; // Create a style set from the file and style BinaryData styleAsset = AssetUtils.LoadAsset(fileName + ".zip"); var package = new ZippedAssetPackage(styleAsset); CompiledStyleSet styleSet = new CompiledStyleSet(package, styleName); // Create datasource and style decoder var source = new CartoOnlineTileDataSource(currentOSM); var decoder = new MBVectorTileDecoder(styleSet); currentLayer = new VectorTileLayer(source, decoder); } ContentView.Menu.LanguageChoiceEnabled = true; ResetLanguage(); } else if (section.Type == SectionType.Raster) { // We know that the value of raster will be Positron or Darkmatter, // as Nutiteq and Mapzen use vector tiles // Additionally, raster tiles do not support language choice string url = (currentSelection == "positron") ? Urls.Positron : Urls.DarkMatter; TileDataSource source = new HTTPTileDataSource(1, 19, url); currentLayer = new RasterTileLayer(source); // Language choice not enabled in raster tiles ContentView.Menu.LanguageChoiceEnabled = false; } else if (section.Type == SectionType.Language) { if (currentLayer is RasterTileLayer) { // Raster tile language chance is not supported return; } UpdateLanguage(selection); } MapView.Layers.Clear(); MapView.Layers.Add(currentLayer); ContentView.Menu.Hide(); currentListener = null; currentListener = MapView.InitializeVectorTileListener(VectorLayer); }
void UpdateBaseLayer(Section section, string selection) { if (section.Type != SectionType.Language) { currentOSM = section.OSM.Value; currentSelection = selection; } if (section.Type == SectionType.Vector) { if (currentOSM == "nutiteq.osm") { // Nutiteq styles are bundled with the SDK, we can initialize them via constuctor if (currentSelection == "default") { currentLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDefault); } else if (currentSelection == "gray") { currentLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleGray); } else { currentLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDark); } } else if (currentOSM == "mapzen.osm") { // Mapzen styles are all bundled in one .zip file. // Selection contains both the style name and file name (cf. Sections.cs in Shared) string fileName = currentSelection.Split(':')[0]; string styleName = currentSelection.Split(':')[1]; // Create a style set from the file and style BinaryData styleAsset = AssetUtils.LoadAsset("styles/" + fileName + ".zip"); var package = new ZippedAssetPackage(styleAsset); CompiledStyleSet styleSet = new CompiledStyleSet(package, styleName); // Create datasource and style decoder var source = new CartoOnlineTileDataSource(currentOSM); var decoder = new MBVectorTileDecoder(styleSet); currentLayer = new VectorTileLayer(source, decoder); } Menu.LanguageChoiceEnabled = true; ResetLanguage(); } else if (section.Type == SectionType.Raster) { // We know that the value of raster will be Positron or Darkmatter, // as Nutiteq and Mapzen use vector tiles // Additionally, raster tiles do not support language choice string url = (currentSelection == "positron") ? Urls.Positron : Urls.DarkMatter; TileDataSource source = new HTTPTileDataSource(1, 19, url); currentLayer = new RasterTileLayer(source); // Language choice not enabled in raster tiles Menu.LanguageChoiceEnabled = false; } else if (section.Type == SectionType.Language) { if (currentLayer is RasterTileLayer) { // Raster tile language chance is not supported return; } UpdateLanguage(selection); } MapView.Layers.Clear(); MapView.Layers.Add(currentLayer); Menu.Hide(); currentListener = null; currentListener = MapView.InitializeVectorTileListener(VectorLayer); }
public static void Update(this MapView MapView, bool withListener, byte[] data, Action completed, Action <string> failed = null) { System.Threading.Tasks.Task.Run(delegate { var sourceId = Parser.GetSourceFromData(data); BinaryData styleAsset = new BinaryData(data); var package = new ZippedAssetPackage(styleAsset); var styleSet = new CompiledStyleSet(package); // UWP doesn't have a version released where simply changing the style set is supported, // need to clear layers and recreate the entire thing #if __UWP__ MapView.Layers.Clear(); var source = new CartoOnlineTileDataSource(OSM); var decoder = new MBVectorTileDecoder(styleSet); var layer = new VectorTileLayer(source, decoder); Device.BeginInvokeOnMainThread(delegate { MapView.Layers.Add(layer); if (completed != null) { completed(); } }); #else if (MapView.Layers.Count == 0) { if (sourceId == null) { sourceId = DefaultSourceId; } var source = new CartoOnlineTileDataSource(sourceId); MBVectorTileDecoder decoder = null; try { decoder = new MBVectorTileDecoder(styleSet); } catch (System.ApplicationException e) { if (failed != null) { failed(e.Message); return; } } var layer = new VectorTileLayer(source, decoder); if (withListener) { var popupSource = new LocalVectorDataSource(MapView.Options.BaseProjection); var popupLayer = new VectorLayer(popupSource); MapView.Layers.Add(popupLayer); layer.VectorTileEventListener = new VectorEventListener(popupSource); } Device.BeginInvokeOnMainThread(delegate { MapView.Layers.Add(layer); if (completed != null) { completed(); } }); } else { var decoder = (MBVectorTileDecoder)(MapView.Layers[MapView.Layers.Count - 1] as VectorTileLayer).TileDecoder; Device.BeginInvokeOnMainThread(delegate { decoder.CompiledStyle = styleSet; if (completed != null) { completed(); } }); } #endif }); }
protected virtual TileDataSource CreateTileDataSource(string osm) { TileDataSource source = new CartoOnlineTileDataSource(osm); return(new MemoryCacheTileDataSource(source)); }