Azure Maps switch between S0 and S1

Tahmid Eshayat 286 Reputation points
2020-12-28T07:04:54.017+00:00

Hi there,

We are using azure maps for our mapping needs. We mostly use the basic map style. But sometimes like once a day users use Sattelite mode. So we using the S1 tier all the time is too expensive for us. We want to switch between S0 and S1. We can detect when users switched to satellite mode. At that time, we want to change the subscription key.

Let us know if it's possible, Cause using S1 all the time doesn't make sense.

Thanks

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

Accepted answer
  1. rbrundritt 18,061 Reputation points Microsoft Employee
    2021-01-19T18:05:54.307+00:00

    What you can do is add a transform request to the map and look for requests to the satellite tiles. When requests for those are seen, swap out the subscription key. Here is a code block example:

    var map, datasource;
    
    var s0Key = '<Your S0 Azure Maps Key>';
    var s1Key = '<Your S1 Azure Maps Key>'; 
    
    function GetMap() {
        //Initialize a map instance.
        map = new atlas.Map('myMap', {
            //Add authentication details for connecting to Azure Maps.
            authOptions: {
                //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: s0Key
            },
            transformRequest: function (url, resourceType) {
    
                //Look for satellite imagery tile requests. Check for V1 and V2 render service requests as the map styles will likely upgrade to point to V2 in the future.
                if (resourceType === 'Tile' && (url.indexOf('&tilesetId=microsoft.imagery') > -1 || url.indexOf('/map/imagery/png?') > -1)) {
                    url = url.replace(s0Key, s1Key);
                }
    
                return { url: url };
            }
        });
    
        //Wait until the map resources are ready.
        map.events.add('ready', function () {
    
            //Add a style control to the map.
            map.controls.add(new atlas.control.StyleControl({
                mapStyles: 'all'
            }), {
                position: 'top-left'
            });
        });
    }
    

    That said, we are looking at ways to better support this scenario in the future.

    1 person found this answer helpful.

4 additional answers

Sort by: Most helpful
  1. AshokPeddakotla-MSFT 33,746 Reputation points
    2020-12-29T09:26:50.607+00:00

    @Tahmid Eshayat You can change/switch Azure Maps pricing tier when needed. Please follow the below process to change pricing tier.

    Goto Azure Portal -> Select your Azure Maps -> Settings -> Choose Pricing Tier -> select S0 or S1 -> Save.

    52001-image.png

    Note: You don't have to generate new subscription keys or client ID (for Azure AD authentication) if you upgrade or downgrade the pricing tier for your Azure Maps account.

    For more details, see Choose the right pricing tier in Azure Maps and Manage the pricing tier of your Azure Maps account

    Hope this helps. Let us know if you need further assistance.

    If an answer is helpful, please "Accept answer" or "Up-Vote" for the same which might be beneficial to other community members reading this thread.

    0 comments No comments

  2. IoTGirl 3,126 Reputation points Microsoft Employee
    2020-12-29T19:46:44.103+00:00

    Hi @Tahmid Eshayat ,

    You can make two Azure Maps accounts, one for S0 and one for S1. I did the following:

    1. Go to Azure Marketplace and search "Azure Maps"
    2. Create a resource group called "AzureMapsTest"
    3. In that resource group, create an Azure Maps S0 instance called "AzureMapsS0"
    4. Return to Azure Marketplace and search "Azure Maps"
    5. Select the resource group called "AzureMapsTest"
    6. In that resource group, create an Azure Maps S1 instance called "AzureMapsS1"

    52010-image.png 52121-image.png

    Now you can use the S0 instance when you do not need S1 features and only use the S1 instance when you need those higher cost features.

    Sincerely,
    IoTGirl


  3. Tahmid Eshayat 286 Reputation points
    2021-01-12T01:17:56.027+00:00

    Hi there @IoTGirl @AshokPeddakotla-MSFT

    Extremely sorry for the delay.

    We are using the key from an environment variable.

    55563-image.png

    And we are initializing the map in this way.

    55584-image.png

    But we want to switch to S1 subscription key runtime.

    For example, when style data gets changes to Satellite, we want to switch to S1

    55591-image.png

    I'm wondering If I have to bind subscription key change on button click instead of style data change.

    But, I change it from here, It doesn't change. The map api still calls the old Key.

    0 comments No comments

  4. IoTGirl 3,126 Reputation points Microsoft Employee
    2021-01-19T17:41:38.903+00:00

    Yes, a Map you create with an S0 key will have issues with S1 calls. However if you call a REST API directly with the S1 key, you should be able to apply that result to the S0 map. See https://video2.skills-academy.com/en-us/azure/azure-maps/how-to-search-for-address and the other

    For Satellite you can create a Second Map control with the S1 that you only launch/show if the scenario goes beyond the S0 use limit and hide the S0 control.

    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.