-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fitBounds and mouse latlng examples
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |