Skip to content

Commit 34a1df4

Browse files
authored
Merge pull request #3 from sqlitecloud/feat/geopoly-tutorial-app
Geopoly extension demo app
2 parents 94a2846 + ed6d45a commit 34a1df4

File tree

12 files changed

+604
-0
lines changed

12 files changed

+604
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**/*/node_modules
2+
package-lock.json
23
.DS_Store
34
.parcel-cache
45
/**/*/dist

geopoly-demo/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Example App using SQLite's Geopoly Extension
2+
3+
<img width="721" alt="Screenshot 2024-08-06 at 3 33 47 PM" src="https://github.com/user-attachments/assets/113ebbdc-778e-4862-a4cb-080c20cb57fd">
4+
5+
## Description
6+
7+
This example demo'es using SQLite's built-in Geopoly extension with SQLite Cloud to create a local attractions finder map-plication.
8+
9+
To build the app from scratch, read this [Tutorial](https://docs.sqlitecloud.io/docs/tutorial-geopoly) in the SQLite Cloud documentation. To quickly try it out, read on!
10+
11+
## Tutorial TL;DR - Get up-and-exploring NYC attractions fast!
12+
13+
1. In your SQLite Cloud account dashboard's left nav, click Databases > Create Database. To minimize code changes, name your new database `geopoly-demo`.
14+
15+
2. Clone and open the `examples` repo in your local editor. Install the `geopoly-demo` app's dependencies.
16+
17+
```
18+
git clone https://github.com/sqlitecloud/examples.git
19+
cd geopoly-demo
20+
npm i
21+
```
22+
23+
3. [Sign up](https://account.mapbox.com/auth/signup/) for an Individual Mapbox account. (We'll stay on the free tier.)
24+
25+
4. In the `geopoly-demo` directory, create a `.env` file. Add 2 env vars:
26+
27+
- `REACT_APP_CONNECTION_STRING`. Copy/ paste your connection string from your SQLite Cloud account dashboard.
28+
- `REACT_APP_MAPBOX_TOKEN`. In your Mapbox account dashboard's nav, click Tokens. Copy/ paste your default public token.
29+
30+
5. Also in the `geopoly-demo` dir, create a `data/geodata.json` file. Complete just step `2. Curate your GeoJSON data` in the app [Tutorial](https://docs.sqlitecloud.io/docs/tutorial-geopoly).
31+
32+
6. Run `npm run create-tables` to create 2 DB tables in the `geopoly-demo` database:
33+
34+
- a `polygons` table to store the polygons generated by Geopoly as you interact with the app map, and
35+
- an `attractions` table to store NYC attraction geodata. Since `data/geodata.json` will contain ~2000 Point features, it will take a little time for this command to finish inserting the attractions as rows.
36+
37+
7. Run `npm start` to start your local dev server. Visit `http://localhost:3000/` (adjust the port as-needed) in your browser to view the app.
38+
39+
- The loaded map is centered at Central Park, NYC.
40+
- In the geocoder (i.e. search input) at the top right of the map, enter "Empire" and select the "Empire State Building" search result.
41+
- A polygon will be generated by Geopoly, added to your `polygons` table, and displayed on the map.
42+
- All attractions from your `attractions` table within the polygon area will be listed (nearest to furthest from the Empire State Building) in the left sidebar AND rendered as map markers.
43+
- The map will zoom in to the closest attraction to your searched location, in this case the "Empire State Building". However, you can click on any attraction listing or marker to center that attraction on the map.
8.9 KB
Loading

geopoly-demo/images/favicon.ico

15 KB
Binary file not shown.

geopoly-demo/images/favicon.svg

Lines changed: 7 additions & 0 deletions
Loading

geopoly-demo/package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "geopoly",
3+
"version": "1.0.0",
4+
"private": true,
5+
"description": "",
6+
"main": "index.js",
7+
"scripts": {
8+
"start": "react-scripts start",
9+
"build": "react-scripts build",
10+
"create-tables": "node src/helpers/createDatabase.js"
11+
},
12+
"eslintConfig": {
13+
"extends": [
14+
"react-app"
15+
]
16+
},
17+
"browserslist": [
18+
"defaults",
19+
"not ie 11"
20+
],
21+
"author": "",
22+
"license": "ISC",
23+
"type": "module",
24+
"dependencies": {
25+
"@mapbox/mapbox-gl-geocoder": "^5.0.2",
26+
"@sqlitecloud/drivers": "^1.0.193",
27+
"@turf/turf": "^7.0.0",
28+
"mapbox-gl": "^3.5.2",
29+
"react": "^18.3.1",
30+
"react-dom": "^18.3.1",
31+
"react-scripts": "^5.0.1"
32+
},
33+
"devDependencies": {
34+
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
35+
"dotenv": "^16.4.5"
36+
}
37+
}

geopoly-demo/public/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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" />
6+
<meta
7+
name="description"
8+
content="Create a React web app that uses Mapbox GL JS to render a map"
9+
/>
10+
<title>Local Attractions Finder</title>
11+
<link rel="icon" type="image/x-icon" href="../images/favicon.ico" />
12+
<link rel="icon" type="image/svg+xml" href="../images/favicon.svg" />
13+
</head>
14+
<body>
15+
<noscript>You need to enable JavaScript to run this app.</noscript>
16+
<div id="root"></div>
17+
</body>
18+
</html>

0 commit comments

Comments
 (0)