bearWalks = {
await visibility();
if (visibility()) {
mutable x = 0;
}
replay;
const container = html`<div style="height:600px; ">`;
yield container;
const map = (container.value = new mapboxgl.Map({
container,
center: [-114.6659426, 49.3],
zoom: r1,
style: r,
scrollZoom: false,
interactive: false
}));
map.addControl(new mapboxgl.ScaleControl({ position: 'bottom-right' }));
const bb = container.getBoundingClientRect();
const height = 600;
const svg = d3
.select(container)
.append("svg")
.style("position", "absolute")
.style("top", 0)
.style("left", 0)
.attr("width", bb.width)
.attr("height", bb.height)
.style("pointer-events", "none");
let cg = svg.append("g").attr("transform", `translate(${685},${35})`);
cg.append("text")
.classed("calendar-date", true)
.text("")
.attr("dy", "-5")
.attr("font-size", "23px")
.attr("text-anchor", "start")
.attr("text-transform", "uppercase")
.attr("font-family", "monospace")
.attr("font-weight", "bold")
.attr("fill", d => {
return r === "mapbox://styles/mapbox/satellite-v9" ? "white" : "black";
});
//Project any point to map's current state
function projectPoint(lon, lat) {
var point = map.project(new mapboxgl.LngLat(lon, lat));
this.stream.point(point.x, point.y);
}
//Projection function
var transform = d3.geoTransform({ point: projectPoint });
var path = d3.geoPath().projection(transform);
// console.log("h", path);
const g = svg.append("g").attr("id", "map-layers");
let current_circle = undefined;
let circle;
// console.log(dataByDate.features[0][0].geometry.coordinates[0]);
circle = svg
.append("circle")
// .append("image")
// .attr("xlink:href", bear)
.attr("r", 6)
.attr(
"transform",
"translate(" + dataByDate.features[0][0].geometry.coordinates[0] + ")"
)
.style("fill", "#8A643C")
.style("stroke", "#8A643C");
function animatePath(ind) {
g.selectAll("#linesMade" + ind)
.transition()
.ease(d3.easeLinear)
.duration(d => {
return duration;
})
.attrTween("stroke-dasharray", tweenDash);
}
// animate
// invalidation;
dataByDate.features.forEach((e, i) => {
setTimeout(function() {
const bearPath = g
.append("g")
.selectAll("path")
.data(e)
.join("path")
.attr("id", "linesMade" + i)
.attr("class", "lines")
.attr("d", path)
.attr("fill", "none")
.attr("stroke-width", 5)
.attr("stroke", (d, i) => {
return "#1E5D6F";
})
// .attr("stroke-opacity", 0.4)
.attr("stroke-linecap", "round");
animatePath(i);
circle
.transition()
.ease(d3.easeLinear)
.duration((d, i) => {
return duration;
})
.attrTween("transform", translateAlong(bearPath.node()))
.end();
// }
// Returns an attrTween for translating along the specified path element.
function translateAlong(circuitLine) {
var l = circuitLine.getTotalLength();
return function(d, i, a) {
return function(t) {
// console.log(t);
var p = circuitLine.getPointAtLength(t * l);
// console.log(p);
return "translate(" + p.x + "," + p.y + ")";
};
};
}
}, i * duration);
});
}