DSContEd / IntroWebDevelopment

At the end of the course, students will be able to plan, design, and implement a web site using current standards and best practices.
1 stars 1 forks source link

Where in the code do we handle "projection"? #14

Open TonyGoodDay2 opened 7 years ago

cmitchell74 commented 7 years ago

var projection = d3.geoMercator().scale(pScale).center(pCenter) .translate(pOffset);

var geoPath = d3.geoPath().projection(projection);

// new projection projection = d3.geoMercator().scale(pScale).center(pCenter).translate(pOffset);

jjsahn commented 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]);
TonyGoodDay2 commented 7 years ago

What is geoPath() in d3?

jjsahn commented 7 years ago

Take JSON data and creates an SVG path

cmitchell74 commented 7 years ago

d3.geo.path() is the D3 Geo Path Data Generator helper class for generating SVG Path instructions from GeoJSON data

TonyGoodDay2 commented 7 years ago

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

TonyGoodDay2 commented 7 years ago

Simply: Lat long to x/y