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 explains how to add label markers to your SVG map. Label markers display icons, shapes, or custom images with tooltips and optional labels below, positioned precisely using coordinates.
A Label Marker is a type of map marker that combines a symbol (like a circle, square, or image) with a text label beneath or beside it. This allows you to visually mark a point on the map and describe it using readable text.
Use Label Markers when you want to:
βοΈ Mark airports, landmarks, or tourist spots with icons and names
π Highlight cities, towns, or capitals
π Display key data points with labels (e.g., top producers, weather stations)
π§ Help users locate items quickly via icon + label combo
Make sure the following files are correctly placed:
your-project/ βββ gmh-plugin/ β βββ assets/ β β βββ css/ β β β βββ style.css β β βββ js/ β β β βββ script/ β β β β βββ geomaphub.js β β β β βββ lib/ β β β β β βββ labels-below-marker-automatically-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.
/**
* Marker Configuration
*
* This section defines different types of markers that can be added to the map.
* Each marker type has its own structure and properties, allowing customization for
* specific use cases such as displaying images, labels, vectors, or color markers.
*
* Supported Marker Types:
* - label_marker: Markers with text labels.
*/
"markers": [
{
"targetClass": "MARKER-US-WA-1", // Unique identifier for this marker.
/*
* Label Marker Configuration
* Defines label markers that can be displayed on the map with customizable positioning, shapes, tooltips, and labels.
*/
"label_marker": [
{
"targetClass": "LM-US-WA-1", // Unique identifier for the label marker
/*
* Shape of the Label Marker
* Defines the marker's visual style (e.g., "rounded", "cubic").
* If using a custom marker (e.g., an image), leave this empty.
*/
"shape": "", // Example: "rounded" or "cubic"
/*
* Custom Marker Source
* If using a custom SVG or image as the marker, specify the file path here.
*/
"src": "assets/images/icons/airplane.svg", // Path to the custom marker
"tooltip": "Washington", // Tooltip text displayed when hovering over the marker
/*
* Positioning Properties
* Specifies the coordinates (x, y) for placing the marker on the map.
*/
"position": {
"x": 110, // X-coordinate for the marker's position
"y": 50 // Y-coordinate for the marker's position
},
"on_click": {
"url": "https://en.wikipedia.org/wiki/Washington",
"target": "_blank",
"cursor": "pointer"
},
/*
* Size Properties
* Defines the marker's dimensions. Use "radius" for rounded shapes, and "width" and "height" for custom shapes.
*/
"size": {
"radius": 7, // Radius for rounded markers
"width": 12, // Width for cubic or custom markers
"height": 12 // Height for cubic or custom markers
},
/*
* Color Properties
* Configures the marker's default, hover, and active states.
*/
"color": {
"default": "#ec962a", // Default marker color
"on_hover": "#005999" // Marker color on hover
},
/*
* Stroke (Border) Properties
* Defines the border color and width for the marker.
*/
"stroke": {
"color": "white", // Border color
"width": "1px" // Border width
},
/*
* Label Configuration
* Defines the label text, positioning, and font styling associated with the marker.
*/
"label": {
"text": "Washington", // Text displayed as the label
/*
* Positioning for the Label
* Specifies the label's position relative to the marker.
*/
"position": {
"x": 0, // X-coordinate for label placement
"y": 0 // Y-coordinate for label placement
},
/*
* Adjustments for Fine-Tuning
* Allows manual offsets for precise label placement.
*/
"adjustments": {
"x": 4, // Horizontal adjustment
"y": 18 // Vertical adjustment
},
/*
* Font Styling for the Label
* Configures the font size, color, and weight for the label text.
*/
"font": {
"size": "7px", // Font size for the label text
"color": "black", // Font color for the label text
"weight": "normal" // Font weight for the label text
}
}
},
],
}
],
},
];
| Key | Description |
|---|---|
targetClass |
Unique identifier for the region (e.g., "US-WA" for Washington). |
name |
Display name of the region shown in tooltips or labels (e.g., "Washington"). |
heat_map.value |
Numeric value representing data intensity for the heat map visualization (e.g., population count). |
heat_map.on_click |
(Optional) Click action configuration with: |
url |
URL to open when the region is clicked. |
target |
Specifies where to open the URL (_blank, _self, etc.). |
cursor |
Cursor style on hover (usually "pointer"). |
πΉ general_config
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. */
"marker_id": "US-MARKER-GMH", /** ID for the marker element. */
},
/*
* Label Marker Configuration
* This section defines the configuration for label markers on the map,
* including color and stroke settings for the label marker elements.
*/
"label_marker": {
/*
* Map Color Settings
* These define the default and hover colors for the label markers on the map.
*/
"color": {
"default": "#f3faff", /** Default color for the label marker. */
"on_hover": "#005999" /** Color when the label marker is hovered over. */
},
/*
* Stroke Settings
* These define the border (stroke) properties for the label marker,
* including the color and width of the border.
*/
"stroke": {
"color": "#6B8B9E", /** Border color for the label marker. */
"width": "0.8px" /** Border width for the label marker. */
},
},
}
| Key | Description |
|---|---|
tooltip |
Tooltip template; {value} is replaced with region's heat value. |
html_id |
DOM element ID for optional heat legend UI. |
color.default |
Default background color if no value is provided for a region. |
color.on_hover |
Background color of a region when hovered by the cursor. |
stroke.color |
Border color for the map regions. |
stroke.width |
Border width for the map regions. |
start.color |
RGB array for the lowest value color (e.g., light blue). |
start.population |
Minimum expected data value (e.g., 5,000). |
start.display_text |
Text label for the minimum value in the legend (e.g., "5K"). |
end.color |
RGB array for the highest value color (e.g., dark blue). |
end.population |
Maximum expected data value (e.g., 40,000,000). |
end.display_text |
Text label for the maximum value in the legend (e.g., "4M"). |
<!-- Labels below markers automatically -->
<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 {geoMapHubLabelsBelowMarker} = await import('/gmh-plugin/assets/js/script/lib/labels-below-marker-automatically-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(geoMapHubLabelsBelowMarker);
map.registerPlugin(geoMapHubInteractiveTooltip);
map.init();
} catch (error) {
console.error("Error initializing map:", error);
}
}
initMap();
</script>
<!-- Labels below markers automatically -->
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 – Label Marker</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="row row-gap-2">
<div class="col-lg-12 col-12">
<div class="svg-container-gmh">
<div id="svg-wrapper-gmh"></div>
</div>
</div>
</div>
<!-- Labels below markers automatically -->
<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 {geoMapHubLabelsBelowMarker} = await import('/gmh-plugin/assets/js/script/lib/labels-below-marker-automatically-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(geoMapHubLabelsBelowMarker);
map.registerPlugin(geoMapHubInteractiveTooltip);
map.init();
} catch (error) {
console.error("Error initializing map:", error);
}
}
initMap();
</script>
<!-- Labels below markers automatically -->
</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.
β
Custom image or shape marker appears at x, y on the map
β Tooltip appears on hover
β Clickable link optional
β Label text auto-positioned with adjustments
β
Consistent styling through general_config
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.