Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time
<!DOCTYPE html>
<html lang="en">
<title>Filter Symbols by Property - 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 filter symbols on the map by property by creating a layer fro each property value and then toggling the visibility of that layer accordingly. " />
<meta name="keywords" content="Microsoft maps, map, gis, API, SDK, symbols, markers, pins, pushpins, styling, style, layer" />
<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, client, datasource, layer;
var categories = ['bar', 'coffee', 'restaurant'];
function GetMap() {
//Point the Azure Maps domain to the US Azure Gov Cloud domain.
//Initialize a map instance.
map = new atlas.Map('myMap', {
center: [-122.338124, 47.6078],
zoom: 16,
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 = '';
fetch(tokenServiceUrl).then(r => r.text()).then(token => resolve(token));
//Alternatively, use an Azure Maps key. Get an Azure Maps key at NOTE: The primary key should be used as the key.
//authType: 'subscriptionKey',
//subscriptionKey: '<Your Azure Maps Key>'
//Wait until the map resources are ready.'ready', function () {
//Create a data source and add it to the map.
datasource = new atlas.source.DataSource();
//Add a data set to the data source.
new[-122.338913, 47.607471]), { category: 'bar' }),
new[-122.341187, 47.608192]), { category: 'bar' }),
new[-122.335014, 47.607960]), { category: 'bar' }),
new[-122.337555, 47.608620]), { category: 'bar' }),
new[-122.338524, 47.606907]), { category: 'coffee' }),
new[-122.336655, 47.606251]), { category: 'coffee' }),
new[-122.336182, 47.607185]), { category: 'coffee' }),
new[-122.337784, 47.607784]), { category: 'coffee' }),
new[-122.338455, 47.606880]), { category: 'restaurant' }),
new[-122.336823, 47.607239]), { category: 'restaurant' }),
new[-122.339027, 47.608040]), { category: 'restaurant' }),
new[-122.335892, 47.607594]), { category: 'restaurant' })
//Create a symbol layer to render the points.
layer = new atlas.layer.SymbolLayer(datasource, null, {
iconOptions: {
//The map control has built in icons for bar, coffee and restaurant that we can use.
image: ['get', 'category'],
anchor: 'center',
allowOverlap: true
function filterSymbols(elm, category) {
//Set the visibility of the layer.
if (elm.checked) {
//Add the category to the categories array.
} else {
//Remove the category to the categories array.
categories.splice(categories.indexOf(category), 1);
//Create a filter that grabs the category of each point and checks that it is in the array of categories.
var filter = ['in', ['get', 'category'], ['literal', categories]];
//Update the filter in the layer.
filter: filter
<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;background-color:white;padding:10px;border-radius:10px;">
<input type="checkbox" checked="checked" onclick="filterSymbols(this, 'bar')" /> Bar<br />
<input type="checkbox" checked="checked" onclick="filterSymbols(this, 'coffee')" /> Coffee<br />
<input type="checkbox" checked="checked" onclick="filterSymbols(this, 'restaurant')" /> Restaurant
<fieldset style="width:calc(100% - 30px);min-width:290px;margin-top:10px;">
<legend><h1 style="font-size:16px">Filter Points by Symbols</h1></legend>
This sample shows how to filter symbols on the map by property by creating a layer fro each property value and then toggling the visibility of that layer accordingly.