open-index/open-npm huggingface dataset:
npm package: @jawg/map-session
Description: Map session for the Jawg MapLoad pricing
Author: Jawg Maps
Latest version: 1.0.0

![Jawg Logo](https://media.jawg.io/logo/jawgmaps-blue.svg)

# MapSession

[![npm](https://img.shields.io/npm/v/@jawg/map-session)](https://www.npmjs.com/package/@jawg/map-session)

Generate a map session token and authenticate request URLs for the JawgMaps mapload pricing with [MapLibre GL JS](https://github.com/maplibre/maplibre-gl-js).

> Note that your account requires the per-mapload pricing to be enabled.
> Please contact us at [contact@jawg.io](mailto:contact@jawg.io) for more information.

## Install

Available via npm as the package [@jawg/map-session](https://www.npmjs.com/package/@jawg/map-session).

```sh
npm i @jawg/map-session
```

or

```sh
yarn add @jawg/map-session
```

Alternatively you may add the umd package directly to the html document using the unpkg link.

```html
<script src="https://unpkg.com/@jawg/map-session@1.0.0/dist/map-session.js"></script>
```

When adding via unpkg, the `MapSession` class can be accessed with the module name:

```javascript
const MapSession = window.jawg_map_session;

const session = new MapSession();
```

## Usage

This library is intended to work with maplibre-gl-js. See the [Quickstart](https://maplibre.org/maplibre-gl-js-docs/api/#quickstart) section for installation.

> Get your own access-token in the [Lab](https://www.jawg.io/lab/access-tokens).

```javascript
import MapSession from "@jawg/map-session";
import maplibregl from "maplibre-gl";

// Create a new map session and generate a session token
// The MapLoad count will be incremented only on the first tile request
const session = new MapSession();

var map = new maplibregl.Map({
  container: "map",
  style:
    "https://api.jawg.io/styles/jawg-streets.json?access-token=<YOUR_ACCESS_TOKEN>",
  zoom: 15,
  center: [1.43649, 43.59818],
  transformRequest: (url, resourceType) => {
    return {
      // Add the session token as query parameter
      url: session.authenticateUrl(url, resourceType),
    };
  },
});
```

## Feedback

Contact us at [contact@jawg.io](mailto:contact@jawg.io) for new features or when something is not working properly.