Repository navigation
Expand file tree
/
Copy pathLegend control options.html
More file actions
283 lines (254 loc) · 10.8 KB
/
Copy pathLegend control options.html
File metadata and controls
283 lines (254 loc) · 10.8 KB
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
271
272
273
274
275
276
277
278
279
280
281
282
283
<!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 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" /><meta name="version" content="1.0" />
<meta name="screenshot" content="screenshot.jpg" />
<!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
<link href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.css" rel="stylesheet" />
<script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.js"></script>
<!-- Load in the JavaScript and CSS files that has our custom control. -->
<link rel="stylesheet" href="/lib/azure-maps/azure-maps-layer-legend.min.css" type="text/css" />
<script src="/lib/azure-maps/azure-maps-layer-legend.min.js"></script>
<script>
var map, legend;
function getMap() {
//Initialize a map instance.
map = new atlas.Map('myMap', {
view: 'Auto',
language: 'Auto',
//Add authentication details for connecting to Azure Maps.
authOptions: {
// Use SAS token for authentication
authType: 'sas',
getToken: function (resolve, reject, map) {
// URL to your authentication service that retrieves a SAS Token
var tokenServiceUrl = 'https://samples.azuremaps.com/api/GetAzureMapsSasToken';
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: '/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
});
}
function updateMaxWidth(elm) {
legend.setOptions({
maxWidth: parseFloat(elm.value)
});
}
</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>Legend control options</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)" title="Title" />
</td>
</tr>
<tr title="How multiple legends are laid out.">
<td>Layout:</td>
<td>
<select onchange="setLayout(this)" title="Layout">
<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" title="Show toggle" /></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)" title="Minimized" /></td>
</tr>
<tr title="The style of the control.">
<td>Style:</td>
<td>
<select onchange="setStyle(this)" title="Style">
<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" title="Visible" /></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)" title="Container" /> show in test area</td>
</tr>
<tr title='Specifies the maximium width the legend control can expand to. If greater than the width of the map, the legend control will have a max width of the maps width minus 20 pixels.'>
<td>Max width:</td>
<td>
<form oninput="maxWidth.value=MaxWidth.value">
<input type="range" id="MaxWidth" value="1000" min="50" max="1000" step="50" oninput="updateMaxWidth(this)" />
<output name="maxWidth" for="MaxWidth">1000</output>
</form>
</td>
</tr>
</table>
<fieldset style="width:320px;margin-bottom:10px;">
<legend>Test area</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>