Mechanism to access existing controls in map
Motivation
I'm trying to implement a utility function to solve #6531: map.U.lockRotation().
Because the navigation control would have already been constructed and added to the map, it's too late to just not add it. Hence I need to find the existing navigation control and either modify it, or remove it then re-add it.
Design Alternatives
-
map.getControl(mapboxgl.NavigationControl)?
@stevage in your design, does mapboxgl.NavigationControl refer to the class/ or an instance of it? How would this work if a control type was able to add multiple instances with different values/options?
Alternatively
- Extend
IControlto include a read-onlycontrolNameproperty that can be set to a fixed name or dynamically - that is up to each individual control implementation. - Implement
map.getControl(controlName: string)and updatemap.removeControl(control: string | IControl)to also act on control names.
Want to put up a PR for it?
does mapboxgl.NavigationControl refer to the class/ or an instance of it?
The class. If I had an instance of it, I wouldn't need this function.
How would this work if a control type was able to add multiple instances with different values/options?
Probably the function should always return an array of instances.
I like your alternative suggestion. I can't really see a way, atm, to work out which type of control an element of map._controls[] is.
Hi @stevage @asheemmamoowala
I'm in a situation where I particularly need this potential map.getControl(controlName: string) method, would love to know if there's any update on it.
Thanks.
@IAMOTZ We'd welcome a PR.
You can for some get the name via control.constructor.name
Any update please? Need a way to get the existing draw control from mapbox-gl-draw