Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
<!DOCTYPE html>
<html lang="en">
<head>
<title>Animation easings - Azure Maps Web SDK Samples</title>
<meta charset="utf-8" />
<link rel="shortcut icon" href="/favicon.ico"/>
<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 demonstrates the different built in easing functions in the azure-maps-animation library." />
<meta name="keywords" content="Microsoft maps, map, gis, API, SDK, animation, animate, animations, point, symbol, pushpin, marker, pin, easing" />
<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>
<!-- Loading in a charting library for the sample. -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.css" type="text/css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<!-- Add reference to the animation module. -->
<script src="../Common/scripts/azure-maps-animations.min.js"></script>
<script type='text/javascript'>
var map, point;
function GetMap() {
//Point the Azure Maps domain to the US Azure Gov Cloud domain.
atlas.setDomain('atlas.azure.us');
//Initialize a map instance.
map = new atlas.Map('myMap', {
zoom: 3,
pitch: 60,
view: 'Auto',
//Add authentication details for connecting to Azure Maps.
authOptions: {
//Use Azure Active Directory authentication.
authType: 'anonymous',
clientId: 'c9f2f391-13f1-407b-a4a5-f0a241bacfbf', //Your Azure Active Directory client id for accessing your Azure Maps account.
getToken: function (resolve, reject, map) {
//URL to your authentication service that retrieves an Azure Active Directory Token.
var tokenServiceUrl = 'https://azuremapscodesamples.azurewebsites.us/Common/TokenService.ashx';
fetch(tokenServiceUrl).then(r => r.text()).then(token => resolve(token));
}
//Alternatively, use an Azure Maps key. Get an Azure Maps key at https://azure.com/maps. NOTE: The primary key should be used as the key.
//authType: 'subscriptionKey',
//subscriptionKey: '<Your Azure Maps Key>'
}
});
//Wait until the map resources are ready.
map.events.add('ready', function () {
point = new atlas.Shape(new atlas.data.Point([0,0]));
//Create a data source and add it to the map.
datasource = new atlas.source.DataSource();
map.sources.add(datasource);
//Add the data to the data source.
datasource.add(point);
//Add a layer for rendering point data. This could be any layer that supports rendering point data.
map.layers.add(new atlas.layer.SymbolLayer(datasource, null, {
iconOptions: {
offset: ['get', 'offset'],
//For smoother animation, ignore the placement of the icon. This skips the label collision calculations and allows the icon to overlap map labels.
ignorePlacement: true,
//For smoother animation, allow symbol to overlap all other symbols on the map.
allowOverlap: true
}
}));
//Load the easing function dropdown
//Get a list of the easing functions.
var html = ['<option value=""></option>'];
atlas.animations.getEasingNames().forEach(e => {
html.push(`<option value="${e}">${e}</option>`);
});
document.getElementById('easingFns').innerHTML = html.join('');
//Initialize the chart.
easingChart = new Chart(document.getElementById('easingChart'), {
type: 'line',
data: {
//X-axis
labels: xAxis
},
options: {
legend: {
display: false
},
elements: {
line: {
fill: false,
borderColor: 'red',
},
point:{
radius: 0
}
},
responsive: true,
title: {
display: false
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Progress'
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
}
}]
}
}
});
});
}
var xAxis = [0,0.1, 0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1];
var easingChart;
var easing;
var animation;
function easingChanged(elm){
//Chart the easing function.
if(elm){
easingName = elm.value;
}
var easingFn = atlas.animations.getEasingFn(easingName);
var data = [];
if(easingFn){
for(var i = 0; i < xAxis.length; i++){
data.push(easingFn(xAxis[i]));
}
}
easingChart.data.datasets[0] = {
data: data
};
easingChart.update();
//Animate the point to a new random location using the easing function.
var randomPos = [Math.random() * 360 - 180, Math.random() * 170 - 85];
if(animation){
animation.dispose();
}
animation = atlas.animations.drop(point, null, null, {
duration: 2000,
easing: easingName,
autoPlay: true
});
}
</script>
</head>
<body onload="GetMap()">
<div id="myMap" style="position:relative;width:100%;min-width:290px;height:600px;"></div>
<div style="position:absolute;top:15px;left:15px;border-radius:5px;padding:5px;background-color:white;">
<b>Easing:</b>
<select id="easingFns" onchange="easingChanged(this)"></select>
<input type="button" value="Play" onclick="easingChanged()"/>
<br/><br/>
<div style="display:block;width:250px;height:250px;">
<canvas id="easingChart" style="display:block;width:250px;height:250px;" width="250" height="250"></canvas>
</div>
</div>
<fieldset style="width:calc(100% - 30px);min-width:290px;margin-top:10px;">
<legend><h1 style="font-size:16px">Animation easings</h1></legend>
This sample demonstrates the different built in easing functions in the Azure Maps animation module.
This sample uses the open source <a href="https://github.com/Azure-Samples/azure-maps-animations" target="_blank">Azure Maps Animation module</a>
</fieldset>
</body>
</html>