Skip to content

Add support for authorization header#138

Merged
giswqs merged 1 commit intomainfrom
header
Nov 23, 2025
Merged

Add support for authorization header#138
giswqs merged 1 commit intomainfrom
header

Conversation

@giswqs
Copy link
Copy Markdown
Member

@giswqs giswqs commented Nov 23, 2025

import anymap

# Create a map with authorization headers
m = anymap.Map(
    center=[-74.0060, 40.7128],
    zoom=12,
    request_headers={"Authorization": "Bearer YOUR_TOKEN_HERE"},
)

m

Copilot AI review requested due to automatic review settings November 23, 2025 01:13
@github-actions
Copy link
Copy Markdown

@github-actions github-actions Bot temporarily deployed to pull request November 23, 2025 01:14 Inactive
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for custom HTTP headers (specifically authorization headers) to MapLibreMap, enabling access to private tile servers that require authentication. The implementation uses MapLibre GL JS's transformRequest callback to inject custom headers into all tile requests.

Key changes:

  • Added request_headers parameter to MapLibreMap for passing custom HTTP headers
  • Implemented transformRequest callback in JavaScript to apply headers to tile requests
  • Created comprehensive documentation with examples showing various authentication scenarios

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
anymap/maplibre.py Added request_headers traitlet with documentation in the class docstring
anymap/static/maplibre_widget.js Implemented transformRequest callback to inject custom headers into tile requests
docs/examples/maplibre/authorization_headers_example.ipynb Added comprehensive notebook with 6 examples demonstrating authorization header usage
Comments suppressed due to low confidence (1)

anymap/maplibre.py:134

  • The request_headers parameter is missing from the __init__ method signature. While it can be passed via **kwargs, it should be an explicit parameter for better API discoverability and type checking. Add request_headers: Dict[str, str] = None to the parameter list and include it in the Args section of the docstring.
    def __init__(
        self,
        center: List[float] = [0, 20],
        zoom: float = 1.0,
        style: Union[str, Dict[str, Any]] = "dark-matter",
        width: str = "100%",
        height: str = "680px",
        bearing: float = 0.0,
        pitch: float = 0.0,
        controls: Dict[str, str] = {
            "navigation": "top-right",
            "fullscreen": "top-right",
            "scale": "bottom-left",
            "globe": "top-right",
            "layers": "top-right",
        },
        projection: str = "mercator",
        add_sidebar: bool = False,
        sidebar_visible: bool = False,
        sidebar_width: int = 360,
        sidebar_args: Optional[Dict] = None,
        layer_manager_expanded: bool = True,
        **kwargs: Any,
    ) -> None:

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread anymap/static/maplibre_widget.js
@giswqs giswqs merged commit 605baa3 into main Nov 23, 2025
15 checks passed
@giswqs giswqs deleted the header branch November 23, 2025 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants