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.
Globe Projection renders a 3D globe using D3 and
TopoJSON. It reads country data from JSON files, applies global water color, country
fill, stroke, and hover styles. Map elements are injected into the container
(canvas-container-gmh) and styled via general_config.
The Globe Projection Plugin displays a 3D globe-style projection of countries using D3.js and TopoJSON. It allows you to render the earth on a canvas element with interactive hover effects, strokes, and custom coloring for land and water.
Render an interactive world globe.
Visualize country boundaries on a spherical projection.
Apply hover and click effects to countries.
Customize globe styling using canvas and JSON-based map data.
Ensure your project follows this structure:
your-project/ βββ gmh-plugin/ β βββ assets/ β β βββ css/ β β β βββ style.css β β βββ js/ β β β βββ lib/ β β β β βββ d3.min.js β β β β βββ topojson.js β β β βββ script/ β β β β βββ geomaphub.js β β β β βββ lib/ β β β β β βββ globe-projection-gmh.js β Required β βββ data/ β β βββ globe/ β β β βββ countries-50m.json β β β βββ countries.json β β β βββ map-content.js β index.html
πΉ general_config
export const general_config = {
"html_element": {
"tooltip_id": "tooltip-gmh", // ID for displaying tooltips
"canva_container_id": "canvas-container-gmh" // Container for rendering the globe
},
"globle": {
"water_color": "#00000073", // Color of the ocean/water on the globe
},
"country": {
"background_color": "#ebdebb", // Default fill color of countries
"hover_color": "#FF5733", // Color when hovering over a country
"stroke_color": "#ffa635", // Country border color
"stroke_width": 0.5 // Border thickness
},
"data": {
"world_country": "/gmh-plugin/data/globe/countries-50m.json", // TopoJSON for country outlines (simplified)
"globe_world": "/gmh-plugin/data/globe/countries.json" // Possibly detailed country features (GeoJSON or TopoJSON)
}
};
| Key | Sub-Key | Description |
|---|---|---|
html_element.tooltip_id |
tooltip-gmh |
HTML ID for tooltip display. |
html_element.canva_container_id |
canvas-container-gmh |
ID of the canvas container to render the globe. |
globle.water_color |
#00000073 |
RGBA color for water/background. |
country.background_color |
#ebdebb |
Default fill color for countries. |
country.hover_color |
#FF5733 |
Fill color on hover. |
country.stroke_color |
#ffa635 |
Border color around countries. |
country.stroke_width |
0.5 |
Width of the stroke line. |
data.world_country |
countries-50m.json |
TopoJSON data for detailed borders. |
data.globe_world |
countries.json |
Simpler country definitions if needed. |
<!-- Globe Projection -->
<script src="/gmh-plugin/assets/js/lib/d3.min.js"></script>
<script src="/gmh-plugin/assets/js/lib/topojson.js"></script>
<!-- Globe Projection -->
<script type="module">
async function initMap() {
try {
// Dynamically import map-specific data
const {general_config} = await import(`/gmh-plugin/data/globe/map-content.js`);
const {GEOMapHub} = await import('/gmh-plugin/assets/js/script/geomaphub.js');
const {geoMapHubGlobeProjection} = await import('/gmh-plugin/assets/js/script/lib/globe-projection-gmh.js');
const map = new GEOMapHub("#canvas-container-gmh", {generalConfig: general_config});
map.registerPlugin(geoMapHubGlobeProjection);
map.init();
} catch (error) {
console.error("Error initializing map:", error);
}
}
initMap();
</script>
<!-- Globe Projection -->
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 – Globe Projection</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 id="canvas-container-gmh"></div>
<!-- Globe Projection -->
<script src="/gmh-plugin/assets/js/lib/d3.min.js"></script>
<script src="/gmh-plugin/assets/js/lib/topojson.js"></script>
<!-- Globe Projection -->
<script type="module">
async function initMap() {
try {
// Dynamically import map-specific data
const {general_config} = await import(`/gmh-plugin/data/globe/map-content.js`);
const {GEOMapHub} = await import('/gmh-plugin/assets/js/script/geomaphub.js');
const {geoMapHubGlobeProjection} = await import('/gmh-plugin/assets/js/script/lib/globe-projection-gmh.js');
const map = new GEOMapHub("#canvas-container-gmh", {generalConfig: general_config});
map.registerPlugin(geoMapHubGlobeProjection);
map.init();
} catch (error) {
console.error("Error initializing map:", error);
}
}
initMap();
</script>
<!-- Globe Projection -->
</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 | Result |
|---|---|
| π§ Globe Rendering | Displays an interactive rotating 3D globe using the canvas. |
| π Hover Effect | Country fills with hover_color (#FF5733) when hovered. |
| π Water Background | Water areas are styled with water_color (#00000073>). |
| πΊοΈ Country Borders | Country borders styled with stroke_color and stroke_width. |
| π§© Data Source | TopoJSON files (countries-50m.json) drive map data resolution. |
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.