Change basemap

This sample demonstrates how to dynamically change the basemap displayed in a Map.

Change basemap


// Copyright 2016 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific 
// language governing permissions and limitations under the License.

using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Linq;

namespace ArcGISRuntimeXamarin.Samples.ChangeBasemap
    public class ChangeBasemap : Activity
        // Create and hold reference to the used MapView
        private MapView _myMapView = new MapView();

        // String array to store basemap constructor types
        private string[] _basemapTypes = new string[]

        protected override void OnCreate(Bundle bundle)

            Title = "Change basemap";

            // Create the UI, setup the control references and execute initialization 

        private void Initialize()
            // Create new Map with basemap
            Map myMap = new Map(Basemap.CreateTopographic());
            // Provide used Map to the MapView
            _myMapView.Map = myMap;

        private void OnBasemapsClicked(object sender, EventArgs e)
            var mapsButton = sender as Button;

            // Create menu to show map options
            var mapsMenu = new PopupMenu(this, mapsButton);
            mapsMenu.MenuItemClick += OnBasemapsMenuItemClicked;

            // Create menu options
            foreach (var basemapType in _basemapTypes)

            // Show menu in the view

        private void OnBasemapsMenuItemClicked(object sender, PopupMenu.MenuItemClickEventArgs e)
            // Get title from the selected item
            var selectedBasemapType = e.Item.TitleCondensedFormatted.ToString();

            // Get index that is used to get the selected url
            var selectedIndex = _basemapTypes.ToList().IndexOf(selectedBasemapType);

            switch (selectedIndex)
                case 0:
                    // Set the basemap to Topographic
                    _myMapView.Map.Basemap = Basemap.CreateTopographic();

                case 1:
                    // Set the basemap to Streets
                    _myMapView.Map.Basemap = Basemap.CreateStreets();

                case 2:
                    // Set the basemap to Imagery
                    _myMapView.Map.Basemap = Basemap.CreateImagery();

                case 3:
                    // Set the basemap to Oceans
                    _myMapView.Map.Basemap = Basemap.CreateOceans();

        private void CreateLayout()
            // Create a new vertical layout for the app
            var layout = new LinearLayout(this) { Orientation = Orientation.Vertical };

            // Create button to show possible map options
            var mapsButton = new Button(this);
            mapsButton.Text = "Basemaps";
            mapsButton.Click += OnBasemapsClicked;
            // Add maps button to the layout

            // Add the map view to the layout

            // Show the layout in the app

In this topic
  1. Code