Published
Edited
Jul 24, 2022
Fork of base map
1 star
Insert cell
# Police UAV
Insert cell
d3 = require("d3@7", "d3-geo-scale-bar@1.2", "d3-tile@1")
Insert cell
scaleBar = d3.geoScaleBar()
.top(0.908)
.left(.775)
//.label("Yards")
.units({units: "1000 Yards", radius: 6967419.888})
//.distance(width <= 400 ? 1200 : 1000)
.distance(1000)
Insert cell
chart = {
const width = 960,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [50, 50, width-100, height-100]);

// Use Mercator projection
var projection = d3
.geoMercator()
.fitSize([width - 50, height - 50], boundingbox1);

svg
.append('rect')
.attr('fill',"rgb(34, 38, 72)")
.attr('stroke',"rgb(0,0,0)")
.attr('stroke-width',"3px")
.attr('x',0)
.attr('y',0)
.attr('width',"1000")
.attr('height',"1000")


var path1 = d3.geoPath().projection(projection);
var path2 = d3.geoPath().projection(projection);
var path3 = d3.geoPath().projection(projection);

var g = svg.append("g").attr("id", "paths");
//i'm not using the boundary lines, so I'm going to comment them out
/*
g.selectAll("path1") //d3 geopath
.data(boundary.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path1) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")
*/

g.selectAll("path8") //d3 geopath
.data(grid100m.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path3) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "rgb(255, 255, 255)")
.style("fill-opacity", "0")
.style('stroke-opacity','.4')
.style("stroke-width", '.2')
.style("stroke", "rgb(255,255,255)")

g.selectAll("path9") //d3 geopath
.data(grid1km.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path3) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "rgb(255, 255, 255)")
.style("fill-opacity", "0")
.style('stroke-opacity','.4')
.style("stroke-width", '.5')
.style("stroke", "rgb(255,255,255)")
g.selectAll("path7") //d3 geopath
.data(roadline.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr('stroke-dasharray','4 4')
.attr("d", path3) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "rgb(255, 255, 255)")
.style("fill-opacity", "0")
.style('stroke-opacity','.4')
.style("stroke-width", '1')
.style("stroke", "white")
g.selectAll("path5") //d3 geopath
.data(footprint.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path3) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "rgb(52, 96, 137)")
.style("fill-opacity", "1")
.style('stroke-opacity',"1")
.style("stroke-width", '0.5')
.style("stroke", "rgb(24, 18, 54)")



g.selectAll("path3") //d3 geopath
.data(park1.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path3) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "rgb(170, 125, 163)")
.style("fill-opacity", "1")
.style('stroke-opacity','.4')
.style("stroke-width", '.5')
.style("stroke", "rgb(0,0,0)")
g.selectAll("path4") //d3 geopath
.data(os1.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path3) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "rgb(81, 207, 247)")
.style("fill-opacity", ".5")
.style('stroke-opacity','.4')
.style("stroke-width", '.5')
.style("stroke", "black")

g.selectAll("path2") //d3 geopath
.data(subline1.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path2) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "none")
.style('stroke-opacity','1')
.style("stroke-width", '1.5')
.style("stroke", "rgb(61, 179, 207)")

g.selectAll("path6") //d3 geopath
.data(siteZone.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr('stroke-dasharray','12 10')
.attr("d", path3) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "rgb(200, 200, 200)")
.style("fill-opacity", "0")
.style('stroke-opacity','.8')
.style("stroke-width", '3')
.style("stroke", "rgb(50, 214, 137)")

var t = svg.selectAll("text")
.data(subwaystop.features)
.enter() //there are more data than elements, this selects them
.append("text") //appends path to data
.attr("x", function(d) {return path1.centroid(d)[0]})
.attr("y", function(d) {return path1.centroid(d)[1]-5})
.attr('font-family','helvetica')
.attr('font-size','.6em')
.attr('font-weight','100')
.style("fill", "rgb(180, 180,180)")
.attr('text-anchor','middle')
.text(function(d) {return d.properties.name})

g.selectAll("path10") //d3 geopath
.data(routeline01.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path3) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "rgb(255, 255, 255)")
.style("fill-opacity", "0")
.style('stroke-opacity','1')
.style("stroke-width", '3')
.style("stroke", "rgb(50, 214, 137)")
g.selectAll("path11") //d3 geopath
.data(routeline02.features) //get data to define path
.enter() //there are more data than elements, this selects them
.append("path") //appends path to data
.attr('class','outlines')
.attr("d", path3) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", "rgb(255, 255, 255)")
.style("fill-opacity", "0")
.style('stroke-opacity','.8')
.style("stroke-width", '.5')
.style("stroke", "rgb(247, 217, 103)")
.on('mouseover', potMouse)
.on('mouseout', potMouseout)

function potMouse(event,d){
d3.select(this).style("stroke-width", '2')
d3.select(this).style("stroke", 'white')
}
function potMouseout(event,d){
d3.select(this).style("stroke-width", '1')
d3.select(this).style("stroke", 'white')
}
//


var c = svg.selectAll("circle") //d3 geopath
.data(subwayStop.features)
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr("cx", function(d) {return path1.centroid(d)[0]})
.attr("cy", function(d) {return path1.centroid(d)[1]})
.attr('r',3.5)
.attr('fill', "rgb(188, 223, 223)")
.style('fill-opacity',"1")

var c = svg.selectAll("circle03") //d3 geopath
.data(nypdShootingIncidentDataYearToDate.features)
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr("cx", function(d) {return path1.centroid(d)[0]})
.attr("cy", function(d) {return path1.centroid(d)[1]})
.attr('r',4)
.attr('fill', "rgb(247, 217, 103)")
.style('fill-opacity','1')
.style("stroke-width", '1')
.style("stroke", "rgb(0, 0, 0)")
.on('mouseover', SpotMouse)
.on('mouseout',SpotMouseout) // mouseleave for polygons

function SpotMouse(event,d){
d3.select(this).attr('r',8)
svg
.append('text')
.attr('x',"75")
.attr('y',"100")
.attr('class',"review")
.attr('font-family',"Helvetica")
.attr('font-size',"1em")
.style('dont-weight',"bold")
.style('fill',"rgb(255,255,255)")
.text(d.properties.occur_date)
svg
.append('text')
.attr('x',"75")
.attr('y',"120")
.attr('class',"review")
.attr('font-family',"Helvetica")
.attr('font-size',"1em")
.style('dont-weight',"bold")
.style('fill',"rgb(255,255,255)")
.text(d.properties.occur_time)
svg
.append('text')
.attr('x',"75")
.attr('y',"140")
.attr('class',"review")
.attr('font-family',"Helvetica")
.attr('font-size',".8em")
.style('dont-weight',"bold")
.style('fill',"rgb(255,255,255)")
.text(d.properties.perp_race)
svg
.append('text')
.attr('x',"75")
.attr('y',"160")
.attr('class',"review")
.attr('font-family',"Helvetica")
.attr('font-size',".8em")
.style('dont-weight',"bold")
.style('fill',"rgb(255,255,255)")
.text(d.properties.perp_age_group) //
svg
.append('text')
.attr('x',"150")
.attr('y',"120")
.attr('class',"review")
.attr('font-family',"Helvetica")
.attr('font-size',"1em")
.style('dont-weight',"bold")
.style('fill',"rgb(255,255,255)")
.text(d.properties.loc_of_occur_desc)






}
function SpotMouseout(event,d){
d3.select(this).attr('r',4)


d3.selectAll('text.review').remove()
}
var c = svg.selectAll("circle02") //d3 geopath
.data(policeStop.features)
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr("cx", function(d) {return path1.centroid(d)[0]})
.attr("cy", function(d) {return path1.centroid(d)[1]})
.attr('stroke',"black")
.attr('stroke-width',"1px")
.attr('stroke-opacity',"1")
.attr('r',8)
.attr('fill', "rgb(255, 255, 255)")
.style('fill-opacity','1')
.on('mouseover', UAVMouse)
.on('mouseout', UAVMouseout)

function UAVMouse(event,d){
d3.select(this).attr('fill', "red")
d3.select(this).attr('r',12)
}
function UAVMouseout(event,d){
d3.select(this).attr('fill', "rgb(255, 255, 255)")
d3.select(this).attr('r',8)
}
svg
.append("text")
.attr('class','title')
.attr('x','480')
.attr('y','460')
.attr('font-family','helvetica')
.attr('font-size','1em')
.attr('font-weight','bold')
.style("fill", "rgb(236, 220, 98)")
.style("fill-opacity", "1")
.text('PATROL ZONE')
svg
.append('rect')
.attr('fill',"rgb(61, 179, 207)")
.attr('fill-opacity',".7")
.attr('stroke',"rgb(236, 220, 98)")
.attr('stroke-width',"2px")
.attr('stroke-opacity',".7")
.attr('x',730)
.attr('y',800)
.attr('width',160)
.attr('height',35)
svg
.append("text")
.attr('class','title')
.attr('x','480')
.attr('y','475')
.attr('font-family','helvetica')
.attr('font-size','.6em')
.attr('font-weight','bold')
.style("fill", "rgb(236, 220, 98)")
.style("fill-opacity", "1")
.text('FUTURE POLICE UAV')
scaleBar
.projection(projection)
.size([width, height]);

svg.append("g")
.call(scaleBar);


return svg.node();
}
Insert cell
routeline01 = FileAttachment("routeline01.geojson").json()
Insert cell
routeline02 = FileAttachment("routeline02.geojson").json()
Insert cell
grid100m = FileAttachment("grid100m.geojson").json()
Insert cell
grid1km = FileAttachment("grid1km.geojson").json()
Insert cell
roadline = FileAttachment("roadline.geojson").json()
Insert cell
footprint = FileAttachment("footprint.geojson").json()
Insert cell
boundingbox1 = FileAttachment("boundingbox@1.geojson").json()
Insert cell
subline1 = FileAttachment("subline@1.geojson").json()
Insert cell
subSts = FileAttachment("sub_stops.geojson").json()
Insert cell
bldgs = FileAttachment("bldgs.geojson").json()
Insert cell
bbox = FileAttachment("site_boundary.geojson").json()
Insert cell
subLns = FileAttachment("subway_lines.geojson").json()
Insert cell
boundary = FileAttachment("nyc_boundary.geojson").json()
Insert cell
os = FileAttachment("OS.geojson").json()
Insert cell
park1 = FileAttachment("Park@1.geojson").json()
Insert cell
os1 = FileAttachment("OS@1.geojson").json()
Insert cell
subwayStop = FileAttachment("subway stop.geojson").json()
Insert cell
nypdShootingIncidentDataYearToDate = FileAttachment("NYPD Shooting Incident Data (Year To Date).geojson").json()
Insert cell
policeStop = FileAttachment("police stop.geojson").json()
Insert cell
siteZone = FileAttachment("site zone.geojson").json()
Insert cell
subwaystop = FileAttachment("subwaystop.geojson").json()
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more