-
Notifications
You must be signed in to change notification settings - Fork 447
/
Gradient legend options.html
231 lines (209 loc) · 9.32 KB
/
Gradient legend 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Gradient 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 gradient 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 gradient options.
var gradientLegend = {
type: 'gradient',
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'
}
]
};
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 () {
//Add the custom control to the map.
legend = new atlas.control.LegendControl({
legends: [gradientLegend]
});
//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 _updateLegend(property, value){
//Copy the options so that the properties don't flow through without being set.
gradientLegend = Object.assign({}, gradientLegend);
gradientLegend[property] = value;
legend.setOptions({
legends: [gradientLegend]
});
}
</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>Gradient legend options</legend>
This sample shows how the different options of the gradient 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 orientation of the legend. ">
<td>Orientation:</td>
<td>
<select onchange="updateLegend('orientation', this)" title="Orientation">
<option selected="selected">horizontal</option>
<option>vertical</option>
</select>
</td>
</tr>
<tr title="The length of the gradient bar in pixels.">
<td>Bar length:</td>
<td>
<form oninput="barLength.value=BarLength.value">
<input type="range" id="BarLength" value="256" min="1" max="500" step="2" onchange="updateLegendRange('barLength', this)" title="Bar length" />
<output name="barLength" for="BarLength">256</output>
</form>
</td>
</tr>
<tr title="How thick the gradient bar should be in pixels.">
<td>Bar thickness:</td>
<td>
<form oninput="barThickness.value=BarThickness.value">
<input type="range" id="BarThickness" value="20" min="1" max="50" step="1" onchange="updateLegendRange('barThickness', this)" title="Bar thickness" />
<output name="barThickness" for="BarThickness">20</output>
</form>
</td>
</tr>
<tr title="The font size of the labels.">
<td>Font size:</td>
<td>
<form oninput="fontSize.value=FontSize.value">
<input type="range" id="FontSize" value="12" min="1" max="24" step="1" onchange="updateLegendRange('fontSize', this)" title="Font size" />
<output name="fontSize" for="FontSize">12</output>
</form>
</td>
</tr>
<tr title="Amount of pixel space added to the ends of bars to allow space for text.">
<td>Tick size:</td>
<td>
<form oninput="tickSize.value=TickSize.value">
<input type="range" id="TickSize" value="5" min="0" max="20" step="1" onchange="updateLegendRange('tickSize', this)" title="Tick size" />
<output name="tickSize" for="TickSize">5</output>
</form>
</td>
</tr>
</table>
<p>
The category legend type also has options for;
<ul>
<li>stops - color stops in the gradient.</li>
<li>cssClass - CSS class to customize legend.</li>
<li>fontFamily - The font family used for labels.</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>