2

I'm working with Mike Bostock's Choropleth example for US counties.

I have it working fully with my data, but I'm unable to get the projection to scale as I've seen in other examples. I need to zoom in on the center of one state at a time. It can be statically programmed if necessary.

I've tried adding this but it badly distorts the results, so I'm assuming it is not the correct implementation:

var unemployment = d3.map();

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

var path = d3.geoPath(projection);

What is the correct syntax to transform and scale this projection?

Added: Here is a link to a Plukr showing what I'm getting as my incorrect results.

Keith
  • 312
  • 2
  • 12
  • What do you mean by badly distorted? Do you have a screenshot? – Andrew Reid Nov 14 '17 at 22:59
  • You can see paths being drawn on the svg, but it is unrecognizable as a map. So I'm thinking that either geoAlbersUsa is the wrong map, or my syntax for adding the projection data is incorrect. – Keith Nov 14 '17 at 23:26
  • Can you link to the specific block - you may be dealing with data that is already projected - the link looks like it was truncated. – Andrew Reid Nov 14 '17 at 23:26
  • I've added a link to a Plunkr showing what I'm getting, instead of the map. For some reason it takes about 10 seconds to load as well. – Keith Nov 14 '17 at 23:32
  • This is a common issue with that dataset. See this [answer](https://stackoverflow.com/a/42430876/7106086) which deals with the same dataset. To use a projection you need unprojected data, which earlier versions of some chloropleths by Mike used ([here](https://bl.ocks.org/mbostock/8ca036b3505121279daf)) – Andrew Reid Nov 14 '17 at 23:35
  • Link also fixed in the original question, not sure how that got cut off. – Keith Nov 14 '17 at 23:35
  • Also, translate values should be [width/2,height/2] to center the coordinate at the center of the projection at the center of the svg. – Andrew Reid Nov 14 '17 at 23:37
  • Yes, I had the width/2, height/2 originally, just tried it as zero and forgot to change back in the example. I'm reading through the links you added now as well, though it seems like a slightly different situation he's describing. – Keith Nov 14 '17 at 23:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/159012/discussion-between-andrew-reid-and-keith). – Andrew Reid Nov 14 '17 at 23:40

0 Answers0