Google JSAPI: Adding Invisible Data For Marker Geo

2019-09-02 23:29发布

I need to add an "invisible" column, which would be triggered on select.

Something like:

  var data = new google.visualization.DataTable();
  data.addColumn('number', 'Lat'); // Latitude Value
  data.addColumn('number', 'Lon'); // Longitude Value
  data.addColumn('string', 'Name'); // 
  data.addColumn('number', 'Consumer Price Index (CPI)', 'Value'); // 
  data.addColumn('string', 'Invisible'); // 

And later on:

  google.visualization.events.addListener(geomap, 'select', function() {
      var selection = geomap.getSelection()[0];
      window.location = selection[4];
  });

I'm getting Error message while loading the map:

Incompatible data table: Error: Table contains more columns than expected (Expecting 4 columns)

So it looks like DataTable doesn't accept my Invisible column.

Any idea how to fix that?

1条回答
聊天终结者
2楼-- · 2019-09-02 23:58

Although I haven't found the answer to my question, I've found a workaround which doesn't use DataView (data transform could potentially be slow) and therefore, it is probably much faster.

I've created another array with additional data (variable hrefs) in the same order as main DataTable and I do use it in the event as:

google.visualization.events.addListener(chart, 'select', function() {
    var selection = chart.getSelection();
    var row = selection[0].row;
    window.location = hrefs[row];
});

It works at least in Chrome ;-)

查看更多
登录 后发表回答