Published
Edited
Apr 3, 2019
1 star
Insert cell
Insert cell
Insert cell
{
const svg = d3
.select(DOM.svg(width, height))
.style("width", width)
.style("height", "auto");

const g = svg.append("g");
const g2 = svg.append("g");

svg.append("defs").append("pattern")
.attr('id','bgimage')
.attr("width", "100%")
.attr("height", "100%")
.attr("x", "0")
.attr("y", "0")
.attr("viewBox", "0 0 5400 3800")
.append('image')
.attr('width',5400)
.attr('height',3800)
.attr('xlink:href','https://s3.amazonaws.com/files.zevross.org/temp-geo/terrain_img.png')
// points
let aa = [-122.490402, 37.786453];
let bb = [-122.389809, 37.72728];
// add circles to svg
let circles = svg.selectAll("circle")
.data([aa,bb]).enter()
.append("circle")
.attr("cx", function (d) { return projection(d)[0]; })
.attr("cy", function (d) { return projection(d)[1]; })
.attr("r", "8px")
.attr("fill", "red")
var zoom = d3
.zoom()
.scaleExtent([.3, 16])
.on("zoom", zoomed);

function zoomed() {
g.attr("transform", d3.event.transform);
circles.attr("transform", d3.event.transform);
g2.attr("transform", d3.event.transform);
}

svg.call(zoom);

g.append("path")
.datum(land)
.attr("d", path)
.attr("class", "land")
.style("fill", land_color);

let g2Path = g2.append("path")
.datum(box.geometry)
.attr("d", path)
.attr("class", "")
.attr('fill','url(#bgimage)')
.style("opacity","0.6")
.style("border","solid 1px black")
return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more