Move/resize Alaska and Hawaii on choropleth map

255 views
Skip to first unread message

tal y

unread,
Jan 30, 2013, 3:08:01 PM1/30/13
to d3...@googlegroups.com
Is there a way to adjust the size and position of just these two states? I would like to increase the scale of my map but my bounding box keeps cutting off Alaska.

Perhaps edit an existing method to modify the projection?

var alaska = d3.geo.albers()
.translate(?,?)

Then integrate it into my path:

var projection = d3.geo.albersUsa()
.scale(width)
.translate([width/2, height/2]);

var path = d3.geo.path()
.projection(projection)
.projection(alaska);


Any help would be appreciated
Thanks!

tal y

unread,
Feb 4, 2013, 4:12:05 PM2/4/13
to d3...@googlegroups.com
Found this code and modified the scale and position:

// A composite projection for the United States, 960x500. The set of standard
// parallels for each region comes from USGS, which is published here:
// TODO allow the composite projection to be rescaled?

d3.geo.myAlbersUsa = function() {
  var lower48 = d3.geo.albers();

  var alaska = d3.geo.albers()
      .origin([-160, 60])
      .parallels([55, 65]);

  var hawaii = d3.geo.albers()
      .origin([-160, 20])
      .parallels([8, 18]);

  var puertoRico = d3.geo.albers()
      .origin([-60, 10])
      .parallels([8, 18]);

  function albersUsa(coordinates) {
    var lon = coordinates[0],
        lat = coordinates[1];
    return (lat > 50 ? alaska
        : lon < -140 ? hawaii
        : lat < 21 ? puertoRico
        : lower48)(coordinates);
  }

  albersUsa.scale = function(x) {
    if (!arguments.length) return lower48.scale();
    lower48.scale(x);
    alaska.scale(x * .4);
    hawaii.scale(x);
    puertoRico.scale(x * 1.25);
    return albersUsa.translate(lower48.translate());
  };

  albersUsa.translate = function(x) {
    if (!arguments.length) return lower48.translate();
    var dz = lower48.scale() / 1000,
        dx = x[0],
        dy = x[1];
    lower48.translate(x);
    alaska.translate([dx - 290 * dz, dy + 180 * dz]);
    hawaii.translate([dx - 175 * dz, dy + 200 * dz]);
    puertoRico.translate([dx + 580 * dz, dy + 430 * dz]);
    return albersUsa;
  };

  return albersUsa.scale(lower48.scale());
};


var projection = d3.geo.myAlbersUsa()
.scale(width+250)
.translate([width/2, height/2]);

var path = d3.geo.path()
.projection(projection);
Reply all
Reply to author
Forward
0 new messages