-
Notifications
You must be signed in to change notification settings - Fork 437
/
Layer control options.html
371 lines (315 loc) · 14.6 KB
/
Layer 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
<!DOCTYPE html>
<html lang="en">
<head>
<title>Layer 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, layer 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, layerControl;
function getMap() {
//Initialize a map instance.
map = new atlas.Map('myMap', {
view: 'Auto',
//Add authentication details for connecting to Azure Maps.
authOptions: {
//Use Microsoft Entra ID authentication.
authType: 'anonymous',
clientId: 'e6b6ab59-eb5d-4d25-aa57-581135b927f0', //Your Azure Maps client id for accessing your Azure Maps account.
getToken: function (resolve, reject, map) {
//URL to your authentication service that retrieves an Microsoft Entra ID Token.
var tokenServiceUrl = 'https://samples.azuremaps.com/api/GetAzureMapsToken';
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 () {
//Create the layer control.
layerControl = new atlas.control.LayerControl({
//Specify the layer groups for the control.
layerGroups: [
//A dropdown layer group option.
{
layout: 'dropdown',
//A title for this layer group.
groupTitle: 'Symbol label',
//The layers affected by this group.
layers: ['earthquake-labels'],
items: [{
label: 'mag',
//Optionally specify if the state is enabled or not initially.
enabled: true,
//The style to apply to the layers when this state is enabled.
enabledStyle: {
textOptions: {
//An expression is used to concerte the "mag" property value into a string and appends the letter "m" to the end of it.
textField: ['concat', ['to-string', ['get', 'mag']], 'm']
}
}
}, {
label: 'place',
//The style to apply to the layers when this state is enabled.
enabledStyle: {
textOptions: {
textField: ['get', 'place']
}
}
}]
},
//A range sliders layer group option.
{
layout: 'range',
//A title for this layer group, in this case using a value that has a match in the localization resources (resx).
groupTitle: 'rangeSlider',
//The layers affected by this group.
layers: ['earthquake-circles'],
//Settings for one or more range sliders.
items: [{
//Optionally format the label.
label: '{rangeValue}px',
//Set the initial value.
value: 0.5,
//Specify the style applied to the layers as the range sliders value changes.
style: {
opacity: '{rangeValue}',
//Use a style expression to apply custom logic, in this case, applying the opposite value to the stroke.
strokeOpacity: ['-', 1, '{rangeValue}']
},
//Specify is the layer styles should update as the slider is moving, rather than waiting until it has finished moving.
updateOnInput: true
}
]
},
//A radio button layer group options.
{
layout: 'radio',
//A title for this layer group.
groupTitle: 'Stroke Width',
//The layers affected by this group.
layers: ['earthquake-circles'],
items: [{
label: '5px',
//Style to apply when a radio item is selected.
enabledStyle: {
strokeWidth: 5
}
},
{
label: '10px',
//Style to apply when a radio item is selected.
enabledStyle: {
strokeWidth: 10
}
},
{
label: '15px',
//Style to apply when a radio item is selected.
enabledStyle: {
strokeWidth: 15
}
}
]
}
]
});
//Add the layer control to the map.
map.controls.add(layerControl, {
position: 'top-left'
});
//Load some mock data for the example.
loadMockData();
});
}
function setTitle(elm) {
layerControl.setOptions({
title: elm.value
});
}
function setLayout(elm){
layerControl.setOptions({
layout: elm.value
});
}
function setStyle(elm){
layerControl.setOptions({
style: elm.value
});
}
function setVisible(elm){
layerControl.setOptions({
visible: elm.checked
});
}
function setContainerId(elm) {
var containerId = null;
if (elm.checked) {
containerId = 'test';
}
layerControl.setOptions({
container: containerId
});
}
function showToggle(elm) {
layerControl.setOptions({
showToggle: elm.checked
});
}
function setMinimized(elm) {
layerControl.setOptions({
minimized: elm.checked
});
}
function loadMockData(){
//Create a data source and add it to the map.
var source = new atlas.source.DataSource();
map.sources.add(source);
//Load the earthquake data.
source.importDataFromUrl('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/significant_month.geojson');
map.layers.add([
//Create a layer that defines how to render the shapes in the data source and add it to the map.
new atlas.layer.BubbleLayer(source, 'earthquake-circles', {
//Bubbles are made semi-transparent.
opacity: 0.75,
createIndicators: true, // to enable bubble layer a11y feature
//Color of each bubble based on the value of "mag" property using a color gradient of green, yellow, orange, and red.
color: [
'interpolate',
['linear'],
['get', 'mag'],
0, 'green',
5, 'yellow',
6, 'orange',
7, 'red'
],
/*
* Radius for each data point scaled based on the value of "mag" property.
* When "mag" = 0, radius will be 2 pixels.
* When "mag" = 8, radius will be 40 pixels.
* All other "mag" values will be a linear interpolation between these values.
*/
radius: [
'interpolate',
['linear'],
['get', 'mag'],
0, 2,
8, 40
]
}),
//Create a symbol layer using the same data source to render the magnitude as text above each bubble and add it to the map.
new atlas.layer.SymbolLayer(source, 'earthquake-labels', {
iconOptions: {
//Hide the icon image.
image: 'none'
},
textOptions: {
//An expression is used to concerte the "mag" property value into a string and appends the letter "m" to the end of it.
textField: ['concat', ['to-string', ['get', 'mag']], 'm'],
textSize: 12
}
})
]);
//Add a style control to the map.
map.controls.add(new atlas.control.StyleControl({
mapStyles: 'all'
}), {
position: 'top-left'
});
}
</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>Layer control options</legend>
This sample shows how the different options of the layer control change the user experience.
</fieldset>
<table>
<tr title="Global title of the layer control.">
<td>Title:</td>
<td>
<input type="text" oninput="setTitle(this)" title="Title" />
</td>
</tr>
<tr title="How multiple layer groups 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 layer 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 layer 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>
</table>
<fieldset style="width:320px;margin-bottom:10px;">
<legend>Test area</legend>
<div id="test"></div>
</fieldset>
<p>
The LayerControl also has options for;
<ul>
<li>layerGroups - layer group and states.</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>