{"action":"created","comment":{"url":"https://api.github.com/repos/openlayers/ol3/pulls/comments/43134216","id":43134216,"diff_hunk":"@@ -0,0 +1,262 @@\n+//FIXME Implement projection handling\n+\n+goog.provide('ol.format.MVT');\n+\n+goog.require('goog.asserts');\n+goog.require('ol.Feature');\n+goog.require('ol.ext.pbf');\n+goog.require('ol.ext.vectortile');\n+goog.require('ol.format.Feature');\n+goog.require('ol.format.FormatType');\n+goog.require('ol.geom.Geometry');\n+goog.require('ol.geom.GeometryLayout');\n+goog.require('ol.geom.GeometryType');\n+goog.require('ol.geom.LineString');\n+goog.require('ol.geom.MultiLineString');\n+goog.require('ol.geom.MultiPoint');\n+goog.require('ol.geom.Point');\n+goog.require('ol.geom.Polygon');\n+goog.require('ol.proj');\n+goog.require('ol.proj.Projection');\n+goog.require('ol.proj.Units');\n+goog.require('ol.render.Feature');\n+\n+\n+\n+/**\n+ * @classdesc\n+ * Feature format for reading data in the Mapbox MVT format.\n+ *\n+ * @constructor\n+ * @extends {ol.format.Feature}\n+ * @param {olx.format.MVTOptions=} opt_options Options.\n+ * @api\n+ */\n+ol.format.MVT = function(opt_options) {\n+\n+  goog.base(this);\n+\n+  var options = opt_options ? opt_options : {};\n+\n+  /**\n+   * @type {ol.proj.Projection}\n+   */\n+  this.defaultDataProjection = new ol.proj.Projection({\n+    code: 'EPSG:3857',\n+    units: ol.proj.Units.TILE_PIXELS\n+  });\n+\n+  /**\n+   * @private\n+   * @type {function((ol.geom.Geometry|Object.<string, *>)=)|\n+   *     function(ol.geom.GeometryType,Array.<number>,\n+   *         (Array.<number>|Array.<Array.<number>>),Object.<string, *>)}\n+   */\n+  this.featureClass_ = options.featureClass ?\n+      options.featureClass : ol.render.Feature;\n+\n+  /**\n+   * @private\n+   * @type {string}\n+   */\n+  this.geometryName_ = options.geometryName ?\n+      options.geometryName : 'geometry';\n+\n+  /**\n+   * @private\n+   * @type {string}\n+   */\n+  this.layerName_ = options.layerName ? options.layerName : 'layer';\n+\n+  /**\n+   * @private\n+   * @type {Array.<string>}\n+   */\n+  this.layers_ = options.layers ? options.layers : null;\n+\n+  this.rightHandedPolygons = true;\n+\n+};\n+goog.inherits(ol.format.MVT, ol.format.Feature);\n+\n+\n+/**\n+ * @inheritDoc\n+ */\n+ol.format.MVT.prototype.getType = function() {\n+  return ol.format.FormatType.ARRAY_BUFFER;\n+};\n+\n+\n+/**\n+ * @private\n+ * @param {Object} rawFeature Raw Mapbox feature.\n+ * @param {string} layer Layer.\n+ * @param {olx.format.ReadOptions=} opt_options Read options.\n+ * @return {ol.Feature} Feature.\n+ */\n+ol.format.MVT.prototype.readFeature_ = function(\n+    rawFeature, layer, opt_options) {\n+  var feature = new this.featureClass_();\n+  var values = rawFeature.properties;\n+  values[this.layerName_] = layer;\n+  var geometry = ol.format.Feature.transformWithOptions(\n+      ol.format.MVT.readGeometry_(rawFeature), false,\n+      this.adaptOptions(opt_options));\n+  if (geometry) {\n+    goog.asserts.assertInstanceof(geometry, ol.geom.Geometry);\n+    values[this.geometryName_] = geometry;\n+  }\n+  feature.setProperties(rawFeature.properties);\n+  feature.setGeometryName(this.geometryName_);\n+  return feature;\n+};\n+\n+\n+/**\n+ * @private\n+ * @param {Object} rawFeature Raw Mapbox feature.\n+ * @param {string} layer Layer.\n+ * @return {ol.render.Feature} Feature.\n+ */\n+ol.format.MVT.prototype.readRenderFeature_ = function(rawFeature, layer) {\n+  var coords = rawFeature.loadGeometry();\n+  var end = 0;\n+  var ends = [];\n+  var flatCoordinates = [];\n+  var line, coord;\n+  for (var i = 0, ii = coords.length; i < ii; ++i) {\n+    line = coords[i];\n+    for (var j = 0, jj = line.length; j < jj; ++j) {\n+      coord = line[j];\n+      // Non-tilespace coords can be calculated here when a TileGrid and\n+      // TileCoord are known.\n+      flatCoordinates.push(coord.x, coord.y);\n+    }\n+    end += 2 * j;\n+    ends.push(end);\n+  }\n+\n+  var type = rawFeature.type;\n+  /** @type {ol.geom.GeometryType} */\n+  var geometryType;\n+  if (type === 1) {\n+    geometryType = coords.length === 1 ?\n+        ol.geom.GeometryType.POINT : ol.geom.GeometryType.MULTI_POINT;\n+  } else if (type === 2) {\n+    if (coords.length === 1) {\n+      geometryType = ol.geom.GeometryType.LINE_STRING;\n+    } else {\n+      geometryType = ol.geom.GeometryType.MULTI_LINE_STRING;\n+    }\n+  } else {\n+    geometryType = ol.geom.GeometryType.POLYGON;","path":"src/ol/format/mvtformat.js","position":153,"original_position":153,"commit_id":"1895695cc09ca9cbe2339e71d6778eb2b7db6843","original_commit_id":"1895695cc09ca9cbe2339e71d6778eb2b7db6843","user":{"login":"bartvde","id":319678,"avatar_url":"https://avatars.githubusercontent.com/u/319678?v=3","gravatar_id":"","url":"https://api.github.com/users/bartvde","html_url":"https://github.com/bartvde","followers_url":"https://api.github.com/users/bartvde/followers","following_url":"https://api.github.com/users/bartvde/following{/other_user}","gists_url":"https://api.github.com/users/bartvde/gists{/gist_id}","starred_url":"https://api.github.com/users/bartvde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bartvde/subscriptions","organizations_url":"https://api.github.com/users/bartvde/orgs","repos_url":"https://api.github.com/users/bartvde/repos","events_url":"https://api.github.com/users/bartvde/events{/privacy}","received_events_url":"https://api.github.com/users/bartvde/received_events","type":"User","site_admin":false},"body":"Should you handle type === 3 here as well (unknown)?","created_at":"2015-10-27T15:06:52Z","updated_at":"2015-10-27T15:06:52Z","html_url":"https://github.com/openlayers/ol3/pull/4219#discussion_r43134216","pull_request_url":"https://api.github.com/repos/openlayers/ol3/pulls/4219","_links":{"self":{"href":"https://api.github.com/repos/openlayers/ol3/pulls/comments/43134216"},"html":{"href":"https://github.com/openlayers/ol3/pull/4219#discussion_r43134216"},"pull_request":{"href":"https://api.github.com/repos/openlayers/ol3/pulls/4219"}}},"pull_request":{"url":"https://api.github.com/repos/openlayers/ol3/pulls/4219","id":46841031,"html_url":"https://github.com/openlayers/ol3/pull/4219","diff_url":"https://github.com/openlayers/ol3/pull/4219.diff","patch_url":"https://github.com/openlayers/ol3/pull/4219.patch","issue_url":"https://api.github.com/repos/openlayers/ol3/issues/4219","number":4219,"state":"open","locked":false,"title":"Support tiled vector data and Mapbox vector tiles","user":{"login":"ahocevar","id":211514,"avatar_url":"https://avatars.githubusercontent.com/u/211514?v=3","gravatar_id":"","url":"https://api.github.com/users/ahocevar","html_url":"https://github.com/ahocevar","followers_url":"https://api.github.com/users/ahocevar/followers","following_url":"https://api.github.com/users/ahocevar/following{/other_user}","gists_url":"https://api.github.com/users/ahocevar/gists{/gist_id}","starred_url":"https://api.github.com/users/ahocevar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahocevar/subscriptions","organizations_url":"https://api.github.com/users/ahocevar/orgs","repos_url":"https://api.github.com/users/ahocevar/repos","events_url":"https://api.github.com/users/ahocevar/events{/privacy}","received_events_url":"https://api.github.com/users/ahocevar/received_events","type":"User","site_admin":false},"body":"This pull request adds support for rendering tiled vector data. The key elements to achieve this are\r\n\r\n1. `ol.layer.VectorTile`. A simple layer to hint renderers that a tiled renderer is to be used, instead of a viewport renderer like for `ol.layer.Vector`.\r\n1. `ol.source.VectorTile` and `ol.VectorTile`. Features are handled by the tile, not the source. Like image tiles, vector tiles can be cached. The existing `ol.source.TileVector` is removed, and its functionality is integrated into `ol.source.VectorTile`. To improve the inheritance chain, `ol.source.UrlTile` was added. Both `ol.source.ImageTile` and `ol.source.VectorTile` inherit common functionality related to url loading from that new class.\r\n1. `ol.renderer.canvas.VectorTileLayer`. This renderer gets tiles from `ol.source.VectorTile`, creates a replay group for each tile, and stores the replay group on the tile for rendering. Tiles are clipped at the tile boundary, so stroked polygons won't have a stroke at the tile boundary when a buffer is used on the server that creates the vector tiles.\r\n\r\nSupport for Mapbox vector tiles is provided by the new `ol.format.MVT` format, which relies on https://www.npmjs.com/package/pbf to read the protobuffers and https://www.npmjs.com/package/vector-tile to parse layers and features. To support pixel relative coordinates,`ol.proj.Units.TILE_PIXELS` was introduced. For efficient feature and geometry creation, a lightweight, read-only `ol.render.Feature` was added, which does not register any event listeners. Another performance improvement was achieved by skipping lineTo/moveTo calls for repeated coordinates when replaying vector batches at a lower resolution than it was created for.","created_at":"2015-10-05T22:13:29Z","updated_at":"2015-10-27T15:06:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a7b44c30f2983c8f4147698ef3cc8dc019f1f756","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openlayers/ol3/pulls/4219/commits","review_comments_url":"https://api.github.com/repos/openlayers/ol3/pulls/4219/comments","review_comment_url":"https://api.github.com/repos/openlayers/ol3/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openlayers/ol3/issues/4219/comments","statuses_url":"https://api.github.com/repos/openlayers/ol3/statuses/1895695cc09ca9cbe2339e71d6778eb2b7db6843","head":{"label":"ahocevar:vectortile","ref":"vectortile","sha":"1895695cc09ca9cbe2339e71d6778eb2b7db6843","user":{"login":"ahocevar","id":211514,"avatar_url":"https://avatars.githubusercontent.com/u/211514?v=3","gravatar_id":"","url":"https://api.github.com/users/ahocevar","html_url":"https://github.com/ahocevar","followers_url":"https://api.github.com/users/ahocevar/followers","following_url":"https://api.github.com/users/ahocevar/following{/other_user}","gists_url":"https://api.github.com/users/ahocevar/gists{/gist_id}","starred_url":"https://api.github.com/users/ahocevar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahocevar/subscriptions","organizations_url":"https://api.github.com/users/ahocevar/orgs","repos_url":"https://api.github.com/users/ahocevar/repos","events_url":"https://api.github.com/users/ahocevar/events{/privacy}","received_events_url":"https://api.github.com/users/ahocevar/received_events","type":"User","site_admin":false},"repo":{"id":4974939,"name":"ol3","full_name":"ahocevar/ol3","owner":{"login":"ahocevar","id":211514,"avatar_url":"https://avatars.githubusercontent.com/u/211514?v=3","gravatar_id":"","url":"https://api.github.com/users/ahocevar","html_url":"https://github.com/ahocevar","followers_url":"https://api.github.com/users/ahocevar/followers","following_url":"https://api.github.com/users/ahocevar/following{/other_user}","gists_url":"https://api.github.com/users/ahocevar/gists{/gist_id}","starred_url":"https://api.github.com/users/ahocevar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahocevar/subscriptions","organizations_url":"https://api.github.com/users/ahocevar/orgs","repos_url":"https://api.github.com/users/ahocevar/repos","events_url":"https://api.github.com/users/ahocevar/events{/privacy}","received_events_url":"https://api.github.com/users/ahocevar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ahocevar/ol3","description":"OpenLayers 3","fork":true,"url":"https://api.github.com/repos/ahocevar/ol3","forks_url":"https://api.github.com/repos/ahocevar/ol3/forks","keys_url":"https://api.github.com/repos/ahocevar/ol3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ahocevar/ol3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ahocevar/ol3/teams","hooks_url":"https://api.github.com/repos/ahocevar/ol3/hooks","issue_events_url":"https://api.github.com/repos/ahocevar/ol3/issues/events{/number}","events_url":"https://api.github.com/repos/ahocevar/ol3/events","assignees_url":"https://api.github.com/repos/ahocevar/ol3/assignees{/user}","branches_url":"https://api.github.com/repos/ahocevar/ol3/branches{/branch}","tags_url":"https://api.github.com/repos/ahocevar/ol3/tags","blobs_url":"https://api.github.com/repos/ahocevar/ol3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ahocevar/ol3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ahocevar/ol3/git/refs{/sha}","trees_url":"https://api.github.com/repos/ahocevar/ol3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ahocevar/ol3/statuses/{sha}","languages_url":"https://api.github.com/repos/ahocevar/ol3/languages","stargazers_url":"https://api.github.com/repos/ahocevar/ol3/stargazers","contributors_url":"https://api.github.com/repos/ahocevar/ol3/contributors","subscribers_url":"https://api.github.com/repos/ahocevar/ol3/subscribers","subscription_url":"https://api.github.com/repos/ahocevar/ol3/subscription","commits_url":"https://api.github.com/repos/ahocevar/ol3/commits{/sha}","git_commits_url":"https://api.github.com/repos/ahocevar/ol3/git/commits{/sha}","comments_url":"https://api.github.com/repos/ahocevar/ol3/comments{/number}","issue_comment_url":"https://api.github.com/repos/ahocevar/ol3/issues/comments{/number}","contents_url":"https://api.github.com/repos/ahocevar/ol3/contents/{+path}","compare_url":"https://api.github.com/repos/ahocevar/ol3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ahocevar/ol3/merges","archive_url":"https://api.github.com/repos/ahocevar/ol3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ahocevar/ol3/downloads","issues_url":"https://api.github.com/repos/ahocevar/ol3/issues{/number}","pulls_url":"https://api.github.com/repos/ahocevar/ol3/pulls{/number}","milestones_url":"https://api.github.com/repos/ahocevar/ol3/milestones{/number}","notifications_url":"https://api.github.com/repos/ahocevar/ol3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ahocevar/ol3/labels{/name}","releases_url":"https://api.github.com/repos/ahocevar/ol3/releases{/id}","created_at":"2012-07-10T14:11:39Z","updated_at":"2015-04-21T14:20:28Z","pushed_at":"2015-10-25T09:40:27Z","git_url":"git://github.com/ahocevar/ol3.git","ssh_url":"git@github.com:ahocevar/ol3.git","clone_url":"https://github.com/ahocevar/ol3.git","svn_url":"https://github.com/ahocevar/ol3","homepage":null,"size":57064,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"openlayers:master","ref":"master","sha":"eb174f7a82e94f3817bc448d245739fe67492d40","user":{"login":"openlayers","id":240579,"avatar_url":"https://avatars.githubusercontent.com/u/240579?v=3","gravatar_id":"","url":"https://api.github.com/users/openlayers","html_url":"https://github.com/openlayers","followers_url":"https://api.github.com/users/openlayers/followers","following_url":"https://api.github.com/users/openlayers/following{/other_user}","gists_url":"https://api.github.com/users/openlayers/gists{/gist_id}","starred_url":"https://api.github.com/users/openlayers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openlayers/subscriptions","organizations_url":"https://api.github.com/users/openlayers/orgs","repos_url":"https://api.github.com/users/openlayers/repos","events_url":"https://api.github.com/users/openlayers/events{/privacy}","received_events_url":"https://api.github.com/users/openlayers/received_events","type":"Organization","site_admin":false},"repo":{"id":4723248,"name":"ol3","full_name":"openlayers/ol3","owner":{"login":"openlayers","id":240579,"avatar_url":"https://avatars.githubusercontent.com/u/240579?v=3","gravatar_id":"","url":"https://api.github.com/users/openlayers","html_url":"https://github.com/openlayers","followers_url":"https://api.github.com/users/openlayers/followers","following_url":"https://api.github.com/users/openlayers/following{/other_user}","gists_url":"https://api.github.com/users/openlayers/gists{/gist_id}","starred_url":"https://api.github.com/users/openlayers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openlayers/subscriptions","organizations_url":"https://api.github.com/users/openlayers/orgs","repos_url":"https://api.github.com/users/openlayers/repos","events_url":"https://api.github.com/users/openlayers/events{/privacy}","received_events_url":"https://api.github.com/users/openlayers/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openlayers/ol3","description":"OpenLayers 3","fork":false,"url":"https://api.github.com/repos/openlayers/ol3","forks_url":"https://api.github.com/repos/openlayers/ol3/forks","keys_url":"https://api.github.com/repos/openlayers/ol3/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openlayers/ol3/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openlayers/ol3/teams","hooks_url":"https://api.github.com/repos/openlayers/ol3/hooks","issue_events_url":"https://api.github.com/repos/openlayers/ol3/issues/events{/number}","events_url":"https://api.github.com/repos/openlayers/ol3/events","assignees_url":"https://api.github.com/repos/openlayers/ol3/assignees{/user}","branches_url":"https://api.github.com/repos/openlayers/ol3/branches{/branch}","tags_url":"https://api.github.com/repos/openlayers/ol3/tags","blobs_url":"https://api.github.com/repos/openlayers/ol3/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openlayers/ol3/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openlayers/ol3/git/refs{/sha}","trees_url":"https://api.github.com/repos/openlayers/ol3/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openlayers/ol3/statuses/{sha}","languages_url":"https://api.github.com/repos/openlayers/ol3/languages","stargazers_url":"https://api.github.com/repos/openlayers/ol3/stargazers","contributors_url":"https://api.github.com/repos/openlayers/ol3/contributors","subscribers_url":"https://api.github.com/repos/openlayers/ol3/subscribers","subscription_url":"https://api.github.com/repos/openlayers/ol3/subscription","commits_url":"https://api.github.com/repos/openlayers/ol3/commits{/sha}","git_commits_url":"https://api.github.com/repos/openlayers/ol3/git/commits{/sha}","comments_url":"https://api.github.com/repos/openlayers/ol3/comments{/number}","issue_comment_url":"https://api.github.com/repos/openlayers/ol3/issues/comments{/number}","contents_url":"https://api.github.com/repos/openlayers/ol3/contents/{+path}","compare_url":"https://api.github.com/repos/openlayers/ol3/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openlayers/ol3/merges","archive_url":"https://api.github.com/repos/openlayers/ol3/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openlayers/ol3/downloads","issues_url":"https://api.github.com/repos/openlayers/ol3/issues{/number}","pulls_url":"https://api.github.com/repos/openlayers/ol3/pulls{/number}","milestones_url":"https://api.github.com/repos/openlayers/ol3/milestones{/number}","notifications_url":"https://api.github.com/repos/openlayers/ol3/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openlayers/ol3/labels{/name}","releases_url":"https://api.github.com/repos/openlayers/ol3/releases{/id}","created_at":"2012-06-20T06:53:59Z","updated_at":"2015-10-27T11:14:47Z","pushed_at":"2015-10-27T07:29:37Z","git_url":"git://github.com/openlayers/ol3.git","ssh_url":"git@github.com:openlayers/ol3.git","clone_url":"https://github.com/openlayers/ol3.git","svn_url":"https://github.com/openlayers/ol3","homepage":"http://openlayers.org","size":102831,"stargazers_count":1447,"watchers_count":1447,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":826,"mirror_url":null,"open_issues_count":376,"forks":826,"open_issues":376,"watchers":1447,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openlayers/ol3/pulls/4219"},"html":{"href":"https://github.com/openlayers/ol3/pull/4219"},"issue":{"href":"https://api.github.com/repos/openlayers/ol3/issues/4219"},"comments":{"href":"https://api.github.com/repos/openlayers/ol3/issues/4219/comments"},"review_comments":{"href":"https://api.github.com/repos/openlayers/ol3/pulls/4219/comments"},"review_comment":{"href":"https://api.github.com/repos/openlayers/ol3/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openlayers/ol3/pulls/4219/commits"},"statuses":{"href":"https://api.github.com/repos/openlayers/ol3/statuses/1895695cc09ca9cbe2339e71d6778eb2b7db6843"}}}}