npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@teritorio/openmaptiles-gl-language

v1.5.4

Published

Mapbox GL JS plugin for OpenMapTiles style for switching language to the browser language.

Downloads

83

Readme

OpenMapTiles Language

Adds support for switching the language of your map style in Mapbox GL JS maps.

Requires maplibre-gl-js or older mapbox-gl-js.

Multiple language supported with style transforms

Automatic style transformations for different languages

Switch language based on user agent

Switch language based on user agent

Example

var map = new mapboxgl.Map({
    container: 'map',
    style: 'https://raw.githubusercontent.com/openmaptiles/osm-bright-gl-style/gh-pages/style-local.json',
    center: [-77.0259, 38.9010],
    zoom: 9
});

// Add RTL support if you want to support Arabic
// mapboxgl.setRTLTextPlugin('https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.10.1/mapbox-gl-rtl-text.js');

// Language can be fixed at initialization or not
const languageControl = new OpenMapTilesLanguage({
    defaultLanguage: 'it',
})

// Language can be set later
languageControl.setLanguage('es');

Check examples/ for more usage examples.

Usage

The project is bundled in several formats so you can use it everywhere.

If you don't know what format is better for you, choose UMD ;)

UMD (Universal Module Definition)

To use in your HTML files:

<script
  type="text/javascript"
  src="https://unpkg.com/@teritorio/openmaptiles-gl-language/dist/openmaptiles_gl_language.umd.production.min.js"
></script>

CommonJS

To import the library in your bundled project:

import { OpenMapTilesLanguage } from '@teritorio/openmaptiles-gl-language'

const languageControl = new OpenMapTilesLanguage({
    defaultLanguage: 'it',
});

ES Module

<script type="module">
  import { OpenMapTilesLanguage } from 'https://unpkg.com/@teritorio/openmaptiles-gl-language/dist/openmaptiles_gl_language.esm.js';

const languageControl = new OpenMapTilesLanguage();
</script>

API

Table of Contents

OpenMapTilesLanguage

Create a new Mapbox GL JS plugin that modifies the layers of the map style to use the 'text-field' that matches the browser language.

Parameters

  • options object Options to configure the plugin.
    • options.supportedLanguages Array<string>? List of supported languages
    • options.languageField RegExp RegExp to match if a text-field is a language field (optional, default /^name:/)
    • options.getLanguageField Function? Given a language choose the field in the vector tiles
    • options.languageSource string? Name of the source that contains the different languages.
    • options.defaultLanguage string? Name of the default language to initialize style after loading.
    • options.excludedLayerIds Array<string>? Name of the layers that should be excluded from translation.

setLanguage

Explicitly change the language for a style.

Parameters
  • language string The language iso code

Returns object the modified style

Develop

Run the linter and watch for changes to rebuild with browserify.

npm install
npm run test

Languages

Showcasing the languages supported by OpenMapTiles.

Or manual switch.

Supported Styles

You can configure the plugin to support your own custom style using style transforms and custom language fields. By default, this plugin works best with OpenMapTiles styles or derived.