【问题标题】:Heatmap.js Leaflet HeatmapHeatmap.js 传单热图
【发布时间】:2015-02-06 12:25:29
【问题描述】:

我正在尝试通过 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上看到它

如果有人有想法那就太好了,我可能只是愚蠢

【问题讨论】:

    标签: javascript leaflet heatmap


    【解决方案1】:

    只是一个简短的建议。

    您是否尝试过使用 Vladimir Agafonkin(Leaflet.js 的作者本人)的 Leaflet.Heatmap 插件。插件页面好像没有列出来。

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

    【讨论】:

      【解决方案2】:

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

          <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>
      

      你说的打开链接是一个演示页面并检查代码。修复这个孤立的&lt;/script 标签,看看它现在是否工作。

      【讨论】:

      • 感谢您的建议! “”标签肯定是错误的,但这并没有解决问题。我读过 3 阀门只是点强度,所以不可能根据 Wifi 信号强度给点自己的颜色?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      相关资源
      最近更新 更多