Ability to change the road color in Azure maps?

Anonymous
2025-05-22T17:46:28.7966667+00:00

Hello. We are moving from Bing maps and are now using the "road_shaded_relief" style of interactive Azure maps. Is there a way to change the color of the roads to a lighter shade of orange or a different color in general? We have map pins that are the same color, and it makes them a bit difficult to see. Thank you.

User's image

Azure Maps
Azure Maps

An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.


Answer accepted by question author
Anonymous
2025-05-23T04:15:49.14+00:00

Hello Richelle Frazier,

I see you’re looking to change the color of the roads in the "road_shaded_relief" style of Azure Maps. Currently, Azure Maps provides built-in styles, but unfortunately, direct customization of road colors isn’t supported in the same way you might be used to with other mapping services.

Here are a couple of options you might consider:

  1. Use different map styles: You could switch to a different map style that might provide better contrast with your map pins. The road or grayscale_light styles might be worth looking into.
  2. Overlaying additional visuals: While you can't change the road colors directly, you could potentially overlay a custom visual that puts markers or animations that stand out more. This way, the pins could be more distinguishable from the roads.
  3. Map Style Sheets: Azure Maps has Map Style Sheets that you can apply, but these don't include direct road color changes. Here's how you can use it in JavaScript:
    
       map.setStyle("roadLight");
    
    
  4. Custom Pins: Consider customizing the color of your pins to make them stand out more against the road colors.

Ref doc: Azure Maps supported built-in map styles

Please take a moment to accept this answer if you acknowledged our inputs.

Thank you!

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. rbrundritt 20,451 Reputation points Volunteer Moderator
    2025-05-27T22:03:33.8033333+00:00

    There are a couple of ways to do this.

    1. There is what @Anonymous suggested which is to use a different map style, however, you may not find a style that has exactly what you are looking for.
    2. Override the style. There is an official option in the map to override certain styles, however, when it comes to roads you only really have the options to hide them. There is an unofficial way to override the styles, but there are some limitations:
      • Changes in the map tile structure could break this code without any warning.
      • Depending on what you are styling it may not work for all areas and zoom levels due to how Azure Maps optimizes rendering (e.g. detailed roads are rendered via a raster tile layer and not stylable with this method until you are zoomed in. Some regions, like China, may all be rendered using raster tiles and this do not support client side styling).

    Taking that into consideration, here is how you would do this. Azure Maps loads most of the data on the map using vector tiles. These get rendered on the client side using Mapbox vector tile styles (under the hood Azure Maps leverages MapLibre). It is possible to access these tiles using an undocumented method (thus not official supported) and override these styles via map._getMap().setLayoutProperty and map._getMap().setPaintProperty. To do this you need to know the name of the vector tile source and the names of the layers you want to style. This sample can help with that: https://samples.azuremaps.com/?search=inspect&sample=inspect-features-under-the-mouse From here you would wait for a map style to be loaded, then loop through the layers in it and override the styles you want. You would have to override these styles every time the map style changes.

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title>Custom map styles</title>
    
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    
        <!-- 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>
    
        <script>
            var map, currentMapStyle;
    
    		function GetMap() {
    			//Initialize a map instance.
    			map = new atlas.Map('myMap', {
                    center: [-122.33, 47.6],
                    zoom: 12,
    				view: 'Auto',
    
    				authOptions: {
    					authType: 'subscriptionKey',
    					subscriptionKey: '<Your Azure Maps Key>'
    				}
    			});
    
    			//Wait until the map resources are ready.
    			map.events.add('ready', function () {
    				//When the map style changes, the layers rendered will update, so you would likely need to reapply your changes.
    				//Monitor for when the map style changes.
    				map.events.add('styledata', styleChanged);
    
    				//Set the initial custom styles.
    				styleChanged();
    
    				//Add a style control to the map so we can test that the custom styles persist when the map style changes.
    				map.controls.add(new atlas.control.StyleControl(), {
    					position: 'top-right'
    				});
    			});
    		}
    
    		function styleChanged() {
    			//Get the basemap style.
    			var mapStyle = map.getStyle().style;
    
    			//Make sure the basemap style has changed.
    			//We need to do this as the style data event will fire every time any change is made to any layer style.
    			if (currentMapStyle !== mapStyle) {
    				currentMapStyle = mapStyle;
    
    //You could add a bit of logic that only overrides the styles for specific map styles. This way you don't change the road color for all map styles.
    				applyCustomStyle();
    			}
    		}
    
    		function applyCustomStyle() {
    			//Access internal map object. Warning: undocumented/unsupported.
    			var innerMap = map.map;
    
    			//Loop through all layers in the inner map and apply the custom styles.
    			var layers = innerMap.getStyle().layers;
    
    			for (var i = 0; i < layers.length; i++) {
    				const l = layers[i];
    
    				//Change the color of highways to a lighter shade of orange.
                    //Look for any layer that has an id with the word 'highway' in it, or 'cah' (controlled access highway), or is a high speed ramp.
    				if (l.id.indexOf('highway') !== -1 || l.id.indexOf('microsoft.bing.maps.roads.cah') !== -1 || 
                        l.id.indexOf('microsoft.bing.maps.roads.ramp_high_speed') !== -1) {
    					//Apply the custom style to the highway layer.
    					if (l.type === 'line') {
                            innerMap.setPaintProperty(l.id, 'line-color', '#FCC981');
    					} else if (l.type === 'fill') {
                            innerMap.setPaintProperty(l.id, 'fill-color', '#FCC981');
                            innerMap.setPaintProperty(l.id, 'fill-outline-color', '#FCC981');
    					}
                    }
    			}
    		}
        </script>
        <style>
            html, body {
                margin: 0;
                padding: 0;
                width: 100%;
                height: 100%;
            }
    
            #myMap {
                position: relative;
                width: 100%;
                height: 100%;
            }
        </style>
    </head>
    <body onload="GetMap()">
        <div id="myMap"></div>
    </body>
    </html>
    

    You can try this out here: https://rbrundritt.azurewebsites.net/Tools/Styles/CustomHighwayColorStyle.html

    Alternatively, if you want to significantly change the style of the map, you could simply leverage the vector tiles directly and create your own rendering layers. The blank_accessible map style will load the vector tiles without displaying them, allowing you to access them with custom layers. Here is an example:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <title>Custom style - Azure Maps Web SDK Samples</title>
    
        <meta charset="utf-8" />
        <meta http-equiv="x-ua-compatible" content="IE=Edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
        <meta name="description" content="This sample shows how to the renderWolrdCopies map style option changes the layout of the map when zoomed out." />
        <meta name="keywords" content="Microsoft maps, map, gis, API, SDK, map, worldwrap, map options" />
        <meta name="author" content="Microsoft Azure Maps" />
    
        <!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
        <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>
    
        <script type='text/javascript'>
            var map;
    
            function GetMap() {
                //Initialize a map instance.
                map = new atlas.Map('myMap', {
                    style: 'blank_accessible',
                    zoom: 2,
                    view: 'Auto',
    
    				//Add your Azure Maps subscription key to the map SDK. Get an Azure Maps key at https://azure.com/maps
                    authOptions: {
                        authType: 'subscriptionKey',
                        subscriptionKey: '<Your Azure Maps Key>'
                    }
                });
    
                //Add some data to the map so that we can see how the rendering of data also changes.
                map.events.add('ready', function () {
                    var baseMapSource = 'bing-mvt';
    
                    map.layers.add([
                        new atlas.layer.LineLayer(baseMapSource, null, {
                            sourceLayer: 'water_feature',
                            strokeColor: '#83888D',
                            strokeWidth: 3,
                            lineJoin: 'round',
                            lineCap: 'round'
                        }),
    
                        new atlas.layer.PolygonLayer(baseMapSource, null, {
                            sourceLayer: 'water_feature',
                            fillColor: 'white',
                            fillOpacity: 1
                        }),
    
                        new atlas.layer.LineLayer(baseMapSource, null, {
                            sourceLayer: 'country_region',
                            strokeColor: '#BABABA',
                            lineJoin: 'round',
                            lineCap: 'round'
                        }),
    
                        new atlas.layer.SymbolLayer(baseMapSource, null, {
                            sourceLayer: 'country_region',
                            iconOptions: {
                                image: 'none'
                            },
                            textOptions: {
                                textField: ['get', 'name'],
                                textFont: [
                                    'SegoeFrutigerHelveticaMYingHei-Bold'
                                ],
                                size: [
                                    'interpolate',
                                    ['exponential', 2],
                                    ['zoom'],
                                    0, 10,
                                    7, 28
                                ],
                                ignorePlacement: false
                            }
                        }),
    
                         new atlas.layer.SymbolLayer(baseMapSource, null, {
                             sourceLayer: 'admin_division1',
                             iconOptions: {
                                 image: 'none'
                             },
                             textOptions: {
                                 textField: ['get', 'name'],
                                 textFont: [
                                     'SegoeFrutigerHelveticaMYingHei-Regular'
                                 ],
                                 color: '#646464',
                                 size: [
                                     'interpolate',
                                     ['linear'],
                                     ['zoom'],
                                     0, 7,
                                     8, 22
                                 ],
                                 ignorePlacement: false
                             }
                         })
                    ]);
                });
            }
        </script>
        <style>
            html, body, #myMap {
                width: 100%;
                height: 100%;
                margin: 0;
                padding: 0;
            }
        </style>
    </head>
    <body onload="GetMap()">
        <div id="myMap"></div>
    </body>
    </html>
    

    You can try this out here: https://rbrundritt.azurewebsites.net/Demos/AzureMaps/CustomStyles/LightBorderMap.html

    Was this answer helpful?

    0 comments No comments

Your answer

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