Skip to content

Unexpected behaviour when projection is not specified in style #6817

@ztzthu

Description

@ztzthu

maplibre-gl-js version: 5.14.0 (latest)

Steps to Trigger Behavior

  1. In the style document if I do not specify the projection, then the default projection is mercator as per the documentation.
  2. In this case map.getProjection() returns undefined, which is understandable because the projection is not defined after all.
  3. I explicitly set the projection to mercator using map.setProjection()
  4. map.getProjection() still returns undefined - this is unexpected.
  5. Setting the projection to globe to an undefined projection has the correct behaviour though.

Link to Demonstration

Minimal example

Expected Behavior

  1. After map.setProjection({type: "mercator"}) to an undefined style, map.getProjection() should return mercator.
  2. If map.getProjection() is allowed to return undefined, then the wording in the style documentation

Optional projectionDefinition. Defaults to "mercator".

should be improved to

Optional projectionDefinition. If not specified the map will be rendered as if "mercator" projection is used.

Actual Behavior

See Steps to Trigger Behavior

Use-case

I had this problem because I wanted to define the projection based on zoom values. I also needed to dynamically set the projection at initialzation based on zoom level, hence there was no default projection defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions