Background Vector
KR
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.

πŸ”­ Different Projection - GEO Map Hub Plugin

The Different Projections feature enables users to display maps using various geographic projection styles, offering flexibility and accuracy based on the nature and scale of the data. This is particularly useful for tailoring map presentations to specific analytical or visual needs.

Supported Projections
  • Natural Earth Projection A visually balanced projection ideal for world maps, providing a realistic and aesthetically pleasing representation of the globe.

    Note: To use this projection, import file like this: world-map/map-content.js

  • Miller Projection A cylindrical projection that reduces distortion near the poles, making it suitable for global data with a more uniform scale.

    Note: To use this projection, import file like this: miller-projection-world-map/map-content.js

  • Mercator Projection A widely used projection for navigation and web mapping, preserving direction but distorting size near the poles.

    Note: To use this projection, include file like this: mercator-projection-world-map/map-content.js

πŸ“ Folder Structure for Natural Earth Projection

Ensure your project follows this structure:

your-project/
β”œβ”€β”€ gmh-plugin/
β”‚    β”œβ”€β”€ assets/
β”‚    β”‚    β”œβ”€β”€ css/
β”‚    β”‚    β”‚    └── style.css
β”‚    β”‚    β”œβ”€β”€ js/
β”‚    β”‚    β”‚    └── script/
β”‚    β”‚    β”‚    β”‚    β”œβ”€β”€ geomaphub.js
β”‚    β”‚    β”‚    β”‚    └── lib/
β”‚    β”‚    β”‚    β”‚    β”‚   └── feature-gmh.js // add feature plugin files
β”‚    β”œβ”€β”€ data/
β”‚    β”‚    β”œβ”€β”€ world-map/                          ← Natural Earth Projection Map
β”‚    β”‚    β”‚    β”œβ”€β”€ map-content.js
β”‚    β”‚    β”‚    └── world-map.svg
β”‚ index.html

Here's a working example

<script type="module">
  async function initMap() {
    try {
      // Dynamically import map-specific data
      const {map_config, general_config} = await import(`/gmh-plugin/data/world-map/map-content.js`);
      const {GEOMapHub} = await import('/gmh-plugin/assets/js/script/geomaphub.js');

      // import feature plugins to use

      const map = new GEOMapHub("#svg-wrapper-gmh", {
        svgUrl: `/gmh-plugin/data/world-map/world-map.svg`,
        mapConfig: map_config,
        generalConfig: general_config,
      });

      // Register Plugins

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

  initMap();
</script>
πŸ“ Folder Structure for Miller Projection

Ensure your project follows this structure:

your-project/
β”œβ”€β”€ gmh-plugin/
β”‚    β”œβ”€β”€ assets/
β”‚    β”‚    β”œβ”€β”€ css/
β”‚    β”‚    β”‚    └── style.css
β”‚    β”‚    β”œβ”€β”€ js/
β”‚    β”‚    β”‚    └── script/
β”‚    β”‚    β”‚    β”‚    β”œβ”€β”€ geomaphub.js
β”‚    β”‚    β”‚    β”‚    └── lib/
β”‚    β”‚    β”‚    β”‚    β”‚   └── feature-gmh.js // add feature plugin files
β”‚    β”œβ”€β”€ data/
β”‚    β”‚    β”œβ”€β”€ miller-projection-world-map/                          ← Miller Projection Map
β”‚    β”‚    β”‚    β”œβ”€β”€ map-content.js
β”‚    β”‚    β”‚    └── miller-projection-world-map.svg
β”‚ index.html

Here's a working example

<script type="module">
  async function initMap() {
    try {
      // Dynamically import map-specific data
      const {map_config, general_config} = await import(`/gmh-plugin/data/miller-projection-world-map/map-content.js`);
      const {GEOMapHub} = await import('/gmh-plugin/assets/js/script/geomaphub.js');

      // import feature plugins to use

      const map = new GEOMapHub("#svg-wrapper-gmh", {
        svgUrl: `/gmh-plugin/data/miller-projection-world-map/miller-projection-world-map.svg`,
        mapConfig: map_config,
        generalConfig: general_config,
      });

      // Register Plugins

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

  initMap();
</script>
πŸ“ Folder Structure for Mercator Projection

Ensure your project follows this structure:

your-project/
β”œβ”€β”€ gmh-plugin/
β”‚    β”œβ”€β”€ assets/
β”‚    β”‚    β”œβ”€β”€ css/
β”‚    β”‚    β”‚    └── style.css
β”‚    β”‚    β”œβ”€β”€ js/
β”‚    β”‚    β”‚    └── script/
β”‚    β”‚    β”‚    β”‚    β”œβ”€β”€ geomaphub.js
β”‚    β”‚    β”‚    β”‚    └── lib/
β”‚    β”‚    β”‚    β”‚    β”‚   └── feature-gmh.js // add feature plugin files
β”‚    β”œβ”€β”€ data/
β”‚    β”‚    β”œβ”€β”€ mercator-projection-world-map/                          ← Mercator Projection Map
β”‚    β”‚    β”‚    β”œβ”€β”€ map-content.js
β”‚    β”‚    β”‚    └── mercator-projection-world-map.svg
β”‚ index.html

Here's a working example

<script type="module">
  async function initMap() {
    try {
      // Dynamically import map-specific data
      const {map_config, general_config} = await import(`/gmh-plugin/data/mercator-projection-world-map/map-content.js`);
      const {GEOMapHub} = await import('/gmh-plugin/assets/js/script/geomaphub.js');

      // import feature plugins to use

      const map = new GEOMapHub("#svg-wrapper-gmh", {
        svgUrl: `/gmh-plugin/data/mercator-projection-world-map/mercator-projection-world-map.svg`,
        mapConfig: map_config,
        generalConfig: general_config,
      });

      // Register Plugins

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

  initMap();
</script>
⚠️ 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.