Last active
January 20, 2021 08:35
-
-
Save oscarlorentzon/c92bbefbd4c74d4a490a8b37c85a1a7b to your computer and use it in GitHub Desktop.
Enable and disable keyboard handlers
This file contains hidden or 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/[email protected]/dist/mapillary.min.js'></script> | |
<link href='https://unpkg.com/[email protected]/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='keySequenceNavigation' type='checkbox' name='rtoggle' value='keySequenceNavigation'> | |
<label for='keySequenceNavigation'>key sequence navigation</label> | |
<input id='keySpatialNavigation' type='checkbox' name='rtoggle' value='keySpatialNavigation'> | |
<label for='keySpatialNavigation'>key spatial navigation</label> | |
<input id='keyZoom' type='checkbox' name='rtoggle' value='keyZoom'> | |
<label for='keyZoom'>key zoom</label> | |
</div> | |
<script> | |
var mly = new Mapillary.Viewer({ | |
apiClient: "QjI1NnU0aG5FZFZISE56U3R5aWN4Zzo3NTM1MjI5MmRjODZlMzc0", | |
component: { | |
keyboard: { | |
keySequenceNavigation: false, | |
keySpatialNavigation: false, | |
keyZoom: false, | |
}, | |
sequence: false, | |
}, | |
container: "mly", | |
}); | |
mly.moveToKey("Xrx4uuN5TTZERFQDW5C9Rw").catch(function(e) { console.error(e); }); | |
var keyboardComponent = mly.getComponent("keyboard"); | |
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 === "keySequenceNavigation") { | |
keyboardComponent.keySequenceNavigation.enable(); | |
} else if (handler === "keySpatialNavigation") { | |
keyboardComponent.keySpatialNavigation.enable(); | |
} else if (handler === "keyZoom") { | |
keyboardComponent.keyZoom.enable(); | |
} | |
} else { | |
if (handler === "keySequenceNavigation") { | |
keyboardComponent.keySequenceNavigation.disable(); | |
} else if (handler === "keySpatialNavigation") { | |
keyboardComponent.keySpatialNavigation.disable(); | |
} else if (handler === "keyZoom") { | |
keyboardComponent.keyZoom.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