Skip to content

Commit 5d07669

Browse files
committed
Update legend control version
- Update to the latest legend control version. - Extend options sample to include new maxWidth option.
1 parent 6939c2d commit 5d07669

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

Samples/Controls/Legend control options/Legend control options.html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@
177177
minimized: elm.checked
178178
});
179179
}
180+
181+
function updateMaxWidth(elm) {
182+
legend.setOptions({
183+
maxWidth: parseFloat(elm.value)
184+
});
185+
}
180186
</script>
181187
<style>
182188
.sidePanel {
@@ -206,7 +212,7 @@
206212
<tr title="The global title of the legend control.">
207213
<td>Title:</td>
208214
<td>
209-
<input type="text" oninput="setTitle(this)" title="Title" />
215+
<input type="text" oninput="setTitle(this)" title="Title" />
210216
</td>
211217
</tr>
212218
<tr title="How multiple legends are laid out.">
@@ -215,7 +221,7 @@
215221
<select onchange="setLayout(this)" title="Layout">
216222
<option>accordion</option>
217223
<option selected="selected">carousel</option>
218-
<option>list</option>
224+
<option>list</option>
219225
</select>
220226
</td>
221227
</tr>
@@ -246,6 +252,15 @@
246252
<td>Container:</td>
247253
<td><input type="checkbox" onclick="setContainerId(this)" title="Container" /> show in test area</td>
248254
</tr>
255+
<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.'>
256+
<td>Max width:</td>
257+
<td>
258+
<form oninput="maxWidth.value=MaxWidth.value">
259+
<input type="range" id="MaxWidth" value="1000" min="50" max="1000" step="50" oninput="updateMaxWidth(this)" />
260+
<output name="maxWidth" for="MaxWidth">1000</output>
261+
</form>
262+
</td>
263+
</tr>
249264
</table>
250265

251266
<fieldset style="width:320px;margin-bottom:10px;">

Static/lib/azure-maps/azure-maps-layer-legend.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,10 @@ MIT License
15141514
opt.layout = options.layout;
15151515
self._needsRebuild = true;
15161516
}
1517+
if (options.maxWidth > 0 && opt.maxWidth !== options.maxWidth) {
1518+
opt.maxWidth = options.maxWidth;
1519+
self._adjustSize();
1520+
}
15171521
if (options.showToggle !== undefined && opt.showToggle !== options.showToggle) {
15181522
opt.showToggle = options.showToggle;
15191523
if (!options.showToggle) {
@@ -1578,13 +1582,13 @@ MIT License
15781582
var opt = self._baseOptions;
15791583
var container = self._container;
15801584
if (self._map) {
1581-
var maxWidth_1 = 'unset';
1585+
var maxWidth_1 = opt.maxWidth ? opt.maxWidth + 'px' : 'unset';
15821586
var maxHeight_1 = 'unset';
15831587
//When legend is displayed within the map, need to restrict the size of the legend content.
15841588
if (!opt.container) {
15851589
var rect = self._map.getCanvasContainer().getClientRects()[0];
1586-
//Subtract 20 pixels to account for padding around controls in the map.
1587-
maxWidth_1 = (rect.width - 20) + 'px';
1590+
//Subtract 20 pixels to account for padding around controls in the map.
1591+
maxWidth_1 = Math.min(opt.maxWidth || 10000, rect.width - 20) + 'px';
15881592
var maxContainerHeight = rect.height - 20;
15891593
var cp = self._controlPosition;
15901594
if (cp && cp !== '' && cp !== 'non-fixed') {
@@ -1993,6 +1997,7 @@ MIT License
19931997
case 'container':
19941998
case 'layout':
19951999
case 'zoomBehavior':
2000+
case 'maxWidth':
19962001
//@ts-ignore
19972002
opt[key] = val;
19982003
break;
@@ -2497,6 +2502,12 @@ MIT License
24972502
var textStyle = void 0;
24982503
var barWidth = void 0;
24992504
var barHeight = void 0;
2505+
//Ensure all stops have an offset value.
2506+
legendType.stops.forEach(function (item) {
2507+
if (typeof item.offset !== 'number') {
2508+
item.offset = 0;
2509+
}
2510+
});
25002511
//Ensure stops are sorted by offset.
25012512
legendType.stops.sort(function (a, b) {
25022513
return a.offset - b.offset;
@@ -2721,6 +2732,7 @@ MIT License
27212732
case 'container':
27222733
case 'layout':
27232734
case 'zoomBehavior':
2735+
case 'maxWidth':
27242736
//@ts-ignore
27252737
opt[key] = val;
27262738
break;

Static/lib/azure-maps/azure-maps-layer-legend.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)