You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<imgwidth="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 demos 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 and/or customize the attractions, read the [Tutorial](https://docs.sqlitecloud.io/docs/tutorial-geopoly) in the SQLite Cloud documentation.
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.
3.[Sign up](https://account.mapbox.com/auth/signup/) for an Individual Mapbox account. (We'll stay on the free tier.)
24
+
25
+
4. 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. Run `npm run create-tables` to create 2 DB tables in the `geopoly-demo` database:
31
+
32
+
- a `polygons` table to store the polygons generated by Geopoly as you interact with the app map, and
33
+
- an `attractions` table to store NYC attraction geodata. Since `data/geodata.json` contains ~2000 Point features, it will take a little time for this command to finish inserting the attractions as rows.
34
+
35
+
6. 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.
36
+
37
+
- The loaded map is centered at Central Park, NYC.
38
+
- In the geocoder (i.e. search input) at the top right of the map, enter "Empire" and select the "Empire State Building" search result.
39
+
- A polygon will be generated by Geopoly, added to your `polygons` table, and displayed on the map.
40
+
- 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.
41
+
- 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.
awaitdb.sql`USE DATABASE ${db_name}; SELECT name, coordinates FROM attractions WHERE geopoly_contains_point(${polygonCoords[0]['geopoly_json(_shape)']}, lng, lat);`;// here, lng and lat are the cols in the attractions table
36
+
awaitdb.sql`USE DATABASE ${db_name}; SELECT name, coordinates FROM attractions WHERE geopoly_contains_point(${polygonCoords[0]['geopoly_json(_shape)']}, lng, lat);`;
awaitdb.sql`CREATE VIRTUAL TABLE polygons USING geopoly()`;
12
12
13
13
awaitdb.sql`CREATE TABLE attractions (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, lng REAL NOT NULL, lat REAL NOT NULL, coordinates TEXT NOT NULL)`;
14
14
15
-
// stick to node (Point) data from Overpass API!
16
15
for(constfeatureofgeodata['features']){
17
16
const{ name }=feature.properties;
18
17
const{ coordinates }=feature.geometry;
@@ -29,34 +28,3 @@ async function createDatabase() {
29
28
}
30
29
31
30
createDatabase();
32
-
33
-
/*
34
-
Overpass API query:
35
-
36
-
[out:json][timeout:25];
37
-
38
-
// Define areas for Paris, New York, and Tokyo
39
-
area[name="New York"]->.newyork;
40
-
41
-
// Fetch nodes, ways, and relations tagged as tourist attractions in these areas
0 commit comments