title: Datamaps.js access default projection and change it
body: <p>I would like to use Datamaps.js in a similar way as Google Charts in order to select some regions around the world.</p>
  
  <p>Firstly, I would like to access the default "<strong>setProjection</strong>" function, but I do not know how.</p>
  
  <p>Then, I would like to create <strong>projections</strong> in several regions around the world.
  However, I have seen only the Africa example in the <a href="http://datamaps.github.io/" rel="nofollow">Datamaps</a> web</p>
  
  <p>Any help would be appreciated.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>What I am currently testing is this code. It surely could be improved, but it works:</p>
  
  <pre><code>    function getProjection() {
    //Projection por defecto
    var currentProjection;
    var region = $("#mapRegions")[0].value;
  
    if (region === 0) {
      // Zoom in on World
      currentProjection = function(element) {
        var projection = d3.geo.mercator()
          .center([0, 20])
          .rotate([-10, 0])
          .scale(65)
          .translate([element.offsetWidth / 2, element.offsetHeight / 2]);
        var path = d3.geo.path()
          .projection(projection);
  
        return {
          path: path,
          projection: projection
        };
      }
    } else if (region == 1) {
      // Zoom in on Africa
      currentProjection = function(element) {
        var projection = d3.geo.mercator()
          .center([23, 5])
          .rotate([4.4, 0])
          .scale(150)
          .translate([element.offsetWidth / 2, element.offsetHeight / 2]);
        var path = d3.geo.path()
          .projection(projection);
  
        return {
          path: path,
          projection: projection
        };
      }
    } else if (region == 2) {
      // Zoom in on Europa
      currentProjection = function(element) {
        var projection = d3.geo.mercator()
          .center([45, 60])
          .rotate([0, 0])
          .scale(150)
          .translate([element.offsetWidth / 2, element.offsetHeight / 2]);
        var path = d3.geo.path()
          .projection(projection);
  
        return {
          path: path,
          projection: projection
        };
      }
    }
    return currentProjection;
  }
  </code></pre>
  
  <p>The key was to <strong>change the d3.geo projection,</strong> as I am currently working with Mercator.</p>