Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
91 lines (75 sloc) 4.33 KB
<!DOCTYPE html>
<html>
<head>
<title>Limit Scroll Wheel Zoom - Azure Maps Web SDK Samples</title>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="This sample shows how to limit the scroll zooming functionality of the map such that the map will only be zoomed when the CTRL key is pressed. When the CTRL key is not pressed, the scroll wheel will scroll the page when over the map." />
<meta name="keywords" content="map, gis, API, SDK, mouse wheel, mousewheel, scroll page, map, user interaction, scrollZoomInteraction" />
<meta name="author" content="Microsoft Azure Maps" />
<!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
<link rel="stylesheet" href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.css" type="text/css" />
<script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.js"></script>
<script type='text/javascript'>
var map, datasource;
function GetMap() {
//Initialize a map instance.
map = new atlas.Map('myMap', {
view: 'Auto',
//Add your Azure Maps subscription key to the map SDK. Get an Azure Maps key at https://azure.com/maps
authOptions: {
authType: 'subscriptionKey',
subscriptionKey: '<Your Azure Maps Key>'
}
});
//Limit the scroll wheel zooming such that the map is only zoomed when the CTRL key is pressed.
LimitScrollWheelZoom(map);
}
function LimitScrollWheelZoom(map) {
map.setUserInteraction({ scrollZoomInteraction: false });
//Create a message dialog to tell the user how to zoom the map if they use the scroll wheel on the map without CTRL.
var msgDialog = document.createElement('div');
msgDialog.innerHTML = '<div style="display:none;position:absolute;top:0;left:0;width:100%;height:100%;background-color:rgba(0,0,0,0.5);color:white;font-size:24px;font-weight:bold;transition:visibility 0s linear 0s, opacity 500ms;"><div style="position:relative;float:left;top:50%;left:50%;transform:translate(-50%,-50%);">Use ctrl + scroll to zoom the map</div></div>'
msgDialog = msgDialog.firstChild;
map.getMapContainer().append(msgDialog);
//Show the message dialog for 2 seconds then fade out over 300ms.
var showMsgDialog = function () {
msgDialog.style.display = '';
msgDialog.style.opacity = 1;
setTimeout(function () {
msgDialog.style.opacity = 0;
setTimeout(function () {
msgDialog.style.display = 'none';
}, 300);
}, 2000);
};
map.getMapContainer().addEventListener('mousewheel', function (e) {
if (!e.ctrlKey) {
showMsgDialog();
}
});
window.addEventListener('keydown', function (e) {
if (e.ctrlKey) {
map.setUserInteraction({ scrollZoomInteraction: true });
}
});
window.addEventListener('keyup', function (e) {
if (!e.ctrlKey) {
map.setUserInteraction({ scrollZoomInteraction: false });
}
});
}
</script>
</head>
<body onload="GetMap()">
<div id="myMap" style="position:relative;width:100%;min-width:290px;height:600px;"></div>
<fieldset style="width:calc(100% - 30px);min-width:290px;margin-top:10px;">
<legend>Limit Scroll Wheel Zoom</legend>
This sample shows how to limit the scroll zooming functionality of the map such that the map will only be zoomed when the CTRL key is pressed.
When the CTRL key is not pressed, the scroll wheel will scroll the page when over the map.
</fieldset>
<br /><br />Adding several new lines so that the page can be scrolled.<br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</body>
</html>
You can’t perform that action at this time.