Last active
January 20, 2021 08:34
-
-
Save oscarlorentzon/37d28603212de2b8326bb65e49418368 to your computer and use it in GitHub Desktop.
Mouse and touch handlers
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='utf-8' /> | |
<title></title> | |
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> | |
<script src='https://unpkg.com/mapillary-js@3.1.0/dist/mapillary.min.js'></script> | |
<link href='https://unpkg.com/mapillary-js@3.1.0/dist/mapillary.min.css' rel='stylesheet' /> | |
<style> | |
html, body { margin: 0; padding: 0; height: 100%; } | |
#mly { height: 100%; width: 100%; position: absolute; } | |
#menu { | |
position: absolute; | |
background: #fff; | |
padding: 10px; | |
font-family: 'Open Sans', sans-serif; | |
} | |
</style> | |
</head> | |
<body> | |
<div id='mly'></div> | |
<div id='menu'> | |
<input id='doubleClickZoom' type='checkbox' name='rtoggle' value='doubleClickZoom'> | |
<label for='doubleClickZoom'>double click zoom</label> | |
<input id='dragPan' type='checkbox' name='rtoggle' value='dragPan'> | |
<label for='dragPan'>drag pan</label> | |
<input id='scrollZoom' type='checkbox' name='rtoggle' value='scrollZoom'> | |
<label for='scrollZoom'>scroll zoom</label> | |
<input id='touchZoom' type='checkbox' name='rtoggle' value='touchZoom'> | |
<label for='touchZoom'>touch zoom</label> | |
</div> | |
<script> | |
var mly = new Mapillary.Viewer({ | |
apiClient: "QjI1NnU0aG5FZFZISE56U3R5aWN4Zzo3NTM1MjI5MmRjODZlMzc0", | |
component: { | |
mouse: { | |
doubleClickZoom: false, | |
dragPan: false, | |
scrollZoom: false, | |
touchZoom: false, | |
}, | |
sequence: false, | |
}, | |
container: "mly", | |
}); | |
mly.moveToKey("Xrx4uuN5TTZERFQDW5C9Rw").catch(function(e) { console.error(e); }); | |
var mouseComponent = mly.getComponent("mouse"); | |
var handlerList = document.getElementById('menu'); | |
var inputs = handlerList.getElementsByTagName('input'); | |
function switchHandler(e) { | |
var handler = e.target.value; | |
var checked = e.target.checked; | |
if (checked) { | |
if (handler === "doubleClickZoom") { | |
mouseComponent.doubleClickZoom.enable(); | |
} else if (handler === "dragPan") { | |
mouseComponent.dragPan.enable(); | |
} else if (handler === "scrollZoom") { | |
mouseComponent.scrollZoom.enable(); | |
} else if (handler === "touchZoom") { | |
mouseComponent.touchZoom.enable(); | |
} | |
} else { | |
if (handler === "doubleClickZoom") { | |
mouseComponent.doubleClickZoom.disable(); | |
} else if (handler === "dragPan") { | |
mouseComponent.dragPan.disable(); | |
} else if (handler === "scrollZoom") { | |
mouseComponent.scrollZoom.disable(); | |
} else if (handler === "touchZoom") { | |
mouseComponent.touchZoom.disable(); | |
} | |
} | |
} | |
for (var i = 0; i < inputs.length; i++) { | |
inputs[i].onclick = switchHandler; | |
} | |
window.addEventListener("resize", function() { mly.resize(); }); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment