Here is a simple yet inspiring topojson of a single state:
https://bl.ocks.org/mbostock/7061976
It is drawn by data from a json containing only that state as follows:
d3.json("va-counties.json", function(error, topo) {
if (error) throw error;
What I want to do is dynamically project a county. Suppose there is a keyboard event or something that runs a function doing this: read into the parsed data, find the county id, and return a topojson feature of only that county. The difference between the above block and my case is that my json file would have all the counties in America, but I would only need 1 county at a time. Is there a way to achieve this in D3?
Just as a simple litmus test, for county id=1000, I tried:
var current_county = topojson.feature(topo, topo.objects.counties).filter(function(d) { return d.id=1000;})),
bounds = path.bounds(county);
Yet I kept getting persistent errors, no matter how much I toiled with it. Or it would stop throwing errors, but yet still not 'work'. Maybe .filter()
is not the best tool for the job? What are other opinions?
Thank you for reading