-
Notifications
You must be signed in to change notification settings - Fork 472
Expand file tree
/
Copy pathCategory legend options.html
More file actions
260 lines (236 loc) · 10.6 KB
/
Category legend options.html
File metadata and controls
260 lines (236 loc) · 10.6 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Category legend 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 category legend type." />
<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;
//Initial category options.
var categoryLegend = {
type: 'category',
items: [
{
color: 'DodgerBlue',
label: 'Hello',
shape: '/images/icons/campfire.png',
alt: 'Campfire'
}, {
color: 'Yellow',
label: 'World',
shape: 'square'
}, {
label: '10',
shapeSize: 10
}, {
label: '20',
shapeSize: 20
}, {
label: '30',
shapeSize: 30
}, {
label: '40',
shapeSize: 40
}
]
};
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({
legends: [categoryLegend]
});
//Add the legend control to the map.
map.controls.add(legend, {
position: 'bottom-left'
});
});
}
function updateLegend(property, elm){
_updateLegend(property, elm.value);
}
function updateLegendCheck(property, elm){
_updateLegend(property, elm.checked);
}
function updateLegendRange(property, elm){
_updateLegend(property, parseInt(elm.value));
}
function updateLegendCheckValue(property, elm){
_updateLegend(property, elm.checked ? elm.value : null);
}
function _updateLegend(property, value){
//Copy the options so that the properties don't flow through without being set.
categoryLegend = Object.assign({}, categoryLegend);
categoryLegend[property] = value;
legend.setOptions({
legends: [categoryLegend]
});
}
</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;
}
.customLegendCSS svg {
stroke: red !important;
stroke-dasharray: 2 2;
}
</style>
</head>
<body onload="getMap()">
<div class="sidePanel">
<fieldset style="width:320px;margin-bottom:10px;">
<legend>Category legend options</legend>
This sample shows how the different options of the category legend type.
</fieldset>
<table>
<tr title="The title of the individual legend.">
<td>Subtitle:</td>
<td>
<input type="text" oninput="updateLegend('subtitle', this)" title="Subtitle" />
</td>
</tr>
<tr title="The footer of the legend.">
<td>Footer:</td>
<td>
<input type="text" oninput="updateLegend('footer', this)" title="Footer" />
</td>
</tr>
<tr title="An integer specifying the minimum zoom level to render the legend 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" onchange="updateLegendRange('minZoom', this)" title="Min Zoom" />
<output name="minz" for="MinZoom">0</output>
</form>
</td>
</tr>
<tr title="An integer specifying the maximum zoom level to render the legend at.">
<td>Max Zoom:</td>
<td>
<form oninput="maxz.value=MaxZoom.value">
<input type="range" id="MaxZoom" value="24" min="0" max="24" step="1" onchange="updateLegendRange('maxZoom', this)" title="Max Zoom" />
<output name="maxz" for="MaxZoom">24</output>
</form>
</td>
</tr>
<tr title="The layout of all items relatively.">
<td>Layout:</td>
<td>
<select onchange="updateLegend('layout', this)" title="Layout">
<option selected="selected">column</option>
<option>column-reverse</option>
<option>row</option>
<option>row-reverse</option>
</select>
</td>
</tr>
<tr title="The layout of individual items.">
<td>Item Layout:</td>
<td>
<select onchange="updateLegend('itemLayout', this)" title="Item Layout">
<option>column</option>
<option>column-reverse</option>
<option selected="selected">row</option>
<option>row-reverse</option>
</select>
</td>
</tr>
<tr title="The fill color of SVGs.">
<td>Color:</td>
<td><input type="color" id="Color" value="#ffffff" onchange="updateLegend('color', this)" title="Color" /></td>
</tr>
<tr title="Specifies if all items should be fit into the largest container created by an item.">
<td>Fit items:</td>
<td><input id="fitItems" type="checkbox" onclick="updateLegendCheck('fitItems', this)" title="Fit items" /></td>
</tr>
<tr title="Specifies if all items should be fit into the largest container created by an item.">
<td>Labels Overlap Shapes:</td>
<td><input id="labelsOverlapShapes" type="checkbox" onclick="updateLegendCheck('labelsOverlapShapes', this)" title="Labels Overlap Shapes" /></td>
</tr>
<tr title="The shape of the color swatches of all items. Supports image urls and SVG strings.">
<td>Shape:</td>
<td>
<select onchange="updateLegend('shape', this)" title="Shape">
<option selected="selected">circle</option>
<option>line</option>
<option>square</option>
<option>triangle</option>
</select>
</td>
</tr>
<tr title="The size of the all shapes in pixels. Used to scale the width of the shape.">
<td>Shape size:</td>
<td>
<form oninput="shapeSize.value=ShapeSize.value">
<input type="range" id="ShapeSize" value="20" min="1" max="50" step="1" onchange="updateLegendRange('shapeSize', this)" title="Shape size" />
<output name="shapeSize" for="ShapeSize">20</output>
</form>
</td>
</tr>
<tr title="The thickness of the stroke on SVG shapes in pixels.">
<td>Stroke Width:</td>
<td>
<form oninput="strokeWidth.value=StrokeWidth.value">
<input type="range" id="StrokeWidth" value="1" min="0" max="9" step="1" onchange="updateLegendRange('strokeWidth', this)" title="Stroke Width" />
<output name="strokeWidth" for="StrokeWidth">1</output>
</form>
</td>
</tr>
<tr title="A CSS class to customize the legend.">
<td>CSS class:</td>
<td><input id="cssClass" type="checkbox" value="customLegendCSS" onclick="updateLegendCheckValue('cssClass', this)" title="CSS class" /></td>
</tr>
</table>
<p>
The category legend type also has options for;
<ul>
<li>items - individual items with the legend.</li>
<li>numberFormat - the formatting options for number labels.</li>
<li>numberFormatLocales - the locale for formatting numbers.</li>
</ul>
</p>
</div>
<div id="myMap"></div>
</body>
</html>