Skip to content

Commit 2a27da6

Browse files
authored
Merge pull request #288689 from Chia-Chi-Shen/map-add-controls
Update map-add-controls for scale and fullscreen controls
2 parents 0fc7c44 + 2d871ed commit 2a27da6

File tree

4 files changed

+52
-11
lines changed

4 files changed

+52
-11
lines changed

articles/azure-maps/map-add-controls.md

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Add controls to a map | Microsoft Azure Maps
33
description: How to add zoom control, pitch control, rotate control and a style picker to a map in Microsoft Azure Maps.
44
author: sinnypan
55
ms.author: sipa
6-
ms.date: 05/15/2023
6+
ms.date: 11/05/2024
77
ms.topic: how-to
88
ms.service: azure-maps
99
ms.subservice: web-sdk
@@ -61,24 +61,51 @@ map.controls.add(new atlas.control.CompassControl(), {
6161
> [!VIDEO //codepen.io/azuremaps/embed/GBEoRb/?height=500&theme-id=0&default-tab=js,result&embed-version=2&editable=true]
6262
---------------------------------------------------------->
6363

64+
## Add scale control
65+
66+
A scale control adds a scale bar to the map. The following code sample creates an instance of the [ScaleControl] class and adds it to the bottom-left corner of the map.
67+
68+
```javascript
69+
//Construct a scale control and add it to the map.
70+
map.controls.add(new atlas.control.ScaleControl(), {
71+
position: 'bottom-left'
72+
});
73+
```
74+
75+
## Add fullscreen control
76+
77+
A fullscreen control adds a button to toggle the map or specified HTML element between fullscreen and normal view. The following code sample creates an instance of the [FullscreenControl] class and adds it to the top-right corner of the map.
78+
79+
```javascript
80+
//Construct a fullscreen control and add it to the map.
81+
map.controls.add(new atlas.control.FullscreenControl(), {
82+
position: 'top-right'
83+
});
84+
```
85+
6486
## A Map with all controls
6587

6688
Multiple controls can be put into an array and added to the map all at once and positioned in the same area of the map to simplify development. The following code snippet adds the standard navigation controls to the map using this approach.
6789

6890
```javascript
69-
map.controls.add([
91+
map.controls.add(
92+
[
7093
new atlas.control.ZoomControl(),
71-
new atlas.control.CompassControl(),
7294
new atlas.control.PitchControl(),
73-
new atlas.control.StyleControl()
74-
], {
75-
position: "top-right"
76-
});
95+
new atlas.control.CompassControl(),
96+
new atlas.control.StyleControl(),
97+
new atlas.control.FullscreenControl(),
98+
new atlas.control.ScaleControl(),
99+
],
100+
{
101+
position: 'top-right',
102+
}
103+
);
77104
```
78105

79-
The following image shows a map with the zoom, compass, pitch, and style picker controls in the top-right corner of the map. Notice how they automatically stack. The order of the control objects in the script dictates the order in which they appear on the map. To change the order of the controls on the map, you can change their order in the array.
106+
The following image shows a map with the zoom, pitch, compass, style, fullscreen, and scale controls in the top-right corner of the map. Notice how they automatically stack. The order of the control objects in the script dictates the order in which they appear on the map. To change the order of the controls on the map, you can change their order in the array.
80107

81-
:::image type="content" source="./media/map-add-controls/map-with-all-controls.png" lightbox="./media/map-add-controls/map-with-all-controls.png" alt-text="Screenshot showing a map displaying zoom, compass, pitch and style controls.":::
108+
:::image type="content" source="./media/map-add-controls/map-with-all-controls.png" lightbox="./media/map-add-controls/map-with-all-controls.png" alt-text="Screenshot showing a map displaying zoom, pitch, compass, style, fullscreen, and scale controls.":::
82109

83110
<!----------------------------------------------------------
84111
<br/>
@@ -91,7 +118,11 @@ The style picker control is defined by the [StyleControl] class. For more inform
91118

92119
The [Navigation Control Options] sample is a tool to test out the various options for customizing the controls. For the source code for this sample, see [Navigation Control Options source code].
93120

94-
:::image type="content" source="./media/map-add-controls/map-navigation-control-options.png" lightbox="./media/map-add-controls/map-navigation-control-options.png" alt-text="Screenshot showing the Map Navigation Control Options sample, which contains a map displaying zoom, compass, pitch and style controls and options on the left side of the screen that enable you to change the Control Position, Control Style, Zoom Delta, Pitch Delta, Compass Rotation Delta, Picker Styles, and Style Picker Layout properties.":::
121+
:::image type="content" source="./media/map-add-controls/map-navigation-control-options.png" lightbox="./media/map-add-controls/map-navigation-control-options.png" alt-text="Screenshot showing the Map Navigation Control Options sample, which contains a map displaying zoom, compass, pitch, style and scale controls and options on the left side of the screen that enable you to change the Control Position, Control Style, Zoom Delta, Pitch Delta, Compass Rotation Delta, Picker Styles, Style Picker Layout, Scale Max Width, and Scale Unit properties.":::
122+
123+
The [Fullscreen Control Options] sample provides a tool to test out the options for customizing the fullscreen control. For the source code for this sample, see [Fullscreen Control Options source code].
124+
125+
:::image type="content" source="./media/map-add-controls/fullscreen-control-options.png" lightbox="./media/map-add-controls/fullscreen-control-options.png" alt-text="Screenshot showing the Fullscreen Control Options sample, which contains a map displaying a fullscreen control and options on the left side of the screen that enable you to change the Control Style, and Fullscreen Control properties.":::
95126

96127
<!----------------------------------------------------------
97128
<br/>
@@ -104,6 +135,9 @@ If you want to create customized navigation controls, create a class that extend
104135

105136
Learn more about the classes and methods used in this article:
106137

138+
> [!div class="nextstepaction"]
139+
> [ZoomControl]
140+
107141
> [!div class="nextstepaction"]
108142
> [CompassControl]
109143
@@ -114,7 +148,10 @@ Learn more about the classes and methods used in this article:
114148
> [StyleControl]
115149
116150
> [!div class="nextstepaction"]
117-
> [ZoomControl]
151+
> [ScaleControl]
152+
153+
> [!div class="nextstepaction"]
154+
> [FullscreenControl]
118155
119156
See the following articles for full code:
120157

@@ -138,8 +175,12 @@ See the following articles for full code:
138175
[PitchControl]: /javascript/api/azure-maps-control/atlas.control.pitchcontrol
139176
[CompassControl]: /javascript/api/azure-maps-control/atlas.control.compasscontrol
140177
[StyleControl]: /javascript/api/azure-maps-control/atlas.control.stylecontrol
178+
[ScaleControl]: /javascript/api/azure-maps-control/atlas.control.scalecontrol
179+
[FullscreenControl]: /javascript/api/azure-maps-control/atlas.control.fullscreencontrol
141180
[Navigation Control Options]: https://samples.azuremaps.com/controls/map-navigation-control-options
142181
[Navigation Control Options source code]: https://github.com/Azure-Samples/AzureMapsCodeSamples/blob/main/Samples/Controls/Map%20Navigation%20Control%20Options/Map%20Navigation%20Control%20Options.html
182+
[Fullscreen Control Options]: https://samples.azuremaps.com/controls/fullscreen-control-options
183+
[Fullscreen Control Options source code]: https://github.com/Azure-Samples/AzureMapsCodeSamples/blob/main/Samples/Controls/Fullscreen%20control%20options/Fullscreen%20control%20options.html
143184
[choose a map style]: choose-map-style.md
144185
[Add a pin]: map-add-pin.md
145186
[Add a popup]: map-add-popup.md
529 KB
Loading
-230 KB
Loading
-191 KB
Loading

0 commit comments

Comments
 (0)