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/README.md +3 -7
- package/dist/index.min.js +1 -1
- package/package.json +1 -1
- package/src/helpers/project.js +30 -7
- package/src/index.js +9 -9
package/package.json
CHANGED
package/src/helpers/project.js
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const d3 = Object.assign({}, { geoProject });
|
|
1
|
+
import { geoPath } from "d3-geo";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* @function project
|
|
6
|
-
* @description
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
7
|
+
export { h3 } from "./grid/h3.js";
|
|
8
8
|
export { pointstogrid } from "./operator/pointstogrid.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
export { polygonstogrid } from "./operator/polygonstogrid.js";
|
|
10
|
+
export { linestogrid } from "./operator/linestogrid.js";
|
|
11
|
+
export { project } from "./helpers/project.js";
|