Background Vector
UZ
Background Vector

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.

🧩 Group Region - GEO Map Hub Plugin

This guide explains how to group multiple regions on your SVG map. Grouped regions share styling, tooltips, and optional click actions, making it easier to represent larger zones or categories visually.

πŸ“˜ What is Group Region?

Group Region allows you to apply shared styling, tooltips, and click interactions across multiple regions on your map using a single configuration. Rather than styling each region individually, this feature groups them together as one logical block for unified behavior.

πŸ’‘ Use Case

βœ… Common use cases for Group Region:

  • πŸ—ΊοΈ Grouping U.S. states into zones (e.g., West Coast, Midwest)

  • πŸ“Š Visualizing data clusters such as sales territories or climate zones

  • 🌍 Highlighting regions with shared characteristics (language, policy, etc.)

  • 🧭 Adding click behavior to a set of connected regions

Example: When hovering over any state in the "West Coast Group" (US-WA, US-OR, US-CA), all regions highlight and show a group tooltip. Clicking any of them opens a shared Wikipedia page.

πŸ“ Folder Structure

Make sure the following files are correctly placed:

your-project/
β”œβ”€β”€ gmh-plugin/
β”‚    β”œβ”€β”€ assets/
β”‚    β”‚    β”œβ”€β”€ css/
β”‚    β”‚    β”‚    └── style.css
β”‚    β”‚    β”œβ”€β”€ js/
β”‚    β”‚    β”‚    └── script/
β”‚    β”‚    β”‚    β”‚    β”œβ”€β”€ geomaphub.js
β”‚    β”‚    β”‚    β”‚    └── lib/
β”‚    β”‚    β”‚    β”‚    β”‚   β”œβ”€β”€ group-region-gmh.js       ← Required
β”‚    β”‚    β”‚    β”‚    β”‚   └── interactive-tooltip-gmh.js  ← Required for interactive (tooltips and links.)
β”‚    β”œβ”€β”€ data/
β”‚    β”‚    β”œβ”€β”€ us/
β”‚    β”‚    β”‚    β”œβ”€β”€ map-content.js
β”‚    β”‚    β”‚    └── us.svg
β”‚ index.html
βœ… Configuration Breakdown

πŸ”Ή group_map_config

/*
 * Group Map Configuration
 * This section defines the configuration for groups of regions,
 * their colors, tooltips, and other styling properties.
*/
export const group_map_config = [
  {
    "targetClass": "GMC-01", /** Unique identifier for the group map configuration. */

    "tooltip": "Group 01", /** Tooltip text displayed on hover for the group. */

    // Optional
    "on_click": {
      "url": "https://en.wikipedia.org/wiki/Washington",
      "target": "_blank",
      "cursor": "pointer"
    },

    "color": {
      "default": "#f3faff",  /** Default fill color for the group. */
      "on_hover": "#005999",  /** Fill color when the group is hovered over. */
    },

    "stroke": {
      "on_hover": "white",  /** Fill color when the group is hovered over. */
      "color": "#6B8B9E",  /** Border color for the group. */
      "width": "0.8px"     /** Border width for the group. */
    },

    /*
     * A list of region identifiers that belong to this group.
     * These regions will share the same styling.
    */
    "targetClasses": "US-WA, US-MT, US-OR, US-ID, US-NV, US-CA",
  },
]
Key Description
targetClass Unique group identifier, used by the plugin internally.
tooltip Tooltip shown when hovering over any region in the group.
on_click.url URL to open when a group region is clicked.
on_click.target _blank to open in new tab.
on_click.cursor CSS cursor style when hovering (e.g., pointer).
color.default Base fill color for all regions in the group.
color.on_hover Fill color on hover.
stroke.color Border color.
stroke.width Border thickness.
stroke.on_hover hover border color.
targetClasses Comma-separated list of targetClass values of regions to group.

βš™οΈ Script Setup

<script type="module">
  const currentCountry = "us";

  async function initMap() {
    try {
      const {group_map_config, colored_legend, general_config} = await import(`/gmh-plugin/data/${currentCountry}/map-content.js`);
      const {GEOMapHub} = await import('/gmh-plugin/assets/js/script/geomaphub.js');
      const {geoMapHubGroupRegion} = await import('/gmh-plugin/assets/js/script/lib/group-region-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`,
        groupMapConfig: group_map_config,
        generalConfig: general_config,
      });

      map.registerPlugin(geoMapHubGroupRegion);
      map.registerPlugin(geoMapHubInteractiveTooltip);
      map.init();
    } catch (error) {
      console.error("Error initializing map:", error);
    }
  }

  initMap();
</script>

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 – Group Region</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>

  <!-- Group Region -->
  <script type="module">
    const currentCountry = "us";

    async function initMap() {
      try {
        // Dynamically import map-specific data
        const {group_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 {geoMapHubGroupRegion} = await import('/gmh-plugin/assets/js/script/lib/group-region-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`,
          groupMapConfig: group_map_config,
          generalConfig: general_config,
        });

        map.registerPlugin(geoMapHubGroupRegion);
        map.registerPlugin(geoMapHubInteractiveTooltip);

        map.init();
      } catch (error) {
        console.error("Error initializing map:", error);
      }
    }

    initMap();
  </script>
  <!-- Group Region -->
</body>

</html>
⚠️ Local CORS Warning

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.

βœ… How to Fix

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.

πŸ“Œ Final Checklist

βœ… Each group has a unique targetClass

βœ… targetClasses include comma-separated region

βœ… geoMapHubGroupRegion plugin is registered

βœ… Tooltip and color settings are correctly configured

βœ… URL and target behavior defined if needed

🎯 Result

Once set up, all specified regions in a group:

  • πŸ–±οΈ Highlight together on hover

  • πŸ’¬ Show a unified tooltip

  • 🌐 Redirect or trigger unified action on click

  • 🎨 Share consistent styles (color, stroke)