This tutorial shows you how to use the navbar.js plugin to add a scrollable navigation bar above your SimpleMaps interactive map. The bar displays clickable regions or states, with hover effects that highlight corresponding map areas. It adapts dynamically: regions are shown when zoomed out, and states appear when zoomed into a region. Scroll arrows appear when the list overflows, making it ideal for maps with many regions or states.
Below is a working example using the US map. Hover over a region name to pulse it on the map, or click to zoom in and see its states.
Interactive Demo: The example above shows a US map with a scrollable navigation bar. Try hovering over region names to see them pulse on the map, or click to zoom in and see individual states.
Here is how you can add this to your map:
Embed the following on your webpage:
<script type="text/javascript" src="mapdata.js"></script>
<script type="text/javascript" src="usmap.js"></script>
<script type="text/javascript" src="navbar.js"></script>
<script>
simplemaps_navbar.map = simplemaps_usmap; // tells the script which map to work with
/* set any other options here */
</script>
Place the following HTML on your webpage where you want your map to appear:
<div id="map"></div>
The plugin will automatically create the navigation bar inside the map container. No additional divs are required!
That's it! Your map will now have a scrollable navigation bar automatically created inside the map container that lists regions when zoomed out and states when zoomed into a region.
The plugin supports the following configuration options:
map | The map object the plugin should work with. Defaults to simplemaps_usmap. |
exclude | Array of region or state IDs to hide from the bar. Example: simplemaps_navbar.exclude = ['AK', 'HI']; |
list_to_map | Enable hover effects linking the bar to the map. When enabled, hovering over navbar items will pulse regions/states on the map. Defaults to false. |
level_to_show | Set the default level to display. Options: 'regions', 'states', or 'default'. Default behavior shows regions when zoomed out, states when zoomed in. Defaults to 'default'. |
apply_css | Use default styles. Set to false to apply your own CSS. Defaults to true. |
states_label | Custom label for the states heading. Defaults to 'States'. |
regions_label | Custom label for the regions heading. Defaults to 'Regions'. |
Example configuration:
simplemaps_navbar.map = simplemaps_usmap;
simplemaps_navbar.exclude = ['AK'];
simplemaps_navbar.list_to_map = true;
simplemaps_navbar.level_to_show = 'states';
simplemaps_navbar.apply_css = false;
simplemaps_navbar.states_label = 'Provinces';
simplemaps_navbar.regions_label = 'Areas';
The plugin includes default CSS for a clean, scrollable look. Here's a snippet of the default styles:
.map_navbar {
display: flex;
align-items: center;
background-color: #f8f9fa;
padding: 5px 10px;
}
.map_navbar_elements li {
padding: 8px 16px;
font-size: 16px;
cursor: pointer;
}
.map_navbar_elements li:hover {
color: #343a40;
background-color: #e9ecef;
}
.map_navbar_arrow {
font-size: 20px;
color: #343a40;
cursor: pointer;
}
To customize, set simplemaps_navbar.apply_css = false
and add your own styles targeting these classes.
The navigation bar operates dynamically based on the map's zoom level and user interaction:
Zoomed Out: The bar shows regions (e.g., "Northeast," "Southwest") sorted alphabetically. Click a region to zoom in.
Zoomed In: The bar switches to states within the selected region (e.g., "Texas," "Oklahoma").
Hover Effects: With list_to_map: true
, hovering over a name pulses the region/state on the map.
Scrolling: Arrows appear when the list exceeds the container width, with smooth scrolling on click.
Ensure your mapdata.js
includes region definitions (e.g., mapdata.regions
) for region-level navigation to work. If the bar doesn't appear, check the console for warnings (e.g., missing container or map variable).
Still have questions? Search our FAQs or contact support at [email protected].
Home | License | Privacy | Releases | Testimonials | Resources | Documentation | Order Lookup | All Maps | FAQs
Formerly FlashUSAmap.com and FlashWorldMap.com
SimpleMaps.com is a product of Pareto Software, LLC. © 2010-2025.