I was wondering whether there is a D3-API call that translates a d3.geo.bounds() array to a path.bounds pixel array given a width and height of the map?
I was unable to find such a call in the API documentation. I know that there are projections that should to the trick, but I failed in getting to the actual pixel bound from a geo bound.
Also, is there an API implementation of computing the lat/long centroid of a series of features?
I appreciate any help!
Example
Assume the user wants to zoom Germany and Poland to fullscreen. My computed lat-long boundary is:
lat:47.27148371456806 long: 5.850585058505857
(1321.6041604160416,246.58117844670664)
lat:55.06843452896922 long: 24.140414041404142
(1451.6651665166517,157.87336991900156)
Checking with google-maps, the lat-long coordinates are correct. However, the computed pixel values (using the approach from https://stackoverflow.com/a/14457180/974815) seem weird to me. The screen resolution is 2560x1258.
I want to translate the lat-long boundaries to pixel boundaries in order to compute the offset for the mercator projection:
var offset = [
this.width - (bounds[0][0] + bounds[1][0])/2,
this.height - (bounds[0][1] + bounds[1][1])/2
];
return d3.geo.path().projection(
d3.geo.mercator()
.center(this.__computeCentroid(features))
.scale(scale)
.translate(offset)
);
Best, Sebastian