Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
<!DOCTYPE html>
<html lang="en">
<head>
<title>Extruded choropleth map - 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 shows how to create a choropleth map of extruded polygons using data driven styling." />
<meta name="keywords" content="Microsoft maps, map, gis, API, SDK, thematic, choropleth, heatmap, heat map, polygon extrusion, extruded polygons" />
<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;
var defaultColor = '#00ff80';
var colorScale = [
10, '#09e076',
20, '#0bbf67',
50, '#f7e305',
100, '#f7c707',
200, '#f78205',
500, '#f75e05',
1000, '#f72505'
];
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', {
center: [-94.6, 39.1],
zoom: 3,
//Pitch the map so that the extrusion of the polygons is visible.
pitch: 45,
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>'
}
});
//Create a legend.
createLegend();
//Wait until the map resources are ready.
map.events.add('ready', function () {
//Create a data source to add your data to.
datasource = new atlas.source.DataSource();
map.sources.add(datasource);
//Load a dataset of polygons that have metadata we can style against.
datasource.importDataFromUrl('../Common/data/geojson/US_States_Population_Density.json');
//Create a stepped expression based on the color scale.
var steppedExp = [
'step',
['get', 'density'],
defaultColor
];
steppedExp = steppedExp.concat(colorScale);
//Create and add a polygon extrusion layer to the map below the labels so that they are still readable.
map.layers.add(new atlas.layer.PolygonExtrusionLayer(datasource, null, {
base: 100,
fillColor: steppedExp,
fillOpacity: 0.7,
height: [
'interpolate',
['linear'],
['get', 'density'],
0, 100,
1200, 960000
]
}), 'labels');
});
}
function createLegend() {
var html = [];
html.push('<i style="background:', defaultColor, '"></i> 0-', colorScale[0], '<br/>');
for (var i = 0; i < colorScale.length; i += 2) {
html.push(
'<i style="background:', (colorScale[i + 1]), '"></i> ',
colorScale[i], (colorScale[i + 2] ? '&ndash;' + colorScale[i + 2] + '<br/>' : '+')
);
}
document.getElementById('legend').innerHTML += html.join('');
}
</script>
<style>
#legend {
position: absolute;
top: 1px;
left: 5px;
font-family: Arial;
font-size: 12px;
background-color: rgba(255, 255, 255, 0.8);
border-radius: 5px;
padding: 5px;
line-height: 20px;
}
#legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
}
</style>
</head>
<body onload="GetMap()">
<div id="myMap" style="position:relative;width:100%;min-width:290px;height:600px;"></div>
<div id="legend">Population Density<br />(people/mi<sup>2</sup>)<br /></div>
<fieldset style="width:calc(100% - 30px);min-width:290px;margin-top:10px;">
<legend><h1 style="font-size:16px">Extruded choropleth map</h1></legend>
This sample shows how to create a choropleth map of extruded polygons using data driven styling.
A choropleth map is a thematic map in which areas are shaded or patterned in proportion to the measurement
of the statistical variable being displayed on the map, in this case the population density of each state.
</fieldset>
</body>
</html>