首页 > 解决方案 > 如何使热图可点击?

问题描述

我在下面附上了我用来尝试生成可点击热图的代码。实际的热图已生成,但我无法生成点击事件。

这是我的代码:

const centerLocation = new google.maps.LatLng(
  Number(28.555040),
  Number(77.241920)
);
const mapProp = {
  center: centerLocation,
  zoom: 12,
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  clickableIcons: true
};
this.map = new google.maps.Map(this.gmapElement.nativeElement, mapProp);
const location = new google.maps.LatLng(
  Number(28.555040),
  Number(77.241920)
);

for (let i = 0; i < userData.length; i++) {
  this.marker = new google.maps.Marker({
    position: new google.maps.LatLng(+userData[i][1], +userData[i][2]),
    map: this.map,
    icon: this.userimage,
    title: userData[i][0]
  });
  // tslint:disable-next-line:no-shadowed-variable
  google.maps.event.addListener(this.marker, 'click', (function (marker, i) {
    return function () {
      infowindow.setContent('<a href="#">' + userData[i][0] + '</a>');
      infowindow.open(this.map, this);
    };
  })(this.marker, i));

}
const infowindow = new google.maps.InfoWindow();
for (let i = 0; i < eventData.length; i++) {
  this.marker = new google.maps.Marker({
    position: new google.maps.LatLng(+eventData[i][1], +eventData[i][2]),
    map: this.map,
    icon: this.image,
    title: eventData[i][0]
  });


  // tslint:disable-next-line:no-shadowed-variable
  google.maps.event.addListener(this.marker, 'click', (function (marker, i) {
    return function () {
      infowindow.setContent('<a href="#">' + eventData[i][0] + '</a>');
      infowindow.open(this.map, this);
    };
  })(this.marker, i));
}

// console.warn(location);

this.marker.setPosition(location);
this.heatmap = new google.maps.visualization.HeatmapLayer({
  data: heatmapData,
  dissipating: true,
  radius: 50
});

this.heatmap.setMap(this.map);

// For heatmap color
const gradient = [
  'rgba(0, 255, 255, 0)',
  'rgba(0, 255, 255, 1)',
  'rgba(0, 191, 255, 1)',
  'rgba(0, 127, 255, 1)',
  'rgba(0, 63, 255, 1)',
  'rgba(0, 0, 255, 1)',
  'rgba(0, 0, 223, 1)',
  'rgba(0, 0, 191, 1)',
  'rgba(0, 0, 159, 1)',
  'rgba(0, 0, 127, 1)',
  'rgba(63, 0, 91, 1)',
  'rgba(127, 0, 63, 1)',
  'rgba(191, 0, 31, 1)',
  'rgba(255, 0, 0, 1)'
];
this.heatmap.set('gradient', gradient);
// For heatmap color

this.heatmap.set('opacity', 0.6);

标签: heatmapclickable

解决方案


如果“可点击”是指交互式,则可能需要查看提供该特定实用程序的复杂热图。支持文档可在此处找到。可以在此页面上找到可能的交互级别的示例。

使用以下方法之一下载包...

最近(您必须使用 force = TRUE):

library(devtools)
install_github("jokergoo/ComplexHeatmap", force = TRUE)
library(ComplexHeatmap)

稳定的:

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("ComplexHeatmap", version = "3.8")

或者,您可能想看看使用iheatmapr,尽管我对此知之甚少。由于它的设计具有交互性,因此它可能对您有用。这是《开源软件杂志》中对其进行描述的方式。

R 中有很棒的工具可用于创建简单的交互式热图(Galili 2016、Cheng 和 Galili (2016))或创建静态复杂热图(Gu、Eils 和 Schlesner 2016)。但是,没有工具可以帮助创建复杂的交互式热图。iheatmapr 包填补了这一空白,允许使用绘图库创建高度可定制、交互式、复杂的热图(Sievert 等人,2016 年)。生成的交互式可视化可以轻松地合并到可重现的 R Markdown 报告中,以便与合作者共享


推荐阅读