mapaVectorial = {
const projection = opcionesVectorial.projection()
projection.scale(opcionesVectorial.scale).center(opcionesVectorial.center)
const pathGenerator = d3.geoPath(projection);
const svg = d3.create("svg").attr("width", opcionesVectorial.width).attr("height", opcionesVectorial.height).style("background", "lightblue");
const g = svg.append("g");
const colorScale = d3.scaleOrdinal(d3.schemePastel1)
g.selectAll("path")
.data(opcionesVectorial.geoJson.features)
.join("path")
.attr("d", pathGenerator)
.attr("fill", d => colorScale(d.properties.NOMBRE_DPT))
.attr("stroke", "steelblue")
.attr("stroke-width", 1)
.on("mouseover", function(event, d) {
d3.select(this)
.attr("fill", "magenta");
tooltip.style("visibility", "visible")
.text(d.properties.NOMBRE_DPT)
.style("top", `${event.pageY + 10}px`)
.style("left", `${event.pageX + 10}px`);
})
.on("mouseout", function() {
d3.select(this).attr("fill", d =>
colorScale(d.properties.NOMBRE_DPT));
tooltip.style("visibility", "hidden");
})
const tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.attr("type", "text")
.style("position", "absolute")
.style("visibility", "hidden")
.style("background", "white")
.style("border", "1px solid blue")
.style("padding", "10px")
.style("border-radius", "10px")
.style("box-shadow", "0 0 5px rgba(0,0,0,0.6)");
//Leyenda etiqueta
const legend = svg.append("g")
.attr("class", "legend")
.attr("transform", `translate(${opcionesVectorial.width - 750}, 20)`);
const legendData = [
{ color: "blue", label: "Viajes de Sara 2024"},
];
legend.selectAll("rect")
.data(legendData)
.enter()
.append("rect")
.attr("x", 0)
.attr("y", (d, i) => i * 20)
.attr("width", 20)
.attr("height", 20)
.attr("fill", d => d.color);
legend.selectAll("text")
.data(legendData)
.enter()
.append("text")
.attr("x", 20)
.attr("y", (d, i) => i * 20 + 9)
.attr("dy", "0.40em") //Mueve el texto hacía arriba o abajo del rect.
.text(d => d.label);
//Dibujar círculos
g.append("g")
.selectAll("circle")
.enter()
.data(datosMapa)
.join("circle")
.attr("transform", d => `translate(${projection([d.lon, d.lat])})`)
.attr("fill", "blue") //(d, i) => colorScale(i)) también podría dejarse de un color cada punto.
.attr("r", 9)
.transition()
.duration(1000)
.attr("r", 12)
.transition()
.duration(1000)
.attr("r", 9);
// Agregar etiquetas
g.append("g")
.selectAll("text")
.data(opcionesVectorial.geoJson)
.join("text")
.attr("transform", d => `translate(${projection([d.lon, d.lat])})`)
.attr("dy", -10)
.attr("text-anchor", "middle")
.text(d => d.DPTO)
.attr("font-size", "7px")
return svg.node();
}