-
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.
account for padding in getBounds (#10386)
* account for padding in getBounds * add debug page * update documentation * lint * add unit test to check that getBounds returns the inset with padding
- Loading branch information
1 parent
9d90327
commit 9a08dd4
Showing
5 changed files
with
108 additions
and
4 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,84 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Mapbox GL JS debug page</title> | ||
<meta charset='utf-8'> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> | ||
<link rel='stylesheet' href='../dist/mapbox-gl.css' /> | ||
<style> | ||
body { margin: 0; padding: 0; } | ||
html, body, #map { height: 100%; } | ||
#getBounds { position: absolute; top: 0; left; 0; } | ||
#setBounds { position: absolute; top: 0; left: 78px; } | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id='map'></div> | ||
<button id="getBounds">getBounds</button> | ||
<button id="setBounds">setBounds</button> | ||
|
||
<script src='../dist/mapbox-gl-dev.js'></script> | ||
<script src='../debug/access_token_generated.js'></script> | ||
<script> | ||
|
||
var map = window.map = new mapboxgl.Map({ | ||
container: 'map', | ||
zoom: 12.5, | ||
center: [-122.4194, 37.7749], | ||
style: 'mapbox://styles/mapbox/streets-v10', | ||
hash: true | ||
}); | ||
|
||
map.setPadding({ | ||
left: 400, | ||
top: 50, | ||
right: 50, | ||
bottom: 50 | ||
}); | ||
map.showPadding = true; | ||
|
||
map.on('load', function () { | ||
map.addSource('bounds', { | ||
type: 'geojson', | ||
data: { | ||
type: 'FeatureCollection', | ||
features: [] | ||
} | ||
}); | ||
map.addLayer({ | ||
type: 'line', | ||
id: 'bounds', | ||
source: 'bounds', | ||
paint: { | ||
'line-width': 10 | ||
} | ||
}); | ||
}); | ||
|
||
var bounds; | ||
document.getElementById('getBounds').addEventListener('click', function () { | ||
bounds = map.getBounds(); | ||
map.getSource('bounds').setData({ | ||
type: 'Feature', | ||
properties: {}, | ||
geometry: { | ||
type: 'Polygon', | ||
coordinates: [[ | ||
bounds.getNorthEast().toArray(), | ||
bounds.getSouthEast().toArray(), | ||
bounds.getSouthWest().toArray(), | ||
bounds.getNorthWest().toArray(), | ||
bounds.getNorthEast().toArray() | ||
]] | ||
} | ||
}); | ||
}); | ||
document.getElementById('setBounds').addEventListener('click', function () { | ||
map.fitBounds(bounds, { | ||
duration: 0 | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
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
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
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
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