Skip to content

Commit c199325

Browse files
committed
add dynamic-markers-react tutorial directory
1 parent 57f197c commit c199325

File tree

12 files changed

+3157
-0
lines changed

12 files changed

+3157
-0
lines changed

dynamic-markers-react/.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

dynamic-markers-react/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# dynamic-markers-react
2+
3+
This is supporting code for the Mapbox turorial [Add Dynamic Markers and Popups to a Map in a React app](https://docs.mapbox.com/help/tutorials/dynamic-markers-react/).
4+
5+
## Overview
6+
7+
This Mapbox tutorial walks through how to integrate [Mapbox GL JS](https://docs.mapbox.com/mapbox-gl-js/) with custom React components to create a dynamic map with custom markers and popups using external data sources.
8+
9+
You'll learn how to:
10+
- Build a React component to display a Mapbox GL JS map.
11+
- Query [geoJSON data](https://docs.mapbox.com/glossary/geojson) from an external API using the map's current bounds.
12+
- Add markers to the map using a composable React component.
13+
- Use React state to add an active state to a marker on click.
14+
- Show a popup for the active marker using a composable React component.
15+
16+
The combination of markers, popups, and bounds-based data is commonly used in real estate and store locator apps where users are exploring point features on an interactive map.
17+
18+
The finished product shows earthquake data from the USGS API on a map, with magnitude data shown in each marker. When the user drags the map, new data is fetched for the current map bounds. When the user clicks on a marker, its style is changed to show that it is active, and a popup appears with additional data about the earthquake.
19+
20+
## How to run
21+
22+
Prerequisites: Node.js v18 or higher and npm
23+
24+
- Clone this repository and navigate to this directory
25+
- Install dependencies `npm install`
26+
- Replace `YOUR_MAPBOX_ACCESS_TOKEN` in `src/Map.jsx` with an access token from your Mapbox account.
27+
- Run the vite development server `npm run dev` and open the app in your browser.
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import js from '@eslint/js'
2+
import globals from 'globals'
3+
import reactHooks from 'eslint-plugin-react-hooks'
4+
import reactRefresh from 'eslint-plugin-react-refresh'
5+
6+
export default [
7+
{ ignores: ['dist'] },
8+
{
9+
files: ['**/*.{js,jsx}'],
10+
languageOptions: {
11+
ecmaVersion: 2020,
12+
globals: globals.browser,
13+
parserOptions: {
14+
ecmaVersion: 'latest',
15+
ecmaFeatures: { jsx: true },
16+
sourceType: 'module',
17+
},
18+
},
19+
plugins: {
20+
'react-hooks': reactHooks,
21+
'react-refresh': reactRefresh,
22+
},
23+
rules: {
24+
...js.configs.recommended.rules,
25+
...reactHooks.configs.recommended.rules,
26+
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
27+
'react-refresh/only-export-components': [
28+
'warn',
29+
{ allowConstantExport: true },
30+
],
31+
},
32+
},
33+
]

dynamic-markers-react/index.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Demo: Add Dynamic Markers and Popups to a React App</title>
7+
<meta name="robots" content="noindex, nofollow" />
8+
<meta name="viewport" content="width=device-width, initial-scale=1" />
9+
</head>
10+
<body>
11+
12+
<div id="root"></div>
13+
<script type="module" src="/src/main.jsx"></script>
14+
</body>
15+
</html>

0 commit comments

Comments
 (0)