You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Create a consistent convention for getters, setters, and constructor options #4029
Many attributes of the map have getters, setters, and constructor options (for example, minZoom, getMinZoom, setMinZoom 👍 )
Some have only a subset of the three, even though it would be practical and useful to have all three. (for example, maxBounds and setMaxBounds exist but getMaxBounds does not) (for example, renderWorldCopies exists as a constructor option but we do not provide setRenderWorldCopies or getRenderWorldCopies).
We should do a review of all getters, setters, and constructor options to ensure that
for every constructor option, there exists a getter
for every constructor option that could be changed at runtime, there exists a setter
for every getter that could be set in the constructor, there exists a constructor option
for every setter, there exists a getter
We may want to create some infrastructure to automatically plumb together constructor options and getters.
Reacted by Molly Lloyd, Tom Manderson, Lucas Wojciechowski, Vito Macchia, Andrew Harvey, Bart Corremans, agatheblues and clem
I'd love to have getters/setters for each properties. While this gets implemented, I found a small workaround for setting interaction on/off (currently only possible per constructor settings) and getMaxBounds (there is a setter, but strangely no getter for this).
In this snippet, map is an instance of mapboxgl.Map
// A collection of handler namesconstmapInteractionHandlers=['scrollZoom','dragPan','touchZoomRotate','dragRotate','keyboard','boxZoom','doubleClickZoom'];// Returns true if at least one of the above handlers is enabledfunctionisInteractionEnabled(map){returnmapInteractionHandlers.reduce((isEnabled,nextHandler)=>{returnmap[nextHandler].isEnabled()&&isEnabled;},true);}// Enable map interaction (all handlers)functionenableInteraction(map){for(lethandlerofmapInteractionHandlers){map[handler].enable();}}// Disable map interaction (all handlers)functiondisableInteraction(map){for(lethandlerofmapInteractionHandlers){map[handler].disable();}}// Returns true if the maxBounds have been set using the corresponding setterfunctionhasMaxBounds(map){return(!Array.isArray(map.transform.latRange)||map.transform.latRange.length===0)&&(!Array.isArray(map.transform.lngRange)||map.transform.lngRange.length===0);}// Returns maxBounds from map.transform as Array<Array> if they are set// or nullfunctiongetMaxBounds(map){if(!hasMaxBounds(map)){returnnull;}else{lettransform=map.transform;let{ latRange, lngRange }=transform;letne=[lngRange[1],latRange[1]];letsw=[lngRange[0],latRange[0]];return[ne,sw];}}
@lamuertepeluda are you interested in submitting a PR based on that? It looks like you should be able to simply place this code within GL JS just adding JS doc and tests.
@andrewharvey thanks, I'm sorry I couldn't do it but I'm happy if somebody gets to integrate this stuff... I think it's useful to have all setters and getters coherently for each parameter.
I also hope the E6/7 setters/getters convention will be used in the next releases.
I'd also like a function for atomically set/get all or some map state parameters for serialization/deseralization and other purposes, e.g. something as
map.setState({zoom,
center,
pitch,
bearing,
boundingBox,
...
});letmapState=map.getState();// mapState = {zoom, center, pitch, bearing, boundingBox, ...}
This would be helpful in combination with state management libraries such as redux, or simply for storing and reading the map state in the local storage or remotely...
get/set cooperativeGestures would be nice. For example to disable it when the map takes up the full window (so no page scroll, but not fullscreen at the browser level).
Activity
anandthakker commentedon Jan 20, 2017
@lucaswoj might be worth considering doing this auto-plumbing in conjunction with #2741
mollymerp commentedon Jan 23, 2017
Opened #4039 before I saw this issue!
lucaswoj commentedon Jan 30, 2017
We may want to consider using ES6 getters / setters in leu of
getFoo/setFoomethods.lamuertepeluda commentedon Apr 18, 2017
I'd love to have getters/setters for each properties. While this gets implemented, I found a small workaround for setting interaction on/off (currently only possible per constructor settings) and
getMaxBounds(there is a setter, but strangely no getter for this).In this snippet, map is an instance of
mapboxgl.Mapandrewharvey commentedon Jun 25, 2017
@lamuertepeluda are you interested in submitting a PR based on that? It looks like you should be able to simply place this code within GL JS just adding JS doc and tests.
add map.getMaxBounds method
andrewharvey commentedon Jun 26, 2017
I've attempted to implement a getMapBounds at #4890.
/cc @lamuertepeluda
lamuertepeluda commentedon Jun 26, 2017
@andrewharvey thanks, I'm sorry I couldn't do it but I'm happy if somebody gets to integrate this stuff... I think it's useful to have all setters and getters coherently for each parameter.
I also hope the E6/7 setters/getters convention will be used in the next releases.
I'd also like a function for atomically set/get all or some map state parameters for serialization/deseralization and other purposes, e.g. something as
This would be helpful in combination with state management libraries such as redux, or simply for storing and reading the map state in the local storage or remotely...
add map.getMaxBounds method (#4890)
rares-lupascu commentedon Feb 28, 2019
so are the methods available?
enableInteraction
disableInteraction
waissbluth commentedon Mar 24, 2020
also curious about this, specifically interested in
pitchWithRotateallison-strandberg commentedon May 7, 2020
Seconding interest in a
pitchWithRotatesetter, as a previous approach to setting this value no longer works in v1.10.0. #9666andrewharvey commentedon Jun 28, 2022
get/set
cooperativeGestureswould be nice. For example to disable it when the map takes up the full window (so no page scroll, but not fullscreen at the browser level).