Add touch-only pitch adjustment

master
Skylar Ittner 5 years ago
parent 1e4522fddc
commit 41a94380ec

@ -13,14 +13,49 @@ const map = new mapboxgl.Map({
container: 'mapbox', container: 'mapbox',
style: SETTINGS['map_style_json'], style: SETTINGS['map_style_json'],
attributionControl: false, attributionControl: false,
touchZoomRotate: 'center', dragPan: false,
pitch: 0, pitch: 0,
zoom: 0, zoom: 0,
maxZoom: 20 maxZoom: 20
}); });
map.touchZoomRotate.enable({around: 'center'}); var dpPoint = null;
map.dragPan.disable(); var dpPitch = null;
map.on('touchstart', function (data) {
if (data.points.length == 2) {
var diff = Math.abs(data.points[0].y - data.points[1].y);
if (diff <= 50) {
dpPoint = data.point;
map.touchZoomRotate.disable();
dpPitch = map.getPitch();
}
}
});
map.on('touchmove', function (data) {
if (dpPoint) {
data.preventDefault();
var pitchdiff = (dpPoint.y - data.point.y) * 0.5;
map.setPitch(dpPitch + pitchdiff);
}
});
map.on('touchend', function (data) {
if (dpPoint) {
map.touchZoomRotate.enable();
}
dpPoint = null;
dpPitch = null;
});
map.on('touchcancel', function (data) {
if (dpPoint) {
map.touchZoomRotate.enable();
}
dpPoint = null;
dpPitch = null;
});
function mapEasing(t) { function mapEasing(t) {
return t * (2 - t); return t * (2 - t);
@ -98,7 +133,7 @@ function updatePlaceLayer(latitude, longitude) {
function animateMapIn(latitude, longitude, zoom, heading) { function animateMapIn(latitude, longitude, zoom, heading) {
if (typeof zoom == 'undefined') { if (typeof zoom == 'undefined') {
zoom = 15; zoom = 17;
} }
if (typeof heading == 'undefined') { if (typeof heading == 'undefined') {
heading = 0; heading = 0;
@ -115,7 +150,7 @@ function animateMapIn(latitude, longitude, zoom, heading) {
}); });
// Set min zoom after some time to fly in // Set min zoom after some time to fly in
setTimeout(function () { setTimeout(function () {
map.setMinZoom(15); map.setMinZoom(16);
map.setPitch(45); map.setPitch(45);
}, 1000); }, 1000);
} }
Loading…
Cancel
Save