{
replay;
const container = html`<div style="height:600px;">`;
yield container;
const map = (container.value = new mapboxgl.Map({
container,
center: [-114.4659426, 49.07319046],
zoom: 8,
style: "mapbox://styles/jguerrag/cjuerw13z2vja1fndc9wzk7eo",
scrollZoom: false
}));
const bb = container.getBoundingClientRect();
const height = 500;
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},${135})`);
// element.selectAll("*").remove();
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", "black");
// }
// calendar(cg);
let count = 0;
d3.interval(() => {
d3.select(".calendar-date")
.transition()
.text(
bear_data[0].properties.dates[count].toLocaleString(undefined, {
year: "numeric",
month: "short",
day: "numeric"
})
);
count++;
}, (speed * 1000) / bear_data[0].properties.dates.length);
//Project any point to map's current state
function projectPoint(lon, lat) {
// let dateIndex = bear_data[0].geometry.coordinates.findIndex(
// d => d[0] === lon
// );
// console.log(lon, lat);
// if (dateIndex !== -1) {
// mutable name = newBear.properties.dates[dateIndex];
// }
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;
function tweenDash() {
// console.log(this);
var l = this.getTotalLength(),
i = d3.interpolateString("0," + l, l + "," + l);
return function(t) {
// console.log(t);
return i(t);
};
}
const bearPath = g
.append("g")
.selectAll("path")
.data(bear_data)
.join("path")
.attr("class", "lines")
.attr("d", path)
.attr("fill", "none")
.attr("stroke-width", 5)
.attr("stroke", (d, i) => {
// console.log("here", d);
return "steelblue";
// return color(d.properties);
})
.attr("stroke-opacity", 0.5)
.attr("stroke-linecap", "round");
const circle = svg
.append("circle")
.attr("r", 6)
.attr(
"transform",
"translate(" + bear_data[0].geometry.coordinates[0] + ")"
)
.style("fill", "yellow")
.style("stroke", "#444");
// transition();
animatePath();
function transition() {
circle
.transition()
.ease(d3.easeLinear)
.duration(speed * 1000)
.attrTween("transform", translateAlong(bearPath.node()))
.end()
.then(transition);
}
// 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) {
var p = circuitLine.getPointAtLength(t * l);
// console.log(p);
return "translate(" + p.x + "," + p.y + ")";
};
};
}
function animatePath() {
g.selectAll(".lines")
.transition()
.ease(d3.easeLinear)
.duration(speed * 1000)
.attrTween("stroke-dasharray", tweenDash);
}
// return svg.node();
// yield container;
}