Skip to content

Commit 5ea40a1

Browse files
authored
Merge pull request #10 from mapbox/cw/add-poi-search-react
add poi-search-react code
2 parents f1cf7a7 + 0b03cb4 commit 5ea40a1

File tree

12 files changed

+5248
-0
lines changed

12 files changed

+5248
-0
lines changed

poi-search-react/.gitignore

Lines changed: 24 additions & 0 deletions
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?

poi-search-react/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# poi-search
2+
3+
This is supporting code for the Mapbox turorial [Add Point of Interest (POI) Search to a Map in a React app](https://docs.mapbox.com/help/tutorials/poi-search-react/).
4+
5+
## Overview
6+
7+
This Mapbox tutorial walks through how to integrate Points of Interest (POI) search results from the [Mapbox Search Box API](https://docs.mapbox.com/api/search/search-box/) into a React app, allowing the user to discover nearby businesses and services for a given map location.
8+
9+
10+
You'll learn how to:
11+
- Build UI to trigger category search queries in a mapping application.
12+
- Use the `SearchBoxCore` component of [Mapbox Search JS](https://docs.mapbox.com/mapbox-search-js/api/core/search/#searchboxcore) to search for POIs.
13+
- Get the map's bounds and use them as a search option to limit results to the current map view.
14+
- Use a React component to add custom markers and popups to the map for each point of interest in the search results.
15+
- Add a "search this area" button to trigger another category search if the user moves the map.
16+
17+
Buttons on a map to search for nearby points of interest is a common UX pattern in mapping applications and can be useful for users to find nearby businesses, services, or other locations of interest. For example, in a real estate app, users may want to explore nearby schools, parks, or grocery stores. In a travel app, users may want to find nearby restaurants, hotels, or attractions.
18+
19+
The Mapbox [Search Box API](https://docs.mapbox.com/api/search/search-box/) provides a powerful and flexible way to search for points of interest, and the `SearchBoxCore` component of *Mapbox Search JS* allows for seamless integration in a JavaScript environment.
20+
21+
22+
## How to run
23+
24+
Prerequisites: Node.js v18 or higher and npm
25+
26+
- Clone this repository and navigate to this directory
27+
- Install dependencies `npm install`
28+
- Replace `YOUR_MAPBOX_ACCESS_TOKEN` in `src/App.jsx` with an access token from your [Mapbox account](https://console.mapbox.com/).
29+
- Run the vite development server `npm run dev` and open the app in your browser.

poi-search-react/eslint.config.js

Lines changed: 33 additions & 0 deletions
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+
]

poi-search-react/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Mapbox POI Search Tutorial</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.jsx"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)