geogrid 0.0.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "geogrid",
3
- "version": "0.0.4",
3
+ "version": "1.0.0",
4
4
  "description": "Regular and irregular geoJSON grids ",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -1,14 +1,37 @@
1
- import { geoProject } from "d3-geo-projection";
2
- const d3 = Object.assign({}, { geoProject });
1
+ import { geoPath } from "d3-geo";
3
2
 
4
3
  /**
5
4
  * @function project
6
- * @description The function `project` use geoproject from d3-geo-projection to project a geoJSON. It returns a GeoJSON FeatureCollection with coordinates in the page map.
7
- * @property {object} data - a GeoJSON FeatureCollection
8
- * @property {function} options.projection - projection definition. See [d3-geo](https://github.com/d3/d3-geo) & [d3-geo-projection](https://github.com/d3/d3-geo-projection)
5
+ * @description Projects a GeoJSON FeatureCollection using a D3 projection.
6
+ * @param {object} data - GeoJSON FeatureCollection
7
+ * @param {object} options
8
+ * @property {function} options.projection - D3 projection function (e.g., d3.geoOrthographic(), d3.geoMercator())
9
+ * @returns {object} - new GeoJSON FeatureCollection with projected coordinates
10
+ *
9
11
  * @example
10
- * let newGeoJSON = project(world, { projection: d3.geoOrthographic()})
12
+ * import { geoOrthographic } from "d3-geo-projection";
13
+ * const projected = geoproject(world, { projection: geoOrthographic() });
11
14
  */
12
15
  export function project(data, { projection = null } = {}) {
13
- return projection == null ? data : d3.geoProject(data, projection);
16
+ if (!projection) return data; // if no projection, return original
17
+
18
+ function projectCoords(coords) {
19
+ if (typeof coords[0] === "number") {
20
+ // [lon, lat] => [x, y]
21
+ return projection(coords);
22
+ } else {
23
+ // Array of coordinates (nested for LineString, Polygon, MultiPolygon)
24
+ return coords.map(projectCoords);
25
+ }
26
+ }
27
+
28
+ const projectedFeatures = data.features.map((feat) => ({
29
+ ...feat,
30
+ geometry: {
31
+ ...feat.geometry,
32
+ coordinates: projectCoords(feat.geometry.coordinates),
33
+ },
34
+ }));
35
+
36
+ return { ...data, features: projectedFeatures };
14
37
  }
package/src/index.js CHANGED
@@ -1,11 +1,11 @@
1
- // export { square } from "./grid/square.js";
2
- // export { triangle } from "./grid/triangle.js";
3
- // export { dot } from "./grid/dot.js";
4
- //export { random } from "./grid/random.js";
5
- // export { diamond } from "./grid/diamond.js";
1
+ export { square } from "./grid/square.js";
2
+ export { triangle } from "./grid/triangle.js";
3
+ export { dot } from "./grid/dot.js";
4
+ export { random } from "./grid/random.js";
5
+ export { diamond } from "./grid/diamond.js";
6
6
  export { hexbin } from "./grid/hexbin.js";
7
- // export { h3 } from "./grid/h3.js";
7
+ export { h3 } from "./grid/h3.js";
8
8
  export { pointstogrid } from "./operator/pointstogrid.js";
9
- // export { polygonstogrid } from "./operator/polygonstogrid.js";
10
- // export { linestogrid } from "./operator/linestogrid.js";
11
- // export { project } from "./helpers/project.js";
9
+ export { polygonstogrid } from "./operator/polygonstogrid.js";
10
+ export { linestogrid } from "./operator/linestogrid.js";
11
+ export { project } from "./helpers/project.js";