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 ?
答案 0 :(得分:7)
您对Mapbox的自定义控件应实现下一个界面:
onAdd(map)
- 一个获取地图对象并应返回控制对象的函数。将控件添加到地图时将调用它。
onRemove(map)
- 一个获取地图对象的函数,将在从地图中删除控件时调用。您可以使用此方法取消绑定事件侦听器。
这是CodePen example。只需使用您的访问令牌。