Skip to content

Commit

Permalink
Merge pull request cfachicago#6 from ryanbriones/working-sidewalks
Browse files Browse the repository at this point in the history
Working sidewalks
  • Loading branch information
GovInTrenches committed Dec 4, 2012
2 parents 44f1883 + 92ca2db commit 5f19def
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,39 @@ You can see a running version of the application at
cd adopt-a-sidewalk
bundle install

### Setting up the database

1. Install PostgreSQL with the PostGIS extensions: e.g. `brew install postgis`
2. Download the chicagosidewalks shape file from the City of Chicago Data Portal http://data.cityofchicago.org
3. Convert the shapefile into PostGIS SQL: `shp2pgsql -s 3435:4326 -g the_geom -I chicagosidewalks.shp chicagosidewalks.sql`
* `-s 3435:4326` This converts the geospatial data from the EPSG:3435 (NAD83 / Illinois East) project to ESPG:4326 (WGS84, lat/long)
* `-g the_geom` name the geocolumn `the_geom` to match what's in the Rails code
* `-I` generate a spatial index on the geocolumn.
4. Create a database that will host your app: e.g. `createdb adoptasidewalk_dev`
5. Add the PostGIS extensions to your database: e.g. `psql adoptasidewalk_dev -c "CREATE EXTENSION postgis;"`
* MAGIC
6. Load in `chicagosidewalks.sql`: e.g. `psql adoptasidewalk_dev <chicagosidewalks.sql`
7. Configure `database.yml` to point to your database
8. Run Rails migrations: `rake db:migrate`

### Google Maps KML Endpoint

**tl;dr** Set the environment variable `GMAPS_KML_ENDPOINT` to the address of your publicly-exposed host

This part is tricky. The Rails app is designed so that a client-side call to a Google Maps function loads up KML from HTTP endpoint in the app. What this means is that your running app has to be exposed to the Internet in order to load up the sidewalk KML on the map. This is fine in production, but in development (read: on your laptop, etc) you're likely behind a firewall and Google will be unable to load the KML.

One solution to this problem is to use SSH Remote Forwarding.

1. Have an Internet exposed Linux Server (e.g. AWS instance)
2. Configure sshd to have "GatewayPorts yes"
3. On development machine create a remote forward connection: ssh -nNTR *:3000:localhost:3000 your.remote.server.com
4. Set `GMAPS_KML_ENDPOINT` to "your.remote.server.com:3000"
* `GMAPS_KML_ENDPOINT=your.remote.server.com:3000 rails s`
* `export GMAPS_KML_ENDPOINT=your.remote.server.com:3000; rails s`
* Use foremen and .env (http://ddollar.github.com/foreman/#ENVIRONMENT)

In production, this is likely the hostname or IP of your production server.

## <a name="usage">Usage</a>
rails server

Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/main.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $(function() {
function refreshKML(auto_fetch_info) {
var c = map.getCenter();
if (bDebug) console.info("Rendering sidewalks of [%s, %s]", c.lat(), c.lng());
var url = 'http://167.165.233.18/sidewalks.kml?lat=' + c.lat() + '&lng=' + c.lng() + '&r=' + (new Date()).valueOf();
var url = 'http://<%= ENV["GMAPS_KML_ENDPOINT"] %>/sidewalks.kml?lat=' + c.lat() + '&lng=' + c.lng() + '&r=' + (new Date()).valueOf();
if (bDebug) console.info(url);

if (sidewalks_kml != undefined || sidewalks_kml != null)
Expand Down
5 changes: 5 additions & 0 deletions config/initializers/ensure_gmaps_kml_endpoint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# See README "Google Maps KML Endpoint"

unless ENV["GMAPS_KML_ENDPOINT"]
abort "Missing GMAPS_KML_ENDPOINT environment variable: #{__FILE__}:#{__LINE__}"
end

0 comments on commit 5f19def

Please sign in to comment.