{
let container = html`<div style='height:1200px;' />`;
let map;
yield container;
map = new mapboxgl.Map({
container,
center: [-122.159846, 37.601883],
zoom: 9.95,
style: "mapbox://styles/mapbox/streets-v9"
});
function project(d) {
return map.project(new mapboxgl.LngLat(d[0], d[1]));
}
function invert(d) {}
function projection(cx, cy) {
var x = parseFloat(cx);
var y = parseFloat(cy);
var test = map.project(new mapboxgl.LngLat(x, y));
return test;
}
var svg = d3
.select(container)
.append("svg")
.attr("width", "100%")
.attr("height", "1200")
.style("position", "absolute")
.style("z-index", 2);
var dots = svg
.append("g")
.selectAll("circle")
.data(location_data)
.enter()
.append("circle")
.attr("r", 1.4)
.style("opacity", 0.85)
.style("fill", "grey");
let dataA = [circleStartPt[0]];
let dataB = [circleStartPt[1]];
var circleA = svg
.append("g")
.selectAll("circle")
.data(dataA)
.join("circle")
.attr("id", "circA")
.attr("r", 120)
.attr("cx", (d) => project(d).x)
.attr("cy", (d) => project(d).y)
.attr("fill", "white")
.attr("stroke", "black")
.attr("opacity", 0.6)
.call(drag);
var circleB = svg
.append("g")
.selectAll("circle")
.data(dataB)
.join("circle")
.attr("id", "circB")
.attr("r", 120)
.attr("cx", (d) => project(d).x)
.attr("cy", (d) => project(d).y)
.attr("fill", "red")
.attr("stroke", "black")
.attr("opacity", 0.35)
.call(drag);
function inCircle(a, b, x, y, r) {
var dist_points = (a - x) * (a - x) + (b - y) * (b - y);
r *= r;
if (dist_points < r) {
return true;
}
return false;
}
function inBothCircles(d) {
var dx = project(d).x;
var dy = project(d).y;
var c1x = circleA.attr("cx");
var c1y = circleA.attr("cy");
var c2x = circleB.attr("cx");
var c2y = circleB.attr("cy");
return inCircle(dx, dy, c1x, c1y, 120) && inCircle(dx, dy, c2x, c2y, 120);
}
function render() {
dots
.attr("cx", function(d) {
return project(d).x;
})
.attr("cy", function(d) {
return project(d).y;
})
.style("fill", function(d) {
return inBothCircles(d) ? "#fa1090" : "grey";
})
.style("opacity", 1)
.raise();
}
render();
setInterval(render, 100);
invalidation.then(() => map.remove());
}