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.
The Trigger Custom JavaScript feature allows developers to execute
custom scripts when users interact with specific regions on the map. This enables dynamic content rendering, workflow
automation, and interactive UI responses. Each region can define tooltip text, interaction content, and
state-based colors. Configuration is managed via map_config and general_config,
and executed through the geoMapHubTriggerCustomJS plugin.
This plugin lets you run custom JavaScript actions when clicking on a region. The interaction can show descriptive content, update the UI, or trigger lightboxes, modals, etc.
Displaying historical or informational text on click
Opening a lightbox or modal
Triggering page navigation or API requests
Interactive educational maps
Make sure the following files are correctly placed:
your-project/ βββ gmh-plugin/ β βββ assets/ β β βββ css/ β β β βββ style.css β β βββ js/ β β β βββ script/ β β β β βββ geomaphub.js β β β β βββ lib/ β β β β β βββ trigger-custom-js-gmh.js β Required β β β β β βββ interactive-tooltip-gmh.js β Required for interactive (tooltips and links.) β βββ data/ β β βββ us/ β β β βββ map-content.js β β β βββ us.svg β index.html
πΉ map_config
export const map_config = [
{
"targetClass": "US-WA", // Unique identifier for region.
"name": "Washington", // Display name for the region.
/*
* Trigger Custom JavaScript Configuration
* Defines a region on the map that triggers custom JavaScript actions on interaction.
*/
"trigger_custom_js": {
"tooltip": "Washington", // Tooltip text displayed when hovering over the region
/*
* Content to Display on Click
* This is descriptive text or information related to the region.
*/
"content": `Washington most commonly refers to, George Washington (1732–1799), the first
president of the United States. Washington (state), a state in the Pacific Northwest of the
United States. Washington, D.C., the capital of the United States. A metonym for the
federal government of the United States. Washington metropolitan area, the metropolitan
area centered on Washington, D.C.`, // Content displayed on click interaction
/*
* Color Configuration
* Defines the appearance of the region in different states.
*/
"color": {
"default": "#afcde3", // Default background color
"on_hover": "#005999", // Background color when hovered
"active": "#005999" // Background color when active (clicked)
}
},
},
]
| Property | Description |
|---|---|
tooltip |
Text shown in the tooltip on hover. |
content |
HTML/text content to be displayed when the region is clicked. |
color.default |
Default background color of the region. |
color.on_hover |
Background color when hovering over the region. |
color.active |
Background color when the region is in an active (clicked) state. |
πΉ general_config
/*
* 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. */
},
/*
* Trigger Custom JavaScript Configuration
* This section defines the configuration for custom JavaScript triggers,
* including color and stroke settings for the interactive elements.
*/
"trigger_custom_js": {
/*
* Color Settings
* These define the default and hover colors for the interactive trigger element
* that can be controlled via custom JavaScript.
*/
"color": {
"default": "#f3faff", /** Default color for the trigger element. */
"on_hover": "#005999" /** Color when the trigger element is hovered over. */
},
/*
* Stroke Settings
* These define the border (stroke) properties for the trigger element,
* including the color and width of the border.
*/
"stroke": {
"color": "#6B8B9E", /** Border color for the trigger element. */
"width": "0.8px" /** Border width for the trigger element. */
},
},
}
π general_config β id
| Key | Description |
|---|---|
svg_id |
ID for the main SVG map container. |
tooltip_id |
ID for the tooltip element. |
custom_tooltip_id |
ID for the custom tooltip (can be used for rich HTML content, etc.). |
βοΈ general_config β trigger_custom_js
| Property | Description |
|---|---|
color.default |
Default fill color for the regions with custom JavaScript trigger. |
color.on_hover |
Hover fill color for the regions with custom JavaScript trigger. |
stroke.color |
Border color for the trigger region. |
stroke.width |
Width of the border around the trigger region. |
<!-- Trigger Custom JS -->
<script type="module">
const currentCountry = "us";
async function initMap() {
try {
// Dynamically import map-specific data
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 {geoMapHubTriggerCustomJS} = await import('/gmh-plugin/assets/js/script/lib/trigger-custom-js-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(geoMapHubTriggerCustomJS);
map.registerPlugin(geoMapHubInteractiveTooltip);
map.init();
} catch (error) {
console.error("Error initializing map:", error);
}
}
initMap();
</script>
<!-- Trigger Custom JS -->
Here's a working example to display the map
<!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 – Trigger Custom JS</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>
<!-- Trigger Custom JS -->
<script type="module">
const currentCountry = "us";
async function initMap() {
try {
// Dynamically import map-specific data
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 {geoMapHubTriggerCustomJS} = await import('/gmh-plugin/assets/js/script/lib/trigger-custom-js-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(geoMapHubTriggerCustomJS);
map.registerPlugin(geoMapHubInteractiveTooltip);
map.init();
} catch (error) {
console.error("Error initializing map:", error);
}
}
initMap();
</script>
<!-- Trigger Custom JS -->
</body>
</html>
If you're testing with a .html file locally and see this error:
Access to script at 'file:///...' from origin 'null' has been blocked by CORS policy...
It means you're loading the file using the file:// protocol.
Option 1: Use a Local Server (Recommended for HTML)
Live Server (VS Code Extension)
Install Live Server, right-click your HTML, and choose βOpen with Live Serverβ.
Or use any other local server:
# 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.
| Behavior | Description |
|---|---|
| π±οΈ On Click | Triggers JavaScript with custom content |
| πΌοΈ Tooltip | Displays custom tooltip text |
| π¨ Colors | Region highlights with hover and active colors |
| π§© Plugin Callback | You can extend this plugin to use modals, tabs, or third-party libraries |
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.