I am using the LeafletJS plugin to display a full page map in a ReactJS single page app. I followed the instructions here. However, the tiles are not displayed in correct order. They are ordered randomly (?). I found a similar problem here but in that case the order was fixed on page refresh. That is not true for me. My code is (excluding boilerplate):
index.html
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="stylesheets/atlas.css">
</head>
<body>
<div id="app">
Loading...
</div>
<script src="javascripts/atlas.js"></script>
</body>
</html>
index.js
render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('app')
)
App.jsx
import LiveMap from './LiveMap';
// App component
const App = () => (
<LiveMap />
)
export default App;
LiveMap.jsx
class LiveMap extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div id='map'></div>
);
}
componentDidMount() {
let _map = this.map = L.map(ReactDOM.findDOMNode(this)).setView([-41.2858, 174.78682], 14);
L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://openstreetmap.org">OpenStreetMap</a> Contributors',
maxZoom: 18,
}).addTo(_map);
}
componentWillUnmount() {...}
shouldComponentUpdate() {return false;}
};
export default LiveMap;
componentDidMountcan be somewhat misleading in that the element has been inserted into the DOM but not fully rendered (no width and height). Leaflet needs the width and height to render properly...atlas.cssandatlas.jsfiles made of? The shuffled tiles is usually a symptom of not loadingleaflet.cssstylesheet.leaflet.cssexplicitly. Still no success.