Heatmap.js Leaflet Heatmap

时间:2015-02-06 12:25:30

标签: javascript 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

上查看 如果有人有想法,那将会很棒,mybe我只是愚蠢

2 个答案:

答案 0 :(得分:0)

只是一个快速的建议。

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

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

答案 1 :(得分:0)

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

    <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标记,看看它是否正常运行。