Open TonyGoodDay2 opened 7 years ago
// new projection projection = d3.geoMercator().scale(pScale).center(pCenter).translate(pOffset);
var chartMap = svg.append("g"); //help with zoom
svg.selectAll("path")
.attr("class", quantifyChropleth);
var legendRectSize = 25;
var legendSpacing = 5;
var legend = d3.select('svg')
.append("g")
.selectAll("g")
.data(color.domain())
.enter()
.append('g')
.attr('class', 'legend')
.attr('transform', function(d, i) {
var height = legendRectSize;
var yaxisPosition = 4;
var xaxisPosition = getWindowWidth() - 200; // 0;
var y = (i + yaxisPosition) * height;
return 'translate(' + xaxisPosition + ',' + y + ')';
});
legend.append('rect')
.attr('width', legendRectSize)
.attr('height', legendRectSize)
.style('fill', color)
.style('stroke', '#808080');
legend.append('text')
.style("font-size", "12px")
.attr('x', legendRectSize + legendSpacing)
.attr('y', legendRectSize - legendSpacing)
.text(function(d) {
return d;
});
var legendTitle = d3.select("svg").append("text")
.attr("x", getWindowWidth() - 200)
.attr("y", 85)
//.attr("text-anchor", "middle")
.style("font-size", "12px")
//.style("text-decoration", "underline")
.text(indicatorFriendlyLegendHash[primaryEntity]);
What is geoPath() in d3?
Take JSON data and creates an SVG path
d3.geo.path() is the D3 Geo Path Data Generator helper class for generating SVG Path instructions from GeoJSON data
D3 includes a set of Path Data Generator helper classes for generating SVG Path instructions GeoJSON is a geospatial data interchange format based on the JavaScript Object Notation d3.geo.path() is the D3 Geo Path Data Generator helper class for generating SVG Path instructions from GeoJSON data If you pass a GeoJSON Geometry or GeoJSON Feature Object, d3.geo.path() will generate the SVG Path Mini-Language instructions for you You can then pass this SVG Path instructions to the "d" attribute of the SVG path in order to have the SVG Path display on the screen The D3 Geo Path Data Generator, d3.geo.path(), converts the Spherical Coordinates (longitude and latitude) to Cartesian Coordinates (x and y in pixels) The d3.geo.path() path generator functions allows you to select which Map Projection you want to use for the translation from Geo Coordinates to Cartesian Coordinates
Simply: Lat long to x/y
var projection = d3.geoMercator().scale(pScale).center(pCenter) .translate(pOffset);
// new projection projection = d3.geoMercator().scale(pScale).center(pCenter).translate(pOffset);