-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { | ||
getRes0Cells, | ||
cellToChildren, | ||
isPentagon, | ||
cellToBoundary, | ||
} from "h3-js"; | ||
|
||
/** | ||
* @function grid/h3 | ||
* @description The `grid.h3` function allows to create a hexbin geoJSON grid in geographical coordinates. | ||
* @see {@link https://observablehq.com/@neocartocnrs/regular-grids} | ||
* @property {number} [level = 0] - level of the grid. Form 0 (large hexagons) to 4 (small hexagons). See: https://h3geo.org | ||
* @example | ||
* geoviz.grid.h3(1) | ||
*/ | ||
export function h3(level = 0) { | ||
return { | ||
type: "FeatureCollection", | ||
features: getRes0Cells() | ||
.map((i) => cellToChildren(i, level)) | ||
.flat() | ||
.map((d) => ({ | ||
type: "Feature", | ||
properties: { id: d, pentagon: isPentagon(d) }, | ||
geometry: { | ||
type: "Polygon", | ||
coordinates: [cellToBoundary(d, true).reverse()], | ||
}, | ||
})), | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,52 @@ | ||
import { square } from "./square.js"; | ||
import { dot } from "./dot.js"; | ||
import { dotgeo } from "./dotgeo.js"; | ||
import { squaregeo } from "./squaregeo.js"; | ||
import { diamond } from "./diamond.js"; | ||
import { arbitrary } from "./arbitrary.js"; | ||
import { hexbin } from "./hexbin.js"; | ||
import { triangle } from "./triangle.js"; | ||
import { h3 } from "./h3.js"; | ||
|
||
export function make(svg, { step, type = "square" } = {}) { | ||
/** | ||
* @function grid/make | ||
* @description The `grid.make` function allows to create a regular grid geoJSON. For all types, For all grid types (except "h3"), the function returns a geojson with svg coordinates in the layout of the page. For type "h3", the function returns geographic coordinates in latitude and longitude. | ||
* @see {@link https://observablehq.com/@neocartocnrs/regular-grids} | ||
* | ||
* @property {string} [type = "square"] - Type of grid ("square", "dot", "diamond", "hexbin" (or "hex"), "trangle", "arbitrary" (or "randmon"), "h3" (or "h3geo", "hexgeo", "hexbingeo")) | ||
* @property {number} [step = 50] - step of grids (except for "h3" type) | ||
* @property {number} [level = 0] - level oh geographical hexbin grids ("h3" type only). Form 0 (large hexagons) to 4 (small hexagons). See: https://h3geo.org | ||
* @example | ||
* // There are several ways to use this function | ||
* geoviz.grid.make(svg, { type:"diamond", step:100 }) // where svg is the container | ||
* svg.grid.make({ type:"diamond", step:100 }) // where svg is the container | ||
*/ | ||
|
||
export function make(svg, { step = 50, type = "square", level = 0 } = {}) { | ||
switch (type) { | ||
case "square": | ||
return square(step, svg.width, svg.height); | ||
break; | ||
case "arbitrary": | ||
case "random": | ||
return arbitrary(step, svg.width, svg.height); | ||
break; | ||
case "dot": | ||
return dot(step, svg.width, svg.height); | ||
break; | ||
case "dotgeo": | ||
return dotgeo(step, svg.domain, svg.projection); | ||
case "diamond": | ||
return diamond(step, svg.width, svg.height); | ||
break; | ||
case "hexbin": | ||
case "hex": | ||
return hexbin(step, svg.width, svg.height); | ||
break; | ||
case "triangle": | ||
return triangle(step, svg.width, svg.height); | ||
break; | ||
case "squaregeo": | ||
return squaregeo(step, svg.domain, svg.projection); | ||
case "h3": | ||
case "h3geo": | ||
case "hexgeo": | ||
case "hexbingeo": | ||
return h3(level); | ||
break; | ||
} | ||
} |