Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
136 lines (116 sloc) 5.16 KB
<!DOCTYPE html>
<html lang="en">
<title>Extruded choropleth map - 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 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="" type="text/css" />
<script src=""></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.
//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 your Azure Maps subscription key to the map SDK. Get an Azure Maps key at
authOptions: {
authType: 'subscriptionKey',
subscriptionKey: '<Your Azure Maps Key>'
//Create a legend.
//Wait until the map resources are ready.'ready', function () {
//Create a data source to add your data to.
datasource = new atlas.source.DataSource();
//Load a dataset of polygons that have metadata we can style against.
//Create a stepped expression based on the color scale.
var steppedExp = [
['get', 'density'],
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: [
['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) {
'<i style="background:', (colorScale[i + 1]), '"></i> ',
colorScale[i], (colorScale[i + 2] ? '&ndash;' + colorScale[i + 2] + '<br/>' : '+')
document.getElementById('legend').innerHTML += html.join('');
#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;
<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.
You can’t perform that action at this time.