繁体   English   中英

Heatmap.js Leaflet 热图

[英]Heatmap.js Leaflet Heatmap

我正在尝试通过Leafletplugin //www.patrick-wied.at/static/heatmapjs/plugin-leaflet-layer.html 实现 Leaflet 的热图,

但由于某种原因,它似乎忽略了我的“价值”,所以所有数据点都具有相同的颜色

 window.onload = function() {


        var baseLayer = L.tileLayer(
          'http://{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png',{
            attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
            maxZoom: 20
          }
        );

        var cfg = {
          // radius should be small ONLY if scaleRadius is true (or small radius is intended)
          "radius": 0.00007,
          minOpacity: 0.5,
          maxOpacity: 1, 

          // scales the radius based on map zoom
          "scaleRadius": true, 
          // if set to false the heatmap uses the global maximum for colorization
          // if activated: uses the data maximum within the current map boundaries 
          //   (there will always be a red spot with useLocalExtremas true)
          "useLocalExtrema": false,
          // which field name in your data represents the latitude - default "lat"
          latField: 'lat',
          // which field name in your data represents the longitude - default "lng"
          lngField: 'lng',
          // which field name in your data represents the data value - default "value"
          value: 'sig',
          blur:0,

            gradient: {
                // enter n keys between 0 and 1 here
                // for gradient color customization
                '1': 'red',
                '.3': 'yellow',
                '0.9': 'green'
              },

        };


        var heatmapLayer = new HeatmapOverlay(cfg);

        var map = new L.Map('map-canvas', {
          center: new L.LatLng(52.400458, 13.052260),
          zoom: 14,
          layers: [baseLayer, heatmapLayer]
        });

        heatmapLayer.setData(testData);
        // make accessible for debugging
    layer = heatmapLayer;

    };  

我的数据如下所示:

var testData = {
 data:[{lat:52.40486, lng:13.04916, sig:30}, {lat:52.40486, lng:13.04916, sig:70}, {lat:52.40496, lng:13.04894, sig:67}, {lat:52.40496, lng:13.04894, sig:72}, {lat:52.40486, lng:13.04916, sig:74}, {lat:52.40486, lng:13.04916, sig:78}, {lat:52.40493, lng:13.04925, sig:67},]}

你可以在http://www.frief.de/heatmap/test2.html上看到它

如果有人有想法会很棒,我可能只是愚蠢

只是一个快速的建议。

您是否尝试过使用Vladimir Agafonkin(Leaflet.js的作者本人)的Leaflet.Heatmap插件。 似乎未在插件页面上列出。

我认为它更快,可能会是一个更好的解决方案: https : //github.com/Leaflet/Leaflet.heat http://mourner.github.io/simpleheat/demo/

我认为这不起作用,因为您的代码在这里是错误的:

    <div class="wrapper">
      <div class="heatmap" id="map-canvas">

      </div>
    </div>

</script> <----THIS     <script src="src/heatmap.js"></script>
<script src="src/leaflet-heatmap.js"></script>

您说的打开链接是演示页,并检查代码。 修复此孤立的</script标记,然后查看它是否正在运行。

我知道这很旧,但我刚刚遇到了这个问题,所以这就是我解决它的方法。 在“pa7_leaflet_hm.min.js”库中,有一部分用于设置最小值/最大值,并且硬编码为 1 和 0

this._data = []; 
this._max = 1; 
this._min = 0;

显然,这会根据值控制点的强度,并且仅当useLocalExtrema设置为 false 时才会被覆盖,这将始终将其设置为最高可见点。

如果您不希望始终根据可见区域检查最大值,您可以将this._max值更改为更高的值,或者甚至将其设置为配置中的值,以公开它

this._data = []; 
this._max = (this.cfg.max ? this.cfg.max : 1); 
this._min = (this.cfg.min ? this.cfg.min : 0);

这样,您将获得更传统的功能热图

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM