This is a quick & dirty Node/Express application that's used in conjunction with my Let's Talk About Your
Geostack workshop & deck. It's the result of a basic Express
scaffold, with /routes/users.js
deleted, /routes/amenities.js
added, and /app.js
adjusted accordingly.
The requirements for this to work are that
-
you have Node and
npm
installed -
there's a spatially-enabled (PostgreSQL + PostGIS) database running on
localhost
-
the database contains OpenStreetMap data, likely a metro extract
-
the data import was done with
osm2pgsql
and included all tags, meaning that--hstore-all
was used, e.g.osm2pgsql -H localhost --hstore-all -d portland_from_osm ~/Downloads/portland.osm.pbf
The workshop demonstrates how all components of a contemporary web mapping application can be run locally, on your own computer, using open source software and open data. OpenStreetMap data is used with TileMill and TileStream to generate and serve map tiles as a base layer, and with Leaflet to generate map overlays for points of interest.
The dynamic.html
page in a companion repo, geostack-map-pages,
consumes data from this api in order to create and display a Leaflet GeoJSON Layer.
-
git clone
this repository. -
cd geostack-api
-
npm install
-
alter line 11 of
/routes/amenities.js
to account for your database name and authentication parameters. The general form ispg://user_name:user_password@localhost:port_number/database_name
-
npm start
-
visit or make an AJAX call to
http://localhost:3000/amenities/
to retrieve a GeoJSON FeatureCollection of restaurants and their cuisines
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-123.201866018855,
45.2027315841557
]
},
"properties": {
"name": "El Primo",
"cuisine": null
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-123.192975122993,
45.2237749069396
]
},
"properties": {
"name": "Chan's Restuarant",
"cuisine": "chinese"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-122.230128012966,
45.3831193176103
]
},
"properties": {
"name": "Calamity Jane's",
"cuisine": "burger"
}
}
]
}