{"action":"created","comment":{"url":"https://api.github.com/repos/CartoDB/Windshaft/pulls/comments/22928052","id":22928052,"diff_hunk":"@@ -0,0 +1,143 @@\n+var abaculus = require('abaculus'),\n+    request = require('request'),\n+    SphericalMercator = require('sphericalmercator'),\n+    Step = require('step');\n+\n+function StaticMapsController(app, renderCache, options) {\n+    this._app = app;\n+    this._renderCache = renderCache;\n+    this._options = options || {};\n+}\n+\n+module.exports = StaticMapsController;\n+\n+\n+StaticMapsController.prototype.register = function(app) {\n+    app.get(app.base_url_mapconfig + '/static/center/:token/:z/:lat/:lng/:width/:height.:format', this.center.bind(this));\n+    app.get(app.base_url_mapconfig + '/static/bbox/:token/:west,:south,:east,:north/:width/:height.:format', this.bbox.bind(this));\n+};\n+\n+StaticMapsController.prototype.bbox = function(req, res) {\n+    var west = +req.params.west,\n+        south = +req.params.south,\n+        east = +req.params.east,\n+        north = +req.params.north,\n+\n+        width = +req.params.width,\n+        height = +req.params.height;\n+\n+    var zoom = boundsZoom(\n+        {\n+            nw: [west, north],\n+            se: [east, south]\n+        },\n+        {\n+            width: width,\n+            height: height\n+        }\n+    );\n+    this.staticMap(req, res, zoom, {\n+        x: west + Math.abs(west - east) / 2,\n+        y: south + Math.abs(south - north) / 2,\n+        w: width,\n+        h: height\n+    });\n+};\n+\n+StaticMapsController.prototype.center = function(req, res) {\n+    this.staticMap(req, res, +req.params.z, {\n+        x: +req.params.lng,\n+        y: +req.params.lat,\n+        w: +req.params.width,\n+        h: +req.params.height\n+    });\n+};\n+\n+StaticMapsController.prototype.staticMap = function(req, res, zoom, center) {\n+    this._app.doCORS(res);\n+\n+    var renderer;\n+\n+    var format = req.params.format == 'jpg' ? 'jpeg' : 'png';\n+\n+    req.params.format = 'png';","path":"lib/windshaft/controllers/static_maps.js","position":63,"original_position":63,"commit_id":"0958a743aaf8393f0d803779bcc726c9ee95d5ac","original_commit_id":"0958a743aaf8393f0d803779bcc726c9ee95d5ac","user":{"login":"rochoa","id":45346,"avatar_url":"https://avatars.githubusercontent.com/u/45346?v=3","gravatar_id":"","url":"https://api.github.com/users/rochoa","html_url":"https://github.com/rochoa","followers_url":"https://api.github.com/users/rochoa/followers","following_url":"https://api.github.com/users/rochoa/following{/other_user}","gists_url":"https://api.github.com/users/rochoa/gists{/gist_id}","starred_url":"https://api.github.com/users/rochoa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rochoa/subscriptions","organizations_url":"https://api.github.com/users/rochoa/orgs","repos_url":"https://api.github.com/users/rochoa/repos","events_url":"https://api.github.com/users/rochoa/events{/privacy}","received_events_url":"https://api.github.com/users/rochoa/received_events","type":"User","site_admin":false},"body":"See my other comment about `format` and `layer` params and renderers.","created_at":"2015-01-14T10:26:33Z","updated_at":"2015-01-14T10:26:33Z","html_url":"https://github.com/CartoDB/Windshaft/pull/246#discussion_r22928052","pull_request_url":"https://api.github.com/repos/CartoDB/Windshaft/pulls/246","_links":{"self":{"href":"https://api.github.com/repos/CartoDB/Windshaft/pulls/comments/22928052"},"html":{"href":"https://github.com/CartoDB/Windshaft/pull/246#discussion_r22928052"},"pull_request":{"href":"https://api.github.com/repos/CartoDB/Windshaft/pulls/246"}}},"pull_request":{"url":"https://api.github.com/repos/CartoDB/Windshaft/pulls/246","id":27293025,"html_url":"https://github.com/CartoDB/Windshaft/pull/246","diff_url":"https://github.com/CartoDB/Windshaft/pull/246.diff","patch_url":"https://github.com/CartoDB/Windshaft/pull/246.patch","issue_url":"https://api.github.com/repos/CartoDB/Windshaft/issues/246","number":246,"state":"open","locked":false,"title":"static preview endpoints","user":{"login":"rochoa","id":45346,"avatar_url":"https://avatars.githubusercontent.com/u/45346?v=3","gravatar_id":"","url":"https://api.github.com/users/rochoa","html_url":"https://github.com/rochoa","followers_url":"https://api.github.com/users/rochoa/followers","following_url":"https://api.github.com/users/rochoa/following{/other_user}","gists_url":"https://api.github.com/users/rochoa/gists{/gist_id}","starred_url":"https://api.github.com/users/rochoa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rochoa/subscriptions","organizations_url":"https://api.github.com/users/rochoa/orgs","repos_url":"https://api.github.com/users/rochoa/repos","events_url":"https://api.github.com/users/rochoa/events{/privacy}","received_events_url":"https://api.github.com/users/rochoa/received_events","type":"User","site_admin":false},"body":"This feature includes:\r\n\r\n * Torque png rendering using node-canvas\r\n * HTTP layers\r\n * Static preview endpoints: being able to request a preview from a mapconfig\r\n   * Using base layers (HTTP layers)\r\n   * Using torque layers\r\n\r\nPart of the functionality in server.js was split into several pieces: controllers, backends\r\nRender cache was also split into smaller components: renderer factory and several renderers","created_at":"2015-01-13T18:29:58Z","updated_at":"2015-01-14T10:26:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bc0068e0f8d4803cf3a75f2881cc3bf8896e5f7b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CartoDB/Windshaft/pulls/246/commits","review_comments_url":"https://api.github.com/repos/CartoDB/Windshaft/pulls/246/comments","review_comment_url":"https://api.github.com/repos/CartoDB/Windshaft/pulls/comments/{number}","comments_url":"https://api.github.com/repos/CartoDB/Windshaft/issues/246/comments","statuses_url":"https://api.github.com/repos/CartoDB/Windshaft/statuses/0958a743aaf8393f0d803779bcc726c9ee95d5ac","head":{"label":"CartoDB:static-controller","ref":"static-controller","sha":"0958a743aaf8393f0d803779bcc726c9ee95d5ac","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":2303178,"name":"Windshaft","full_name":"CartoDB/Windshaft","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/Windshaft","description":"A map tile server for PostGIS based on node.js and Mapnik","fork":false,"url":"https://api.github.com/repos/CartoDB/Windshaft","forks_url":"https://api.github.com/repos/CartoDB/Windshaft/forks","keys_url":"https://api.github.com/repos/CartoDB/Windshaft/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/Windshaft/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/Windshaft/teams","hooks_url":"https://api.github.com/repos/CartoDB/Windshaft/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/Windshaft/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/Windshaft/events","assignees_url":"https://api.github.com/repos/CartoDB/Windshaft/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/Windshaft/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/Windshaft/tags","blobs_url":"https://api.github.com/repos/CartoDB/Windshaft/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/Windshaft/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/Windshaft/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/Windshaft/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/Windshaft/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/Windshaft/languages","stargazers_url":"https://api.github.com/repos/CartoDB/Windshaft/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/Windshaft/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/Windshaft/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/Windshaft/subscription","commits_url":"https://api.github.com/repos/CartoDB/Windshaft/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/Windshaft/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/Windshaft/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/Windshaft/issues/comments/{number}","contents_url":"https://api.github.com/repos/CartoDB/Windshaft/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/Windshaft/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/Windshaft/merges","archive_url":"https://api.github.com/repos/CartoDB/Windshaft/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/Windshaft/downloads","issues_url":"https://api.github.com/repos/CartoDB/Windshaft/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/Windshaft/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/Windshaft/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/Windshaft/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/Windshaft/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/Windshaft/releases{/id}","created_at":"2011-08-31T18:16:27Z","updated_at":"2015-01-13T17:38:15Z","pushed_at":"2015-01-13T18:25:13Z","git_url":"git://github.com/CartoDB/Windshaft.git","ssh_url":"git@github.com:CartoDB/Windshaft.git","clone_url":"https://github.com/CartoDB/Windshaft.git","svn_url":"https://github.com/CartoDB/Windshaft","homepage":"","size":5317,"stargazers_count":130,"watchers_count":130,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":35,"mirror_url":null,"open_issues_count":35,"forks":35,"open_issues":35,"watchers":130,"default_branch":"master"}},"base":{"label":"CartoDB:master","ref":"master","sha":"a753f255ddfd5eba336c65906d65dba184a39471","user":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"repo":{"id":2303178,"name":"Windshaft","full_name":"CartoDB/Windshaft","owner":{"login":"CartoDB","id":1799254,"avatar_url":"https://avatars.githubusercontent.com/u/1799254?v=3","gravatar_id":"","url":"https://api.github.com/users/CartoDB","html_url":"https://github.com/CartoDB","followers_url":"https://api.github.com/users/CartoDB/followers","following_url":"https://api.github.com/users/CartoDB/following{/other_user}","gists_url":"https://api.github.com/users/CartoDB/gists{/gist_id}","starred_url":"https://api.github.com/users/CartoDB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CartoDB/subscriptions","organizations_url":"https://api.github.com/users/CartoDB/orgs","repos_url":"https://api.github.com/users/CartoDB/repos","events_url":"https://api.github.com/users/CartoDB/events{/privacy}","received_events_url":"https://api.github.com/users/CartoDB/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CartoDB/Windshaft","description":"A map tile server for PostGIS based on node.js and Mapnik","fork":false,"url":"https://api.github.com/repos/CartoDB/Windshaft","forks_url":"https://api.github.com/repos/CartoDB/Windshaft/forks","keys_url":"https://api.github.com/repos/CartoDB/Windshaft/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CartoDB/Windshaft/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CartoDB/Windshaft/teams","hooks_url":"https://api.github.com/repos/CartoDB/Windshaft/hooks","issue_events_url":"https://api.github.com/repos/CartoDB/Windshaft/issues/events{/number}","events_url":"https://api.github.com/repos/CartoDB/Windshaft/events","assignees_url":"https://api.github.com/repos/CartoDB/Windshaft/assignees{/user}","branches_url":"https://api.github.com/repos/CartoDB/Windshaft/branches{/branch}","tags_url":"https://api.github.com/repos/CartoDB/Windshaft/tags","blobs_url":"https://api.github.com/repos/CartoDB/Windshaft/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CartoDB/Windshaft/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CartoDB/Windshaft/git/refs{/sha}","trees_url":"https://api.github.com/repos/CartoDB/Windshaft/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CartoDB/Windshaft/statuses/{sha}","languages_url":"https://api.github.com/repos/CartoDB/Windshaft/languages","stargazers_url":"https://api.github.com/repos/CartoDB/Windshaft/stargazers","contributors_url":"https://api.github.com/repos/CartoDB/Windshaft/contributors","subscribers_url":"https://api.github.com/repos/CartoDB/Windshaft/subscribers","subscription_url":"https://api.github.com/repos/CartoDB/Windshaft/subscription","commits_url":"https://api.github.com/repos/CartoDB/Windshaft/commits{/sha}","git_commits_url":"https://api.github.com/repos/CartoDB/Windshaft/git/commits{/sha}","comments_url":"https://api.github.com/repos/CartoDB/Windshaft/comments{/number}","issue_comment_url":"https://api.github.com/repos/CartoDB/Windshaft/issues/comments/{number}","contents_url":"https://api.github.com/repos/CartoDB/Windshaft/contents/{+path}","compare_url":"https://api.github.com/repos/CartoDB/Windshaft/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CartoDB/Windshaft/merges","archive_url":"https://api.github.com/repos/CartoDB/Windshaft/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CartoDB/Windshaft/downloads","issues_url":"https://api.github.com/repos/CartoDB/Windshaft/issues{/number}","pulls_url":"https://api.github.com/repos/CartoDB/Windshaft/pulls{/number}","milestones_url":"https://api.github.com/repos/CartoDB/Windshaft/milestones{/number}","notifications_url":"https://api.github.com/repos/CartoDB/Windshaft/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CartoDB/Windshaft/labels{/name}","releases_url":"https://api.github.com/repos/CartoDB/Windshaft/releases{/id}","created_at":"2011-08-31T18:16:27Z","updated_at":"2015-01-13T17:38:15Z","pushed_at":"2015-01-13T18:25:13Z","git_url":"git://github.com/CartoDB/Windshaft.git","ssh_url":"git@github.com:CartoDB/Windshaft.git","clone_url":"https://github.com/CartoDB/Windshaft.git","svn_url":"https://github.com/CartoDB/Windshaft","homepage":"","size":5317,"stargazers_count":130,"watchers_count":130,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":35,"mirror_url":null,"open_issues_count":35,"forks":35,"open_issues":35,"watchers":130,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/CartoDB/Windshaft/pulls/246"},"html":{"href":"https://github.com/CartoDB/Windshaft/pull/246"},"issue":{"href":"https://api.github.com/repos/CartoDB/Windshaft/issues/246"},"comments":{"href":"https://api.github.com/repos/CartoDB/Windshaft/issues/246/comments"},"review_comments":{"href":"https://api.github.com/repos/CartoDB/Windshaft/pulls/246/comments"},"review_comment":{"href":"https://api.github.com/repos/CartoDB/Windshaft/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/CartoDB/Windshaft/pulls/246/commits"},"statuses":{"href":"https://api.github.com/repos/CartoDB/Windshaft/statuses/0958a743aaf8393f0d803779bcc726c9ee95d5ac"}}}}