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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With