can't get atlas.control.ScaleControl to work. The scale does not show up on the map

Mike Pettis 20 Reputation points
2025-04-23T22:59:47.04+00:00

This will not display the scale on the map. Any ideas??

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<title>Azure Maps with Scale</title>

<!-- Load the Azure Maps SDK -->

<script src="https://atlas.microsoft.com/sdk/js/atlas.min.js?api-version=2.0"></script>

<link rel="stylesheet" href="https://atlas.microsoft.com/sdk/css/atlas.min.css?api-version=2.0" />

<style>

    /* Reset page styles */

    * {

        margin: 0;

        padding: 0;

        box-sizing: border-box;

    }

    /* Map container */

    #myMap {

        width: 100vw;

        height: 100vh;

    }

</style>

</head>

<body>

<div id="myMap"></div>

<script>

    // Replace with your Azure Maps subscription key

    const subscriptionKey = 'maps key here';

    // Initialize the map

    const map = new atlas.Map('myMap', {

        center: [-81.5749, 28.5653], // Coordinates for Winter Garden, FL

        zoom: 12,

        authOptions: {

            authType: 'subscriptionKey',

            subscriptionKey: subscriptionKey

        }

    });

    // Add event listener for when the map is ready

    map.events.add('ready', () => {

        console.log('Map is ready.');

        // Add a ScaleControl to the map

        const scaleControl = new atlas.control.ScaleControl({

            style: 'bar', // Options: 'bar' or 'line'

            maxWidth: 200

        });

        // Place the ScaleControl on the bottom-left of the map

        map.controls.add(scaleControl, {

            position: atlas.ControlPosition.BottomLeft

        });

    });

</script>

</body>

</html>

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
817 questions
{count} votes

Accepted answer
  1. IoTGirl 3,621 Reputation points Microsoft Employee Moderator
    2025-04-24T14:12:49.2966667+00:00

    Hi @Mike Pettis ,

    If you use the full sample code for the working sample in future you will avoid this. Samples.AzureMaps.com is fully searchable and supported by the Azure Maps Team so should you have an issue, you can provide feedback right in GitHub and it will be reviewed by a team member.

    You can also check out our blog at https://techcommunity.microsoft.com/blog/azuremapsblog/why-upgrading-to-the-latest-azure-maps-apis-matters/4395364

    Sincerely,

    IoTGirl

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Manas Mohanty 3,965 Reputation points Microsoft External Staff Moderator
    2025-04-24T08:41:46.8666667+00:00

    Hi Mike Pettis

    I have been able to replicate no scale control on above code.

    You seem to be using older version of script source (2.0) but as per map control we need 3.0 script source.

    I replaced below lines in your code to get scale control on map.

    <script src="https://atlas.microsoft.com/sdk/js/atlas.min.js?api-version=2.0"></script> <link rel="stylesheet" href="https://atlas.microsoft.com/sdk/css/atlas.min.css?api-version=2.0" />
    

    with

    <link rel="stylesheet" href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.css" type="text/css" />
    <script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/3/atlas.min.js"></script>
    
    

    Attached screenshot with maptcontrol/3 for reference.

    with3.0javascript

    You can see scale control on bottom left side.

    Hope it helps.

    Thank you.

    2 people found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.