react-leaflet mapboxgl integration not working
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.
I don't know what am I doing wrong here.
reactjs leaflet mapbox mapbox-gl-js react-leaflet
add a comment |
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.
I don't know what am I doing wrong here.
reactjs leaflet mapbox mapbox-gl-js react-leaflet
add a comment |
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.
I don't know what am I doing wrong here.
reactjs leaflet mapbox mapbox-gl-js react-leaflet
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.
I don't know what am I doing wrong here.
reactjs leaflet mapbox mapbox-gl-js react-leaflet
reactjs leaflet mapbox mapbox-gl-js react-leaflet
asked Nov 14 '18 at 7:17
BardiaBardia
103110
103110
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
that's correct the issue waswithLeaflet(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 gettingCannot 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
add a comment |
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
that's correct the issue waswithLeaflet(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 gettingCannot 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
add a comment |
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.
that's correct the issue waswithLeaflet(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 gettingCannot 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
add a comment |
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.
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.
answered Nov 15 '18 at 4:28
Murli PrajapatiMurli Prajapati
1,40411121
1,40411121
that's correct the issue waswithLeaflet(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 gettingCannot 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
add a comment |
that's correct the issue waswithLeaflet(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 gettingCannot 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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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