why leaflet map doesn't render on react app
I included leaflet map with js
implementation instead of jsx
implementation but I have a problem as it overflows its scope.
this is how I imported leaflet:
import L from 'leaflet';
and implemented:
componentDidMount()
// create map
this.map = L.map('map',
center: [49.8419, 24.0315],
zoom: 16,
layers: [
L.tileLayer('http://s.tile.osm.org/z/x/y.png',
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
),
]
);
and usage:
<div id="map" >
and this is what i got
javascript reactjs leaflet react-leaflet
add a comment |
I included leaflet map with js
implementation instead of jsx
implementation but I have a problem as it overflows its scope.
this is how I imported leaflet:
import L from 'leaflet';
and implemented:
componentDidMount()
// create map
this.map = L.map('map',
center: [49.8419, 24.0315],
zoom: 16,
layers: [
L.tileLayer('http://s.tile.osm.org/z/x/y.png',
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
),
]
);
and usage:
<div id="map" >
and this is what i got
javascript reactjs leaflet react-leaflet
Check stackoverflow.com/a/38836996/2626313
– xmojmr
Nov 14 '18 at 12:39
2
Possible duplicate of Leaflet drawing tiles disjointly
– peeebeee
Nov 14 '18 at 14:31
adding leaflet css file fixed the problem, thanks @xmojmr
– S.Aminnejad
Nov 14 '18 at 15:07
add a comment |
I included leaflet map with js
implementation instead of jsx
implementation but I have a problem as it overflows its scope.
this is how I imported leaflet:
import L from 'leaflet';
and implemented:
componentDidMount()
// create map
this.map = L.map('map',
center: [49.8419, 24.0315],
zoom: 16,
layers: [
L.tileLayer('http://s.tile.osm.org/z/x/y.png',
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
),
]
);
and usage:
<div id="map" >
and this is what i got
javascript reactjs leaflet react-leaflet
I included leaflet map with js
implementation instead of jsx
implementation but I have a problem as it overflows its scope.
this is how I imported leaflet:
import L from 'leaflet';
and implemented:
componentDidMount()
// create map
this.map = L.map('map',
center: [49.8419, 24.0315],
zoom: 16,
layers: [
L.tileLayer('http://s.tile.osm.org/z/x/y.png',
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
),
]
);
and usage:
<div id="map" >
and this is what i got
javascript reactjs leaflet react-leaflet
javascript reactjs leaflet react-leaflet
edited Nov 15 '18 at 5:13
Murli Prajapati
1,41411121
1,41411121
asked Nov 14 '18 at 12:12
S.AminnejadS.Aminnejad
84
84
Check stackoverflow.com/a/38836996/2626313
– xmojmr
Nov 14 '18 at 12:39
2
Possible duplicate of Leaflet drawing tiles disjointly
– peeebeee
Nov 14 '18 at 14:31
adding leaflet css file fixed the problem, thanks @xmojmr
– S.Aminnejad
Nov 14 '18 at 15:07
add a comment |
Check stackoverflow.com/a/38836996/2626313
– xmojmr
Nov 14 '18 at 12:39
2
Possible duplicate of Leaflet drawing tiles disjointly
– peeebeee
Nov 14 '18 at 14:31
adding leaflet css file fixed the problem, thanks @xmojmr
– S.Aminnejad
Nov 14 '18 at 15:07
Check stackoverflow.com/a/38836996/2626313
– xmojmr
Nov 14 '18 at 12:39
Check stackoverflow.com/a/38836996/2626313
– xmojmr
Nov 14 '18 at 12:39
2
2
Possible duplicate of Leaflet drawing tiles disjointly
– peeebeee
Nov 14 '18 at 14:31
Possible duplicate of Leaflet drawing tiles disjointly
– peeebeee
Nov 14 '18 at 14:31
adding leaflet css file fixed the problem, thanks @xmojmr
– S.Aminnejad
Nov 14 '18 at 15:07
adding leaflet css file fixed the problem, thanks @xmojmr
– S.Aminnejad
Nov 14 '18 at 15:07
add a comment |
2 Answers
2
active
oldest
votes
Yeah you're missing the css file.
incidentally this is not how you should be using react-leaflet
.
componentDidMount is not the place for doing what you're doing. Put that in the render like
import Map, TileLayer from 'react-leaflet';
<Map>
<TileLayer url="'http://s.tile.osm.org/z/x/y.png'" />
</Map>
add a comment |
You have not added the leaflet css file in your index.html
.
For leaflet version 1.3.4
, add the following to index.html
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css"
integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
crossorigin=""/>
In your map component css file, override the leaflet-container
class with desired height and width.
.leaflet-container
height: 600px;
width: 100%;
Once you have added that, use Map
and TileLayer
Components of react-leaflet
to render map.
import React, Component from "react";
import ReactDOM from "react-dom";
import Map, TileLayer from "react-leaflet";
import "./styles.css";
class App extends Component
state =
center: [51.505, -0.091],
zoom: 13
;
render()
return (
<div>
<Map center=this.state.center zoom=this.state.zoom>
<TileLayer
attribution='&copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://s.tile.osm.org/z/x/y.png"
/>
</Map>
</div>
);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
You can find working code here. https://codesandbox.io/s/2wnv7o1mlr
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%2f53299962%2fwhy-leaflet-map-doesnt-render-on-react-app%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
Yeah you're missing the css file.
incidentally this is not how you should be using react-leaflet
.
componentDidMount is not the place for doing what you're doing. Put that in the render like
import Map, TileLayer from 'react-leaflet';
<Map>
<TileLayer url="'http://s.tile.osm.org/z/x/y.png'" />
</Map>
add a comment |
Yeah you're missing the css file.
incidentally this is not how you should be using react-leaflet
.
componentDidMount is not the place for doing what you're doing. Put that in the render like
import Map, TileLayer from 'react-leaflet';
<Map>
<TileLayer url="'http://s.tile.osm.org/z/x/y.png'" />
</Map>
add a comment |
Yeah you're missing the css file.
incidentally this is not how you should be using react-leaflet
.
componentDidMount is not the place for doing what you're doing. Put that in the render like
import Map, TileLayer from 'react-leaflet';
<Map>
<TileLayer url="'http://s.tile.osm.org/z/x/y.png'" />
</Map>
Yeah you're missing the css file.
incidentally this is not how you should be using react-leaflet
.
componentDidMount is not the place for doing what you're doing. Put that in the render like
import Map, TileLayer from 'react-leaflet';
<Map>
<TileLayer url="'http://s.tile.osm.org/z/x/y.png'" />
</Map>
answered Nov 14 '18 at 15:09
jbccollinsjbccollins
19713
19713
add a comment |
add a comment |
You have not added the leaflet css file in your index.html
.
For leaflet version 1.3.4
, add the following to index.html
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css"
integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
crossorigin=""/>
In your map component css file, override the leaflet-container
class with desired height and width.
.leaflet-container
height: 600px;
width: 100%;
Once you have added that, use Map
and TileLayer
Components of react-leaflet
to render map.
import React, Component from "react";
import ReactDOM from "react-dom";
import Map, TileLayer from "react-leaflet";
import "./styles.css";
class App extends Component
state =
center: [51.505, -0.091],
zoom: 13
;
render()
return (
<div>
<Map center=this.state.center zoom=this.state.zoom>
<TileLayer
attribution='&copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://s.tile.osm.org/z/x/y.png"
/>
</Map>
</div>
);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
You can find working code here. https://codesandbox.io/s/2wnv7o1mlr
add a comment |
You have not added the leaflet css file in your index.html
.
For leaflet version 1.3.4
, add the following to index.html
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css"
integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
crossorigin=""/>
In your map component css file, override the leaflet-container
class with desired height and width.
.leaflet-container
height: 600px;
width: 100%;
Once you have added that, use Map
and TileLayer
Components of react-leaflet
to render map.
import React, Component from "react";
import ReactDOM from "react-dom";
import Map, TileLayer from "react-leaflet";
import "./styles.css";
class App extends Component
state =
center: [51.505, -0.091],
zoom: 13
;
render()
return (
<div>
<Map center=this.state.center zoom=this.state.zoom>
<TileLayer
attribution='&copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://s.tile.osm.org/z/x/y.png"
/>
</Map>
</div>
);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
You can find working code here. https://codesandbox.io/s/2wnv7o1mlr
add a comment |
You have not added the leaflet css file in your index.html
.
For leaflet version 1.3.4
, add the following to index.html
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css"
integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
crossorigin=""/>
In your map component css file, override the leaflet-container
class with desired height and width.
.leaflet-container
height: 600px;
width: 100%;
Once you have added that, use Map
and TileLayer
Components of react-leaflet
to render map.
import React, Component from "react";
import ReactDOM from "react-dom";
import Map, TileLayer from "react-leaflet";
import "./styles.css";
class App extends Component
state =
center: [51.505, -0.091],
zoom: 13
;
render()
return (
<div>
<Map center=this.state.center zoom=this.state.zoom>
<TileLayer
attribution='&copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://s.tile.osm.org/z/x/y.png"
/>
</Map>
</div>
);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
You can find working code here. https://codesandbox.io/s/2wnv7o1mlr
You have not added the leaflet css file in your index.html
.
For leaflet version 1.3.4
, add the following to index.html
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css"
integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
crossorigin=""/>
In your map component css file, override the leaflet-container
class with desired height and width.
.leaflet-container
height: 600px;
width: 100%;
Once you have added that, use Map
and TileLayer
Components of react-leaflet
to render map.
import React, Component from "react";
import ReactDOM from "react-dom";
import Map, TileLayer from "react-leaflet";
import "./styles.css";
class App extends Component
state =
center: [51.505, -0.091],
zoom: 13
;
render()
return (
<div>
<Map center=this.state.center zoom=this.state.zoom>
<TileLayer
attribution='&copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
url="https://s.tile.osm.org/z/x/y.png"
/>
</Map>
</div>
);
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
You can find working code here. https://codesandbox.io/s/2wnv7o1mlr
answered Nov 15 '18 at 3:31
Murli PrajapatiMurli Prajapati
1,41411121
1,41411121
add a comment |
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%2f53299962%2fwhy-leaflet-map-doesnt-render-on-react-app%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
Check stackoverflow.com/a/38836996/2626313
– xmojmr
Nov 14 '18 at 12:39
2
Possible duplicate of Leaflet drawing tiles disjointly
– peeebeee
Nov 14 '18 at 14:31
adding leaflet css file fixed the problem, thanks @xmojmr
– S.Aminnejad
Nov 14 '18 at 15:07