1.0.0 • Published 1 year ago

@jawg/map-session v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

Jawg Logo

MapSession

npm

Generate a map session token and authenticate request URLs for the JawgMaps mapload pricing with MapLibre GL JS.

Note that your account requires the per-mapload pricing to be enabled. Please contact us at contact@jawg.io for more information.

Install

Available via npm as the package @jawg/map-session.

npm i @jawg/map-session

or

yarn add @jawg/map-session

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

<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:

const MapSession = window.jawg_map_session;

const session = new MapSession();

Usage

This library is intended to work with maplibre-gl-js. See the Quickstart section for installation.

Get your own access-token in the Lab.

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 for new features or when something is not working properly.