question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

About ReactMapboxGl design: Map properties and options

See original GitHub issue

Hi 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:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
lamuertepeludacommented, Mar 27, 2017

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…

2reactions
z0d14ccommented, Mar 29, 2017

+1 for interactive not being able to change 😩

Read more comments on GitHub >

github_iconTop Results From Across the Web

Properties and options | Mapbox GL JS
Mapbox GL JS's global properties and options that you can access while initializing your map or accessing information about its status.
Read more >
A Complete Guide to Sources and Layers in React and ...
We will use Mapbox GL JS and React to build an interactive map with several custom sources and layers. We will be adding...
Read more >
react-map-gl | Upgrade Guide
Add mapbox-gl (or a compatible fork) to your package.json. react-map-gl no longer lists a specific map renderer in its dependencies, so you are...
Read more >
visgl/react-map-gl: React friendly API wrapper around ... - GitHub
react -map-gl is a suite of React components designed to provide a React API for Mapbox GL JS-compatible libraries. More information in the...
Read more >
react-map-gl | Yarn - Package Manager
react -map-gl is a suite of React components designed to provide a React API for Mapbox GL JS-compatible libraries. More information in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found