-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anand Thakker
committed
Jun 22, 2016
1 parent
cd94dc9
commit d7371c5
Showing
3 changed files
with
215 additions
and
52 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,171 @@ | ||
<!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%; } | ||
#checkboxes { | ||
position: absolute; | ||
background: #fff; | ||
top:0; | ||
left:0; | ||
padding:10px; | ||
} | ||
#buffer { | ||
position: absolute; | ||
top:100px; | ||
left:0; | ||
pointer-events: none; | ||
} | ||
#buffer div { | ||
background-color: #fff; | ||
padding: 5px 0; | ||
text-indent: 10px; | ||
white-space: nowrap; | ||
text-shadow: | ||
-1px -1px 0 #fff, | ||
1px -1px 0 #fff, | ||
-1px 1px 0 #fff, | ||
1px 1px 0 #fff; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id='map'></div> | ||
<div id='checkboxes'> | ||
<input id='show-tile-boundaries-checkbox' name='show-tile-boundaries' type='checkbox'> <label for='show-tile-boundaries'>tile debug</label><br /> | ||
<input id='show-symbol-collision-boxes-checkbox' name='show-symbol-collision-boxes' type='checkbox'> <label for='show-symbol-collision-boxes'>collision debug</label><br /> | ||
<input id='show-overdraw-checkbox' name='show-overdraw' type='checkbox'> <label for='show-overdraw'>overdraw debug</label><br /> | ||
<input id='buffer-checkbox' name='buffer' type='checkbox'> <label for='buffer'>buffer stats</label> | ||
</div> | ||
|
||
<div id='buffer' style="display:none"> | ||
<em>Waiting for data...</em> | ||
</div> | ||
|
||
<script src='https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.14/proj4-src.js'></script> | ||
<script src='mapbox-gl.js'></script> | ||
<script src='access-token.js'></script> | ||
|
||
<script> | ||
var style = { | ||
"version": 8, | ||
"sources": { | ||
"states": { | ||
"type": "vector", | ||
"url": "mapbox://devseed.states-albers" | ||
} | ||
}, | ||
"layers": [{ | ||
"id": "background", | ||
"type": "background", | ||
"paint": { | ||
"background-color": "rgb(4,7,14)" | ||
} | ||
}, { | ||
"id": "states", | ||
"type": "line", | ||
"source": "states", | ||
"source-layer": "states", | ||
"paint": { | ||
"line-color": "#EC8D8D", | ||
"line-width": { | ||
"base": 1.5, | ||
"stops": [ | ||
[ | ||
5, | ||
0.75 | ||
], | ||
[ | ||
18, | ||
32 | ||
] | ||
] | ||
} | ||
} | ||
}] | ||
}; | ||
|
||
// Custom projection. The dataset was generated by (a) projecting into albers | ||
// (using precisely the projection string being passed to `proj4` below, and then | ||
// (b) piping into tippecanoe with -s EPSG:3785. | ||
// With this option set, tippecanoe does NOT try to project fron lnglat, but it | ||
// DOES do an affine transformation to go from EPSG's projected space (meters) to | ||
// tile space -- hence the small additional bits of math after `proj.forward` and | ||
// before `proj.inverse`. | ||
|
||
var proj = proj4('WGS84', '+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs') | ||
var C = 2 * Math.PI * 6378137.0; | ||
var projection = { | ||
latRange: undefined, | ||
project: function (lnglat, worldSize) { | ||
var pt = proj.forward([lnglat.lng, lnglat.lat]) | ||
var scale = (worldSize || this.worldSize); | ||
pt[0] = scale * (pt[0] / C + 0.5); | ||
pt[1] = scale * (0.5 - pt[1] / C); | ||
return new mapboxgl.Point(pt[0], pt[1]); | ||
}, | ||
unproject: function (point, worldSize) { | ||
var scale = (worldSize || this.worldSize); | ||
var ll = proj.inverse([ | ||
C * ((point.x / scale) - 0.5), | ||
C * (0.5 - (point.y / scale)) | ||
]); | ||
return mapboxgl.LngLat.convert(ll); | ||
} | ||
} | ||
|
||
var map = window.map = new mapboxgl.Map({ | ||
container: 'map', | ||
zoom: 5.5, | ||
center: [-77.01866, 38.888], | ||
style: style, | ||
projection: projection, | ||
hash: true | ||
}); | ||
|
||
map.addControl(new mapboxgl.Navigation()); | ||
map.addControl(new mapboxgl.Geolocate()); | ||
|
||
map.on('click', function(e) { | ||
if (e.originalEvent.shiftKey) return; | ||
(new mapboxgl.Popup()) | ||
.setLngLat(map.unproject(e.point)) | ||
.setHTML("<h1>Hello World!</h1>") | ||
.addTo(map); | ||
}); | ||
|
||
document.getElementById('show-tile-boundaries-checkbox').onclick = function() { | ||
map.showTileBoundaries = !!this.checked; | ||
}; | ||
|
||
document.getElementById('show-symbol-collision-boxes-checkbox').onclick = function() { | ||
map.showCollisionBoxes = !!this.checked; | ||
}; | ||
|
||
document.getElementById('show-overdraw-checkbox').onclick = function() { | ||
map.showOverdrawInspector = !!this.checked; | ||
}; | ||
|
||
document.getElementById('buffer-checkbox').onclick = function() { | ||
document.getElementById('buffer').style.display = this.checked ? 'block' : 'none'; | ||
}; | ||
|
||
// keyboard shortcut for comparing rendering with Mapbox GL native | ||
document.onkeypress = function(e) { | ||
if (e.charCode === 111 && !e.shiftKey && !e.metaKey && !e.altKey) { | ||
var center = map.getCenter(); | ||
location.href = "mapboxgl://?center=" + center.lat + "," + center.lng + "&zoom=" + map.getZoom() + "&bearing=" + map.getBearing(); | ||
return false; | ||
} | ||
}; | ||
</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