Skip to content

Commit a8fe85e

Browse files
Udpated Version
2 parents 6efed09 + 6b8835c commit a8fe85e

File tree

1 file changed

+102
-12
lines changed

1 file changed

+102
-12
lines changed

README.md

Lines changed: 102 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,96 @@
1-
# React + TypeScript + Vite
1+
# React Mapbox Field Renderer
22

3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3+
A modern React component library built with TypeScript and Vite.
44

5-
Currently, two official plugins are available:
5+
## Features
66

7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
7+
- Built with Mapbox, React 20+ and TypeScript
8+
- Powered by Vite for lightning-fast development
9+
- Hot Module Replacement (HMR) for seamless development experience
10+
- ESLint configuration with TypeScript support
11+
- Minimal setup with maximum flexibility
12+
13+
## Installation
14+
15+
```bash
16+
npm i @syngenta/mapbox-field-renderer
17+
```
18+
19+
## Usage
20+
21+
```tsx
22+
import React, { useEffect, useRef, useState } from "react";
23+
import mapboxgl from "mapbox-gl";
24+
import {
25+
initializeMap,
26+
addTrialPlotsToMap,
27+
zoomToSourceId,
28+
updateMapWithSelectedProperty,
29+
addBufferZoneToMap,
30+
addMarkerAtPoint,
31+
addGeoJsonSource,
32+
addLineLayer,
33+
zoomToGeoJson,
34+
parallelLinesLayerfromPoint,
35+
} from "@syngenta/mapbox-field-renderer";
36+
37+
38+
39+
function App() {
40+
const mapContainer = useRef<HTMLDivElement | null>(null);
41+
const map = useRef<mapboxgl.Map | null>(null);
42+
const tooltipRef = useRef<HTMLDivElement>(null);
43+
44+
useEffect(() => {
45+
if (map.current) return; // Initialize map only once
46+
const center = getMapCenter(field);
47+
if (mapContainer.current && field.geometry) {
48+
initializeMap(map, mapContainer, center, field.geometry, {
49+
token: process.env.NEXT_PUBLIC_MAPBOX_TOKEN!,
50+
preserveDrawingBuffer: mode === "pdf",
51+
zoom: 13,
52+
navigationControl: {
53+
showZoom: false,
54+
},
55+
});
56+
}
57+
}, [field, selectedField, data, mode]);
58+
59+
60+
return (
61+
<div>
62+
<div
63+
ref={mapContainer}
64+
className="w-full h-[60vh] md:h-[80vh] rounded-md "
65+
/>
66+
</div>
67+
);
68+
}
69+
```
70+
71+
## Development
972

10-
## Expanding the ESLint configuration
73+
### Prerequisites
1174

12-
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
75+
- Node.js 18+
76+
- npm or yarn
77+
78+
## Build
79+
80+
```bash
81+
npm run build
82+
```
83+
84+
## Technology Stack
85+
86+
- **React**: UI library
87+
- **TypeScript**: Type safety
88+
- **Vite**: Build tool and development server
89+
- **ESLint**: Code quality and consistency
90+
91+
## ESLint Configuration
92+
93+
This project includes a robust ESLint setup. For production applications, we recommend enabling type-aware lint rules:
1394

1495
```js
1596
export default tseslint.config({
@@ -22,7 +103,6 @@ export default tseslint.config({
22103
...tseslint.configs.stylisticTypeChecked,
23104
],
24105
languageOptions: {
25-
// other options...
26106
parserOptions: {
27107
project: ['./tsconfig.node.json', './tsconfig.app.json'],
28108
tsconfigRootDir: import.meta.dirname,
@@ -31,7 +111,7 @@ export default tseslint.config({
31111
})
32112
```
33113

34-
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
114+
For React-specific lint rules, you can install and configure these plugins:
35115

36116
```js
37117
// eslint.config.js
@@ -40,15 +120,25 @@ import reactDom from 'eslint-plugin-react-dom'
40120

41121
export default tseslint.config({
42122
plugins: {
43-
// Add the react-x and react-dom plugins
44123
'react-x': reactX,
45124
'react-dom': reactDom,
46125
},
47126
rules: {
48-
// other rules...
49-
// Enable its recommended typescript rules
50127
...reactX.configs['recommended-typescript'].rules,
51128
...reactDom.configs.recommended.rules,
52129
},
53130
})
54131
```
132+
133+
## Available Vite Plugins
134+
135+
Two official plugins are available:
136+
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
137+
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
138+
139+
## License
140+
Check LICENSE File(MIT License)
141+
142+
## Contributing
143+
144+
Contributions are welcome! Please feel free to submit a Pull Request.

0 commit comments

Comments
 (0)