Search code examples
javascripttooltipkartograph

edit tooltip on a kartograph map


I'm using kartograph on a map to adapt style/tooltip depending on data, so I follow this showcase : http://kartograph.org/showcase/choropleth/

map.addLayer('layer_0', {
  styles: {
    'stroke-width': 0.7,
    fill: function(d) {
            return color(stars[d["nuts-id"]]?
                         stars[d["nuts-id"]].total_stars:
                         0);
            },
    stroke: function(d) {
              return color(stars[d["nuts-id"]]?
                           stars[d["nuts-id"]].total_stars:
                           0).darker();
    },
  },
  tooltips: function(d) {
              return [d["nuts-id"], stars[d["nuts-id"]]?
                                    stars[d["nuts-id"]].total_stars:
                                    0];
  }
});

The map is good, now I want to edit it.

For the style I did it successfully with :

map.getLayer('layer_0').style('fill', function(d) { ... });
map.getLayer('layer_0').style('stroke', function(d) { ... });

But I don't manage to edit the tooltip function...

I try this solution : https://github.com/kartograph/kartograph.js/wiki/Tooltips but I get a "map.tooltips is not defined" error...


Solution

  • I finally found the correct syntax :

    map.getLayer('layer_0').tooltips(function(d) { ... });