About ReactMapboxGl design: Map properties and options
See original GitHub issueHi again,
I was looking at the source code of the default class (the map) and I think it should be designed as Factory function/Higher Order Component, since there are some properties that cannot be changed after the instantiation (meaning their change has no effect).
For instance, setting interactive={false}
then changing it lately to true, has no effect. This is mostly because it is an option of the underlying map which is passed to the MapBox Map constructor, rather than a property that can be set or read using setters ad getters.
Because of this, I think that properties that cannot be changed by the parent components should be passed to a factory function, e.g. something like this (pseudocode)
const ReactMapboxGlFactory (options) => {
//use options for instantiating the map instance
const opts = {...defaultOptions, ...options};
/*...other initializations */
return class class ReactMapboxGl extends React.Component{
//options are passed to the MapBoxGl constructor
const map = new MapboxGl.Map(opts);
//properties are mapped to the setters/getters of the returned component
}
}
Otherwise we could hold the current structure, but we’d have to find a way of updating the map instance when changing the options, which is trickiest, but would require cloning the current MapBoxGl instance and re-instantiating it with the updated constructor options.
What do you think about it?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:10 (9 by maintainers)
Top GitHub Comments
Uhm, for instance I was trying to make the map not interactive (set to false) until a certain initial ease was made, and I noticed this when I was setting interactive again. That’s what you expect from a react component (unless we put at least some caveats in the docs), that is updating props should reflect in the children…
+1 for interactive not being able to change 😩