map2 = {
const svg = d3
.select(DOM.svg(width, height_cities_map))
.style("width", width)
.attr('class', 'map_cities')
.style("height", height);
const water = svg
.selectAll(".tile")
.data(tiles_all)
.enter()
.append("path")
.style("fill", water_color)
.style("fill-opacity", .35)
.attr("d", d => {
return path_all(d.data.water);
})
.style("stroke-width", 1)
.style("stroke-opacity", .5);
const earth = svg
.selectAll(".tile")
.data(tiles_all)
.enter()
.append("path")
.style("fill", "white")
.style("fill-opacity", 1)
.attr("d", d => {
return path_all(d.data.earth);
});
let cities = svg.append('g');
const tooltip = svg.append("g").style('opacity', 0);
tooltip
.append('rect')
.attr('x', -5)
.attr('y', -15)
.attr('width', 100)
.attr('height', 20)
.style('opacity', 0.7)
.attr('fill', 'white');
tooltip.append('text');
const showTooltip = function(d) {
let dat = d.explicitOriginalTarget.__data__;
let city_name = dat.city.charAt(0).toUpperCase() + dat.city.slice(1);
tooltip.transition().duration(100);
tooltip
.style("opacity", 1)
.attr("transform", `translate (${dat.xmap + 10}, ${dat.ymap + 10})`);
let label = "City: " + city_name;
d3.select(this)
.attr('stroke-opacity', 1)
.attr('stroke', 'blue');
tooltip.select('text').text(label);
tooltip.select('rect').attr('width', label.length * 8);
};
const moveTooltip = function(d) {
let dat = d.explicitOriginalTarget.__data__;
tooltip;
};
const hideTooltip = function(d) {
let dat = d.explicitOriginalTarget.__data__;
tooltip
.transition()
.duration(200)
.style("opacity", 0);
d3.select(this)
.attr('stroke-opacity', 0.5)
.attr('stroke', red_traffic);
};
cities
.selectAll('circle')
.data(db_cities, d => d.detid)
.join('circle')
.attr('cx', d => d.xmap)
.attr('cy', d => d.ymap)
.attr('r', 3)
.attr('fill', 'none')
.attr('stroke', red_traffic)
.attr('stroke-width', 3)
.attr('stroke-opacity', 0.5)
.on("mouseover", showTooltip)
.on("mousemove", moveTooltip)
.on("mouseleave", hideTooltip);
return svg.node();
}