如何使热图可点击?

问题描述 投票:0回答:1

我附上了我的代码,我一直在尝试生成可点击的热图。生成了实际的热图,但我无法生成点击事件。

这是我的代码:

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);
heatmap clickable
1个回答
0
投票

如果通过'clickable'表示交互式,您可能需要查看提供该特定实用程序的complexheatmaps。支持文档可以是found here。可以找到on this page可以达到什么级别的交互性的例子。

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

最近(你必须使用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)。但是,没有工具可以帮助创建复杂的交互式热图。 Theiheatmapr软件包填补了这一空白,使用绘图库创建了高度可定制,交互式,复杂的热图(Sievert等人,2016)。生成的交互式可视化可以轻松地合并到可重现的R Markdown报告中,以便与协作者共享

© www.soinside.com 2019 - 2024. All rights reserved.