react-leaflet mapboxgl integration not working












0















following the answer in this page :
Render mapbox vector tiles inside react-leaflet?



When i export MapBoxGLLayer and import it to my main class,



like



import MapBoxGLLayer from './MapBoxGLLayer';


and try to access it in my render function, like:



<Map>
<MapBoxGLLayer
accessToken={MAPBOX_ACCESS_TOKEN}
style='https://style.example.com/style.json'
/>
</Map>


i'm getting this error which is pretty consistent.



MapLayer.js:77 Uncaught TypeError: Cannot read property 'layerContainer' of undefined
at VectorgridLayer.get (MapLayer.js:77)
at VectorgridLayer.componentDidMount (MapLayer.js:38)


There is no leaflet to the props.



enter image description here



I don't know what am I doing wrong here.










share|improve this question



























    0















    following the answer in this page :
    Render mapbox vector tiles inside react-leaflet?



    When i export MapBoxGLLayer and import it to my main class,



    like



    import MapBoxGLLayer from './MapBoxGLLayer';


    and try to access it in my render function, like:



    <Map>
    <MapBoxGLLayer
    accessToken={MAPBOX_ACCESS_TOKEN}
    style='https://style.example.com/style.json'
    />
    </Map>


    i'm getting this error which is pretty consistent.



    MapLayer.js:77 Uncaught TypeError: Cannot read property 'layerContainer' of undefined
    at VectorgridLayer.get (MapLayer.js:77)
    at VectorgridLayer.componentDidMount (MapLayer.js:38)


    There is no leaflet to the props.



    enter image description here



    I don't know what am I doing wrong here.










    share|improve this question

























      0












      0








      0








      following the answer in this page :
      Render mapbox vector tiles inside react-leaflet?



      When i export MapBoxGLLayer and import it to my main class,



      like



      import MapBoxGLLayer from './MapBoxGLLayer';


      and try to access it in my render function, like:



      <Map>
      <MapBoxGLLayer
      accessToken={MAPBOX_ACCESS_TOKEN}
      style='https://style.example.com/style.json'
      />
      </Map>


      i'm getting this error which is pretty consistent.



      MapLayer.js:77 Uncaught TypeError: Cannot read property 'layerContainer' of undefined
      at VectorgridLayer.get (MapLayer.js:77)
      at VectorgridLayer.componentDidMount (MapLayer.js:38)


      There is no leaflet to the props.



      enter image description here



      I don't know what am I doing wrong here.










      share|improve this question














      following the answer in this page :
      Render mapbox vector tiles inside react-leaflet?



      When i export MapBoxGLLayer and import it to my main class,



      like



      import MapBoxGLLayer from './MapBoxGLLayer';


      and try to access it in my render function, like:



      <Map>
      <MapBoxGLLayer
      accessToken={MAPBOX_ACCESS_TOKEN}
      style='https://style.example.com/style.json'
      />
      </Map>


      i'm getting this error which is pretty consistent.



      MapLayer.js:77 Uncaught TypeError: Cannot read property 'layerContainer' of undefined
      at VectorgridLayer.get (MapLayer.js:77)
      at VectorgridLayer.componentDidMount (MapLayer.js:38)


      There is no leaflet to the props.



      enter image description here



      I don't know what am I doing wrong here.







      reactjs leaflet mapbox mapbox-gl-js react-leaflet






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 7:17









      BardiaBardia

      103110




      103110
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Taking hints from the answer you mentioned, I was able to get it working.

          Your MapBoxGLLayer.js



          import L from "leaflet";
          import {} from "mapbox-gl-leaflet";
          import PropTypes from "prop-types";
          import { GridLayer, withLeaflet } from "react-leaflet";

          class MapBoxGLLayer extends GridLayer {
          createLeafletElement(props){
          return L.mapboxGL(props);
          }
          }

          export default withLeaflet(MapBoxGLLayer);


          The missing thing was the withLeaflet HOC.



          Usage:



          npm i mapbox-gl-leaflet  


          Add mapbox-gl-js and css to index.html



          <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.js'></script>
          <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.css' rel='stylesheet' />

          // Import the MapBoxGLLayer component mentioned above.
          class App extends Component {
          state = {
          center: [51.505, -0.091],
          zoom: 13
          };

          render() {
          return (
          <div>
          <Map center={this.state.center} zoom={this.state.zoom}>
          <MapBoxGLLayer
          accessToken={MAPBOX_ACCESS_TOKEN}
          style="mapbox://styles/mapbox/streets-v9"
          />
          </Map>
          </div>
          );
          }
          }


          You can find the working example here:https://codesandbox.io/s/ooypokn26y
          Add your own mapbox token to see it working.






          share|improve this answer
























          • that's correct the issue was withLeaflet(MapBoxGLLayer) that i was exporting wrong. but now I'm having another issue with my router, when it's trying to unmount itself i'm getting Cannot read property '_leaflet_events' of undefined at removeOne (leaflet-src.js:2702) at Object.off (leaflet-src.js:2635)

            – Bardia
            Nov 15 '18 at 9:04



















          1














          It seems to be a bug in mapbox-gl-leaflet version 0.0.3 that is the "latest" in npm and was released two years ago.



          onRemove: function (map) {
          if (this._map.options.zoomAnimation) {
          L.DomEvent.off(this._map._proxy, L.DomUtil.TRANSITION_END, this._transitionEnd, this);
          }

          map.getPanes().tilePane.removeChild(this._glContainer);
          this._glMap.remove();
          this._glMap = null;
          }


          The object this.map._proxy is not defined. Solution is to disable zoom animations with zoomAnimation={false} in the React Map Component. Then the branch is not taken in mapbox-gl-leaflet and you won't get this error.



          This problem is solved in the master branch of mapbox-gl-leaflet in GitHub:
          https://github.com/mapbox/mapbox-gl-leaflet/blob/954875e2e4269db313c99d522689bc08f4aadad2/leaflet-mapbox-gl.js



          So try to update you libs.






          share|improve this answer


























          • yeap this was another issue with the library, so I ended up creating my own new functions and fixed the proxy not being defined.

            – Bardia
            Jan 18 at 6:58











          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%2f53294923%2freact-leaflet-mapboxgl-integration-not-working%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









          1














          Taking hints from the answer you mentioned, I was able to get it working.

          Your MapBoxGLLayer.js



          import L from "leaflet";
          import {} from "mapbox-gl-leaflet";
          import PropTypes from "prop-types";
          import { GridLayer, withLeaflet } from "react-leaflet";

          class MapBoxGLLayer extends GridLayer {
          createLeafletElement(props){
          return L.mapboxGL(props);
          }
          }

          export default withLeaflet(MapBoxGLLayer);


          The missing thing was the withLeaflet HOC.



          Usage:



          npm i mapbox-gl-leaflet  


          Add mapbox-gl-js and css to index.html



          <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.js'></script>
          <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.css' rel='stylesheet' />

          // Import the MapBoxGLLayer component mentioned above.
          class App extends Component {
          state = {
          center: [51.505, -0.091],
          zoom: 13
          };

          render() {
          return (
          <div>
          <Map center={this.state.center} zoom={this.state.zoom}>
          <MapBoxGLLayer
          accessToken={MAPBOX_ACCESS_TOKEN}
          style="mapbox://styles/mapbox/streets-v9"
          />
          </Map>
          </div>
          );
          }
          }


          You can find the working example here:https://codesandbox.io/s/ooypokn26y
          Add your own mapbox token to see it working.






          share|improve this answer
























          • that's correct the issue was withLeaflet(MapBoxGLLayer) that i was exporting wrong. but now I'm having another issue with my router, when it's trying to unmount itself i'm getting Cannot read property '_leaflet_events' of undefined at removeOne (leaflet-src.js:2702) at Object.off (leaflet-src.js:2635)

            – Bardia
            Nov 15 '18 at 9:04
















          1














          Taking hints from the answer you mentioned, I was able to get it working.

          Your MapBoxGLLayer.js



          import L from "leaflet";
          import {} from "mapbox-gl-leaflet";
          import PropTypes from "prop-types";
          import { GridLayer, withLeaflet } from "react-leaflet";

          class MapBoxGLLayer extends GridLayer {
          createLeafletElement(props){
          return L.mapboxGL(props);
          }
          }

          export default withLeaflet(MapBoxGLLayer);


          The missing thing was the withLeaflet HOC.



          Usage:



          npm i mapbox-gl-leaflet  


          Add mapbox-gl-js and css to index.html



          <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.js'></script>
          <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.css' rel='stylesheet' />

          // Import the MapBoxGLLayer component mentioned above.
          class App extends Component {
          state = {
          center: [51.505, -0.091],
          zoom: 13
          };

          render() {
          return (
          <div>
          <Map center={this.state.center} zoom={this.state.zoom}>
          <MapBoxGLLayer
          accessToken={MAPBOX_ACCESS_TOKEN}
          style="mapbox://styles/mapbox/streets-v9"
          />
          </Map>
          </div>
          );
          }
          }


          You can find the working example here:https://codesandbox.io/s/ooypokn26y
          Add your own mapbox token to see it working.






          share|improve this answer
























          • that's correct the issue was withLeaflet(MapBoxGLLayer) that i was exporting wrong. but now I'm having another issue with my router, when it's trying to unmount itself i'm getting Cannot read property '_leaflet_events' of undefined at removeOne (leaflet-src.js:2702) at Object.off (leaflet-src.js:2635)

            – Bardia
            Nov 15 '18 at 9:04














          1












          1








          1







          Taking hints from the answer you mentioned, I was able to get it working.

          Your MapBoxGLLayer.js



          import L from "leaflet";
          import {} from "mapbox-gl-leaflet";
          import PropTypes from "prop-types";
          import { GridLayer, withLeaflet } from "react-leaflet";

          class MapBoxGLLayer extends GridLayer {
          createLeafletElement(props){
          return L.mapboxGL(props);
          }
          }

          export default withLeaflet(MapBoxGLLayer);


          The missing thing was the withLeaflet HOC.



          Usage:



          npm i mapbox-gl-leaflet  


          Add mapbox-gl-js and css to index.html



          <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.js'></script>
          <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.css' rel='stylesheet' />

          // Import the MapBoxGLLayer component mentioned above.
          class App extends Component {
          state = {
          center: [51.505, -0.091],
          zoom: 13
          };

          render() {
          return (
          <div>
          <Map center={this.state.center} zoom={this.state.zoom}>
          <MapBoxGLLayer
          accessToken={MAPBOX_ACCESS_TOKEN}
          style="mapbox://styles/mapbox/streets-v9"
          />
          </Map>
          </div>
          );
          }
          }


          You can find the working example here:https://codesandbox.io/s/ooypokn26y
          Add your own mapbox token to see it working.






          share|improve this answer













          Taking hints from the answer you mentioned, I was able to get it working.

          Your MapBoxGLLayer.js



          import L from "leaflet";
          import {} from "mapbox-gl-leaflet";
          import PropTypes from "prop-types";
          import { GridLayer, withLeaflet } from "react-leaflet";

          class MapBoxGLLayer extends GridLayer {
          createLeafletElement(props){
          return L.mapboxGL(props);
          }
          }

          export default withLeaflet(MapBoxGLLayer);


          The missing thing was the withLeaflet HOC.



          Usage:



          npm i mapbox-gl-leaflet  


          Add mapbox-gl-js and css to index.html



          <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.js'></script>
          <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.css' rel='stylesheet' />

          // Import the MapBoxGLLayer component mentioned above.
          class App extends Component {
          state = {
          center: [51.505, -0.091],
          zoom: 13
          };

          render() {
          return (
          <div>
          <Map center={this.state.center} zoom={this.state.zoom}>
          <MapBoxGLLayer
          accessToken={MAPBOX_ACCESS_TOKEN}
          style="mapbox://styles/mapbox/streets-v9"
          />
          </Map>
          </div>
          );
          }
          }


          You can find the working example here:https://codesandbox.io/s/ooypokn26y
          Add your own mapbox token to see it working.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 4:28









          Murli PrajapatiMurli Prajapati

          1,34911121




          1,34911121













          • that's correct the issue was withLeaflet(MapBoxGLLayer) that i was exporting wrong. but now I'm having another issue with my router, when it's trying to unmount itself i'm getting Cannot read property '_leaflet_events' of undefined at removeOne (leaflet-src.js:2702) at Object.off (leaflet-src.js:2635)

            – Bardia
            Nov 15 '18 at 9:04



















          • that's correct the issue was withLeaflet(MapBoxGLLayer) that i was exporting wrong. but now I'm having another issue with my router, when it's trying to unmount itself i'm getting Cannot read property '_leaflet_events' of undefined at removeOne (leaflet-src.js:2702) at Object.off (leaflet-src.js:2635)

            – Bardia
            Nov 15 '18 at 9:04

















          that's correct the issue was withLeaflet(MapBoxGLLayer) that i was exporting wrong. but now I'm having another issue with my router, when it's trying to unmount itself i'm getting Cannot read property '_leaflet_events' of undefined at removeOne (leaflet-src.js:2702) at Object.off (leaflet-src.js:2635)

          – Bardia
          Nov 15 '18 at 9:04





          that's correct the issue was withLeaflet(MapBoxGLLayer) that i was exporting wrong. but now I'm having another issue with my router, when it's trying to unmount itself i'm getting Cannot read property '_leaflet_events' of undefined at removeOne (leaflet-src.js:2702) at Object.off (leaflet-src.js:2635)

          – Bardia
          Nov 15 '18 at 9:04













          1














          It seems to be a bug in mapbox-gl-leaflet version 0.0.3 that is the "latest" in npm and was released two years ago.



          onRemove: function (map) {
          if (this._map.options.zoomAnimation) {
          L.DomEvent.off(this._map._proxy, L.DomUtil.TRANSITION_END, this._transitionEnd, this);
          }

          map.getPanes().tilePane.removeChild(this._glContainer);
          this._glMap.remove();
          this._glMap = null;
          }


          The object this.map._proxy is not defined. Solution is to disable zoom animations with zoomAnimation={false} in the React Map Component. Then the branch is not taken in mapbox-gl-leaflet and you won't get this error.



          This problem is solved in the master branch of mapbox-gl-leaflet in GitHub:
          https://github.com/mapbox/mapbox-gl-leaflet/blob/954875e2e4269db313c99d522689bc08f4aadad2/leaflet-mapbox-gl.js



          So try to update you libs.






          share|improve this answer


























          • yeap this was another issue with the library, so I ended up creating my own new functions and fixed the proxy not being defined.

            – Bardia
            Jan 18 at 6:58
















          1














          It seems to be a bug in mapbox-gl-leaflet version 0.0.3 that is the "latest" in npm and was released two years ago.



          onRemove: function (map) {
          if (this._map.options.zoomAnimation) {
          L.DomEvent.off(this._map._proxy, L.DomUtil.TRANSITION_END, this._transitionEnd, this);
          }

          map.getPanes().tilePane.removeChild(this._glContainer);
          this._glMap.remove();
          this._glMap = null;
          }


          The object this.map._proxy is not defined. Solution is to disable zoom animations with zoomAnimation={false} in the React Map Component. Then the branch is not taken in mapbox-gl-leaflet and you won't get this error.



          This problem is solved in the master branch of mapbox-gl-leaflet in GitHub:
          https://github.com/mapbox/mapbox-gl-leaflet/blob/954875e2e4269db313c99d522689bc08f4aadad2/leaflet-mapbox-gl.js



          So try to update you libs.






          share|improve this answer


























          • yeap this was another issue with the library, so I ended up creating my own new functions and fixed the proxy not being defined.

            – Bardia
            Jan 18 at 6:58














          1












          1








          1







          It seems to be a bug in mapbox-gl-leaflet version 0.0.3 that is the "latest" in npm and was released two years ago.



          onRemove: function (map) {
          if (this._map.options.zoomAnimation) {
          L.DomEvent.off(this._map._proxy, L.DomUtil.TRANSITION_END, this._transitionEnd, this);
          }

          map.getPanes().tilePane.removeChild(this._glContainer);
          this._glMap.remove();
          this._glMap = null;
          }


          The object this.map._proxy is not defined. Solution is to disable zoom animations with zoomAnimation={false} in the React Map Component. Then the branch is not taken in mapbox-gl-leaflet and you won't get this error.



          This problem is solved in the master branch of mapbox-gl-leaflet in GitHub:
          https://github.com/mapbox/mapbox-gl-leaflet/blob/954875e2e4269db313c99d522689bc08f4aadad2/leaflet-mapbox-gl.js



          So try to update you libs.






          share|improve this answer















          It seems to be a bug in mapbox-gl-leaflet version 0.0.3 that is the "latest" in npm and was released two years ago.



          onRemove: function (map) {
          if (this._map.options.zoomAnimation) {
          L.DomEvent.off(this._map._proxy, L.DomUtil.TRANSITION_END, this._transitionEnd, this);
          }

          map.getPanes().tilePane.removeChild(this._glContainer);
          this._glMap.remove();
          this._glMap = null;
          }


          The object this.map._proxy is not defined. Solution is to disable zoom animations with zoomAnimation={false} in the React Map Component. Then the branch is not taken in mapbox-gl-leaflet and you won't get this error.



          This problem is solved in the master branch of mapbox-gl-leaflet in GitHub:
          https://github.com/mapbox/mapbox-gl-leaflet/blob/954875e2e4269db313c99d522689bc08f4aadad2/leaflet-mapbox-gl.js



          So try to update you libs.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 13 '18 at 12:59

























          answered Dec 13 '18 at 12:41









          tknapptknapp

          213




          213













          • yeap this was another issue with the library, so I ended up creating my own new functions and fixed the proxy not being defined.

            – Bardia
            Jan 18 at 6:58



















          • yeap this was another issue with the library, so I ended up creating my own new functions and fixed the proxy not being defined.

            – Bardia
            Jan 18 at 6:58

















          yeap this was another issue with the library, so I ended up creating my own new functions and fixed the proxy not being defined.

          – Bardia
          Jan 18 at 6:58





          yeap this was another issue with the library, so I ended up creating my own new functions and fixed the proxy not being defined.

          – Bardia
          Jan 18 at 6:58


















          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%2f53294923%2freact-leaflet-mapboxgl-integration-not-working%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

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python