mkGeoJson = (map) => {
const timeStart = new Date();
const { sqrt3 } = mathConst;
const { xNum, padding } = map;
console.log("Use", { xNum });
var cx = map.getCenter().lng,
cy = map.getCenter().lat,
e = map.getBounds()._ne.lng,
n = map.getBounds()._ne.lat,
w = map.getBounds()._sw.lng,
s = map.getBounds()._sw.lat;
s = 2 * cy - n;
var yNum = parseInt(xNum * aspect);
var xScale = d3.scaleLinear().range([cx, e]).domain([0, xNum]),
yScale = d3
.scaleLinear()
.range([cy, n])
.domain([0, xNum * aspect]);
var rx = xScale(1) - xScale(0),
ry = yScale(1) - yScale(0),
rxFull = rx,
ryFull = ry,
c = sqrt3 / 2;
rx *= 1 - padding;
ry *= 1 - padding;
var coordinates,
type,
properties,
x,
y,
insideStations,
stations,
hull,
uniqueID = 0;
const features = [];
const stationSummary = [];
for (let i = -xNum; i < xNum + 3; i += 3) {
for (let j = -yNum / c; j < yNum / c + 1; j += 1) {
x = xScale(i + 1.5 * (j % 2));
y = yScale(c * j);
coordinates = [hexFunc(rx, ry, x, y)];
hull = hexFunc(rxFull, ryFull, x, y);
insideStations = subwayGeoJson.features.filter((e) =>
d3.polygonContains(hull, e.properties.corrected)
);
stations = insideStations.length;
properties = {
pos: [x, y],
color: colormap(stations),
opacity: stations == 0 ? 0.0 : 0.7,
stations,
insideStations
};
if (stations > 0) {
stationSummary.push(stations);
}
features.push({
type: "Feature",
properties,
id: uniqueID,
geometry: { coordinates, type: "Polygon" }
});
uniqueID += 1;
}
}
charts.histChart = Histogram(stationSummary, {
value: (d) => d,
label: "Amount (%) →",
width,
xDomain: [1, 6],
yDomain: [0, 200],
height: width / 4,
yType: d3.scaleSqrt,
color: "steelblue"
});
document.getElementById("chart-1").innerHTML = charts.histChart.outerHTML;
realTimeSummary.mkGeoJson = new Date() - timeStart;
return { type: "FeatureCollection", features: features };
}