Skip to content

Feature: Expose the original style URL via map.getStyleUrl() #7109

@giswqs

Description

@giswqs

User Story

As a plugin developer, I can retrieve the original style URL used to initialize the map, so that I can fetch the original basemap style and identify which layers came from the basemap vs. layers added dynamically.

Rationale

Why is this feature needed?

When a map is initialized with a style URL, that URL is not accessible later. The map.getStyle() method returns the current style object which includes all layers - both from the original basemap and any layers added dynamically via map.addLayer(). There's no way to distinguish between them.

Example use cases

  • Layer control plugins that want to group basemap layers as a single "Basemap" entry while listing user-added layers individually
  • Style management tools that need to know what basemap is being used
  • Map state serialization that needs to store the original style URL separately from dynamic modifications

Current workaround

Currently, developers must either:

  1. Ask users to manually provide the style URL as a separate option
  2. Track the style URL themselves before passing it to the Map constructor
  3. Have no way to identify original basemap layers

Impact

Without this feature, plugin developers cannot reliably identify which layers came from the original basemap style. This forces either:

  • Manual configuration by end users (poor developer experience)
  • Complex workarounds that require intercepting map initialization
  • Inability to provide features that distinguish basemap from user layers

Proposed API

// Get the style URL (returns undefined if style was provided as object)
const styleUrl = map.getStyleUrl();

// After setStyle() with a URL, it would update accordingly
map.setStyle('https://example.com/style.json');
map.getStyleUrl(); // 'https://example.com/style.json'

// If style was set as an object, returns undefined
map.setStyle({ version: 8, sources: {}, layers: [] });
map.getStyleUrl(); // undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions