// // the container div
// let map = new mapboxgl.Map({
// container,
// //center: [lng, lat],
// zoom: 2,
// style: "mapbox://styles/franckalbinet/ckyaawysn1qlg15ny2auxlk8k",
// projection: {
// name: projMapbox
// // center: [0, 0],
// // parallels: [parMin, parMax]
// }
// });
// map.addControl(new mapboxgl.NavigationControl(), "top-right");
// map.on("load", () => {
// hexagons = getHexbin(
// selectedGeoJSON,
// toPolygon(map.getBounds()),
// resolution
// );
// map.addSource("hexbins", {
// type: "geojson",
// data: hexagons
// });
// // Add a new layer to visualize the polygon.
// map.addLayer({
// id: "hexbins",
// type: "fill",
// source: "hexbins", // reference the data source
// layout: {},
// paint: {
// "fill-color": ["interpolate", ["linear"], ["get", "max"], ...colors],
// "fill-opacity": 0.8
// //"fill-stroke-width": 1,
// //"stroke-color": "red"
// }
// });
// // map.addLayer({
// // id: "outline",
// // type: "line",
// // source: "hexbins",
// // layout: {},
// // paint: {
// // "line-color": "#fff",
// // "line-width": 1,
// // "line-opacity": 0.2
// // }
// // });
// });
// map.on("zoomend", () => {
// hexagons = getHexbin(
// selectedGeoJSON,
// toPolygon(map.getBounds()),
// resolution
// );
// map.getSource("hexbins").setData(hexagons);
// });
// map.on("moveend", () => {
// hexagons = getHexbin(
// selectedGeoJSON,
// toPolygon(map.getBounds()),
// resolution
// );
// map.getSource("hexbins").setData(hexagons);
// });
// function getHexbin(points, clipArea, resolution = 200) {
// let options = { units: "kilometers" };
// // 1. Clips
// const clipped = turf.pointsWithinPolygon(points, clipArea);
// const cellSide = Math.sqrt(turf.area(clipArea)) / (1000 * resolution);
// // 2. Creates grid
// const grid = turf.hexGrid(turf.bbox(clipArea), cellSide, options);
// // 3. Collects points in poly
// const collected = turf.collect(grid, clipped, "value", "values");
// // 4. Filter out "empty" hexagons
// collected.features = collected.features.filter(
// (d) => d.properties.values.length
// );
// // 5. Computes summary stats
// turf.propEach(collected, (props) => {
// props.max = d3.max(props.values);
// props.length = props.values.length;
// });
// return collected;
// }
// function fixAntimeridian(bounds) {
// // let cap = 150;
// // bounds._ne.lng = Math.min(cap, bounds._ne.lng);
// // bounds._sw.lng = Math.max(-cap, bounds._sw.lng);
// return bounds;
// }
// function toPolygon(bounds) {
// return turf.bboxPolygon(fixAntimeridian(bounds).toArray().flat());
// }
// map.addControl(new mapboxgl.FullscreenControl());
// // Be careful to clean up the map's resources using \`map.remove()\` whenever
// // this cell is re-evaluated.
// invalidation.then(() => map.remove());
// }