chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg
.append('rect')
.attr('width', width)
.attr('height', height)
.attr('fill', 'black');
svg.on("click", function(event) {
console.log([event.x, event.y], projection.invert([event.x, event.y]));
});
var pattern = svg
.append("defs")
.append("pattern")
.attr('id', "hash4_4")
.attr("width", "4")
.attr('height', "4")
.attr('patternUnits', "userSpaceOnUse")
.attr('patternTransform', "rotate(60)")
.append("rect")
.attr('width', "1")
.attr('height', "4")
.attr('transform', "translate(0,0)")
.attr('opacity', 0.4)
.attr('fill', "red");
var streets = svg
.selectAll('path')
.data(aggDataGeoJSON.features)
.enter()
.append("path")
.attr('id', (d, i) => `path_${i}`)
.attr("fill", d => {
if (d.properties.highway == 'pedestrian') {
return 'url(#hash4_4)';
} else {
return 'none';
}
})
.attr("stroke", "red")
.attr("stroke-linejoin", "round")
.attr('stroke-dasharray', d => {
if (d.properties.highway == 'footway') {
return '8 3';
} else if (d.properties.highway == 'steps') {
return '1';
} else {
return 'none';
}
})
.attr('class', d => d.properties.highway)
.attr('opacity', d => {
if (
d.properties.highway == 'motorway' ||
d.properties.highway == 'trunk'
) {
return 0.95;
} else if (d.properties.highway == 'primary') {
return 0.9;
} else if (d.properties.highway == 'footway') {
return 1;
} else if (d.properties.highway == 'secondary') {
return 1;
} else if (d.properties.highway == 'tertiary') {
return 0.6;
} else if (d.properties.highway == 'residential') {
return 0.6;
} else if (d.properties.highway == 'pedestrian') {
return 1;
} else {
return 1;
}
})
.attr('stroke-width', d => {
if (
d.properties.highway == 'motorway' ||
d.properties.highway == 'trunk'
) {
return 2;
} else if (d.properties.highway == 'footway') {
return 1.5;
} else if (d.properties.highway == 'primary') {
return 2;
} else if (d.properties.highway == 'secondary') {
return 2;
} else if (d.properties.highway == 'tertiary') {
return 1;
} else if (d.properties.highway == 'residential') {
return 1.5;
} else if (d.properties.highway == 'service') {
return 0.3;
} else {
return 1;
}
})
.attr("d", path)
.attr('transform', (d, i) => {
let row = Math.floor(i / cols);
let col = i % cols;
let centroid = path.centroid(d);
return `translate(${col * (width / cols) - centroid[0]},${row * 50 -
centroid[1]})`;
});
streets
.transition()
.duration(1000)
.delay((d, i) => 500 + i * 50)
.attr('transform', 'translate(0,0)');
const location = projection(myBoat);
svg
.append('text')
.attr('x', location[0])
.attr('y', location[1] - 150)
.attr('fill', 'white')
.attr('font-size', 30)
.attr('font-family', 'monospace')
.style('opacity', 0)
.text('Rovinj')
.transition()
.delay(500 + aggDataGeoJSON.features.length * 50)
.duration(2000)
.style('opacity', 1);
return svg.node();
}