Note: For production, use the blank-map-content.js
file instead of map-content.js (this file is for demo purpose). To
find the map ID, search by the state name in blank-map-content.js.
This guide walks you through configuring specific regions on your SVG map with custom colors, hover effects, tooltips, and clickable actions using the GEO Map Hub plugin.
color_region?
The color_region option allows you to visually differentiate specific regions (e.g., states or
provinces) by applying:
A custom default fill color
A custom hover fill color
A unique border color and width
Tooltips on hover
Optional URL redirection on click
This is ideal for dashboards or interactive visualizations where different regions need to stand out.
Ensure your project follows this structure:
your-project/ βββ gmh-plugin/ β βββ assets/ β β βββ css/ β β β βββ style.css β β βββ js/ β β β βββ script/ β β β β βββ geomaphub.js β β β β βββ lib/ β β β β β βββ regions-with-different-colors-gmh.js β Required β β β β β βββ interactive-tooltip-gmh.js β Required for interactive (tooltips and links.) β βββ data/ β β βββ us/ β β β βββ map-content.js β β β βββ us.svg β index.html
1. Update Your Configuration
In /gmh-plugin/data/us/map-content.js, add a color_region block to each region you want to highlight.
export const map_config = [
{
"targetClass": "US-WA", // Unique identifier for region.
"name": "Washington", // Display name for the region.
/*
* Regions With Different Colors configuration
* This section defines the properties for visualizing specific regions
* with different colors and border settings on the map.
*/
"color_region": {
"tooltip": "Washington", // Tooltip text displayed on hover.
"on_click": {
"url": "https://en.wikipedia.org/wiki/Washington",
"target": "_blank",
"cursor": "pointer"
},
/*
* Color settings for the region.
* Defines the default color and the color when hovered over.
*/
"color": {
"default": "#01467f", // Default fill color of the region.
"on_hover": "#005999" // Fill color when the region is hovered over.
},
/*
* Stroke (border) settings for the region.
* Defines the border color and width of the region.
*/
"stroke": {
"color": "#0095c3", // Border color of the region.
"width": "1px" // Border width of the region.
},
},
},
{
"targetClass": "US-AL", // Unique identifier for region.
"name": "Alabama", // Display name for the region.
/*
* Regions With Different Colors configuration
* This section defines the properties for visualizing specific regions
* with different colors and border settings on the map.
*/
"color_region": {
"tooltip": "Alabama", // Tooltip text displayed on hover.
/*
* Color settings for the region.
* Defines the default color and the color when hovered over.
*/
"color": {
"default": "#006ea8", // Default fill color of the region.
"on_hover": "#005999" // Fill color when the region is hovered over.
},
/*
* Stroke (border) settings for the region.
* Defines the border color and width of the region.
*/
"stroke": {
"color": "#0095c3", // Border color of the region.
"width": "1px" // Border width of the region.
},
},
}
]
2. Add General Config
Also in the same file:
/*
* General Configuration
* This section contains global settings for the map, including
* IDs for various elements like markers, lines, and tooltips.
*/
export const general_config = {
"id": {
/*
* SVG and Element IDs
* These IDs are used to reference specific SVG elements or HTML
* elements in your configuration. If you want to change any of
* these IDs, ensure you update them in the corresponding `svg.js` file.
*/
"svg_id": "US-MAP-GMH", /** ID for the main SVG map element. */
"tooltip_id": "tooltip-gmh", /** ID for the tooltip element. */
"custom_tooltip_id": "custom-tooltip-gmh", /** ID for the tooltip element. */
},
}
3. Create HTML and Script to Load Map
Here's a working example to display the map with the regions with different colors:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GEO Map Hub – Regions With Different Colors</title>
<link rel="stylesheet" href="/gmh-plugin/assets/css/style.css" />
</head>
<body>
<div id="tooltip-gmh"></div>
<div id="custom-tooltip-gmh"></div>
<div class="svg-container-gmh">
<div id="svg-wrapper-gmh"></div>
</div>
<script type="module">
const currentCountry = "us";
async function initMap() {
try {
const { map_config, general_config } = await import(`/gmh-plugin/data/${currentCountry}/map-content.js`);
const { GEOMapHub } = await import('/gmh-plugin/assets/js/script/geomaphub.js');
const { geoMapHubRegionWithDifferentColor } = await import('/gmh-plugin/assets/js/script/lib/regions-with-different-colors-gmh.js');
const { geoMapHubInteractiveTooltip } = await import('/gmh-plugin/assets/js/script/lib/interactive-tooltip-gmh.js');
const map = new GEOMapHub("#svg-wrapper-gmh", {
svgUrl: `/gmh-plugin/data/${currentCountry}/${currentCountry}.svg`,
mapConfig: map_config,
generalConfig: general_config,
});
map.registerPlugin(geoMapHubRegionWithDifferentColor);
map.registerPlugin(geoMapHubInteractiveTooltip);
map.init();
} catch (error) {
console.error("Error initializing map:", error);
}
}
initMap();
</script>
</body>
</html>
| Property | Description |
|---|---|
tooltip |
Text shown on hover (tooltip plugin required) |
color.default |
Default region fill color |
color.on_hover |
Fill color when hovered |
stroke.color |
Border color |
stroke.width |
Border width (e.g., "1px") |
on_click.url |
Optional link to open on click |
on_click.target |
_blank for new tab or _self for same tab |
on_click.cursor |
Cursor style (e.g., "pointer") |
general_config
The general_config object defines global map behavior and styling, including SVG
IDs, default colors, and stroke settings used across all regions and markers.
π id Section
| Property | Description |
|---|---|
svg_id |
The id of the main <svg> tag inside your SVG file. This
allows GEO Map Hub to hook into the map DOM element.
|
marker_id |
Global ID reference for color marker containers. Used to attach new marker groups. |
tooltip_id |
ID of the default tooltip element (used by interactive-tooltip-gmh.js). |
custom_tooltip_id |
ID for custom or extended tooltip blocks (e.g., HTML-based tooltips). |
π‘ These IDs must match what's defined inside your actual .svg file.
If you rename id="US-MAP-GMH" in the SVG, you must update svg_id accordingly.
If loading via file://, you'll hit this error:
Access to script at 'file:///...' from origin 'null' has been blocked by CORS policy...
Option 1: Use a Local Server (Recommended for HTML)
# Python 3 python -m http.server # Node.js npx http-server # PHP php -S localhost:8080
Or use a local web server (e.g., XAMPP or Laragon)
Option 2: Deploy to a Real Server
You can upload your files to:
Your cPanel or shared hosting
A staging VPS or domain
Once the files are accessible via http:// or https://, the plugin works without issues.
| β | Task |
|---|---|
| βοΈ | Region displays with correct color |
| βοΈ | Hover state works |
| βοΈ | Tooltip shows when hovering |
| βοΈ | Clickable region works (if defined) |
| βοΈ | No console errors or broken imports |
When configured properly, each defined region will:
Show its own color and border
Animate on hover
Show a tooltip
Redirect (if on_click.url is set)
Some features may not work in the preview.
Click here to explore the complete website.GEO Map Hub uses cookies to ensure proper functionality and provide an enhanced user experience. By continuing, you consent to the use of all cookies. To learn more, read our Cookie Statement.