This repository has been archived by the owner on Oct 17, 2023. It is now read-only.
/
Legend control options.html
270 lines (242 loc) · 10.4 KB
/
Legend control options.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<!DOCTYPE html>
<html lang="en">
<head>
<title>Legend control options - 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 the different options of the legend control change the user experience." />
<meta name="keywords" content="Microsoft maps, maps, map, API, SDK, GIS, legend, legend control" />
<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>
<!-- Load in the JavaScript and CSS files that has our custom control. -->
<link rel="stylesheet" href="../Common/scripts/azure-maps-layer-legend.min.css" type="text/css" />
<script src="../Common/scripts/azure-maps-layer-legend.min.js"></script>
<script type='text/javascript'>
var map, legend;
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', {
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.net/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 () {
//Add the custom control to the map.
legend = new atlas.control.LegendControl({
//Two sample legend cards.
legends: [
{
type: 'category',
subtitle: 'Category',
layout: 'column',
itemLayout: 'row',
footer: 'A category legend that uses a combination of shapes and icons.',
strokeWidth: 2,
items: [
{
color: 'DodgerBlue',
label: 'Hello',
shape: 'https://azuremapscodesamples.azurewebsites.net/Common/images/icons/campfire.png'
}, {
color: 'Yellow',
label: 'World',
shape: 'square'
}, {
color: 'Orange',
label: 'Ricky',
shape: 'line'
}, {
color: 'Red',
label: 'is',
shape: 'circle'
}, {
color: 'purple',
label: 'awesome!',
shape: 'triangle'
}
]
},{
type: 'gradient',
subtitle: 'Gradient legend',
footer: 'A gradient legend that uses multiple color stops, some having labels.',
stops: [
{
offset: 0,
color: 'royalblue',
label: 'low'
},
{
offset: 0.25,
color: 'cyan'
},
{
offset: 0.5,
color: 'lime',
label: 'medium'
},
{
offset: 0.75,
color: 'yellow'
},{
offset: 1,
color: 'red',
label: 'high'
}
]
}
]
});
//Add the legend control to the map.
map.controls.add(legend, {
position: 'bottom-left'
});
// Add a style control to the map.
map.controls.add(new atlas.control.StyleControl({
mapStyles: 'all'
}), {
position: 'top-left'
});
});
}
function setTitle(elm) {
legend.setOptions({
title: elm.value
});
}
function setLayout(elm){
legend.setOptions({
layout: elm.value
});
}
function setStyle(elm){
legend.setOptions({
style: elm.value
});
}
function setVisible(elm){
legend.setOptions({
visible: elm.checked
});
}
function setContainerId(elm) {
var containerId = null;
if (elm.checked) {
containerId = 'test';
}
legend.setOptions({
container: containerId
});
}
function showToggle(elm) {
legend.setOptions({
showToggle: elm.checked
});
}
function setMinimized(elm) {
legend.setOptions({
minimized: elm.checked
});
}
</script>
<style>
.sidePanel {
width: 350px;
height: 580px;
float: left;
margin-right: 10px;
}
#myMap {
position: relative;
width: calc(100% - 360px);
min-width: 290px;
height: 600px;
float: left;
}
</style>
</head>
<body onload="GetMap()">
<div class="sidePanel">
<fieldset style="width:320px;margin-bottom:10px;">
<legend><h1 style="font-size:16px">Legend control options</h1></legend>
This sample shows how the different options of the legend control change the user experience.
</fieldset>
<table>
<tr title="The global title of the legend control.">
<td>Title:</td>
<td>
<input type="text" oninput="setTitle(this)" />
</td>
</tr>
<tr title="How multiple legends are laid out.">
<td>Layout:</td>
<td>
<select onchange="setLayout(this)">
<option>accordion</option>
<option selected="selected">carousel</option>
<option>list</option>
</select>
</td>
</tr>
<tr title="Specifies if the expand/collapse button show be displayed.">
<td>Show toggle:</td>
<td><input type="checkbox" onclick="showToggle(this)" checked="checked" /></td>
</tr>
<tr title="Specifies if the control should be minimized. Only works when showToggle is true.">
<td>Minimized:</td>
<td><input type="checkbox" onclick="setMinimized(this)" /></td>
</tr>
<tr title="The style of the control.">
<td>Style:</td>
<td>
<select onchange="setStyle(this)">
<option>auto</option>
<option>auto-reverse</option>
<option>dark</option>
<option selected="selected">light</option>
</select>
</td>
</tr>
<tr title="Specifies if the legend control is visible or not.">
<td>Visible:</td>
<td><input id="Visible" type="checkbox" onclick="setVisible(this)" checked="checked" /></td>
</tr>
<tr title="Specifies that the legend control should render in a element outside the map.">
<td>Container:</td>
<td><input type="checkbox" onclick="setContainerId(this)" /> show in test area</td>
</tr>
</table>
<fieldset style="width:320px;margin-bottom:10px;">
<legend><h1 style="font-size:16px">Test area</h1></legend>
<div id="test"></div>
</fieldset>
<p>
The LegendControl also has options for;
<ul>
<li>legends - legend cards to render inside the control.</li>
<li>resx - used specify localization strings.</li>
<li>zoomBehavior - how legends are rendered when outside of zoom range.</li>
</ul>
</p>
</div>
<div id="myMap"></div>
</body>
</html>