Skip to content

This module adds area switcher control which is able to change locations of area quickly to mapbox-gl

License

Notifications You must be signed in to change notification settings

watergis/mapbox-gl-area-switcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mapbox-gl-area-switcher

GitHub

This module adds area switcher control which is able to change locations of area to mapbox-gl

Installation:

npm i @watergis/mapbox-gl-area-switcher --save

Demo:

Try codesandbox.

See demo.

Test:

npm run build
npm start

open http://localhost:8080.

Usage:

import MapboxAreaSwitcherControl from "@watergis/mapbox-gl-area-switcher";
import { Map as MapboxMap } from "mapbox-gl";

import "@watergis/mapbox-gl-area-switcher/css/styles.css";

const map = new MapboxMap();
map.addControl(new MapboxAreaSwitcherControl([
        {title: 'Narok',latlng: [35.87063, -1.08551],zoom: 14,}, 
        {title: "Ololulung'a",latlng: [35.65072, -1.0085],zoom: 13}, 
        {title: "Kilgoris",latlng: [34.87533, -1.00278],zoom: 14}, 
        {title: "Suswa",latlng: [36.33078, -1.05307],zoom: 13}
]), 'top-right');

Specify your areas which you want to change the location quickly by the control.

If number of areas is more than 5, the control will become select box in order to avoid the control become too long. The default limit number of areas can be changed in the second parameter. You may change as below.

map.addControl(new MapboxAreaSwitcherControl([
        {title: 'Narok',latlng: [35.87063, -1.08551],zoom: 14,}, 
        {title: "Ololulung'a",latlng: [35.65072, -1.0085],zoom: 13}, 
        {title: "Kilgoris",latlng: [34.87533, -1.00278],zoom: 14}, 
        {title: "Suswa",latlng: [36.33078, -1.05307],zoom: 13}
], 3), 'top-right');