Skip to content

Commit

Permalink
Add fitBounds and mouse latlng examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Apr 16, 2015
1 parent a270379 commit d5462e2
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs/_posts/examples/3400-01-03-fitbounds.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
layout: example
category: example
title: fitBounds
description: Use fitBounds to show a specific area of the map in view, regardless of the pixel size of the map.
---

<style>
#fit {
display: block;
position: relative;
margin: 0px auto;
width: 50%;
height: 40px;
padding: 10px;
border: none;
border-radius: 3px;
font-size: 12px;
text-align: center;
color: #fff;
background: #ee8a65;
}
</style>
<div id='map'></div>
<br />
<button onclick='fit();' id='fit'>Fit to Kenya</button>
<script>
var map = new mapboxgl.Map({
container: 'map',
style: 'https://www.mapbox.com/mapbox-gl-styles/styles/outdoors-v7.json',
center: [40, -74.50],
zoom: 9
});

function fit() {
map.fitBounds([[
-5.353521,
32.958984
], [
5.615985,
43.50585
]]);
}
</script>
37 changes: 37 additions & 0 deletions docs/_posts/examples/3400-01-03-mouse-latlng.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
layout: example
category: example
title: Get mouse latitude and longitude
description: Use mousemove and unproject to show the geographical position of the mouse cursor
---

<style>
#latlng {
display: block;
position: relative;
margin: 0px auto;
width: 50%;
padding: 10px;
border: none;
border-radius: 3px;
font-size: 12px;
text-align: center;
color: #222;
background: #fff;
}
</style>
<div id='map'></div>
<br />
<pre id='latlng'>...</pre>
<script>
var map = new mapboxgl.Map({
container: 'map',
style: 'https://www.mapbox.com/mapbox-gl-styles/styles/outdoors-v7.json',
center: [40, -74.50],
zoom: 9
});

map.on('mousemove', function(event) {
document.getElementById('latlng').innerHTML = event.latLng.lat + ', ' + event.latLng.lng;
});
</script>

0 comments on commit d5462e2

Please sign in to comment.