Skip to content

Instantly share code, notes, and snippets.

Forked from friedbunny/
Last active Dec 11, 2015
What would you like to do?

Mouseover streets in this D3.js-driven visualization that allows users to visualize the citywide extent of a given street. The City of Philadelphia Streets Department maintains and distributes geospatial data representing and describing the city's street network. The data along with more information is availabe at Open Data Philly. Street location and name data is stored in a CartoDB table. A merge by attribute operation, street name in this case, achieved improvements over the previous file size that approached 3MB.

Download size can be further reduced by using PostGIS functions ST_Simplify or ST_SimplifyPreserveTopology. Without loss of detail, file size is about 600KB at simplication level 0.9.

<!DOCTYPE html>
<meta charset="utf-8">
.streets {
fill: none;
stroke: #aaa;
stroke-width: .5px;
stroke-linecap: round;
.streets:hover {
stroke: #f00;
stroke-width: 3px;
text {
font-family: sans-serif;
font-size: 50px;
<script src=""></script>
<script src=""></script>
var width = 960,
height = 500;
var projection = d3.geo.mercator()
.center([-75.12, 40])
var path = d3.geo.path()
var svg ="body").append("svg")
.attr("width", width)
.attr("height", height);
var text = svg.append("text")
.attr("y", height/10)
.attr("text-anchor", "left")
.text("mouseover streets");
d3.json(" name, ST_SimplifyPreserveTopology(the_geom,0.0007) as the_geom FROM streets", function(error, geojson) {
.attr("class", "streets")
.attr("id", function(d){return;})
.attr("d", path)
.on("mouseover", function(){text.text(;})
.on("mouseout", function(){text.text("");});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment