Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
538 lines (495 sloc) 29.4 KB
<!DOCTYPE html>
<html>
<head>
<title>Symbol Layer Options - 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 the different options of the symbol layer affect rendering." />
<meta name="keywords" content="map, gis, API, SDK, symbols, markers, pins, pushpins, layer" />
<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 src="../Common/scripts/clipboard.min.js"></script>
<script type='text/javascript'>
var map, datasource, symbolLayer, testDataSize = 100, defaultOptions, removeDefaults;
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>'
}
});
//Wait until the map resources are ready.
map.events.add('ready', function () {
//Create a style control and add it to the map.
map.controls.add(new atlas.control.StyleControl({
style: 'dark'
}), {
position: 'top-right'
});
//Create a data source and add it to the map.
datasource = new atlas.source.DataSource();
map.sources.add(datasource);
//Add random point features to data source.
datasource.add(generateRandomPoints(testDataSize));
//Create a layer to render the point data.
symbolLayer = new atlas.layer.SymbolLayer(datasource);
map.layers.add(symbolLayer);
defaultOptions = symbolLayer.getOptions();
//Update the symbol layer with the options in the input fields.
updateSymbolLayer();
});
new ClipboardJS('.copyBtn');
}
function updateSymbolLayer() {
var options = getInputOptions();
//Update all the options in the symbol layer.
symbolLayer.setOptions(options);
document.getElementById('CodeOutput').value = JSON.stringify(options, null, '\t').replace(/\"([^(\")"]+)\":/g, "$1:");
}
function getInputOptions() {
removeDefaults = document.getElementById('RemoveDefaults').checked;
return {
iconOptions: {
image: getPropertyValue('iconOptions.image', getSelectValue('Icon')),
size: getPropertyValue('iconOptions.size', parseFloat(document.getElementById('IconSize').value)),
anchor: getPropertyValue('iconOptions.anchor', getSelectValue('IconAnchor')),
offset: getPropertyValue('iconOptions.offset', [
parseFloat(document.getElementById('IconOffsetX').value),
parseFloat(document.getElementById('IconOffsetY').value)
]),
rotation: getPropertyValue('iconOptions.rotation', parseFloat(document.getElementById('IconRotation').value)),
rotationAlignment: getPropertyValue('iconOptions.rotationAlignment', getSelectValue('IconRotationAlignment')),
opacity: getPropertyValue('iconOptions.opacity', parseFloat(document.getElementById('IconOpacity').value)),
allowOverlap: getPropertyValue('iconOptions.allowOverlap', document.getElementById('IconAllowOverlap').checked),
ignorePlacement: getPropertyValue('iconOptions.ignorePlacement', document.getElementById('IgnoreIconPlacement').checked),
optional: getPropertyValue('iconOptions.optional', document.getElementById('IconOptional').checked)
},
textOptions: {
allowOverlap: getPropertyValue('textOptions.allowOverlap', document.getElementById('TextAllowOverlap').checked),
anchor: getPropertyValue('textOptions.anchor', getSelectValue('TextAnchor')),
color: getPropertyValue('textOptions.color', document.getElementById('FontColor').value),
font: getPropertyValue('textOptions.font', [getSelectValue('TextFont')]),
ignorePlacement: getPropertyValue('textOptions.ignorePlacement', document.getElementById('IgnoreTextPlacement').checked),
haloBlur: getPropertyValue('textOptions.haloBlur', parseFloat(document.getElementById('HaloBlur').value)),
haloColor: getPropertyValue('textOptions.haloColor', document.getElementById('HaloColor').value),
haloWidth: getPropertyValue('textOptions.haloWidth', parseFloat(document.getElementById('HaloWidth').value)),
offset: getPropertyValue('textOptions.offset', [
parseFloat(document.getElementById('TextOffsetX').value),
parseFloat(document.getElementById('TextOffsetY').value)
]),
opacity: getPropertyValue('textOptions.opacity', parseFloat(document.getElementById('TextOpacity').value)),
optional: getPropertyValue('textOptions.optional', document.getElementById('TextOptional').checked),
size: getPropertyValue('textOptions.size', parseFloat(document.getElementById('FontSize').value)),
textField: ['get', 'title']
},
minZoom: getPropertyValue('minZoom', parseFloat(document.getElementById('MinZoom').value)),
maxZoom: getPropertyValue('maxZoom', parseFloat(document.getElementById('MaxZoom').value)),
visible: getPropertyValue('visible', document.getElementById('Visible').checked)
};
}
function getPropertyValue(propertyName, value) {
if (removeDefaults) {
if (propertyName.indexOf('.') > -1) {
var p = propertyName.split('.');
var val = defaultOptions;
for (var i = 0; i < p.length; i++) {
val = val[p[i]];
}
if (val === value) {
return undefined;
}
} else if (defaultOptions[propertyName] === value) {
return undefined;
}
}
return value;
}
function generateRandomPoints(cnt) {
var layerData = [];
for (var i = 0; i < cnt; i++) {
layerData.push(new atlas.data.Feature(new atlas.data.Point([Math.random() * 360 - 180, Math.random() * 170 - 85]), {
title: 'Pin_' + i
}));
}
return layerData;
}
function getSelectValue(id) {
var elm = document.getElementById(id);
return elm.options[elm.selectedIndex].value;
}
function openTab(elm, tabName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(tabName).style.display = "block";
elm.className += " active";
}
</script>
<style>
#myMap {
position: relative;
width: calc(100% - 375px);
min-width:290px;
height: 600px;
float: left;
}
.sidePanel {
width: 325px;
height: 580px;
float: left;
margin-right: 10px;
}
#CodeOutput {
width: 300px;
height: 400px;
overflow-y: auto;
}
.copyBtn {
float: right;
}
table td:nth-of-type(1) {
width: 120px;
}
table td:nth-of-type(2) {
width: 200px;
}
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 6px 8px;
transition: 0.3s;
font-size: 14px;
}
.tab button:hover {
background-color: #ddd;
}
.tab button.active {
background-color: #ccc;
}
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
</style>
</head>
<body onload="GetMap()">
<fieldset class="sidePanel">
<legend>Symbol Layer Options</legend>
This sample shows how the different options of the symbol layer affect rendering.
<br /><br />
<div class="tab">
<button class="tablinks active" onclick="openTab(this, 'BaseStyles')">Base Options</button>
<button class="tablinks" onclick="openTab(this, 'IconOptions')">Icon Options</button>
<button class="tablinks" onclick="openTab(this, 'TextOptions')">Text Options</button>
<button class="tablinks" onclick="openTab(this, 'Code')">Code</button>
</div>
<div id="BaseStyles" class="tabcontent" style="display:block;">
<table>
<tr title="An integer specifying the minimum zoom level to render the layer at.">
<td>Min Zoom:</td>
<td>
<form oninput="minz.value=MinZoom.value">
<input type="range" id="MinZoom" value="0" min="0" max="24" step="1" oninput="updateSymbolLayer()" onchange="updateSymbolLayer()" />
<output name="minz" for="MinZoom">0</output>
</form>
</td>
</tr>
<tr title="An integer specifying the maximum zoom level to render the layer at.">
<td>Min Zoom:</td>
<td>
<form oninput="maxz.value=MaxZoom.value">
<input type="range" id="MaxZoom" value="24" min="0" max="24" step="1" oninput="updateSymbolLayer()" onchange="updateSymbolLayer()" />
<output name="maxz" for="MaxZoom">24</output>
</form>
</td>
</tr>
<tr title="Specifies if the layer is visible or not.">
<td>Visible:</td>
<td><input id="Visible" type="checkbox" onclick="updateSymbolLayer()" checked="checked" /></td>
</tr>
</table>
<p>
In addition to the options in this tool, the SymbolLayer also has options for;
<ul>
<li>sourceLayer - used with VectorTileSource.</li>
<li>lineSpacing - spacing when rendered along a line.</li>
<li>placement - defines if symbol placed on point or along a line.</li>
<li>filter - used to filter data in layer.</li>
</ul>
Many options in this layer also support Expressions which are not demonstrated in this sample.
</p>
</div>
<div id="IconOptions" class="tabcontent">
<table>
<tr title="The name of the image in the map's image sprite to use for drawing the icon.">
<td>Image:</td>
<td>
<select id="Icon" onchange="updateSymbolLayer()">
<option value="marker-black">marker-black</option>
<option value="marker-black-styled">marker-black-styled</option>
<option value="marker-blue">marker-blue</option>
<option value="marker-blue-styled">marker-blue-styled</option>
<option value="marker-darkblue">marker-darkblue</option>
<option value="marker-darkblue-styled">marker-darkblue-styled</option>
<option value="marker-red">marker-red</option>
<option value="marker-red-styled">marker-red-styled</option>
<option value="marker-yellow">marker-yellow</option>
<option value="marker-yellow-styled">marker-yellow-styled</option>
<option value="pin-darkblue" selected="selected">pin-darkblue</option>
<option value="pin-blue">pin-blue</option>
<option value="pin-red">pin-red</option>
<option value="pin-round-darkblue">pin-round-darkblue</option>
<option value="pin-round-blue">pin-round-blue</option>
<option value="pin-round-red">pin-round-red</option>
<option value="none">none</option>
</select>
</td>
</tr>
<tr title="Scales the original size of the icon by the provided factor.">
<td>Size:</td>
<td>
<form oninput="a.value=IconSize.value">
<input type="range" id="IconSize" value="1" min="0.1" max="2" step="0.1" oninput="updateSymbolLayer()" onchange="updateSymbolLayer()" />
<output name="a" for="IconSize">1</output>
</form>
</td>
</tr>
<tr title="Specifies which part of the icon is placed closest to the icons anchor position on the map.">
<td>Anchor:</td>
<td>
<select id="IconAnchor" onchange="updateSymbolLayer()">
<option value="bottom" selected="selected">bottom</option>
<option value="bottom-left">bottom-left</option>
<option value="bottom-right">bottom-right</option>
<option value="center">center</option>
<option value="left">left</option>
<option value="right">right</option>
<option value="top">top</option>
<option value="top-left">top-left</option>
<option value="top-right">top-right</option>
</select>
</td>
</tr>
<tr title="Specifies an offset distance of the icon from its anchor in pixels. Positive values indicate right and down, while negative values indicate left and up. Each component is multiplied by the value of size to obtain the final offset in pixels. When combined with rotation the offset will be as if the rotated direction was up.">
<td>Offset:</td>
<td></td>
</tr>
<tr title="Specifies an offset distance of the icon from its anchor in pixels. Positive values indicate right and down, while negative values indicate left and up. Each component is multiplied by the value of size to obtain the final offset in pixels. When combined with rotation the offset will be as if the rotated direction was up.">
<td align="right">x:</td>
<td>
<form oninput="x.value=IconOffsetX.value">
<input type="range" id="IconOffsetX" value="0" min="-50" max="50" step="1" oninput="updateSymbolLayer()" onchange="updateSymbolLayer()" />
<output name="x" for="IconOffsetX">0</output>
</form>
</td>
</tr>
<tr title="Specifies an offset distance of the icon from its anchor in pixels. Positive values indicate right and down, while negative values indicate left and up. Each component is multiplied by the value of size to obtain the final offset in pixels. When combined with rotation the offset will be as if the rotated direction was up.">
<td align="right">y:</td>
<td>
<form oninput="y.value=IconOffsetY.value">
<input type="range" id="IconOffsetY" value="0" min="-50" max="50" step="01" oninput="updateSymbolLayer()" onchange="updateSymbolLayer()" />
<output name="y" for="IconOffsetY">0</output>
</form>
</td>
</tr>
<tr title="The amount to rotate the icon clockwise in degrees.">
<td>Rotation:</td>
<td>
<form oninput="r.value=IconRotation.value">
<input type="range" id="IconRotation" value="0" min="-360" max="360" step="1" oninput="updateSymbolLayer()" onchange="updateSymbolLayer()" />
<output name="r" for="IconRotation">0</output>
</form>
</td>
</tr>
<tr title="Specifies which part of the icon is placed closest to the icons anchor position on the map.">
<td>Rotation Alignment:</td>
<td>
<select id="IconRotationAlignment" onchange="updateSymbolLayer()">
<option value="auto" selected="selected">auto</option>
<option value="map">map</option>
<option value="viewport">viewport</option>
</select>
</td>
</tr>
<tr title="A number between 0 and 1 that indicates the opacity at which the icon will be drawn.">
<td>Opacity:</td>
<td>
<form oninput="io.value=IconOpacity.value">
<input type="range" id="IconOpacity" value="1" min="0" max="1" step="0.1" oninput="updateSymbolLayer()" onchange="updateSymbolLayer()" />
<output name="io" for="IconOpacity">1</output>
</form>
</td>
</tr>
<tr title="Specifies if the symbol icon can overlay other symbols on the map. If `true` the icon will be visible even if it collides with other previously drawn symbols. Tip: Set this to true if animating an symbol to ensure smooth rendering.">
<td>Allow Overlap:</td>
<td><input id="IconAllowOverlap" type="checkbox" onclick="updateSymbolLayer()" /></td>
</tr>
<tr title="Specifies if other symbols can overlap this symbol. If true, other symbols can be visible even if they collide with the icon.">
<td>Ignore Placement:</td>
<td><input id="IgnoreIconPlacement" type="checkbox" onclick="updateSymbolLayer()" /></td>
</tr>
<tr title="Specifies if a symbols icon can be hidden but its text displayed if it is overlapped with another symbol. If true, text will display without their corresponding icons when the icon collides with other symbols and the text does not.">
<td>Optional:</td>
<td><input id="IconOptional" type="checkbox" onclick="updateSymbolLayer()" /></td>
</tr>
</table>
</div>
<div id="TextOptions" class="tabcontent">
<table>
<tr title="The font stack to use for displaying text.">
<td colspan="2">Font:</td>
</tr>
<tr title="The font stack to use for displaying text.">
<td colspan="2">
<select id="TextFont" onchange="updateSymbolLayer()">
<option value="SegoeFrutigerHelveticaMYingHei-Bold">SegoeFrutigerHelveticaMYingHei-Bold</option>
<option value="SegoeFrutigerHelveticaMYingHei-Medium">SegoeFrutigerHelveticaMYingHei-Medium</option>
<option value="SegoeFrutigerHelveticaMYingHei-Regular">SegoeFrutigerHelveticaMYingHei-Regular</option>
<option value="SegoeUi-Bold">SegoeUi-Bold</option>
<option value="SegoeUi-Light">SegoeUi-Light</option>
<option value="SegoeUi-Regular" selected="selected">SegoeUi-Regular</option>
<option value="SegoeUi-SemiBold">SegoeUi-SemiBold</option>
<option value="SegoeUi-SemiLight">SegoeUi-SemiLight</option>
<option value="SegoeUi-SymbolRegular">SegoeUi-SymbolRegular</option>
<option value="StandardCondensedSegoeUi-Black">StandardCondensedSegoeUi-Black</option>
<option value="StandardCondensedSegoeUi-Bold">StandardCondensedSegoeUi-Bold</option>
<option value="StandardCondensedSegoeUi-Light">StandardCondensedSegoeUi-Light</option>
<option value="StandardCondensedSegoeUi-Regular">StandardCondensedSegoeUi-Regular</option>
<option value="StandardFont-Black">StandardFont-Black</option>
<option value="StandardFont-Bold">StandardFont-Bold</option>
<option value="StandardFontCondensed-Black">StandardFontCondensed-Black</option>
<option value="StandardFontCondensed-Bold">StandardFontCondensed-Bold</option>
<option value="StandardFontCondensed-Light">StandardFontCondensed-Light</option>
<option value="StandardFontCondensed-Regular">StandardFontCondensed-Regular</option>
<option value="StandardFont-Light">StandardFont-Light</option>
<option value="StandardFont-Regular">StandardFont-Regular</option>
</select>
</td>
</tr>
<tr title="The color of the text.">
<td>Color:</td>
<td><input type="color" id="FontColor" onchange="updateSymbolLayer()" /></td>
</tr>
<tr title="A number between 0 and 1 that indicates the opacity at which the text will be drawn.">
<td>Opacity:</td>
<td>
<form oninput="to.value=TextOpacity.value">
<input type="range" id="TextOpacity" value="1" min="0" max="1" step="0.1" oninput="updateSymbolLayer()" onchange="updateSymbolLayer()" />
<output name="to" for="TextOpacity">1</output>
</form>
</td>
</tr>
<tr title="The size of the font in pixels.">
<td>Size:</td>
<td>
<form oninput="b.value=FontSize.value">
<input type="range" id="FontSize" value="16" min="8" max="25" step="1" oninput="updateSymbolLayer()" onchange="updateSymbolLayer()" />
<output name="b" for="FontSize">16</output>
</form>
</td>
</tr>
<tr title="Specifies which part of the icon is placed closest to the icons anchor position on the map.">
<td>Anchor:</td>
<td>
<select id="TextAnchor" onchange="updateSymbolLayer()">
<option value="bottom">bottom</option>
<option value="bottom-left">bottom-left</option>
<option value="bottom-right">bottom-right</option>
<option value="center" selected="selected">center</option>
<option value="left">left</option>
<option value="right">right</option>
<option value="top">top</option>
<option value="top-left">top-left</option>
<option value="top-right">top-right</option>
</select>
</td>
</tr>
<tr title="Specifies an offset distance of the icon from its anchor in ems. Positive values indicate right and down, while negative values indicate left and up.">
<td>Offset:</td>
<td></td>
</tr>
<tr title="Specifies an offset distance of the icon from its anchor in ems. Positive values indicate right and down, while negative values indicate left and up.">
<td align="right">x:</td>
<td>
<form oninput="x.value=TextOffsetX.value">
<input type="range" id="TextOffsetX" value="0" min="-5" max="5" step="0.1" oninput="updateSymbolLayer()" onchange="updateSymbolLayer()" />
<output name="x" for="TextOffsetX">0</output>
</form>
</td>
</tr>
<tr title="Specifies an offset distance of the icon from its anchor in ems. Positive values indicate right and down, while negative values indicate left and up.">
<td align="right">y:</td>
<td>
<form oninput="y.value=TextOffsetY.value">
<input type="range" id="TextOffsetY" value="0" min="-5" max="5" step="0.1" oninput="updateSymbolLayer()" onchange="updateSymbolLayer()" />
<output name="y" for="TextOffsetY">0</output>
</form>
</td>
</tr>
<tr title="The halo's fadeout distance towards the outside in pixels.">
<td>Halo Blur:</td>
<td>
<form oninput="b.value=HaloBlur.value">
<input type="range" id="HaloBlur" value="0" min="0" max="5" step="0.2" oninput="updateSymbolLayer()" onchange="updateSymbolLayer()" />
<output name="b" for="HaloBlur">0</output>
</form>
</td>
</tr>
<tr title="The color of the text's halo, which helps it stand out from backgrounds.">
<td>Halo Color:</td>
<td><input type="color" id="HaloColor" value="#000000" onchange="updateSymbolLayer()" /></td>
</tr>
<tr title="The distance of the halo to the font outline in pixels. The maximum text halo width is 1/4 of the font size.">
<td>Halo Width:</td>
<td>
<form oninput="b.value=HaloWidth.value">
<input type="range" id="HaloWidth" value="0" min="0" max="5" step="0.2" oninput="updateSymbolLayer()" onchange="updateSymbolLayer()" />
<output name="b" for="HaloWidth">0</output>
</form>
</td>
</tr>
<tr title="Specifies if the text will be visible if it collides with other symbols. If true, the text will be visible even if it collides with other previously drawn symbols.">
<td>Allow Overlap:</td>
<td><input id="TextAllowOverlap" type="checkbox" onclick="updateSymbolLayer()" /></td>
</tr>
<tr title="Specifies if the other symbols are allowed to collide with the text. If true, other symbols can be visible even if they collide with the text.">
<td>Ignore Placement:</td>
<td><input id="IgnoreTextPlacement" type="checkbox" onclick="updateSymbolLayer()" /></td>
</tr>
<tr title="Specifies if the text can be hidden if it is overlapped by another symbol. If true, icons will display without their corresponding text when the text collides wit other symbols and the icon does not.">
<td>Optional:</td>
<td><input id="TextOptional" type="checkbox" onclick="updateSymbolLayer()" /></td>
</tr>
</table>
</div>
<div id="Code" class="tabcontent">
<textarea id="CodeOutput"></textarea><br /><br />
<input id="RemoveDefaults" type="checkbox" onclick="updateSymbolLayer()" checked="checked" /> Remove defaults
<button class="copyBtn" data-clipboard-target="#CodeOutput">Copy to clipboard</button>
</div>
</fieldset>
<div id="myMap"></div>
</body>
</html>
You can’t perform that action at this time.