interactionMap = {
let container = DOM.element('div', { style: `width:${width}px;height:${width/1.6}px` });
yield container;
let map = L.map(container).setView([53.2527, -123.1207], 5).fitBounds(L.geoJson(stations).getBounds());
let osmLayer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.svg({clickable: true}).addTo(map)
const svg = d3.select(map.getPanes().overlayPane)
.select('svg')
.attr("pointer-events", "auto")
const tooltip = svg.append("g").style("display", "none")
const path = tooltip.append("path")
const text = tooltip.append("text")
const Dots = svg.selectAll('circle')
.attr("class", "Dots")
.data(stations2020.features)
.join('circle')
.attr("id", "dotties")
.attr("fill", "yellow")
.attr("cx", d => map.latLngToLayerPoint([d.geometry.coordinates[1],d.geometry.coordinates[0]]).x)
.attr("cy", d => map.latLngToLayerPoint([d.geometry.coordinates[1],d.geometry.coordinates[0]]).y)
.attr("r", 5)
.attr("stroke", "black")
.attr("opacity", 0.8)
.on('mouseover', function(e, d) {
const [xm, ym] = d3.pointer(e)
d3.select(this).transition() //D3 selects the object we have moused over in order to perform operations on it
.duration('150') //how long we are transitioning between the two states (works like keyframes)
.ease(d3.easeBounce)
.attr("fill", "red") //change the fill
.attr('r', 15) //change radius
// tooltip
tooltip
.transition()
.duration(200)
.style("display", null)
tooltip.attr("transform", `translate(${xm - 4},${ym + 3})`);
path.attr("fill", "white").attr("stroke", "black");
const textLabel = d.properties["Station Name"]
text
.text(textLabel)
.attr("font-size", 10)
size(text, path)
})
.on('mouseout', function() { //reverse the action based on when we mouse off the the circle
d3.select(this).transition()
.duration('150')
.ease(d3.easeBounce)
.attr("fill", "yellow")
.attr('r', 5)
tooltip
.style("display", "none")
})
// Wraps the text with a callout path of the correct size, as measured in the page.
function size(text, path) {
const {x, y, width: w, height: h} = text.node().getBBox();
text.attr("transform", `translate(${-w / 2},${15 - y})`);
path.attr("d", `M${-w / 2 - 10}, 5H-5l5, -5l5, 5H${w / 2 + 10}v${h + 20}h-${w + 20}z`);
}
const update = () => Dots
.attr("cx", d => map.latLngToLayerPoint([d.geometry.coordinates[1],d.geometry.coordinates[0]]).x)
.attr("cy", d => map.latLngToLayerPoint([d.geometry.coordinates[1],d.geometry.coordinates[0]]).y)
map.on("zoomend", update)
}