{"action":"created","comment":{"url":"https://api.github.com/repos/geoadmin/web-vib/pulls/comments/117057774","pull_request_review_id":38729777,"id":117057774,"diff_hunk":"@@ -45,6 +45,132 @@ var glapi = {};\n     };\n   };\n \n+  glapi.removeLayerGroup = function(map, groupId) {\n+    var style, groupId, layer, removing, beforeLayerId;\n+    removing = false;\n+    style = map.getStyle();\n+    for (var i=0; i < style.layers.length; i++) {\n+      layer =  style.layers[i];\n+      if (layer.id.indexOf(groupdId != -1)) {\n+        removing = true;\n+        map.removeLayer(layer.id);\n+      } else if (removing) {\n+        beforeLayerId = layer.id;\n+        break;\n+      }\n+    }\n+    return beforeLayerId;\n+  };\n+\n+  glapi.getMapStyle = function() {\n+    return $.getJSON('/static/config/style.json');\n+  };\n+\n+  glapi.getMapGroups = function() {\n+    return $.getJSON('/static/config/groups.json');\n+  };\n+\n+  glapi.getGeoJSON = function(sourceId) {\n+    return $.getJSON('/static/config/geojsons/' + sourceId + '.geojson');\n+  };\n+\n+  glapi.getLayerset = function(sourceId, layersetId) {\n+    return $.getJSON('/static/config/layers/' + sourceId + '/' + layersetId + '.json');\n+  };\n+\n+  glapi.MapLayerGroups = function(map) {\n+    this.map = map;\n+    this.data = null;\n+\n+    var that = this;\n+    var deferred = jQuery.Deferred();\n+    this.onReady = deferred.then;\n+\n+    var mapGroups = glapi.getMapGroups();\n+    mapGroups.then(function(data) {\n+      that.data = data;\n+      deferred.resolve(data);\n+    });\n+\n+    this.getAllLayerGroups = function() {\n+      if (!this.data) {\n+        return;\n+      }\n+      return this.data['groups.swisstopo'];\n+    };\n+\n+    this.getAllLayerGroupOptions = function() {\n+      if (!this.data) {\n+        return;\n+      }\n+      return this.data['group-options'];\n+    };\n+\n+    this.getLayerGroupById = function(layerGroupId) {\n+      var layerGroups = this.getAllLayerGroups();\n+      if (layerGroups) {\n+        return layerGroups[layerGroupId];\n+      }\n+    };\n+\n+    this.getLayerGroupOptionsBySourceId = function(sourceId) {\n+      var groupOptions = this.getAllLayerGroupOptions();\n+      if (groupOptions) {\n+        return groupOptions[sourceId];\n+      }\n+    };\n+\n+    this.addLayerGroup = function(layerGroupId, beforeLayerId) {\n+      var that, group, groupOptions, sourceId, addLayerSet, updateGeoJSONSource;\n+      that = this;\n+      const props = ['minzoom', 'maxzoom', 'layout', 'filter', 'type', 'source', 'paint', 'source-layer', 'sourceLayer'];\n+      addLayerSet = function(sourceId, layersetId){\n+        glapi.getLayerset(sourceId, layersetId).then(function(data) {\n+          var ref, extended, layers, layer, prop;\n+          layers = data.layers;\n+          for (var i=0; i < layers.length; i++) {\n+            //layers[i].id = layerGroupId + '-' + i;\n+            layer = layers[i];\n+            if (layer.ref) {\n+              extended = {};\n+              ref = that.map.getLayer(layer.ref);\n+              for (var j in props) {\n+                prop = props[j];\n+                // user defined ref are no longer supported\n+                if (layer[prop]) {\n+                  extended[prop] = layer[prop];\n+                } else if (ref[prop]) {\n+                  propExt = prop == 'sourceLayer' ? 'source-layer' : prop;\n+                  extended[propExt] = ref[prop];\n+                }\n+              }\n+              extended.id = layer.id;\n+              that.map.addLayer(extended, beforeLayerId);\n+            } else {\n+              that.map.addLayer(layers[i], beforeLayerId);\n+            }\n+          }\n+        });\n+      };\n+      updateGeoJSONSource = function(sourceId) {\n+        glapi.getGeoJSON(sourceId).then(function(data) {\n+          that.map.getSource(sourceId).setData(data);\n+        });\n+      };\n+\n+      group = this.getLayerGroupById(layerGroupId);\n+      for (var i=0; i < group.sources.length; i++) {\n+        sourceId = group.sources[i];\n+        layersetId = group.layerset[i];\n+        groupOptions = this.getLayerGroupOptionsBySourceId(sourceId);\n+        addLayerSet(sourceId, layersetId);","path":"vib/static/glcommon.js","position":122,"original_position":122,"commit_id":"cb2726d13a50425a7bfb308f4621121f0184bb12","original_commit_id":"cb2726d13a50425a7bfb308f4621121f0184bb12","user":{"login":"loicgasser","id":3306154,"avatar_url":"https://avatars2.githubusercontent.com/u/3306154?v=3","gravatar_id":"","url":"https://api.github.com/users/loicgasser","html_url":"https://github.com/loicgasser","followers_url":"https://api.github.com/users/loicgasser/followers","following_url":"https://api.github.com/users/loicgasser/following{/other_user}","gists_url":"https://api.github.com/users/loicgasser/gists{/gist_id}","starred_url":"https://api.github.com/users/loicgasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loicgasser/subscriptions","organizations_url":"https://api.github.com/users/loicgasser/orgs","repos_url":"https://api.github.com/users/loicgasser/repos","events_url":"https://api.github.com/users/loicgasser/events{/privacy}","received_events_url":"https://api.github.com/users/loicgasser/received_events","type":"User","site_admin":false},"body":"We need to ensure that the order is identical to the one in layerset --> use promises and wait for all the configs.","created_at":"2017-05-17T17:02:17Z","updated_at":"2017-05-17T17:02:17Z","html_url":"https://github.com/geoadmin/web-vib/pull/18#discussion_r117057774","pull_request_url":"https://api.github.com/repos/geoadmin/web-vib/pulls/18","_links":{"self":{"href":"https://api.github.com/repos/geoadmin/web-vib/pulls/comments/117057774"},"html":{"href":"https://github.com/geoadmin/web-vib/pull/18#discussion_r117057774"},"pull_request":{"href":"https://api.github.com/repos/geoadmin/web-vib/pulls/18"}}},"pull_request":{"url":"https://api.github.com/repos/geoadmin/web-vib/pulls/18","id":121044661,"html_url":"https://github.com/geoadmin/web-vib/pull/18","diff_url":"https://github.com/geoadmin/web-vib/pull/18.diff","patch_url":"https://github.com/geoadmin/web-vib/pull/18.patch","issue_url":"https://api.github.com/repos/geoadmin/web-vib/issues/18","number":18,"state":"open","locked":false,"title":"[WIP] Introduce mapbox group api","user":{"login":"loicgasser","id":3306154,"avatar_url":"https://avatars2.githubusercontent.com/u/3306154?v=3","gravatar_id":"","url":"https://api.github.com/users/loicgasser","html_url":"https://github.com/loicgasser","followers_url":"https://api.github.com/users/loicgasser/followers","following_url":"https://api.github.com/users/loicgasser/following{/other_user}","gists_url":"https://api.github.com/users/loicgasser/gists{/gist_id}","starred_url":"https://api.github.com/users/loicgasser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loicgasser/subscriptions","organizations_url":"https://api.github.com/users/loicgasser/orgs","repos_url":"https://api.github.com/users/loicgasser/repos","events_url":"https://api.github.com/users/loicgasser/events{/privacy}","received_events_url":"https://api.github.com/users/loicgasser/received_events","type":"User","site_admin":false},"body":"https://github.com/mapbox/mapbox-gl-js/issues/3674\r\n\r\nuser specific refs are no longer supported.","created_at":"2017-05-17T12:26:59Z","updated_at":"2017-05-17T17:02:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5a0c5b6d1b0c0bb308b92934247c63d3477441a6","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/geoadmin/web-vib/pulls/18/commits","review_comments_url":"https://api.github.com/repos/geoadmin/web-vib/pulls/18/comments","review_comment_url":"https://api.github.com/repos/geoadmin/web-vib/pulls/comments{/number}","comments_url":"https://api.github.com/repos/geoadmin/web-vib/issues/18/comments","statuses_url":"https://api.github.com/repos/geoadmin/web-vib/statuses/cb2726d13a50425a7bfb308f4621121f0184bb12","head":{"label":"geoadmin:groupapi","ref":"groupapi","sha":"cb2726d13a50425a7bfb308f4621121f0184bb12","user":{"login":"geoadmin","id":3369793,"avatar_url":"https://avatars1.githubusercontent.com/u/3369793?v=3","gravatar_id":"","url":"https://api.github.com/users/geoadmin","html_url":"https://github.com/geoadmin","followers_url":"https://api.github.com/users/geoadmin/followers","following_url":"https://api.github.com/users/geoadmin/following{/other_user}","gists_url":"https://api.github.com/users/geoadmin/gists{/gist_id}","starred_url":"https://api.github.com/users/geoadmin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geoadmin/subscriptions","organizations_url":"https://api.github.com/users/geoadmin/orgs","repos_url":"https://api.github.com/users/geoadmin/repos","events_url":"https://api.github.com/users/geoadmin/events{/privacy}","received_events_url":"https://api.github.com/users/geoadmin/received_events","type":"Organization","site_admin":false},"repo":{"id":85066976,"name":"web-vib","full_name":"geoadmin/web-vib","owner":{"login":"geoadmin","id":3369793,"avatar_url":"https://avatars1.githubusercontent.com/u/3369793?v=3","gravatar_id":"","url":"https://api.github.com/users/geoadmin","html_url":"https://github.com/geoadmin","followers_url":"https://api.github.com/users/geoadmin/followers","following_url":"https://api.github.com/users/geoadmin/following{/other_user}","gists_url":"https://api.github.com/users/geoadmin/gists{/gist_id}","starred_url":"https://api.github.com/users/geoadmin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geoadmin/subscriptions","organizations_url":"https://api.github.com/users/geoadmin/orgs","repos_url":"https://api.github.com/users/geoadmin/repos","events_url":"https://api.github.com/users/geoadmin/events{/privacy}","received_events_url":"https://api.github.com/users/geoadmin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/geoadmin/web-vib","description":"Small reporting platform for complex vector layers parametrization","fork":false,"url":"https://api.github.com/repos/geoadmin/web-vib","forks_url":"https://api.github.com/repos/geoadmin/web-vib/forks","keys_url":"https://api.github.com/repos/geoadmin/web-vib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/geoadmin/web-vib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/geoadmin/web-vib/teams","hooks_url":"https://api.github.com/repos/geoadmin/web-vib/hooks","issue_events_url":"https://api.github.com/repos/geoadmin/web-vib/issues/events{/number}","events_url":"https://api.github.com/repos/geoadmin/web-vib/events","assignees_url":"https://api.github.com/repos/geoadmin/web-vib/assignees{/user}","branches_url":"https://api.github.com/repos/geoadmin/web-vib/branches{/branch}","tags_url":"https://api.github.com/repos/geoadmin/web-vib/tags","blobs_url":"https://api.github.com/repos/geoadmin/web-vib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/geoadmin/web-vib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/geoadmin/web-vib/git/refs{/sha}","trees_url":"https://api.github.com/repos/geoadmin/web-vib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/geoadmin/web-vib/statuses/{sha}","languages_url":"https://api.github.com/repos/geoadmin/web-vib/languages","stargazers_url":"https://api.github.com/repos/geoadmin/web-vib/stargazers","contributors_url":"https://api.github.com/repos/geoadmin/web-vib/contributors","subscribers_url":"https://api.github.com/repos/geoadmin/web-vib/subscribers","subscription_url":"https://api.github.com/repos/geoadmin/web-vib/subscription","commits_url":"https://api.github.com/repos/geoadmin/web-vib/commits{/sha}","git_commits_url":"https://api.github.com/repos/geoadmin/web-vib/git/commits{/sha}","comments_url":"https://api.github.com/repos/geoadmin/web-vib/comments{/number}","issue_comment_url":"https://api.github.com/repos/geoadmin/web-vib/issues/comments{/number}","contents_url":"https://api.github.com/repos/geoadmin/web-vib/contents/{+path}","compare_url":"https://api.github.com/repos/geoadmin/web-vib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/geoadmin/web-vib/merges","archive_url":"https://api.github.com/repos/geoadmin/web-vib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/geoadmin/web-vib/downloads","issues_url":"https://api.github.com/repos/geoadmin/web-vib/issues{/number}","pulls_url":"https://api.github.com/repos/geoadmin/web-vib/pulls{/number}","milestones_url":"https://api.github.com/repos/geoadmin/web-vib/milestones{/number}","notifications_url":"https://api.github.com/repos/geoadmin/web-vib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/geoadmin/web-vib/labels{/name}","releases_url":"https://api.github.com/repos/geoadmin/web-vib/releases{/id}","deployments_url":"https://api.github.com/repos/geoadmin/web-vib/deployments","created_at":"2017-03-15T11:57:55Z","updated_at":"2017-03-15T15:36:46Z","pushed_at":"2017-05-17T16:59:38Z","git_url":"git://github.com/geoadmin/web-vib.git","ssh_url":"git@github.com:geoadmin/web-vib.git","clone_url":"https://github.com/geoadmin/web-vib.git","svn_url":"https://github.com/geoadmin/web-vib","homepage":null,"size":11278,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"geoadmin:master","ref":"master","sha":"50380dbb08140f344d0d6673097d19f3093d6654","user":{"login":"geoadmin","id":3369793,"avatar_url":"https://avatars1.githubusercontent.com/u/3369793?v=3","gravatar_id":"","url":"https://api.github.com/users/geoadmin","html_url":"https://github.com/geoadmin","followers_url":"https://api.github.com/users/geoadmin/followers","following_url":"https://api.github.com/users/geoadmin/following{/other_user}","gists_url":"https://api.github.com/users/geoadmin/gists{/gist_id}","starred_url":"https://api.github.com/users/geoadmin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geoadmin/subscriptions","organizations_url":"https://api.github.com/users/geoadmin/orgs","repos_url":"https://api.github.com/users/geoadmin/repos","events_url":"https://api.github.com/users/geoadmin/events{/privacy}","received_events_url":"https://api.github.com/users/geoadmin/received_events","type":"Organization","site_admin":false},"repo":{"id":85066976,"name":"web-vib","full_name":"geoadmin/web-vib","owner":{"login":"geoadmin","id":3369793,"avatar_url":"https://avatars1.githubusercontent.com/u/3369793?v=3","gravatar_id":"","url":"https://api.github.com/users/geoadmin","html_url":"https://github.com/geoadmin","followers_url":"https://api.github.com/users/geoadmin/followers","following_url":"https://api.github.com/users/geoadmin/following{/other_user}","gists_url":"https://api.github.com/users/geoadmin/gists{/gist_id}","starred_url":"https://api.github.com/users/geoadmin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geoadmin/subscriptions","organizations_url":"https://api.github.com/users/geoadmin/orgs","repos_url":"https://api.github.com/users/geoadmin/repos","events_url":"https://api.github.com/users/geoadmin/events{/privacy}","received_events_url":"https://api.github.com/users/geoadmin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/geoadmin/web-vib","description":"Small reporting platform for complex vector layers parametrization","fork":false,"url":"https://api.github.com/repos/geoadmin/web-vib","forks_url":"https://api.github.com/repos/geoadmin/web-vib/forks","keys_url":"https://api.github.com/repos/geoadmin/web-vib/keys{/key_id}","collaborators_url":"https://api.github.com/repos/geoadmin/web-vib/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/geoadmin/web-vib/teams","hooks_url":"https://api.github.com/repos/geoadmin/web-vib/hooks","issue_events_url":"https://api.github.com/repos/geoadmin/web-vib/issues/events{/number}","events_url":"https://api.github.com/repos/geoadmin/web-vib/events","assignees_url":"https://api.github.com/repos/geoadmin/web-vib/assignees{/user}","branches_url":"https://api.github.com/repos/geoadmin/web-vib/branches{/branch}","tags_url":"https://api.github.com/repos/geoadmin/web-vib/tags","blobs_url":"https://api.github.com/repos/geoadmin/web-vib/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/geoadmin/web-vib/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/geoadmin/web-vib/git/refs{/sha}","trees_url":"https://api.github.com/repos/geoadmin/web-vib/git/trees{/sha}","statuses_url":"https://api.github.com/repos/geoadmin/web-vib/statuses/{sha}","languages_url":"https://api.github.com/repos/geoadmin/web-vib/languages","stargazers_url":"https://api.github.com/repos/geoadmin/web-vib/stargazers","contributors_url":"https://api.github.com/repos/geoadmin/web-vib/contributors","subscribers_url":"https://api.github.com/repos/geoadmin/web-vib/subscribers","subscription_url":"https://api.github.com/repos/geoadmin/web-vib/subscription","commits_url":"https://api.github.com/repos/geoadmin/web-vib/commits{/sha}","git_commits_url":"https://api.github.com/repos/geoadmin/web-vib/git/commits{/sha}","comments_url":"https://api.github.com/repos/geoadmin/web-vib/comments{/number}","issue_comment_url":"https://api.github.com/repos/geoadmin/web-vib/issues/comments{/number}","contents_url":"https://api.github.com/repos/geoadmin/web-vib/contents/{+path}","compare_url":"https://api.github.com/repos/geoadmin/web-vib/compare/{base}...{head}","merges_url":"https://api.github.com/repos/geoadmin/web-vib/merges","archive_url":"https://api.github.com/repos/geoadmin/web-vib/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/geoadmin/web-vib/downloads","issues_url":"https://api.github.com/repos/geoadmin/web-vib/issues{/number}","pulls_url":"https://api.github.com/repos/geoadmin/web-vib/pulls{/number}","milestones_url":"https://api.github.com/repos/geoadmin/web-vib/milestones{/number}","notifications_url":"https://api.github.com/repos/geoadmin/web-vib/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/geoadmin/web-vib/labels{/name}","releases_url":"https://api.github.com/repos/geoadmin/web-vib/releases{/id}","deployments_url":"https://api.github.com/repos/geoadmin/web-vib/deployments","created_at":"2017-03-15T11:57:55Z","updated_at":"2017-03-15T15:36:46Z","pushed_at":"2017-05-17T16:59:38Z","git_url":"git://github.com/geoadmin/web-vib.git","ssh_url":"git@github.com:geoadmin/web-vib.git","clone_url":"https://github.com/geoadmin/web-vib.git","svn_url":"https://github.com/geoadmin/web-vib","homepage":null,"size":11278,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/geoadmin/web-vib/pulls/18"},"html":{"href":"https://github.com/geoadmin/web-vib/pull/18"},"issue":{"href":"https://api.github.com/repos/geoadmin/web-vib/issues/18"},"comments":{"href":"https://api.github.com/repos/geoadmin/web-vib/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/geoadmin/web-vib/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/geoadmin/web-vib/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/geoadmin/web-vib/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/geoadmin/web-vib/statuses/cb2726d13a50425a7bfb308f4621121f0184bb12"}}}}
{"actor":{"display_login":"loicgasser"}}