Module 06 - Basemaps, Styles and the UI

Level 1 · Your First Maps · 🟒 Beginner · 3 hours · Prereq: Module 05


What you'll build

A basemap switcher with live previews, a custom basemap assembled from two layers, a light/dark theme that flips both the basemap and your own UI together, and a properly positioned widget layout with an Expand-collapsed panel.


Why this matters

The basemap is 90% of the pixels on screen and 100% of the first impression. It also drives:

  • The view's spatial reference (Module 05)
  • The visual contrast budget your data has to work within
  • A meaningful share of your tile bandwidth bill
  • Whether your dark mode looks intentional or looks like a bug

Choosing and controlling it properly is cheap. Getting it wrong makes every subsequent cartographic decision harder.


Concepts

1. Three ways to specify a basemap

// 1. A basemap STYLE name - the modern path, served by the basemap styles service
new Map({ basemap: "arcgis/navigation" });

// 2. A well-known legacy ID - still supported
new Map({ basemap: "topo-vector" });

// 3. A Basemap object you construct - full control
new Map({
  basemap: new Basemap({
    baseLayers: [ new VectorTileLayer({ ... }) ],
    referenceLayers: [ new VectorTileLayer({ ... }) ],
    title: "My basemap",
  }),
});

Prefer style names. They resolve to the current, maintained tile sets, support language and worldview parameters, and are what Esri actively develops.

2. The basemap style catalogue

Style Character Good for
arcgis/navigation Muted, road-forward General purpose, the safest default
arcgis/navigation-night Dark road map Dark mode
arcgis/streets Classic street map Urban context
arcgis/topographic Terrain + contours Outdoors, environmental
arcgis/outdoor Trails, parks emphasised Recreation
arcgis/light-gray Near-monochrome, very low contrast Data-heavy maps - your data pops
arcgis/dark-gray Dark monochrome Dark data maps
arcgis/imagery Satellite/aerial, no labels Verification, context
arcgis/imagery/standard Imagery only Compositing your own labels
arcgis/imagery/labels Labels only (a reference layer) Overlaying on imagery
arcgis/oceans Bathymetry Marine
arcgis/human-geography Very light, population-focused Demographic analysis
arcgis/human-geography-dark Dark equivalent Dark demographic maps
arcgis/charted-territory Nautical-chart aesthetic Editorial, distinctive
arcgis/nova Dark, high-chroma Data viz with bright symbols
osm/standard OpenStreetMap No Esri credits consumed
osm/standard-relief OSM + hillshade Terrain context without imagery

The single most useful cartographic rule in this course: if your map is about your data, use light-gray or dark-gray. Every other basemap competes with your symbols for attention. Navigation-style basemaps are for when the basemap is the content.

3. Style parameters - language, worldview, places

import Basemap from "@arcgis/core/Basemap.js";

const basemap = new Basemap({
  style: {
    id: "arcgis/navigation",
    language: "fr",          // label language
    worldview: "morocco",    // disputed-boundary rendering per country's view
    places: "attributed",    // include POIs
  },
});

worldview is not a cosmetic setting. Boundaries in Kashmir, Crimea and Western Sahara are rendered differently depending on which country's official position you select. If you publish in multiple markets, this is a legal and diplomatic consideration, not a styling one. Defaults to a neutral view.

language accepts "global" (local script per region) or an ISO code (en, fr, es, ar, zh-hk, …).

4. baseLayers and referenceLayers

A Basemap has two layer collections and they sandwich your data:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  referenceLayers   (labels)    β”‚  ← drawn ON TOP of your data
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  map.layers        (your data) β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  baseLayers        (imagery)   β”‚  ← drawn UNDER your data
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

This is why labels stay readable over your polygons. It is also how you build "imagery with labels on top of my choropleth":

import Basemap from "@arcgis/core/Basemap.js";
import VectorTileLayer from "@arcgis/core/layers/VectorTileLayer.js";
import TileLayer from "@arcgis/core/layers/TileLayer.js";

const hybrid = new Basemap({
  baseLayers: [
    new TileLayer({
      url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
    }),
  ],
  referenceLayers: [
    new VectorTileLayer({
      url: "https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer",
    }),
  ],
  title: "Imagery with labels",
  thumbnailUrl: "…optional, used by BasemapGallery…",
});

5. Basemap-related widgets

Widget What it does
BasemapToggle Two-state switch between the current and one alternative
BasemapGallery Grid of thumbnails; source can be a portal group or an explicit array
BasemapLayerList Tree of the current basemap's base and reference layers, individually toggleable
import BasemapGallery from "@arcgis/core/widgets/BasemapGallery.js";

const gallery = new BasemapGallery({
  view,
  source: {
    // A portal group of basemaps, or:
    // basemaps: [Basemap, Basemap, ...] for an explicit list
    query: { id: "ca23a6dabaa14a6699b1a44e5c76fc0b" },   // Esri's default basemap group
  },
});

6. Expand - how to have many widgets without a cluttered map

import Expand from "@arcgis/core/widgets/Expand.js";

view.ui.add(
  new Expand({
    view,
    content: gallery,
    expandIcon: "basemap",      // a Calcite icon name
    expandTooltip: "Change basemap",
    group: "top-right",          // widgets sharing a group auto-collapse each other
    expanded: false,
  }),
  "top-right"
);

The group property is the good bit. Give every Expand in a corner the same group and opening one closes the others. Without it, users end up with three overlapping panels.

7. view.ui.components - controlling the defaults

console.log(view.ui.components);
// MapView default: ["attribution", "zoom", "navigation-toggle", "compass"]

view.ui.components = ["attribution", "zoom"];   // keep attribution, drop the rest
view.ui.components = [];                        // remove all defaults (incl. attribution)

Do not silently drop attribution. Esri's terms require basemap attribution to be visible. If the default widget doesn't fit your design, render your own - read view.map.basemap.baseLayers.map(l => l.attributionDataUrl) or use the Attribution widget positioned where you want it.

8. Theming - the part that bites

The SDK ships light and dark themes as separate stylesheets. You load one. Switching at runtime means swapping the stylesheet, not toggling a class:

// src/theme.js
const THEMES = {
  light: () => import("@arcgis/core/assets/esri/themes/light/main.css"),
  dark:  () => import("@arcgis/core/assets/esri/themes/dark/main.css"),
};

That works but is awkward. The pattern most production apps use - including this repository - is: load one SDK theme, then override the specific CSS custom properties that matter.

/* Calcite design tokens the SDK widgets read */
.dark-mode {
  --calcite-color-background:    #060b18;
  --calcite-color-foreground-1:  #0d1628;
  --calcite-color-foreground-2:  #0e1a2e;
  --calcite-color-foreground-3:  #111e35;
  --calcite-color-border-1:      #162544;
  --calcite-color-text-1:        #f0f4fa;
  --calcite-color-text-2:        #b9c4d6;
}

Critical gotcha, and you will meet it in Level 4: CSS custom properties do not cascade into shadow DOM in all the cases you expect. Several ArcGIS widgets render inside shadow roots. When a token set works on some widgets and not others, that's why - the fix is to inject the properties onto the shadow host element from JavaScript. This repository does exactly that in WebSceneViewer.jsx. Full treatment in Module 20.


Build it

Step 1 - Basemap switcher with previews

// src/basemaps.js
export const BASEMAPS = [
  { id: "arcgis/navigation",      label: "Navigation", theme: "light" },
  { id: "arcgis/light-gray",      label: "Light Gray", theme: "light" },
  { id: "arcgis/topographic",     label: "Topographic", theme: "light" },
  { id: "arcgis/imagery",         label: "Imagery",     theme: "dark"  },
  { id: "arcgis/dark-gray",       label: "Dark Gray",   theme: "dark"  },
  { id: "arcgis/navigation-night",label: "Night",       theme: "dark"  },
  { id: "osm/standard",           label: "OpenStreetMap", theme: "light" },
];
// src/main.js
import Basemap from "@arcgis/core/Basemap.js";
import { BASEMAPS } from "./basemaps.js";

const listEl = document.getElementById("basemapList");

for (const entry of BASEMAPS) {
  const button = document.createElement("button");
  button.type = "button";
  button.className = "bm";
  button.dataset.id = entry.id;
  button.innerHTML = `
    <img alt="" width="64" height="44" src="${previewUrl(entry.id)}" />
    <span>${entry.label}</span>
  `;

  button.addEventListener("click", () => {
    map.basemap = entry.id;        // autocast: a string becomes a Basemap
    setTheme(entry.theme);
    markActive(entry.id);
  });

  listEl.append(button);
}

/**
 * A static-map thumbnail for the style, generated by the basemap styles service.
 * Cheaper and always in sync compared to shipping our own PNGs.
 */
function previewUrl(styleId) {
  const params = new URLSearchParams({
    center: "-76.481,44.231",
    zoom: "11",
    width: "128",
    height: "88",
    token: import.meta.env.VITE_ARCGIS_API_KEY,
  });
  return `https://static-map-tiles-api.arcgis.com/arcgis/rest/services/static-basemap-tiles-service/v1/${styleId}/static?${params}`;
}

function markActive(id) {
  for (const el of listEl.querySelectorAll(".bm")) {
    el.classList.toggle("bm--active", el.dataset.id === id);
  }
}

map.basemap = "arcgis/imagery" autocasts a string into a Basemap. Same mechanism as symbols. The view then reloads its base and reference layers.

Watch the network tab while switching. Note that the previously-loaded tiles are not discarded - switch back and it's instant. The SDK keeps a basemap cache.

Step 2 - Theme that follows the basemap

// src/theme.js
export function setTheme(theme) {
  document.body.classList.toggle("theme-dark", theme === "dark");
  document.body.classList.toggle("theme-light", theme !== "dark");
}
:root {
  --panel-bg: #ffffff;
  --panel-fg: #1a1a1a;
  --panel-muted: #6b7280;
  --panel-border: #e5e7eb;
  --accent: #0066ff;
}

body.theme-dark {
  --panel-bg: #0d1628;
  --panel-fg: #f0f4fa;
  --panel-muted: #93a3bd;
  --panel-border: rgba(255, 255, 255, 0.12);
  --accent: #ffc107;

  /* Calcite tokens so SDK widgets follow */
  --calcite-color-background:   #060b18;
  --calcite-color-foreground-1: #0d1628;
  --calcite-color-foreground-2: #0e1a2e;
  --calcite-color-foreground-3: #111e35;
  --calcite-color-border-1:     #162544;
  --calcite-color-text-1:       #f0f4fa;
  --calcite-color-text-2:       #b9c4d6;
}

#panel {
  background: var(--panel-bg);
  color: var(--panel-fg);
  border: 1px solid var(--panel-border);
}
#panel label { color: var(--panel-muted); }
.bm--active { outline: 2px solid var(--accent); }

Never hardcode #0066ff in a component. Define the accent once as a token and use var(--accent) everywhere. This repository learned that the hard way - see the "Accent tokens" section of its CLAUDE.md. Switching themes then costs one class toggle instead of a find-and-replace.

Step 3 - Build a custom basemap

import Basemap from "@arcgis/core/Basemap.js";
import TileLayer from "@arcgis/core/layers/TileLayer.js";
import VectorTileLayer from "@arcgis/core/layers/VectorTileLayer.js";

const imageryWithLabels = new Basemap({
  title: "Imagery + labels",
  id: "custom-hybrid",
  baseLayers: [
    new TileLayer({
      url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
      title: "World Imagery",
    }),
  ],
  referenceLayers: [
    new VectorTileLayer({
      url: "https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer",
      title: "Labels",
      opacity: 0.9,
    }),
  ],
});

document.getElementById("customBasemap").addEventListener("click", () => {
  map.basemap = imageryWithLabels;
  setTheme("dark");
});

Why build one manually when arcgis/imagery exists? Because you may need a specific imagery vintage, a private tile service, an OGC WMTS, or your own cached basemap. Once you know that a Basemap is just two layer collections, "the basemap I need doesn't exist" stops being a blocker.

Step 4 - Toggle individual basemap sub-layers

import BasemapLayerList from "@arcgis/core/widgets/BasemapLayerList.js";
import Expand from "@arcgis/core/widgets/Expand.js";

const basemapLayers = new BasemapLayerList({
  view,
  visibleElements: { statusIndicators: true },
});

view.ui.add(
  new Expand({
    view,
    content: basemapLayers,
    expandIcon: "layers",
    expandTooltip: "Basemap layers",
    group: "top-right",
  }),
  "top-right"
);

Switch to the custom hybrid and open this. You can now turn the labels off independently of the imagery - which is exactly what the reference/base split buys you.

Step 5 - A proper widget layout

import Legend from "@arcgis/core/widgets/Legend.js";
import LayerList from "@arcgis/core/widgets/LayerList.js";
import Search from "@arcgis/core/widgets/Search.js";
import ScaleBar from "@arcgis/core/widgets/ScaleBar.js";
import Fullscreen from "@arcgis/core/widgets/Fullscreen.js";

// Replace the defaults with a considered set
view.ui.components = ["attribution", "zoom", "compass"];

// Search is a primary action - always visible, top-left, first
view.ui.add(new Search({ view }), { position: "top-left", index: 0 });

// Secondary panels - collapsed, grouped so only one opens at a time
const panels = [
  { content: new LayerList({ view }), icon: "layers",  tip: "Layers"  },
  { content: new Legend({ view }),    icon: "legend",  tip: "Legend"  },
  { content: basemapLayers,           icon: "basemap", tip: "Basemap" },
];

for (const panel of panels) {
  view.ui.add(
    new Expand({
      view,
      content: panel.content,
      expandIcon: panel.icon,
      expandTooltip: panel.tip,
      group: "top-right",
      expanded: false,
    }),
    "top-right"
  );
}

view.ui.add(new ScaleBar({ view, unit: "metric", style: "ruler" }), "bottom-left");
view.ui.add(new Fullscreen({ view }), "bottom-right");

The layout reasoning, which is the point of the step:

Position Contains Why
top-left Search, zoom, compass Primary navigation. Left-to-right reading order puts the main action first
top-right Collapsed panels (grouped) Secondary tools; collapsed so they don't eat the map
bottom-left Scale bar Reference information, conventional position, low salience
bottom-right Fullscreen, attribution Chrome. Furthest from where users look

Do not scatter widgets. A map with eight always-open panels is unusable, and the Expand

  • group combination costs three lines.

How it works

What a basemap style actually resolves to

When you write basemap: "arcgis/navigation", the SDK:

  1. Requests the style descriptor from https://basemaps-api.arcgis.com/arcgis/rest/services/styles/v2/styles/arcgis/navigation?token=…
  2. Gets back a Mapbox-GL-style JSON: sources, sprite URL, glyphs URL, and a layers array of paint/layout rules
  3. Constructs VectorTileLayers for the sources
  4. Reads the tile grid's spatial reference (Web Mercator) and hands it to the view
  5. Starts requesting .pbf tiles

You can inspect the style JSON. Paste that URL with your key into a browser tab. It is a few thousand lines of cartography-as-data. Reading it once is genuinely educational - you can see how road hierarchies, label priorities and zoom-dependent widths are expressed.

Why raster and vector basemaps behave differently at fractional zoom

Raster tiles exist only at integer zoom levels. At zoom 13.4 the renderer scales the z=13 tiles by 1.32Γ— and they go slightly soft.

Vector tiles are geometry, so the renderer re-tessellates at the exact scale. Text stays crisp, line widths stay correct. This is why snapToZoom: false (smooth wheel zoom) looks good on a vector basemap and mushy on imagery.

Why switching basemaps can change your view's spatial reference

The view adopts the basemap's spatial reference at initialisation. If you swap to a basemap in a different projection after the view is up, the SDK cannot re-project a live view - it will refuse the swap and log a warning:

The spatial reference of the new basemap does not match the view's spatial reference.

Almost every web basemap is Web Mercator, so you'll rarely hit it. When you do - usually a national grid basemap - you must recreate the view.


Common mistakes

Using a busy basemap under dense data. arcgis/streets under 10,000 coloured points is unreadable. light-gray and the same data is a map. Cartography before code.

Deleting the attribution widget. Licence violation, and it's usually the reviewer's first comment.

Hardcoding theme colours in each component. Define tokens once. This repo's CLAUDE.md documents an entire class of bug that came from an OS dark-mode preference leaking through un-pinned tokens.

Assuming CSS variables reach every widget. Shadow DOM. See Module 20.

Building a custom basemap when a style parameter would do. Want French labels? style: { id: "arcgis/navigation", language: "fr" }. Don't assemble layers by hand for something the service supports.

Adding six always-expanded widgets. Use Expand with a shared group.


Exercises

Exercise 06.1 - The contrast test

Load the US Major Cities layer (URL in RESOURCES.md) with large red circle symbols. View it over each of: navigation, light-gray, imagery, dark-gray, charted-territory.

Screenshot each. Rank them for legibility and write one sentence on why the winner won. Keep this - it's the reference you'll want in Level 3.

Exercise 06.2 - Localised basemaps

Build a language switcher offering English, French, Spanish and Arabic, rebuilding the Basemap with the language style parameter each time.

Then answer: why does changing the language require constructing a new Basemap rather than setting a property on the existing one?

Exercise 06.3 - Basemap from OGC

Build a Basemap whose base layer is a WMTS service (try https://www.terrestris.de/en/openstreetmap-wms/ or your national mapping agency's).

You'll need WMTSLayer. Note what breaks and what you have to specify manually - this exercise is really about the gap between Esri services and open standards, which you will meet in real integration work.

Exercise 06.4 - Persist the preference

Store the chosen basemap and theme in localStorage, restore on load, and respect prefers-color-scheme on first visit only.

Careful with the last part: an explicit user choice must win over the OS preference on every subsequent visit. Write down the precedence rule before you code it.


Checkpoint

  1. What's the difference between baseLayers and referenceLayers, and what does the split buy you?
  2. When would you choose arcgis/light-gray over arcgis/navigation?
  3. What does the worldview style parameter control, and why is it not cosmetic?
  4. Why can't you always change a view's basemap to one in a different spatial reference?
  5. What does Expand's group property do?
  6. Why might a CSS custom property fail to reach an ArcGIS widget?
  1. baseLayers draw beneath your operational layers; referenceLayers (labels, boundaries) draw on top. It keeps labels legible over your data and lets you toggle labels independently of imagery.
  2. When the map is about your data. Low-contrast basemaps leave the visual budget for your symbols; navigation styles compete with them.
  3. How disputed international boundaries are drawn, matching a given country's official position. It has legal/diplomatic implications in some markets.
  4. The view adopts the basemap's spatial reference at init and cannot re-project a live view. A mismatched swap is refused with a console warning; you must rebuild the view.
  5. Widgets sharing a group string auto-collapse each other, so only one panel is open at a time.
  6. The widget's content is inside a shadow root that the property doesn't pierce. The fix is to set the property on the shadow host from JS. (Module 20.)

Further reading


Next: Module 07 - Map Components: the Web Component API