initSVGObject = {
function initSVGObject(geojson, extrudeOn, groupOn, colorOn, colorScale, bll, extrudeMultiplier, addToExtrudeHeight, h, w){
var [minE, maxE] = minMax(geojson.features, extrudeOn)
var [minC, maxC] = minMax(geojson.features, colorOn)
var avgE = getAvg(geojson.features.map(a => a.properties[extrudeOn]))
var avgC = getAvg(geojson.features.map(a => a.properties[colorOn]))
console.log(geojson.features, colorOn, minC, maxC, avgC)
var getColor = (e) => {
var rsp = e.properties[groupOn] == bll ? `#000000` : `${ cchromahroma.scale(colorScale)( (e.properties[colorOn]) / (avgC) -.5 ).hex() } `
return rsp
}
var getExtrude = (e) => { return e.properties[extrudeOn] }
var projection = d3.geoMercator().translate([0, 0]).scale(1);
const path = d3.geoPath().projection(projection);
var b = path.bounds( geojson );
var s = .95 / Math.max((b[1][0] - b[0][0]) / w, (b[1][1] - b[0][1]) / h);
var t = [(w - s * (b[1][0] + b[0][0])) / 2, (h - s * (b[1][1] + b[0][1])) / 2];
projection.scale(s).translate(t)
var svg = d3.select(DOM.svg()).attr("width", w).attr("height", h).attr("id", 'line')
.attr("minE", `${minE}`).attr("maxE", `${maxE}`).attr("avgE", `${avgE}`)
.attr("minC", `${minC}`).attr("maxC", `${maxC}`).attr("avgE", `${avgC}`)
.attr("fill", 'white').attr("stroke", 'gray')
svg.selectAll("path").data(geojson.features).enter().append("path").attr("d", path)
.attr("fill", function(e,i){ return getColor(e) } )
.attr('extrudeOn', function(e){ return JSON.stringify(e.properties[extrudeOn]) } )
.attr('extrude', function(e){ return JSON.stringify( getExtrude(e) ) } )
.attr('groupOn', function(e){ return JSON.stringify(e.properties[groupOn]) } )
.attr('colorOn', function(e){ return JSON.stringify(e.properties[colorOn]) } )
.attr('color', function(e){ return JSON.stringify( getColor(e) ) } )
.attr('onmousemove', function(e){
return `tooltip.innerHTML = "${e.properties[groupOn]} : ${Number.parseFloat(e.properties[extrudeOn]).toFixed(2)}"`
} )
return svg.node()
}
// Start by adding a baselayer by using Turf.JS to create a convex hull of our geometry
var hull = turf.convex(fileContents);
hull.properties[extrudeOn] = minMax(fileContents.features, extrudeOn)[0]/1.25
hull.properties[colorOn] = minMax(fileContents.features, colorOn)[0];
hull.properties[groupOn] = "Baltimore City"
if(fileContents.features[0].properties[groupOn] != "Baltimore City" ){ fileContents.features.unshift(hull) }
return initSVGObject(fileContents, extrudeOn, groupOn, colorOn, ['darkblue', 'blue', 'lightblue','lavender', 'pink', 'red', 'darkred'], "Baltimore City", extrudeMultiplier, addToExtrudeHeight, height, width)
}