uber/react-map-gl getMap & exposed Mapbox API












0















I'm using the following code snippet to try to access the MapBox API from uber react-map-gl: 4.0.2 using mapbox-gl v0.50.0.



 import MapGL from 'react-map-gl';
export default class App extends Component
{
constructor(props) {
super(props);
this.mapRef= React.createRef();
}
componentDidMount()
{
let data = this.mapRef.getMap().getBounds(); <----
}
render() {
<MapGL
{...viewport}
width="100%"
height="100%"
mapStyle={MapStyle}
onViewportChange={this._updateViewport}
ref={map => this.mapRef = map}
mapboxApiAccessToken={TOKEN} >
}
}


if I try to access any other methods like getStyle/getSource and others raise an error "is not a function" & "Cannot read property 'version' of undefined". Am i Doing something wrong or Not all MapBox Api methods are not available through the getMap() method ?



Thanks










share|improve this question





























    0















    I'm using the following code snippet to try to access the MapBox API from uber react-map-gl: 4.0.2 using mapbox-gl v0.50.0.



     import MapGL from 'react-map-gl';
    export default class App extends Component
    {
    constructor(props) {
    super(props);
    this.mapRef= React.createRef();
    }
    componentDidMount()
    {
    let data = this.mapRef.getMap().getBounds(); <----
    }
    render() {
    <MapGL
    {...viewport}
    width="100%"
    height="100%"
    mapStyle={MapStyle}
    onViewportChange={this._updateViewport}
    ref={map => this.mapRef = map}
    mapboxApiAccessToken={TOKEN} >
    }
    }


    if I try to access any other methods like getStyle/getSource and others raise an error "is not a function" & "Cannot read property 'version' of undefined". Am i Doing something wrong or Not all MapBox Api methods are not available through the getMap() method ?



    Thanks










    share|improve this question



























      0












      0








      0


      0






      I'm using the following code snippet to try to access the MapBox API from uber react-map-gl: 4.0.2 using mapbox-gl v0.50.0.



       import MapGL from 'react-map-gl';
      export default class App extends Component
      {
      constructor(props) {
      super(props);
      this.mapRef= React.createRef();
      }
      componentDidMount()
      {
      let data = this.mapRef.getMap().getBounds(); <----
      }
      render() {
      <MapGL
      {...viewport}
      width="100%"
      height="100%"
      mapStyle={MapStyle}
      onViewportChange={this._updateViewport}
      ref={map => this.mapRef = map}
      mapboxApiAccessToken={TOKEN} >
      }
      }


      if I try to access any other methods like getStyle/getSource and others raise an error "is not a function" & "Cannot read property 'version' of undefined". Am i Doing something wrong or Not all MapBox Api methods are not available through the getMap() method ?



      Thanks










      share|improve this question
















      I'm using the following code snippet to try to access the MapBox API from uber react-map-gl: 4.0.2 using mapbox-gl v0.50.0.



       import MapGL from 'react-map-gl';
      export default class App extends Component
      {
      constructor(props) {
      super(props);
      this.mapRef= React.createRef();
      }
      componentDidMount()
      {
      let data = this.mapRef.getMap().getBounds(); <----
      }
      render() {
      <MapGL
      {...viewport}
      width="100%"
      height="100%"
      mapStyle={MapStyle}
      onViewportChange={this._updateViewport}
      ref={map => this.mapRef = map}
      mapboxApiAccessToken={TOKEN} >
      }
      }


      if I try to access any other methods like getStyle/getSource and others raise an error "is not a function" & "Cannot read property 'version' of undefined". Am i Doing something wrong or Not all MapBox Api methods are not available through the getMap() method ?



      Thanks







      mapbox-gl-js uber-api react-map-gl






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 23:31







      user519274

















      asked Nov 23 '18 at 7:33









      user519274user519274

      3771619




      3771619
























          2 Answers
          2






          active

          oldest

          votes


















          0














          If you can get the map object correctly then all the functions should be exposed including getStyle. getSource didn't work for me either, it could be that using mapStyle is not counted as a source? Not sure about this last bit.






          share|improve this answer
























          • The getMap() function is inherited from static map, according to the react-map-gl docs. that's the reason you have no access to getStyle or getSource

            – Mario
            Dec 8 '18 at 16:49



















          0














          I use this to get the initial map boundaries.



              getMapBoundaries = () => {
          // Get map boundaries
          const myMap = this.mapRef.getMap();
          console.log(myMap.getBounds());
          const mapBoundaries = myMap.getBounds();
          this.setState({ mapBoundaries })
          }

          componentDidMount = () => this.getMapBoundaries();


          I also noticed that the import for 'react-map-gl' should be



          import ReactMapGL from 'react-map-gl';


          Why the error?
          It seems you are not using a return function in the componentDidMount method.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442394%2fuber-react-map-gl-getmap-exposed-mapbox-api%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            If you can get the map object correctly then all the functions should be exposed including getStyle. getSource didn't work for me either, it could be that using mapStyle is not counted as a source? Not sure about this last bit.






            share|improve this answer
























            • The getMap() function is inherited from static map, according to the react-map-gl docs. that's the reason you have no access to getStyle or getSource

              – Mario
              Dec 8 '18 at 16:49
















            0














            If you can get the map object correctly then all the functions should be exposed including getStyle. getSource didn't work for me either, it could be that using mapStyle is not counted as a source? Not sure about this last bit.






            share|improve this answer
























            • The getMap() function is inherited from static map, according to the react-map-gl docs. that's the reason you have no access to getStyle or getSource

              – Mario
              Dec 8 '18 at 16:49














            0












            0








            0







            If you can get the map object correctly then all the functions should be exposed including getStyle. getSource didn't work for me either, it could be that using mapStyle is not counted as a source? Not sure about this last bit.






            share|improve this answer













            If you can get the map object correctly then all the functions should be exposed including getStyle. getSource didn't work for me either, it could be that using mapStyle is not counted as a source? Not sure about this last bit.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 8 '18 at 0:04









            HiwaHiwa

            375313




            375313













            • The getMap() function is inherited from static map, according to the react-map-gl docs. that's the reason you have no access to getStyle or getSource

              – Mario
              Dec 8 '18 at 16:49



















            • The getMap() function is inherited from static map, according to the react-map-gl docs. that's the reason you have no access to getStyle or getSource

              – Mario
              Dec 8 '18 at 16:49

















            The getMap() function is inherited from static map, according to the react-map-gl docs. that's the reason you have no access to getStyle or getSource

            – Mario
            Dec 8 '18 at 16:49





            The getMap() function is inherited from static map, according to the react-map-gl docs. that's the reason you have no access to getStyle or getSource

            – Mario
            Dec 8 '18 at 16:49













            0














            I use this to get the initial map boundaries.



                getMapBoundaries = () => {
            // Get map boundaries
            const myMap = this.mapRef.getMap();
            console.log(myMap.getBounds());
            const mapBoundaries = myMap.getBounds();
            this.setState({ mapBoundaries })
            }

            componentDidMount = () => this.getMapBoundaries();


            I also noticed that the import for 'react-map-gl' should be



            import ReactMapGL from 'react-map-gl';


            Why the error?
            It seems you are not using a return function in the componentDidMount method.






            share|improve this answer




























              0














              I use this to get the initial map boundaries.



                  getMapBoundaries = () => {
              // Get map boundaries
              const myMap = this.mapRef.getMap();
              console.log(myMap.getBounds());
              const mapBoundaries = myMap.getBounds();
              this.setState({ mapBoundaries })
              }

              componentDidMount = () => this.getMapBoundaries();


              I also noticed that the import for 'react-map-gl' should be



              import ReactMapGL from 'react-map-gl';


              Why the error?
              It seems you are not using a return function in the componentDidMount method.






              share|improve this answer


























                0












                0








                0







                I use this to get the initial map boundaries.



                    getMapBoundaries = () => {
                // Get map boundaries
                const myMap = this.mapRef.getMap();
                console.log(myMap.getBounds());
                const mapBoundaries = myMap.getBounds();
                this.setState({ mapBoundaries })
                }

                componentDidMount = () => this.getMapBoundaries();


                I also noticed that the import for 'react-map-gl' should be



                import ReactMapGL from 'react-map-gl';


                Why the error?
                It seems you are not using a return function in the componentDidMount method.






                share|improve this answer













                I use this to get the initial map boundaries.



                    getMapBoundaries = () => {
                // Get map boundaries
                const myMap = this.mapRef.getMap();
                console.log(myMap.getBounds());
                const mapBoundaries = myMap.getBounds();
                this.setState({ mapBoundaries })
                }

                componentDidMount = () => this.getMapBoundaries();


                I also noticed that the import for 'react-map-gl' should be



                import ReactMapGL from 'react-map-gl';


                Why the error?
                It seems you are not using a return function in the componentDidMount method.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 8 '18 at 16:48









                MarioMario

                178112




                178112






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53442394%2fuber-react-map-gl-getmap-exposed-mapbox-api%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                    Alcedinidae

                    Can an atomic nucleus contain both particles and antiparticles? [duplicate]