map = {
const newData = overlapData;
const chartWidth = width;
const chartHeight = 800;
const backgroundColor = "#ADD8E6";
const landColor = "#09A573";
const landStroke = "#FCF5E9";
const markerColor = "#5A5A5A";
const projection = d3.geoMercator()
.scale([17000])
.center(markers[0].geometry.coordinates)
.translate([chartWidth / 2, chartHeight / 2]);
const pathGenerator = d3.geoPath(projection);
const svg = d3.create('svg')
.attr("id","map")
.attr("title", "Map")
.attr('width', chartWidth)
.attr('height', chartHeight)
.attr("stroke-width", 0);
svg.append("rect")
.attr("width", chartWidth)
.attr("height", chartHeight)
.attr('fill', backgroundColor);
svg.selectAll('path')
.attr("class","unique")
.data(bayArea.features)
.join('path')
.attr('d', pathGenerator)
.attr('fill', landColor)
.attr('stroke', landStroke)
.attr('stroke-width', 0.5);
const circles = d3.range(2).map(i => ({
x: 100,
y: [100,300],
r: [size1,size2]
}));
svg.selectAll("circle")
.data(circlesData)
.attr("id","circle1")
.join("circle")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("r", (d,i) => d.r[i])
.attr('fill-opacity', 0.25)
.attr('stroke', "black")
.attr('stroke-width', .1)
.attr("fill", "#E26F99")
.call(d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended));
svg.selectAll("circle").enter()
.attr("id", "restaurantMarker")
.data(overlapData)
.join("circle")
.attr("cx", d => projection(d.coordinates)[0])
.attr("cy", d => projection(d.coordinates)[1])
.attr("r", 4)
.attr("fill-opacity", 0.6)
.attr("fill", d => d.selected == 0 ? "#cccccc":"#E26F99")
.attr("stroke", markerColor)
.attr('stroke-width', 1)
.on("mouseover", function (event, d) {
svg.select("#tooltip-text")
.append("text").text(d.name + " (" + d.price + ")");
let positionOffest = 8;
svg.select("#tooltip")
.attr("transform", `translate(${projection(d.coordinates)[0] + positionOffest}, ${projection(d.coordinates)[1] + positionOffest})`)
.style("display", "block");
d3.select(this)
.attr("stroke", "#333333")
.attr("stroke-width", 2);
const path = tooltip.append("path")
.attr("fill", "white")
.attr("stroke", "black");
})
.on("mouseout", function (event, d) {
svg.select("#tooltip").style("display", "none"); // hide tooltip
svg.select("#tooltip-text").text(" ");
d3.select(this).attr("stroke", "none"); // undo the stroke
});
var path = d3.path();
svg.append("path")
.attr("fill", "none")
.attr("stroke", "#FFF")
.attr("d",path)
const tooltip = svg.append("g") // the tooltip needs to be added last so that it stays on top of all circles
.attr("id", "tooltip")
.style("display", "none") // hidden by default
.append("g")
.attr("id", "tooltip-text")
.attr("x", 5)
.attr("y", 15)
.attr("font-size", "14px")
.attr("font-weight", "bold")
.attr("fill", "black")
tooltip.append("text")
.attr("id", "tooltip-text1")
.attr("x", 5)
.attr("y", 30)
.attr("font-size", "14px")
.attr("font-weight", "bold")
.attr("fill", "black")
function dragstarted(event, d) {
d3.select(this).raise().attr("stroke", "black");
}
function dragged(event, d) {
d3.select(this).attr("cx", d.x = event.x).attr("cy", d.y = event.y);
var id = d.id
circlesData[id].x = d.x
circlesData[id].y = d.y
overlapData.forEach(function(d,i) {
var a = projection1(d.coordinates)
var x = a[0]
var y = a[1]
if (overlaps(x,y)){
overlapData[i].selected = 1
d.selected = 1
console.log("overlaps")
} else {
overlapData[i].selected = 0
d.selected = 0
}
})
overlapData.filter(function(d,i) {
var a = projection1(d.coordinates)
var x = a[0]
var y = a[1]
if (overlaps(x,y)){
overlapData[i].selected = 1
d.selected = 1
return d
} else {
overlapData[i].selected = 0
d.selected = 0
return null
}
})
const svg = d3.select("#map")
const marker = svg.select("#restaurantMarker")
d3.selectAll("circle").attr("fill", d => d.selected === 0 ? "#cccccc":"#E26F99").filter(d=>d.selected === 1)
}
function dragended(event, d) {
d3.select(this).attr("stroke", "black");
}
return svg.node()
}