为数百万个点生成热图图层

时间:2018-05-15 07:08:13

标签: javascript php google-maps heatmap google-fusion-tables

我使用Google地图中的热图图层来显示热图,但是,我现在有太多的点并且它停止工作,因为浏览器无法再处理它了。我发现它们提供了Fusion Tables,但它们也受到限制:到100k行,这太低了。我需要渲染数百万的热图或者甚至更多的点。如果我的服务器可以有一些PHP脚本来渲染热图,例如,每天一次,我就会很完美。然后来自js的客户端将只下载预加载的热图(在地图上像谷歌地图,但也可能是不同的地图)。这是否可以通过一些现有技术(可以商业化)?

2 个答案:

答案 0 :(得分:6)

您只需要将点数预先聚类为较少数量的点,然后将这些组传递给Google地图,就好像它是您的原始点一样。因此,如果您有3个附近的值为3,5和10的点,则在坐标的加权平均值处创建一个值为18的点。对所有数据集执行此操作,您将减少3次。将3更改为任何适当的值以进一步减少数据集。

对数据进行分组的简便方法是使用geohashing [1]。这是PHP的很好的geohashing库[2]。您可以在添加时为每个点计算一组不同精度的地理相位,然后使用所需的精度来使用简单的GROUP BY来减少数据集。示例(meta):

use Lvht\GeoHash;

class DataPoint extends ActiveRecord {
    public geo_hash_precision4, geo_hash_precision5, geo_hash_precision6;
    public function save() {
        $this->geo_hash_precision4 = GeoHash::encode($this->lat,$this->lon, 0.0001);
        $this->geo_hash_precision5 = GeoHash::encode($this->lat,$this->lon, 0.00001);
        $this->geo_hash_precision6 = GeoHash::encode($this->lat,$this->lon, 0.000001);
        parent::save();
    }
}

class DataSet extends ActiveQuery {
    /**
     * @param int $p Desired precision
     */
    public function getValues($p = 6) {
        $data = $this->rawQuery("SELECT geo_hash_precision{$p}, SUM(value) FROM {$this->table} GROUP BY geo_hash_precision{$p}");
        // Add bounding box WHERE to reduce set for map size
        foreach ($data as $row) {
            list($minLon, $maxLon, $minLat, $maxLat) = GeoHash::decode($row["geo_hash_precision{$p}"]);
            $row['lat'] = ($maxLat - $minLat) / 2;
            $row['lon'] = ($maxLon - $minLon) / 2;
            unset($row["geo_hash_precision{$p}"]);
        }
    }
}
  1. https://en.wikipedia.org/wiki/Geohash
  2. https://github.com/lvht/geohash

答案 1 :(得分:3)

我使用heatmap.js进行可视化。它真的很快,可以处理很多点。不确定,如果1.5密耳点可以工作。

我能想象的是使用其中一个带有node.js的Javascript解决方案进行预呈现。关于'heatmap js nodejs prerender'的快速谷歌搜索发现了我 https://github.com/substack/node-heatmap和此https://mango-is.com/blog/engineering/pre-render-d3-js-charts-at-server-side/

相关问题