Change the Case of Labels
Change text case of map labels using the text-transform layout property.
const API_KEY = 'toursprung';
const map = new maptoolkit.Map({
container: 'map',
style: `https://static.maptoolkit.net/styles/toursprung/terrain.json?api_key=${API_KEY}`,
center: [11.39085, 47.27574],
zoom: 10,
attributionControl: { compact: false }
});
function setCase(textTransform) {
if (!map.isStyleLoaded()) return;
const layers = map.getStyle().layers;
for (const layer of layers) {
if (layer.type === 'symbol' && layer.layout && layer.layout['text-field']) {
map.setLayoutProperty(layer.id, 'text-transform', textTransform === 'none' ? undefined : textTransform);
}
}
}<!DOCTYPE html>
<html lang="en">
<head>
<title>Change the Case of Labels – Maptoolkit Maps JS</title>
<meta property="og:description" content="Change text case of map labels using the text-transform layout property." />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/@maptoolkit/maps@11.0.0-beta.2/dist/maptoolkit.js"></script>
<link rel="stylesheet" href="https://unpkg.com/@maptoolkit/maps@11.0.0-beta.2/dist/maptoolkit.css" />
<style>
html, body { width: 100%; height: 100%; margin: 0; padding: 0; }
#map { width: 100%; height: 100%; }
#controls {
position: absolute;
top: 10px;
left: 10px;
display: flex;
gap: 6px;
}
#controls button {
padding: 8px 14px;
background: #3887be;
color: white;
border: none;
border-radius: 3px;
cursor: pointer;
font-size: 13px;
}
#controls button:hover { background: #2c6d9e; }
</style>
</head>
<body>
<div id="map"></div>
<div id="controls">
<button onclick="setCase('none')">Default</button>
<button onclick="setCase('uppercase')">UPPERCASE</button>
<button onclick="setCase('lowercase')">lowercase</button>
</div>
<script>
const API_KEY = 'toursprung';
const map = new maptoolkit.Map({
container: 'map',
style: `https://static.maptoolkit.net/styles/toursprung/terrain.json?api_key=${API_KEY}`,
center: [11.39085, 47.27574],
zoom: 10,
attributionControl: { compact: false }
});
function setCase(textTransform) {
if (!map.isStyleLoaded()) return;
const layers = map.getStyle().layers;
for (const layer of layers) {
if (layer.type === 'symbol' && layer.layout && layer.layout['text-field']) {
map.setLayoutProperty(layer.id, 'text-transform', textTransform === 'none' ? undefined : textTransform);
}
}
}
</script>
</body>
</html>