chart = {
const width = 900,
height = 900;
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width-50, height-10]);
var projection = d3
.geoMercator()
.fitSize([width, height], looser);
var path = d3.geoPath().projection(projection);
var path2 = d3.geoPath().projection(projection);
var path3 = d3.geoPath().projection(projection);
var path4 = d3.geoPath().projection(projection);
var path5 = d3.geoPath().projection(projection);
var g = svg.selectAll('g').attr("id", "paths");
var c = svg.selectAll("circle")
var p = svg.selectAll("polyline")
var t = svg.selectAll("text")
var l = svg.selectAll("line")
polyline(seaExtended,'rgb(236,247,254)','100','0.9','rgb(246,244,254)')
staticLines(path5, sea.features,"rgb(236,244,254)",'1','0.2',"rgb(245,246,251)")
staticLines(path5, borough.features,"rgb(230,230,228)",'1','0.2',"rgb(200,200,200)")
staticLines(path5, parks1.features,"rgb(200,215,200)",'1','.1',"rgb(185,200,185)")
staticLines(path5, residential.features,"rgb(250,250,220)",'0.2','1',"rgb(247,247,217)")
staticLines(path5, streetCenterline.features,"none",'1','0.2',"rgb(170,170,170)")
function staticLines(path, data, sfill, sOpac, sW, stroke){
g.enter().append("path")
.data(data) //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", path) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", sfill)
.style('stroke-opacity',sOpac)
.style("stroke-width", sW)
.style("stroke", stroke)
}
//static points from qgis
staticCircles(wifiHotspot.features,'2','rgb(253,236,1)','1',"0")
staticCircles(linkStations.features,'2','rgb(85,65,125)','1',"0")
function staticCircles(data,r,sfill, sOpac, sWidth){
c.enter().append('circle')
.data(data) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('cx',function(d) {return path.centroid(d)[0]})
.attr("cy",function(d) {return path.centroid(d)[1]})
.attr('r', r)
.attr('fill', sfill)
.style('fill-opacity',sOpac)
.style("stroke-width",sWidth)
}
//lines from rhino
polyline(body,'none','1','0.65','rgb(191,63,63)')
polyline(pivot,'none','1','0.55','rgb(155,181,155)')
polyline(camera,'none','1','0.55','rgb(89,166,254)')
polyline(f,'rgb(177,62,66)','1','1','rgb(215,66,72)')
polyline(l1,'rgb(177,62,66)','1','1','rgb(215,66,72)')
polyline(y,'rgb(186,93,81)','1','1','rgb(215,66,72)')
polyline(untitled,'rgb(196,156,155)','1','1','rgb(215,66,72)')
polyline(gCarryingDrone,'none','1','1','rgb(196,156,155)')
polyline(drone,'none','100','0.5','rgb(196,156,155)')
polyline(wifidrone,'none','100','2','rgb(245,236,15)')
polyline(dronelink,'none','100','2','rgb(185,25,25)')
polyline(dronelink1,'none','100','0.9','rgb(185,25,25)')
function polyline(data, sfill, sOpac, sW, stroke){
g.enter().append("polyline")
.data(data) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", function(d){return d}) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", sfill)
.style('stroke-opacity',sOpac)
.style("stroke-width", sW)
.style("stroke", stroke)
}
p.enter().append("polyline")
.data(Newbar) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", martini) //The d attribute defines a path to be drawn, only applies to appended elements
.attr('transform', function(d) {
var coordinates = projection([d.Longitude, d.Latitude]);
return 'translate(' + (coordinates[0] - 10) + ',' + (coordinates[1] + 10) + ')';
})
.style("fill", 'rgb(71,80,216)')
.style("stroke-width", '1')
.style("stroke", 'rgb(85,65,125)')
.on("mouseover", addText)
.on("mouseout", removeText)
p.enter().append("polyline")
.data(wifipoints) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", function(d){return d}) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", 'white')
.style("opacity", '0.5')
.style("stroke-width", '1')
.style("stroke", 'white')
.on("mouseover", addwifistream)
.on("mouseout", removewifistream)
function addwifistream(event, d) {
p.enter().append("polyline")
.data(wifistream) //get data to define path
.enter()
.append('polyline')
.attr('class', 'wifistream')
.attr('points', function(d){return d}) // The d attribute defines a path to be drawn, only applies to appended elements
.style('stroke-width', '0.2')
.style('stroke', 'rgb(186,93,81)')
.style('fill', 'rgb(215,66,72)')
.style('opacity', '0.5')
}
function removewifistream(event, d) {
svg.selectAll('.wifistream').remove(); // Correctly select and remove elements with class 'wifistream'
}
p.enter().append("polyline")
.data(dronepath) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", function(d){return d}) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", 'none')
.style("stroke-width", '1')
.style("stroke-opacity", '0.5')
.style("stroke", 'white')
.style("stroke-dasharray", "5 5")
.on("mouseover", addfire) // add 'mouseover' event listener
.on("mouseout", removefire); // add 'mouseout' event listener
function addfire(event, d) {
p.enter().append("polyline")
.data(fire) //get data to define path
.enter()
.append('polyline')
.attr('class', 'fire')
.attr('points', function(d){return d}) // The d attribute defines a path to be drawn, only applies to appended elements
.style('stroke-width', '1')
.style('stroke', 'rgb(215,66,72)')
.style('stroke-opacity', '1')
.style('fill', 'yellow')
.style('fill-opacity', '0.5')
}
function removefire(event, d) {
svg.selectAll('.fire').remove(); // Correctly select and remove elements with class 'wifistream'
}
p.enter().append("polyline")
.data(bodynew) //get data to define path
.enter() //there are more data than elements, this selects them
.append('polyline')
.attr("points", function(d){return d}) //The d attribute defines a path to be drawn, only applies to appended elements
.style("fill", 'white')
.style("stroke-width", '3')
.style("stroke-opacity", '0.')
.style("stroke", 'rgb(215,66,72)')
.style("stroke-dasharray", "2 3")
.on("mouseover", addextra) // add 'mouseover' event listener
.on("mouseout", removeextra); // add 'mouseout' event listener
function addextra(event, d) {
p.enter().append("polyline")
.data(extra) //get data to define path
.enter()
.append('polyline')
.attr('class', 'extra')
.attr('points', function(d){return d}) // The d attribute defines a path to be drawn, only applies to appended elements
.style('stroke-width', '0.2')
.style('stroke', 'rgb(186,93,81)')
.style('fill', 'rgb(215,66,72)')
.style('opacity', '0.1')
}
function removeextra(event, d) {
svg.selectAll('.extra').remove(); // Correctly select and remove elements with class 'wifistream'
}
//display names from spreadsheet
t.enter().append('text')
.data(symbol) //get data to define path
.enter() //there are more data than elements, this selects them
.append("text") //appends path to data
//.attr('class','spots')
.attr('x',200)
.attr('y',function(d,i) {return 400+(i*15);})
.attr('fill', 'rgb(186,93,81)')
.style('font-family','helvetica')
.style('text-anchor','end')
.style("font-size", "10px")
.text(function(d) {
return d.Name; // assuming 'Name' is a property of your data object
})
.on("mouseover",symboltext)
.on("mouseout",removesymboltext)
function removesymboltext(event,d){
svg.selectall('line.symline').remove()
}
function symboltext(event,d){
//display lines
l.enter().append('line')
.data(symbol) //get data to define path
.enter() //there are more data than elements, this selects them
.append("line") //appends path to data
.attr('class','symline')
.attr('x1',200)
.attr('y1',function(d,i) {return 400+(i*15);})
.attr('x2',function(d) {return projection([d.Long,d.Lat])[0]-5})
.attr("y2",function(d,i) {return 400+(i*15);})
.attr('stroke', 'rgb(71,80,216)')
.attr('stroke-width', '0.2')
.style("stroke-dasharray", "2 3")
//display lines
l.enter().append('line')
.data(symbol) //get data to define path
.enter() //there are more data than elements, this selects them
.append("line") //appends path to data
.attr('class','symline')
.attr('x1',function(d) {return projection([d.Long,d.Lat])[0]-5})
.attr('y1',function(d,i) {return 400+(i*15);})
.attr('x2',function(d) {return projection([d.Long,d.Lat])[0]-5})
.attr("y2",function(d) {return projection([d.Long,d.Lat])[1]+5})
.attr('stroke', 'rgb(71,80,216)')
.attr('stroke-width', '0.2')
.style("stroke-dasharray", "2 3")
//display lines
// l.enter().append('line')
//.data(symbol) //get data to define path
//.enter() //there are more data than elements, this selects them
//.append("line") //appends path to data
//.attr('class','spots')
//.attr('x1',200)
//.attr('y1',function(d,i) {return 400+(i*15);})
//.attr('x2',function(d) {return projection([d.Long,d.Lat])[0]-5})
//.attr("y2",function(d) {return projection([d.Long,d.Lat])[1]+5})
//.attr('stroke', 'rgb(186,93,81)')
//.attr('stroke-width', '1')
}
//points from spreadsheet
c.enter().append('circle')
.data(Newbar) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('class','spots')
.attr('cx',function(d) {return projection([d.Longitude,d.Latitude])[0]-5})
.attr("cy",function(d) {return projection([d.Longitude,d.Latitude])[1]+5})
.attr('r', 1)
.attr('fill', 'yellow')
.style('fill-opacity','1')
.style("stroke-width", "0.5")
.style("stroke", "black")
.on("mouseover", addText)
.on("mouseout", removeText)
c.enter().append('circle')
.data(symbol) //get data to define path
.enter() //there are more data than elements, this selects them
.append("circle") //appends path to data
.attr('class','spots')
.attr('cx',function(d) {return projection([d.Long,d.Lat])[0]-5})
.attr("cy",function(d) {return projection([d.Long,d.Lat])[1]+5})
.attr('r', 1)
.style("stroke-width", "50")
.style("stroke", "rgb(71,80,216)")
.style("stroke-opacity", "0.1")
.on("mouseover", addText)
.on("mouseout", removeText)
function addText(event,d) {
svg//draw text
.append("text") //appends path to data
.attr('class','BText')
.attr('x',projection([d.Longitude,d.Latitude])[0])
.attr("y",projection([d.Longitude,d.Latitude])[1])
.attr('fill', 'rgb(177,62,66)')
.style('font-family','helvetica')
.style("font-size", "15px")
.text(d.Name)
svg//draw text
.append("text") //appends path to data
.attr('class','BText')
.attr('x',50)
.attr("y",375)
.attr('fill', 'rgb(186,93,81)')
.style('font-family','impact')
.style("font-size", "25px")
.text(d.Description)
}
function removeText() {
svg.selectAll('text,BText').remove()
}
return svg.node();
}