JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.css">
<script src="http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.js"></script>
<div id="map"> </div>
SCSS
body {
height:100%;
}
#map {
position:absolute;
top:0;
bottom:0;
left:0;
right:0;
background:black;
}
JavaScript
L.Map.include({
panInsideBounds: function(bounds) {
bounds = L.latLngBounds(bounds);
var viewBounds = this.getBounds(),
viewSw = this.project(viewBounds.getSouthWest()),
viewNe = this.project(viewBounds.getNorthEast()),
sw = this.project(bounds.getSouthWest()),
ne = this.project(bounds.getNorthEast()),
dx = 0,
dy = 0,
cp; // compensate for projection (only works for map mercator)
if (viewNe.y < ne.y) { // north
cp = this.latLngToContainerPoint([85.05112878, 0]).y;
dy = ne.y - viewNe.y + (cp > 0 ? cp : 0);
}
if (viewNe.x > ne.x) { // east
dx = ne.x - viewNe.x;
}
if (viewSw.y > sw.y) { // south
cp = this.latLngToContainerPoint([-85.05112878, 0]).y - this.getSize().y;
dy = sw.y - viewSw.y + (cp < 0 ? cp : 0);
}
if (viewSw.x < sw.x) { // west
dx = sw.x - viewSw.x;
}
return this.panBy(new L.Point(dx, dy, true));
}
});
// create a map in the "map" div, set the view to a given place and zoom
var map = L.map('map', {
layers: [
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
noWrap: true
})],
zoom: 0,
center: [49.009952, 2.548635],
// maxBounds: [[-90.0,-180.0],[90.0,180.0]]
maxBounds: [
[-85.0, -180.0],
[85.0, 180.0]
]
});