Restrict map panning to an area
Prevent a map from being panned to a different place by setting maxBounds.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Restrict map panning to an area</title>
<meta property="og:description" content="Prevent a map from being panned to a different place by setting maxBounds." />
<meta charset='utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/trackasia-gl.css" />
<script src="https://unpkg.com/[email protected]/dist/trackasia-gl.js"></script>
<style>
body { margin: 0; padding: 0; }
html, body, #map { height: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
// Set bounds
const bounds = [
[105.64728500751166,10.58392799015035], // Southwest coordinates
[107.51058699000139,10.97764500765852] // Northeast coordinates
];
const map = new trackasiagl.Map({
container: 'map',
style: 'https://maps.track-asia.com/styles/v2/streets.json?key=public_key',
center: {"lat":10.762622,"lng":106.660172},
zoom: 10,
maxBounds: bounds // Sets bounds as max
});
</script>
</body>
</html>