Moving from Mapbox GL JS to MapLibre with Tilehouse

If you built a web map in the last ten years there's a good chance it runs on Mapbox GL JS. This guide is for people who want to move that map to MapLibre GL JS, the open-source library that grew out of it, with Tilehouse serving the tiles. It covers why people make the move, the code changes, what doesn't come with you, and where Mapbox is still the better choice.

Every MapLibre code sample here was run in a browser against tiles.tilehouse.io before this guide went up.

Why people move

The licence changed. Mapbox GL JS was open source under the BSD licence up to version 1.13. Version 2.0.0, released on 8 December 2020, moved to Mapbox's own terms: by upgrading, you agree to the Mapbox terms of service, and the licence lets you use the library only with Mapbox's products while you have a Mapbox account in good standing. Version 2 and later also check your access token with Mapbox every time a map starts, and blank the map if the token is refused, even if the map shows nothing from Mapbox.

Every map load is billed. From version 2, Mapbox counts a map load each time a Map object is created on a page. As of October 2026, Mapbox's pricing page lists the first 50,000 web map loads a month as free, then per 1,000 loads:

Map loads a month Price per 1,000 loads
50,001 to 100,000 $5.00
100,001 to 200,000 $4.00
200,001 to 1,000,000 $3.00
1,000,001 to 5,000,000 $2.50
Over 5,000,000 Ask Mapbox

A load covers the tiles that map fetches, so panning and zooming don't cost more, and a session counts as a new load after 12 hours. At list price, a site with 200,000 map loads a month pays $650 a month for the map alone. Check Mapbox's pricing page for today's figures: these were read on 13 October 2026.

None of that makes Mapbox a bad choice. It's a good product, and for some projects it's the right one (more on that below). But if your map is a store finder or a "where we work" page, the open library and a fixed monthly price are often a better fit.

What MapLibre is

When Mapbox changed the licence, a group of developers and companies forked the last open version, 1.13, and called it MapLibre GL JS. It's BSD-licensed, needs no account or token, and has moved on a long way since: 3D terrain, globe view and sky are all in it now. At the time of writing the current version is 6.14.

Most of the API is the one you already know. Map, Marker, Popup, addSource, addLayer, on('load'), flyTo and fitBounds all work the way you'd expect. The work is in the places where a Mapbox map talks to Mapbox.

Swap the package

If you install from npm:

npm uninstall mapbox-gl
npm install maplibre-gl

Then change your imports. MapLibre 6 ships as an ES module only and has no default export, so import it as a namespace. When it's bundled, MapLibre also needs to be told where its worker file is, or the map stays blank with "Worker failed to load" in the console. With Vite, that looks like this:

import * as maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
import workerUrl from 'maplibre-gl/dist/maplibre-gl-worker.mjs?worker&url';

maplibregl.setWorkerUrl(workerUrl);

webpack, esbuild and other bundlers need a slightly different worker line; MapLibre's installation notes give one for each.

If you load Mapbox from their CDN with a <script> tag, the MapLibre equivalent has to be a module script, because MapLibre 6 no longer publishes the old maplibre-gl.js file. Pin the version you tested with:

<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@6.14.0/dist/maplibre-gl.css">
<div id="map" style="height: 400px"></div>
<script type="module">
  import * as maplibregl from 'https://unpkg.com/maplibre-gl@6.14.0/dist/maplibre-gl.mjs';

  const KEY = 'YOUR_KEY';
  const HOST = 'tiles.tilehouse.io';

  const map = new maplibregl.Map({
    container: 'map',
    style: `https://${HOST}/styles/liberty?key=${KEY}`,
    center: [-2.24, 53.48],
    zoom: 12,
    transformRequest: (url) => {
      const u = new URL(url);
      if (u.host !== HOST) return { url };
      u.searchParams.set('key', KEY);
      return { url: u.toString() };
    }
  });
</script>

Change the map

Here's a typical Mapbox map:

mapboxgl.accessToken = 'pk.your-mapbox-token';

const map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/streets-v12',
  center: [-2.24, 53.48],
  zoom: 12
});

And the same map on MapLibre and Tilehouse:

const KEY = 'YOUR_KEY';
const HOST = 'tiles.tilehouse.io';

const map = new maplibregl.Map({
  container: 'map',
  style: `https://${HOST}/styles/liberty?key=${KEY}`,
  center: [-2.24, 53.48],
  zoom: 12,
  // The style points at our tiles, fonts and sprites,
  // and each of those needs the key too.
  transformRequest: (url) => {
    const u = new URL(url);
    if (u.host !== HOST) return { url };
    u.searchParams.set('key', KEY);
    return { url: u.toString() };
  }
});

Four things changed:

  1. mapboxgl becomes maplibregl everywhere, including new maplibregl.Marker() and new maplibregl.Popup().
  2. The accessToken line goes. MapLibre has no token.
  3. The mapbox:// style URL becomes a plain HTTPS URL. Tilehouse has five styles: liberty, bright, positron, dark and fiord. Swap the name at the end of the URL.
  4. transformRequest adds your Tilehouse key to every request the map makes to our host: the style, and the tiles, fonts and sprites it points to. Requests to anywhere else are left alone.

Your key comes from the Tilehouse portal. Lock it to the domains your map runs on, so a copy of your key on someone else's site is refused.

If you've styled the map's controls with CSS, rename the classes too: .mapboxgl-ctrl becomes .maplibregl-ctrl, and so on. MapLibre's stylesheet has no mapboxgl- classes.

What doesn't come with you

Some things are Mapbox's alone. Before you start, search your code for each of these.

  • Mapbox Studio styles. A style you designed in Studio lives on Mapbox's servers and points at Mapbox's tiles, fonts and icons, so it can't be pointed at Tilehouse. You'll start again from one of our five styles. Tilehouse doesn't have a visual style editor. A style in your brand colours is part of the Pro plan, which is coming later.
  • mapbox:// URLs. Anything starting mapbox://, whether a style, a source, a sprite or a font, only works against Mapbox's API with a Mapbox token. MapLibre doesn't understand them. Each one needs replacing with an HTTPS URL, or removing.
  • Mapbox Standard and its configuration. Mapbox Standard is built from style imports, with options you set through setConfigProperty. MapLibre's style format has no imports or configuration, so code that uses them has to go.
  • Newer Mapbox style features. Mapbox's style format has gained things that MapLibre's doesn't have: 3D models and the model layer, the building layer and landmark icons, the lights block, snow and rain, featuresets and the interactions API, colour themes, and the raster-particle, slot and clip layer types. If your style or code uses any of these, it needs changing. MapLibre does have 3D terrain, globe view, sky and fog colours, extruded buildings, hillshading and heatmaps, so those can stay.
  • Plugins that call Mapbox. The Mapbox geocoder and directions plugins call Mapbox's APIs, so they still need a Mapbox token and Mapbox still bills for them. Other plugins may work with MapLibre unchanged or with small changes; check each one you use.

Markers and popups

These work as they did, with the new name:

const popup = new maplibregl.Popup({ offset: 25 })
  .setText('Our Manchester office');

new maplibregl.Marker({ color: '#2f6f4f' })
  .setLngLat([-2.2426, 53.4808])
  .setPopup(popup)
  .addTo(map);

Use setText for anything that comes from your users or a database. setHTML is there when you need markup, but it puts the string straight into the page.

Your own data on the map

Adding a GeoJSON source and a layer is the same as on Mapbox. Do it once the style has loaded:

map.on('load', () => {
  map.addSource('offices', {
    type: 'geojson',
    data: {
      type: 'FeatureCollection',
      features: [
        { type: 'Feature', properties: { name: 'Manchester' }, geometry: { type: 'Point', coordinates: [-2.2426, 53.4808] } },
        { type: 'Feature', properties: { name: 'Leeds' }, geometry: { type: 'Point', coordinates: [-1.5491, 53.8008] } },
        { type: 'Feature', properties: { name: 'Liverpool' }, geometry: { type: 'Point', coordinates: [-2.9916, 53.4084] } }
      ]
    },
    attribution: 'Office locations: Example Ltd'
  });

  map.addLayer({
    id: 'offices',
    type: 'circle',
    source: 'offices',
    paint: {
      'circle-radius': 8,
      'circle-color': '#2f6f4f',
      'circle-stroke-width': 2,
      'circle-stroke-color': '#ffffff'
    }
  });

  map.fitBounds([[-3.1, 53.3], [-1.4, 53.9]], { padding: 40 });
});

data can also be the URL of a GeoJSON file. If that file is on your own site, transformRequest leaves the request alone, so your key isn't sent anywhere it isn't needed.

Credits

Keep MapLibre's attribution control on the map. With a Tilehouse style it shows the credits the data needs: OpenMapTiles, whose schema the tiles use, and OpenStreetMap contributors, whose data it all is. The map data is under the Open Database Licence, which requires that credit. If you add a source with its own attribution, as in the example above, MapLibre adds it to the same control.

Our styles and the tile build behind them are OpenFreeMap's open-source work, and we're glad to credit them for it.

You can drop the Mapbox logo and the "Improve this map" link; neither applies any more.

Where Mapbox is still the better choice

I'd rather you picked the right tool than picked us. Mapbox does a lot that Tilehouse doesn't:

  • Search and geocoding. Turning an address or postcode into a point, and back. Tilehouse has no geocoding.
  • Directions and navigation. Routes, travel times and turn-by-turn. We have no routing.
  • Satellite imagery. We serve vector maps drawn from OpenStreetMap, not aerial photos.
  • Studio. A visual editor for designing your own style from scratch.
  • The newer 3D features listed above, such as models and lighting.
  • Scale and guarantees. Mapbox runs a global network with an uptime commitment. An uptime SLA with service credits is on our Agency plan, which is coming later.

If your map needs any of those, stay on Mapbox, or keep Mapbox for that part and check what it costs on its own. If you need a good-looking map of OpenStreetMap data with your own pins and shapes on it, served from Europe at a fixed monthly price, that's what Tilehouse is for.

Try it on your own site

The quickest way to know if the move works for you is to do it on a real page. Start a free two-week pilot, point one map at Tilehouse, and see your real map loads before you choose a plan.

Try Tilehouse Maps free for two weeks

Put our tiles behind your own map for a free two-week pilot. Tell us about your site and we'll set you up with a key.

Start a pilot
Tilehouse Maps

Map data © OpenStreetMap contributors, ODbL. Tilehouse Maps is independent and not endorsed by the OpenStreetMap Foundation.