Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapbox GL How to create custom control?

I want to create custom control using Mapbox gl Api. I'm trying to extend Control class and add my own functionality. It doesn't seem working. I'm getting TypeError: "x" is not a constructor error in my console. Even though after extending the class, I'm using super() in constructor function. Am I doing it wrong, is there any other way how to create custom control ?

like image 665
Linus Avatar asked Oct 20 '16 19:10

Linus


1 Answers

Your custom control for Mapbox should implement the next interface:

  • onAdd(map) — a function that takes map object and should return your control object. It will be called when your control is added to the map.

  • onRemove(map) — a function that takes map object and will be called when control is removed from the map. You can unbind your event listeners in this method.

Here is a CodePen example. Just use your access token.

like image 124
sergei Avatar answered Sep 21 '22 21:09

sergei