<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type="text/xsl" href="atom.xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <id>https://svg-world-maps.vercel.app/de/blog</id>
    <title>SVG World Maps Blog</title>
    <updated>2026-08-28T00:00:00.000Z</updated>
    <generator>https://github.com/jpmonette/feed</generator>
    <link rel="alternate" href="https://svg-world-maps.vercel.app/de/blog"/>
    <subtitle>SVG World Maps Blog</subtitle>
    <icon>https://svg-world-maps.vercel.app/de/img/favicon.ico</icon>
    <entry>
        <title type="html"><![CDATA[From Hours to Seconds: Automating Map Generation for Better DX]]></title>
        <id>https://svg-world-maps.vercel.app/de/blog/automated-map-generator-dx</id>
        <link href="https://svg-world-maps.vercel.app/de/blog/automated-map-generator-dx"/>
        <updated>2026-08-28T00:00:00.000Z</updated>
        <summary type="html"><![CDATA[Adding new maps to our codebase used to be a tedious, manual process that could take up to 30 minutes or even hours for complex regions like Russia or China. Today, we're thrilled to introduce our new Automated Map Generator, a life-changing Developer Experience (DX) upgrade that reduces this workflow to mere seconds.]]></summary>
        <content type="html"><![CDATA[<p>Adding new maps to our codebase used to be a tedious, manual process that could take up to 30 minutes or even hours for complex regions like Russia or China. Today, we're thrilled to introduce our new Automated Map Generator, a life-changing Developer Experience (DX) upgrade that reduces this workflow to mere seconds.</p>
<p>Instead of manually copying, pasting, and formatting hundreds of SVG paths and coordinates, this script intelligently parses a source SVG file and automatically generates a fully populated, production-ready TypeScript map file.</p>
<!-- -->
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="-the-dx-difference">🚀 The DX Difference<a href="https://svg-world-maps.vercel.app/de/blog/automated-map-generator-dx#-the-dx-difference" class="hash-link" aria-label="Direkter Link zur 🚀 The DX Difference" title="Direkter Link zur 🚀 The DX Difference" translate="no">​</a></h2>
<p>We've completely transformed how new maps are added to the codebase. Here is what changed:</p>
<ul>
<li class=""><strong>Before:</strong> Manually extracting paths, formatting arrays, and calculating viewboxes for complex maps took up to hours.</li>
<li class=""><strong>Now:</strong> Drop an SVG, run the script, and get a perfectly formatted <code>.ts</code> file in seconds.</li>
</ul>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="️-how-to-use-the-generator">🗺️ How to Use the Generator<a href="https://svg-world-maps.vercel.app/de/blog/automated-map-generator-dx#%EF%B8%8F-how-to-use-the-generator" class="hash-link" aria-label="Direkter Link zur 🗺️ How to Use the Generator" title="Direkter Link zur 🗺️ How to Use the Generator" translate="no">​</a></h2>
<p>The script automates the extraction of <code>viewBox</code>, states (paths), and labels (coordinates) from a source SVG and injects them into a standardized template.</p>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="step-1-prepare-your-files">Step 1: Prepare Your Files<a href="https://svg-world-maps.vercel.app/de/blog/automated-map-generator-dx#step-1-prepare-your-files" class="hash-link" aria-label="Direkter Link zur Step 1: Prepare Your Files" title="Direkter Link zur Step 1: Prepare Your Files" translate="no">​</a></h3>
<p>Place your source files in the <code>src/maps/optional/</code> directory:</p>
<ul>
<li class=""><strong><code>map.svg</code></strong>: The source SVG file containing your map data.</li>
<li class=""><strong><code>TEMPLATE.ts</code></strong> <em>(Optional)</em>: A base template file. If missing, the script will use a built-in fallback template.</li>
</ul>
<p><strong>Expected SVG Structure:</strong>
For the script to extract data correctly, your SVG should ideally group its elements as follows:</p>
<ul>
<li class=""><strong>Paths/States:</strong> Wrapped in <code>&lt;g id="features"&gt;</code></li>
<li class=""><strong>Labels/Points:</strong> Wrapped in <code>&lt;g id="label_points"&gt;</code></li>
</ul>
<p><em>(Note: The script will gracefully fall back to template defaults if these groups are not found, but extracting them is highly recommended.)</em></p>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="step-2-run-the-generator">Step 2: Run the Generator<a href="https://svg-world-maps.vercel.app/de/blog/automated-map-generator-dx#step-2-run-the-generator" class="hash-link" aria-label="Direkter Link zur Step 2: Run the Generator" title="Direkter Link zur Step 2: Run the Generator" translate="no">​</a></h3>
<p>Execute the script from the root of your project:</p>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#F8F8F2;--prism-background-color:#282A36"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#F8F8F2;background-color:#282A36"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#F8F8F2"><span class="token function" style="color:rgb(80, 250, 123)">node</span><span class="token plain"> scripts/generate-map.js</span><br></div></code></pre></div></div>
<p><em>(Adjust the path if your script is named differently, e.g., <code>map-generator.js</code>)</em></p>
<p>The CLI will interactively prompt you for two pieces of information:</p>
<div class="language-text codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#F8F8F2;--prism-background-color:#282A36"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#F8F8F2;background-color:#282A36"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#F8F8F2"><span class="token plain">🗺️  Map Generator Tool</span><br></div><div class="token-line" style="color:#F8F8F2"><span class="token plain" style="display:inline-block"></span><br></div><div class="token-line" style="color:#F8F8F2"><span class="token plain">Enter SVG map name (e.g., germany): germany</span><br></div><div class="token-line" style="color:#F8F8F2"><span class="token plain">Enter map code (e.g., DE): DE</span><br></div></code></pre></div></div>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="step-3-review-the-output">Step 3: Review the Output<a href="https://svg-world-maps.vercel.app/de/blog/automated-map-generator-dx#step-3-review-the-output" class="hash-link" aria-label="Direkter Link zur Step 3: Review the Output" title="Direkter Link zur Step 3: Review the Output" translate="no">​</a></h3>
<p>The script will read <code>map.svg</code>, extract the necessary data, and generate a new file (e.g., <code>GERMANY.ts</code>).</p>
<p><strong>Example Output:</strong></p>
<div class="language-text codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#F8F8F2;--prism-background-color:#282A36"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="color:#F8F8F2;background-color:#282A36"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#F8F8F2"><span class="token plain">📂 Reading SVG from /src/maps/optional/map.svg...</span><br></div><div class="token-line" style="color:#F8F8F2"><span class="token plain">✅ Extracted viewBox from SVG: "0 0 1000 817"</span><br></div><div class="token-line" style="color:#F8F8F2"><span class="token plain">✅ Extracted 16 states from SVG.</span><br></div><div class="token-line" style="color:#F8F8F2"><span class="token plain">✅ Extracted 16 labels from SVG.</span><br></div><div class="token-line" style="color:#F8F8F2"><span class="token plain" style="display:inline-block"></span><br></div><div class="token-line" style="color:#F8F8F2"><span class="token plain">🎉 Successfully created /src/maps/optional/GERMANY.ts with populated states and labels!</span><br></div></code></pre></div></div>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="️-what-the-script-does-under-the-hood">⚙️ What the Script Does (Under the Hood)<a href="https://svg-world-maps.vercel.app/de/blog/automated-map-generator-dx#%EF%B8%8F-what-the-script-does-under-the-hood" class="hash-link" aria-label="Direkter Link zur ⚙️ What the Script Does (Under the Hood)" title="Direkter Link zur ⚙️ What the Script Does (Under the Hood)" translate="no">​</a></h2>
<p>This tool is built with robust parsing logic to ensure clean, readable, and bug-free output:</p>
<ol>
<li class=""><strong>Dynamic viewBox Extraction:</strong> Automatically reads the <code>viewBox</code> attribute from the root <code>&lt;svg&gt;</code> tag, eliminating manual calculation.</li>
<li class=""><strong>Smart State Extraction:</strong> Scans the <code>&lt;g id="features"&gt;</code> group for <code>&lt;path&gt;</code> elements. It intelligently extracts the <code>d</code> (path), <code>id</code>/<code>data-code</code> (code), and <code>name</code>/<code>title</code> (name), while handling duplicate codes by appending numeric suffixes.</li>
<li class=""><strong>Label Coordinate Extraction:</strong> Scans the <code>&lt;g id="label_points"&gt;</code> group for <code>&lt;circle&gt;</code> elements, extracting <code>cx</code> (x), <code>cy</code> (y), and <code>id</code>/<code>class</code> (code/name).</li>
<li class=""><strong>XML Entity Decoding:</strong> Automatically decodes HTML/XML entities (e.g., <code>&amp;amp;</code>, <code>&amp;#x...;</code>) to ensure names render correctly in tooltips.</li>
<li class=""><strong>Indentation Preservation:</strong> Uses a custom bracket-matching algorithm to replace the states and labels arrays in the template while perfectly preserving your project's indentation style (spaces or tabs).</li>
</ol>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="-post-generation--best-practices">📝 Post-Generation &amp; Best Practices<a href="https://svg-world-maps.vercel.app/de/blog/automated-map-generator-dx#-post-generation--best-practices" class="hash-link" aria-label="Direkter Link zur 📝 Post-Generation &amp; Best Practices" title="Direkter Link zur 📝 Post-Generation &amp; Best Practices" translate="no">​</a></h2>
<p>Once the <code>.ts</code> file is generated, the map data is ready. To make it available in your application:</p>
<ol>
<li class=""><strong>Register the Map:</strong> Import the newly generated file and register it using your library's registration function (e.g., <code>registerMapData('germany', GERMANY)</code>).</li>
<li class=""><strong>Verify Complex Maps:</strong> For highly detailed maps (e.g., Russia, China, USA), quickly spot-check the generated file to ensure no paths were truncated and that the <code>viewBox</code> matches the visual bounds of the SVG.</li>
<li class=""><strong>Clean Up:</strong> You can now remove or replace <code>map.svg</code> for the next map you wish to generate.</li>
</ol>
<h3 class="anchor anchorTargetStickyNavbar_Vzrq" id="-pro-tips-for-contributors">💡 Pro-Tips for Contributors<a href="https://svg-world-maps.vercel.app/de/blog/automated-map-generator-dx#-pro-tips-for-contributors" class="hash-link" aria-label="Direkter Link zur 💡 Pro-Tips for Contributors" title="Direkter Link zur 💡 Pro-Tips for Contributors" translate="no">​</a></h3>
<ul>
<li class=""><strong>Naming Conventions:</strong> Always use lowercase, alphanumeric names with underscores for the map name prompt (e.g., <code>south_africa</code>, <code>great_britain</code>) to maintain consistency and prevent import errors.</li>
<li class=""><strong>Source SVG Quality:</strong> Ensure your source SVG is optimized (e.g., via <a href="https://jakearchibald.github.io/svgomg/" target="_blank" rel="noopener noreferrer" class="">SVGOMG</a>) before running the generator. This keeps the resulting TypeScript file size as small as possible.</li>
<li class=""><strong>Review Before Committing:</strong> Always review the generated <code>.ts</code> file in your Git diff. While the script is highly robust, human verification ensures no edge cases (like malformed paths) slip into production.</li>
</ul>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="️-troubleshooting-common-errors">⚠️ Troubleshooting Common Errors<a href="https://svg-world-maps.vercel.app/de/blog/automated-map-generator-dx#%EF%B8%8F-troubleshooting-common-errors" class="hash-link" aria-label="Direkter Link zur ⚠️ Troubleshooting Common Errors" title="Direkter Link zur ⚠️ Troubleshooting Common Errors" translate="no">​</a></h2>
<p>If things don't go as planned, here are a few common errors and how to fix them:</p>
<ul>
<li class="">❌ <code>"⚠️ No valid states found in &lt;g id='features'&gt;"</code>: Check your SVG structure. Ensure your paths are wrapped in <code>&lt;g id="features"&gt;</code>.</li>
<li class="">❌ <code>"⚠️ Could not find viewBox in SVG. Using default."</code>: Your source SVG is missing a <code>viewBox</code> attribute. Add it manually to the root <code>&lt;svg&gt;</code> tag.</li>
<li class="">❌ <code>"❌ Error: Map name and code are required."</code>: Make sure you provided inputs for both prompts in the CLI.</li>
</ul>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="-scaling-map-additions">🌍 Scaling Map Additions<a href="https://svg-world-maps.vercel.app/de/blog/automated-map-generator-dx#-scaling-map-additions" class="hash-link" aria-label="Direkter Link zur 🌍 Scaling Map Additions" title="Direkter Link zur 🌍 Scaling Map Additions" translate="no">​</a></h2>
<p>This script is the backbone of our scalable map architecture. Because it decouples the visual SVG data from the TypeScript implementation, adding new regions is now a predictable, repeatable, and frictionless process.</p>
<p>Whether you are adding the 31 provinces of Iran, the 50 states of the USA, or a custom imaginary map for a side project, the workflow remains exactly the same: <strong>Drop SVG → Run Script → Register → Done.</strong></p>
<p>Happy mapping! 🗺️✨</p>]]></content>
        <author>
            <name>homayoun</name>
            <uri>https://homayounmmdy.vercel.app/</uri>
        </author>
        <category label="Developer Experience" term="Developer Experience"/>
        <category label="Automation" term="Automation"/>
    </entry>
</feed>