@geothai/maps-react 0.0.0-stage → 0.1.1
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/NOTICE +14 -0
- package/README.md +56 -2
- package/dist/index.d.ts +18 -0
- package/dist/index.js +44 -0
- package/package.json +47 -4
package/NOTICE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
GeoThai boundaries
|
|
2
|
+
|
|
3
|
+
The boundary lines come from the OCHA COD-AB dataset for Thailand, on the Humanitarian
|
|
4
|
+
Data Exchange, <https://data.humdata.org/dataset/cod-ab-tha>.
|
|
5
|
+
|
|
6
|
+
- Drawn by: Royal Thai Survey Department (กรมแผนที่ทหาร), acquired by ICRC and made
|
|
7
|
+
available by OCHA Field Information Services Section
|
|
8
|
+
- License: Creative Commons Attribution 3.0 IGO (LICENSE)
|
|
9
|
+
- Changes by GeoThai: renamed the p-codes `TH…` to DOPA codes, linked 3 old-code shapes to
|
|
10
|
+
their current subdistricts, simplified the lines to 5% of the points, and dissolved the
|
|
11
|
+
district and province shapes out of the subdistrict layer
|
|
12
|
+
|
|
13
|
+
The subdistrict, district and province codes and names come from GeoThai/data, licensed
|
|
14
|
+
under CC BY 4.0: <https://github.com/GeoThai/data>
|
package/README.md
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @geothai/maps-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A React component that draws a map of Thailand on DOPA codes. It draws the same model as
|
|
4
|
+
`toSvg()` of [`@geothai/maps`](https://www.npmjs.com/package/@geothai/maps). The markup is the
|
|
5
|
+
same in every framework. It works in server components with no client JavaScript.
|
|
6
|
+
|
|
7
|
+
[👉 Source](https://github.com/GeoThai/maps)
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @geothai/maps-react @geothai/maps
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Use
|
|
16
|
+
|
|
17
|
+
```jsx
|
|
18
|
+
import { choropleth, districtMap } from '@geothai/maps';
|
|
19
|
+
import { GeoThaiMap } from '@geothai/maps-react';
|
|
20
|
+
|
|
21
|
+
// A React Server Component: the shapes load on the server.
|
|
22
|
+
export async function SuratThani({ values }) {
|
|
23
|
+
const map = await districtMap('84');
|
|
24
|
+
const { fills } = choropleth(map, values);
|
|
25
|
+
return <GeoThaiMap map={map} fills={fills} />;
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```jsx
|
|
30
|
+
import { provinces } from '@geothai/maps';
|
|
31
|
+
|
|
32
|
+
<GeoThaiMap
|
|
33
|
+
map={provinces}
|
|
34
|
+
title="Thailand"
|
|
35
|
+
href={(s) => `/provinces/${s.code}/`}
|
|
36
|
+
highlight={['84']}
|
|
37
|
+
/>;
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Props
|
|
41
|
+
|
|
42
|
+
`<GeoThaiMap>` takes `map` and every option of `render()`:
|
|
43
|
+
|
|
44
|
+
| Prop | What it does |
|
|
45
|
+
| ----------- | -------------------------------------------------------------------- |
|
|
46
|
+
| `map` | `provinces`, or the result of `await districtMap('84')` |
|
|
47
|
+
| `fills` | Fill color per area code |
|
|
48
|
+
| `fill` | Default fill |
|
|
49
|
+
| `stroke` | Color of the borders and the outline |
|
|
50
|
+
| `href` | A function that returns the link of an area, or `undefined` for none |
|
|
51
|
+
| `highlight` | Codes to draw on top with a thick stroke |
|
|
52
|
+
| `label` | Text for each area, shown on hover and to screen readers |
|
|
53
|
+
| `title` | Accessible name of the whole map |
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
The code is MIT, the shapes CC BY 3.0 IGO (`MIT AND CC-BY-3.0-IGO`, full credits in `NOTICE`).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MapShapes, RenderOptions } from "@geothai/maps/types";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
/** Props of `<GeoThaiMap>`: the map to draw, and how. */
|
|
4
|
+
export type GeoThaiMapProps = RenderOptions & {
|
|
5
|
+
/** `provinces`, or the result of `await districtMap('84')`, from `@geothai/maps`. */
|
|
6
|
+
map: MapShapes;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A map of Thailand as React elements. It draws the same model as `toSvg()` and
|
|
10
|
+
* `<geothai-map>`, so the markup is the same in every framework.
|
|
11
|
+
*
|
|
12
|
+
* @param props - The map and the options of `render()`.
|
|
13
|
+
* @returns The `<svg>` element.
|
|
14
|
+
* @example
|
|
15
|
+
* import { provinces } from '@geothai/maps';
|
|
16
|
+
* <GeoThaiMap map={provinces} href={(s) => `/provinces/${s.code}/`} />
|
|
17
|
+
*/
|
|
18
|
+
export declare function GeoThaiMap(props: Readonly<GeoThaiMapProps>): ReactElement;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { render } from "@geothai/maps";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
// src/index.tsx
|
|
4
|
+
function Node({ node }) {
|
|
5
|
+
if (node.kind === "line") return /* @__PURE__ */ jsx("path", {
|
|
6
|
+
d: node.d,
|
|
7
|
+
fill: "none",
|
|
8
|
+
stroke: node.stroke,
|
|
9
|
+
strokeWidth: node.width,
|
|
10
|
+
strokeLinejoin: "round",
|
|
11
|
+
vectorEffect: "non-scaling-stroke"
|
|
12
|
+
});
|
|
13
|
+
const path = /* @__PURE__ */ jsx("path", {
|
|
14
|
+
d: node.d,
|
|
15
|
+
fill: node.fill,
|
|
16
|
+
children: /* @__PURE__ */ jsx("title", { children: node.label })
|
|
17
|
+
});
|
|
18
|
+
return node.href ? /* @__PURE__ */ jsx("a", {
|
|
19
|
+
href: node.href,
|
|
20
|
+
children: path
|
|
21
|
+
}) : path;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A map of Thailand as React elements. It draws the same model as `toSvg()` and
|
|
25
|
+
* `<geothai-map>`, so the markup is the same in every framework.
|
|
26
|
+
*
|
|
27
|
+
* @param props - The map and the options of `render()`.
|
|
28
|
+
* @returns The `<svg>` element.
|
|
29
|
+
* @example
|
|
30
|
+
* import { provinces } from '@geothai/maps';
|
|
31
|
+
* <GeoThaiMap map={provinces} href={(s) => `/provinces/${s.code}/`} />
|
|
32
|
+
*/
|
|
33
|
+
function GeoThaiMap(props) {
|
|
34
|
+
const { map, ...options } = props;
|
|
35
|
+
const model = render(map, options);
|
|
36
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
37
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
38
|
+
viewBox: model.viewBox,
|
|
39
|
+
role: "img",
|
|
40
|
+
"aria-label": model.title,
|
|
41
|
+
children: [/* @__PURE__ */ jsx("title", { children: model.title }), model.nodes.map((n) => /* @__PURE__ */ jsx(Node, { node: n }, n.kind === "area" ? n.code : n.key))]
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export { GeoThaiMap };
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geothai/maps-react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "React component for maps of Thailand, on DOPA codes",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"choropleth",
|
|
7
|
+
"map",
|
|
8
|
+
"react",
|
|
9
|
+
"svg",
|
|
10
|
+
"thailand"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://geothai.fasu.dev",
|
|
13
|
+
"license": "MIT AND CC-BY-3.0-IGO",
|
|
14
|
+
"author": "Pongsakorn Thipayanate",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/GeoThai/maps.git",
|
|
18
|
+
"directory": "packages/react"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist",
|
|
22
|
+
"NOTICE"
|
|
23
|
+
],
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./dist/index.js",
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsdown",
|
|
32
|
+
"test": "bun test",
|
|
33
|
+
"typecheck": "tsc"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@geothai/maps": "^0.1.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@repo/typescript": "workspace:*",
|
|
40
|
+
"@types/react": "19.3.0",
|
|
41
|
+
"@types/react-dom": "19.3.0",
|
|
42
|
+
"react": "19.3.1",
|
|
43
|
+
"react-dom": "19.3.1",
|
|
44
|
+
"tsdown": "0.23.1"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": ">=19"
|
|
48
|
+
}
|
|
49
|
+
}
|