Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mapbox-gl-controls

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mapbox-gl-controls

Controls for mapbox-gl

  • 1.5.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
decreased by-67.85%
Maintainers
1
Weekly downloads
 
Created
Source

Mapbox Controls

Ruler

Usage

Install

npm install mapbox-gl-controls

Include styles

<link href="mapbox-gl-controls/theme.css" rel="stylesheet">

Ruler Control

import RulerControl from 'mapbox-gl-controls/lib/ruler';

map.addControl(new RulerControl(), 'top-right');
map.on('ruler.on', () => console.log('ruler: on'));
map.on('ruler.off', () => console.log('ruler: off'));

// with miles:
map.addControl(new RulerControl({
  units: 'miles',
  labelFormat: n => `${n.toFixed(2)} ml`,
}), 'top-right');

Styles Control

import StylesControl from 'mapbox-gl-controls/lib/styles';

// with default styles:
map.addControl(new StylesControl(), 'top-left');

// with custom styles:
map.addControl(new StylesControl({
  styles: [
    {
      label: 'Streets',
      styleName: 'Mapbox Streets',
      styleUrl: 'mapbox://styles/mapbox/streets-v9',
    }, {
      label: 'Satellite',
      styleName: 'Satellite',
      styleUrl: 'mapbox://styles/mapbox/satellite-v9',
    },
  ],
  onChange: (style) => console.log(style),
}), 'top-left');

Compass Control

import CompassControl from 'mapbox-gl-controls/lib/compass';

map.addControl(new CompassControl(), 'top-right');

Zoom Control

import ZoomControl from 'mapbox-gl-controls/lib/zoom';

map.addControl(new ZoomControl(), 'top-right');

Language Control

import LanguageControl from 'mapbox-gl-controls/lib/language';

// with browser detect:
map.addControl(new LanguageControl());

// with custom language:
const languageControl = new LanguageControl({
  language: 'ru',
});
map.addControl(languageControl);

// change language to multi language after control has been added:
languageControl.setLanguage('mul');

Inspect Control

import InspectControl from 'mapbox-gl-controls/lib/inspect';

map.addControl(new InspectControl(), 'bottom-right');

Tooltip Control

import TooltipControl from 'mapbox-gl-controls/lib/tooltip';

map.addControl(new TooltipControl({ layer: '$fill' }));

API

Compass
Parameters
  • options Object (optional, default {})
    • options.instant Boolean Show compass if bearing is 0 (optional, default true)
Language

Language can be set dynamically with .setLanguage(lang) method.

Parameters
  • options Object (optional, default {})
    • options.supportedLanguages Array? (Supported languages)[https://docs.mapbox.com/help/troubleshooting/change-language/]
    • options.language String? One of the supported languages to apply
    • options.excludedLayerIds Array Array of layer id to exclude from localization (optional, default [])
    • options.getLanguageField Function? Accepts language and returns language field By default fields are name_LANGUAGE and name for multi language (mul)
Ruler

Fires map ruler.on and ruler.offevents at the beginning and at the end of measuring.

Parameters
  • options Object (optional, default {})
    • options.units String Any units @turf/distance supports (optional, default 'kilometers')
    • options.labelFormat Function? Accepts number and returns label. Can be used to convert value to any measuring units
Styles
Parameters
  • options Object (optional, default {})
    • options.styles Array? Array of style objects:
    • options.onChange Function? Triggered on style change. Accepts style object
Tooltip

Shows tooltip on hover

Parameters
  • options Object (optional, default {})
    • options.layer String Layer id to show the tooltip on hover. If not specified, tooltip will be shown for whole map container
    • options.getContent Function? Triggered each time mouse moved over layer option. Accepts event object

FAQs

Package last updated on 08 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc