Stay organized with collections
Save and categorize content based on your preferences.
You can use map styling to hide features on the map. Select an option in this
example to hide or show business points of interest (POIs) and public transit
icons on the map.
letmap:google.maps.Map;functioninitMap():void{map=newgoogle.maps.Map(document.getElementById("map")asHTMLElement,{center:{lat:-33.86,lng:151.209},zoom:13,mapTypeControl:false,});// Add controls to the map, allowing users to hide/show features.conststyleControl=document.getElementById("style-selector-control")asHTMLElement;map.controls[google.maps.ControlPosition.TOP_LEFT].push(styleControl);// Apply new JSON when the user chooses to hide/show features.(document.getElementById("hide-poi")asHTMLElement).addEventListener("click",()=>{map.setOptions({styles:styles["hide"]});});(document.getElementById("show-poi")asHTMLElement).addEventListener("click",()=>{map.setOptions({styles:styles["default"]});});}conststyles:Record<string,google.maps.MapTypeStyle[]>={default:[],hide:[{featureType:"poi.business",stylers:[{visibility:"off"}],},{featureType:"transit",elementType:"labels.icon",stylers:[{visibility:"off"}],},],};declareglobal{interfaceWindow{initMap:()=>void;}}window.initMap=initMap;
letmap;functioninitMap(){map=newgoogle.maps.Map(document.getElementById("map"),{center:{lat:-33.86,lng:151.209},zoom:13,mapTypeControl:false,});// Add controls to the map, allowing users to hide/show features.conststyleControl=document.getElementById("style-selector-control");map.controls[google.maps.ControlPosition.TOP_LEFT].push(styleControl);// Apply new JSON when the user chooses to hide/show features.document.getElementById("hide-poi").addEventListener("click",()=>{map.setOptions({styles:styles["hide"]});});document.getElementById("show-poi").addEventListener("click",()=>{map.setOptions({styles:styles["default"]});});}conststyles={default:[],hide:[{featureType:"poi.business",stylers:[{visibility:"off"}],},{featureType:"transit",elementType:"labels.icon",stylers:[{visibility:"off"}],},],};window.initMap=initMap;
/* * Always set the map height explicitly to define the size of the div element * that contains the map. */#map{height:100%;}/* * Optional: Makes the sample page fill the window. */html,body{height:100%;margin:0;padding:0;}.map-control{background-color:#fff;border:1pxsolid#ccc;box-shadow:02px2pxrgba(33,33,33,0.4);font-family:"Roboto","sans-serif";margin:10px;padding-right:5px;/* Hide the control initially, to prevent it from appearing before the map loads. */display:none;}/* Display the control once it is inside the map. */#map.map-control{display:block;}.selector-control{font-size:14px;line-height:30px;vertical-align:baseline;}
<html>
<head>
<title>Hiding Map Features With Styling</title>
<link rel="stylesheet" type="text/css" href="./style.css" />
<script type="module" src="./index.js"></script>
</head>
<body>
<div id="style-selector-control" class="map-control">
<input
type="radio"
name="show-hide"
id="hide-poi"
class="selector-control"
/>
<label for="hide-poi">Hide</label>
<input
type="radio"
name="show-hide"
id="show-poi"
class="selector-control"
checked="checked"
/>
<label for="show-poi">Show</label>
</div>
<div id="map"></div>
<!--
The `defer` attribute causes the script to execute after the full HTML
document has been parsed. For non-blocking uses, avoiding race conditions,
and consistent behavior across browsers, consider loading using Promises. See
https://developers.google.com/maps/documentation/javascript/load-maps-js-api
for more information.
-->
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&v=weekly"
defer
></script>
</body>
</html>
Git and Node.js are required to run this sample locally. Follow these instructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.
[null,null,["Last updated 2025-08-28 UTC."],[[["\u003cp\u003eThis example demonstrates how to hide or show specific map features like business POIs and transit icons using map styling in Google Maps.\u003c/p\u003e\n"],["\u003cp\u003eUsers can interactively control the visibility of these features through provided controls.\u003c/p\u003e\n"],["\u003cp\u003eThe sample code utilizes JSON styles to define the appearance of map elements, including their visibility.\u003c/p\u003e\n"],["\u003cp\u003eYou can explore the functionality further by trying the sample on JSFiddle or Google Cloud Shell and even clone the sample code for local execution.\u003c/p\u003e\n"]]],["Map styling allows users to hide or show features. This is demonstrated by creating a map with controls to toggle the visibility of business points of interest (POIs) and public transit icons. Clicking \"hide\" applies styles to turn off visibility for `poi.business` and `transit` features. Clicking \"show\" reverts to default styles, showing these elements. The sample code uses JavaScript, HTML, and CSS, with a TypeScript version also provided.\n"],null,["You can use map styling to hide features on the map. Select an option in this\nexample to hide or show business points of interest (POIs) and public transit\nicons on the map.\n\nRead the [documentation](/maps/documentation/javascript/styling). \n\nTypeScript \n\n```typescript\nlet map: google.maps.Map;\n\nfunction initMap(): void {\n map = new google.maps.Map(document.getElementById(\"map\") as HTMLElement, {\n center: { lat: -33.86, lng: 151.209 },\n zoom: 13,\n mapTypeControl: false,\n });\n\n // Add controls to the map, allowing users to hide/show features.\n const styleControl = document.getElementById(\n \"style-selector-control\"\n ) as HTMLElement;\n\n map.controls[google.maps.ControlPosition.TOP_LEFT].push(styleControl);\n\n // Apply new JSON when the user chooses to hide/show features.\n (document.getElementById(\"hide-poi\") as HTMLElement).addEventListener(\n \"click\",\n () =\u003e {\n map.setOptions({ styles: styles[\"hide\"] });\n }\n );\n (document.getElementById(\"show-poi\") as HTMLElement).addEventListener(\n \"click\",\n () =\u003e {\n map.setOptions({ styles: styles[\"default\"] });\n }\n );\n}\n\nconst styles: Record\u003cstring, google.maps.MapTypeStyle[]\u003e = {\n default: [],\n hide: [\n {\n featureType: \"poi.business\",\n stylers: [{ visibility: \"off\" }],\n },\n {\n featureType: \"transit\",\n elementType: \"labels.icon\",\n stylers: [{ visibility: \"off\" }],\n },\n ],\n};\n\n\ndeclare global {\n interface Window {\n initMap: () =\u003e void;\n }\n}\nwindow.initMap = initMap;https://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/samples/hiding-features/index.ts#L8-L60\n```\n| **Note:** Read the [guide](/maps/documentation/javascript/using-typescript) on using TypeScript and Google Maps.\n\nJavaScript \n\n```javascript\nlet map;\n\nfunction initMap() {\n map = new google.maps.Map(document.getElementById(\"map\"), {\n center: { lat: -33.86, lng: 151.209 },\n zoom: 13,\n mapTypeControl: false,\n });\n\n // Add controls to the map, allowing users to hide/show features.\n const styleControl = document.getElementById(\"style-selector-control\");\n\n map.controls[google.maps.ControlPosition.TOP_LEFT].push(styleControl);\n // Apply new JSON when the user chooses to hide/show features.\n document.getElementById(\"hide-poi\").addEventListener(\"click\", () =\u003e {\n map.setOptions({ styles: styles[\"hide\"] });\n });\n document.getElementById(\"show-poi\").addEventListener(\"click\", () =\u003e {\n map.setOptions({ styles: styles[\"default\"] });\n });\n}\n\nconst styles = {\n default: [],\n hide: [\n {\n featureType: \"poi.business\",\n stylers: [{ visibility: \"off\" }],\n },\n {\n featureType: \"transit\",\n elementType: \"labels.icon\",\n stylers: [{ visibility: \"off\" }],\n },\n ],\n};\n\nwindow.initMap = initMap;https://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/hiding-features/docs/index.js#L7-L44\n```\n| **Note:** The JavaScript is compiled from the TypeScript snippet.\n\nCSS \n\n```css\n/* \n * Always set the map height explicitly to define the size of the div element\n * that contains the map. \n */\n#map {\n height: 100%;\n}\n\n/* \n * Optional: Makes the sample page fill the window. \n */\nhtml,\nbody {\n height: 100%;\n margin: 0;\n padding: 0;\n}\n\n.map-control {\n background-color: #fff;\n border: 1px solid #ccc;\n box-shadow: 0 2px 2px rgba(33, 33, 33, 0.4);\n font-family: \"Roboto\", \"sans-serif\";\n margin: 10px;\n padding-right: 5px;\n /* Hide the control initially, to prevent it from appearing\n before the map loads. */\n display: none;\n}\n\n/* Display the control once it is inside the map. */\n#map .map-control {\n display: block;\n}\n\n.selector-control {\n font-size: 14px;\n line-height: 30px;\n vertical-align: baseline;\n}\nhttps://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/hiding-features/docs/style.css#L7-L47\n```\n\nHTML \n\n```html\n\u003chtml\u003e\n \u003chead\u003e\n \u003ctitle\u003eHiding Map Features With Styling\u003c/title\u003e\n\n \u003clink rel=\"stylesheet\" type=\"text/css\" href=\"./style.css\" /\u003e\n \u003cscript type=\"module\" src=\"./index.js\"\u003e\u003c/script\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id=\"style-selector-control\" class=\"map-control\"\u003e\n \u003cinput\n type=\"radio\"\n name=\"show-hide\"\n id=\"hide-poi\"\n class=\"selector-control\"\n /\u003e\n \u003clabel for=\"hide-poi\"\u003eHide\u003c/label\u003e\n \u003cinput\n type=\"radio\"\n name=\"show-hide\"\n id=\"show-poi\"\n class=\"selector-control\"\n checked=\"checked\"\n /\u003e\n \u003clabel for=\"show-poi\"\u003eShow\u003c/label\u003e\n \u003c/div\u003e\n \u003cdiv id=\"map\"\u003e\u003c/div\u003e\n\n \u003c!-- \n The `defer` attribute causes the script to execute after the full HTML\n document has been parsed. For non-blocking uses, avoiding race conditions,\n and consistent behavior across browsers, consider loading using Promises. See\n https://developers.google.com/maps/documentation/javascript/load-maps-js-api\n for more information.\n --\u003e\n \u003cscript\n src=\"https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&v=weekly\"\n defer\n \u003e\u003c/script\u003e\n \u003c/body\u003e\n\u003c/html\u003ehttps://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/hiding-features/docs/index.html#L8-L47\n```\n\nTry Sample \n[JSFiddle.net](https://jsfiddle.net/gh/get/library/pure/googlemaps/js-samples/tree/master/dist/samples/hiding-features/jsfiddle) [Google Cloud Shell](https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fgooglemaps%2Fjs-samples&cloudshell_git_branch=sample-hiding-features&cloudshell_tutorial=cloud_shell_instructions.md&cloudshell_workspace=.)\n\nClone Sample\n\n\nGit and Node.js are required to run this sample locally. Follow these [instructions](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) to install Node.js and NPM. The following commands clone, install dependencies and start the sample application. \n\n git clone -b sample-hiding-features https://github.com/googlemaps/js-samples.git\n cd js-samples\n npm i\n npm start\n\n\nOther samples can be tried by switching to any branch beginning with `sample-`\u003cvar translate=\"no\"\u003eSAMPLE_NAME\u003c/var\u003e. \n\n git checkout sample-\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-nx\"\u003eSAMPLE_NAME\u003c/span\u003e\u003c/var\u003e\n npm i\n npm start"]]