openlayers热力图

直接上代码: 

<!DOCTYPE html>
<html>
<head>
<title>Earthquakes heatmap</title>
<script src="js/jquery.js"></script>
<link rel="js/ol.css" type="text/css">
<script src="js/ol-debug.js"></script>

</head>
<body>
<div class="container-fluid">

<div class="row-fluid">
  <div class="span12">
    <div id="map" class="map"></div>
  </div>
  <div class="span4">
    <form>
      <label>radius size</label>
      <input id="radius" type="range" min="1" max="50" step="1" value="5"/>
      <label>blur size</label>
      <input id="blur" type="range" min="1" max="50" step="1" value="15"/>
    </form>
  </div>
</div>

</div>

js代码 

    //底图
    var raster = new ol.layer.Tile({
      source: new ol.source.Stamen({
        layer: 'toner'
      })
    });
    var map = new ol.Map({
      layers: [raster],
      target: 'map',
      view: new ol.View({
        center: [0, 0],
        zoom: 2
      })
    });
	
    var blur = document.getElementById('blur');
    var radius = document.getElementById('radius');
	blur.addEventListener('input', function() {
        vector.setBlur(parseInt(blur.value, 5));
      });

    radius.addEventListener('input', function() {
	  vector.setRadius(parseInt(radius.value, 10));
    });
	//矢量图层 获取gejson数据
    var vectorSource = new ol.source.Vector({
        features: (new ol.format.GeoJSON()).readFeatures(heatData,{
                                                    dataProjection : 'EPSG:4326',
                                                    featureProjection : 'EPSG:3857'
                                                  })
    });
    // Heatmap热力图             
    var vector = new ol.layer.Heatmap({
      source: vectorSource,
      blur: parseInt(blur.value, 10),
      radius: parseInt(radius.value, 10),
    });
    map.addLayer(vector);

其中的 heatData为热力图geojson数据,如下(为了篇幅删除大部分数据):

var heatData = {
type: "FeatureCollection",
features: [
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 149.042007, -35.349998 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -71.660004, -35.423000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 174.315994, -35.721001 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -64.288002, -36.627998 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -73.055000, -36.826000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 174.761002, -36.903999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 176.154999, -37.700001 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 175.272995, -37.776001 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 145.075104, -37.852959 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 178.016006, -38.659000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -62.274067, -38.725273 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -72.575996, -38.729000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -68.283333, -38.944908 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 174.078003, -39.070000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 176.841003, -39.639999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 175.035004, -39.930000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -62.995026, -40.815025 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 173.248001, -41.297001 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -72.952003, -41.474998 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 171.207001, -42.472000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 147.291000, -42.851002 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -65.099998, -43.299999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 172.638000, -43.523998 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -72.702003, -45.402000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -67.500000, -45.830002 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 170.473999, -45.883999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 168.373001, -46.412998 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -69.228996, -51.625000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -57.848999, -51.701000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -70.934654, -53.166161 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -68.297997, -54.792000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 129.054993, 35.158001 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 23.331871, 42.707264 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -15.598000, 11.864000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 147.147949, -9.497187 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -74.080513, 4.630220 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 12.550000, 55.720001 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 103.831787, 1.268858 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 126.935249, 37.542351 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 16.320986, 48.202118 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -58.449841, -34.622501 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 4.368000, 50.837002 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 96.826080, -12.157536 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -2.973783, 43.282158 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 126.907997, 35.153000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 128.591003, 35.863998 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 100.310997, 5.364000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 165.500000, -21.500000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 166.916702, -0.516700 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 51.448002, 35.773998 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 49.700001, 34.083332 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -5.316700, 35.883301 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 130.933304, 33.950001 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 136.761993, 35.410000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 77.216751, 28.568726 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 35.225220, 31.773746 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 17.934000, 62.633999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 15.638000, 58.402000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 14.178000, 57.785999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 44.233002, 46.266998 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 90.374001, 22.702999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 159.983002, 59.083000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 114.532997, 51.167000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 104.699997, 52.833000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 100.282997, 64.333000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 86.217003, 69.449997 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 69.000000, 61.016998 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 54.667000, 59.016998 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 53.033001, 67.616997 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 44.783001, 43.233002 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 132.899994, 48.817001 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 34.333000, 61.783001 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 32.000000, 63.000000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 23.708000, 70.677002 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -53.553001, 69.244003 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -133.705994, 68.365997 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 64.040001, 67.504997 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -21.895000, 64.135002 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -149.897995, 61.202999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -66.810997, 54.800999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -130.309998, 54.320999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -2.971000, 53.423000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 22.311001, 48.622002 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 100.123001, 46.692001 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -66.068001, 45.264000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 38.960999, 45.036999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 34.104000, 44.962002 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 42.063000, 44.282001 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 71.371002, 42.889000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 109.807999, 40.659000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 23.653000, 37.944000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 39.173000, 21.542999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -96.123001, 19.184999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 42.507999, 18.219999 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -15.978000, 18.084000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 74.843002, 12.869000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -10.797000, 6.301000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 7.068000, 6.215000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 9.454000, 0.391000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 15.299000, -4.321000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 34.743999, -4.817000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -77.044998, -12.082000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -57.283001, -25.406000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -71.332001, -29.959000 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 46.659145, 61.259964 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 174.807220, -41.334835 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 86.599289, 67.493851 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 177.480255, 64.755272 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 17.991455, 59.331165 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 76.280418, 9.970155 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -60.281559, 53.295090 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -2.674783, 42.850159 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ -68.541466, 63.755356 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 51.141739, 43.690456 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 20.412556, 44.799683 ] } }
,
{ "type": "Feature", "properties": { }, "geometry": { type: "Point", "coordinates": [ 19.400000, 42.500000 ] } }

]
};

 

  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值