There are a couple of ways to do this.
- 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.
- 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