map = {
let ctx = DOM.context2d(width, height)
let map_projection = d3.geoMercator()
.scale((1 << 18) / (2* Math.PI))
.translate([width / 2, height / 2])
.center([-118.269, 33.957])
let map_path = d3.geoPath()
.projection(map_projection)
.context(ctx)
let draw_borders = function() {
ctx.beginPath()
ctx.strokeStyle = 'red'
ctx.lineWidth = .5
map_path(mesh_neighborhoods)
ctx.stroke()
ctx.closePath()
}
let county_img = new Image()
county_img.src = 'https://user-images.githubusercontent.com/22920929/52886973-e9a80180-312a-11e9-967a-f8a5363bb914.jpg'
let county_bounds = [[-118.6074416, 34.1450089]
, [-117.5488219, 33.5576005]]
let county = function(){
let WN = map_projection(county_bounds[0])
let ES = map_projection(county_bounds[1])
return {
x: WN[0],
y: WN[1],
w:(ES[0]-WN[0]),
h:(ES[1]-WN[1])
}
}
function draw_everything(){
ctx.drawImage(county_img, county().x,county().y,county().w ,county().h)
draw_borders()
}
county_img.onload = draw_everything()
return ctx.canvas
}