void OnSwitchChange(object sender, EventArgs e) { MapSwitch item = (MapSwitch)sender; UpdateBaseLayer(new Section { OSM = new NameValuePair { Value = currentOSM }, Type = SectionType.None }, currentSelection); }
MapSwitch GetSwitch(string text, string name) { int screenWidth = context.Resources.DisplayMetrics.WidthPixels; int padding = (int)(screenWidth * 0.05); int width = (int)(screenWidth / 2); MapSwitch view = new MapSwitch(context); view.Text = text; view.ParameterName = name; var parameters = new LinearLayout.LayoutParams(width, (int)(width / 5), 1); parameters.LeftMargin = padding; parameters.TopMargin = (int)(padding * 0.75f); view.LayoutParameters = parameters; return(view); }
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); } else if (section.Type == SectionType.None) { // Switch was tapped } if (currentOSM == "nutiteq.osm") { var decoder = ((currentLayer as CartoOnlineVectorTileLayer).TileDecoder as MBVectorTileDecoder); MapSwitch texts = ContentView.Menu.Texts3D; MapSwitch buildings = ContentView.Menu.Buildings3D; decoder.SetStyleParameter(texts.ParameterName, texts.IsChecked.ToString()); decoder.SetStyleParameter(buildings.ParameterName, buildings.IsChecked.ToString()); decoder.SetStyleParameter(texts.ParameterName, texts.ParameterValue); decoder.SetStyleParameter(buildings.ParameterName, texts.ParameterValue); } MapView.Layers.Clear(); MapView.Layers.Add(currentLayer); ContentView.Menu.Hide(); currentListener = null; // Random if case to remove "unused variable" warning if (currentListener != null) { currentListener.Dispose(); } currentListener = MapView.InitializeVectorTileListener(VectorLayer); }