Geospatial

TileStream On Heroku

On my spare time, I decided to build a Geo-spatial application and decided to host my tile server in lieu of using Google Maps. Yes, I decided to create my own map layers with Mapbox’s Tilemill and host the map layers on my own server rather than to use Mapbox or Cloudmade SaaS hosting model.

There are many advantages to using Tilemill – the most important reason for me was the ability to interface with PostGIS, Shapefiles and SQLite. Also, TileMill uses Carto CSS, which is a real joy to use when creating maps.  I am not going to discuss how to use Tilemill, you can reference the online tutorials in order to get a feel for the tool.  Here’s an overview of the steps required to push Tilestream server to Heroku.

TileStream is a high performance Tile Server that renders MBTiles and developed by Mapbox.

First, I rolled out Tilestream on AWS.   AWS provides the ideal scenario for a developer/power user. It provides you with the most administrative and configuration control.   In the long term, I migrated to Heroku only to minimize costs.

First, create a standard Git project and add the following directories and files. The project structure should look like this:
mbtiles -> The Directory, which contains your Mbtiles
README.MD -> Standard Git project descriptor
package.json –> defines the project dependencies
Procfile –> Heroku application file which defines the process types in an app.

Here’s a reference project: https://github.com/jsantisi/flageo. If you decide to clone the project, make sure you get the ssh url.
Creating a new Git project
A. Create a directory for your project
B. Create the mbtiles directory inside your project directory
C. Copy the MBTiles from TileMill into the mbtiles directory (Hint – you have to export your MBTiles from Tilemill)
D. Create the rest of the files at the root level of your project.
E. Use git to initialize the project (Assumes that you have a git account and you are comfortable with Git Commands)
:>git init
:>git add .
:>git commit -m ‘your comment’
:>git push
:>git push heroku master

In order to push your application directly to Heroku you must configure Heroku with Git & ssh. Heroku downloads the app’s dependencies as specified in the package.json. The application is in node.js format (TileStream is a node.js server)
{
“name”: “flageo”,
“version”: “0.0.1”,
“author”: “jsantisi”,
“dependencies”: {
“tilestream”: “1.1.0”
},
“engines”:{
“node”:”0.10.26″,
“npm”: “1.4.3”
}
}

Heroku is smart and figures out that this is a node.js application that needs tilestream, node and npm in order to run. And your console should look like this…

:>git push heroku master
Fetching repository, done.
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 411 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)

—–> Node.js app detected
—–> Requested node range: 0.10.26
—–> Resolved node version: 0.10.26
—–> Downloading and installing node
—–> Restoring node_modules directory from cache
—–> Pruning cached dependencies not specified in package.json
npm WARN package.json flageo@0.0.1 No repository field.
—–> Writing a custom .npmrc to circumvent npm bugs
—–> Exporting config vars to environment
—–> Installing dependencies
npm WARN package.json flageo@0.0.1 No repository field.
npm WARN package.json tilestream@1.1.0 ‘repositories’ (plural) Not supported. Please pick one as the ‘repository’ field
—–> Caching node_modules directory for future builds
—–> Cleaning up node-gyp and npm artifacts
—–> Building runtime environment
—–> Discovering process types
Procfile declares types -> web

—–> Compressing… done, 28.2MB
—–> Launching… done, v16
http://jtilestream.herokuapp.com/ deployed to Heroku

To git@heroku.com:jtilestream.git
7cc236a..a17c1dc master -> master

Procfile
We have to address the procfile since without the correct settings the server will not start or be accessible to the outside world.
web: tilestream --host jtilestream.herokuapp.com --host '*' --uiPort=$PORT --tilePort=$PORT --tiles=./tiles
web: defines a web application
host: the name of your application(Heroku dashboard) or the host that will be allow to connect to tilestream. You can specify all hosts.
uiPort: $PORT is the Heroku application Port value. Heroku provides several environment variables that you must use in order for your application to be able to open a connection.
tilePort: $PORT assigned to your application by Heroku.

One advantage of leveraging a Paas/SaaS model like Heroku, is that the $PORT environment variable is managed for you.  They abstracted the AWS offering from the developers and administrators and provide you with ports for your application along with Git and other application centric service offerings.  This approach makes the hosting model more appealing.   I don’t want to spend my limited playing time configuring Paas and SaaS application services.

 

Advertisements