代码如下,当我把显示热力图语句{ heatmapOverlay = new BMapLib.HeatmapOverlay({"radius": 104}); map.addOverlay(heatmapOverlay); heatmapOverlay.setDataSet({data: p4, max: 100}); heatmapOverlay.show(); } 写到函数 show_heat_map();里后调用该函数不显示热力图,但是当我把上面的司机话写入<script> </script>里面(也就是不用函数)时可以显示热力图,请问这是怎么回事?求指教!
{% block page_content %} {% block scripts %} {{ super() }} <script type="text/javascript" src="{{" url_for('static',="" filename="js/jquery.js" )="" }}=""></script> <script type="text/javascript" src="<a href=" http:="" <a="" href="http://api.map.baidu.com" rel="nofollow">api.map.baidu.com="" api?v="2.0&ak="" rel="nofollow">http://api.map.baidu.com/api?v=2.0&ak="></script> {# 热力图 js 文件#} <script type="text/javascript" src="{{" url_for('static',="" filename="js/Heatmap_min.js" )="" }}=""></script>
{% endblock %}
<div id="allmap" style="width: 100%; height: 600px; float: left"></div>
<script>
var map = new BMap.Map("allmap"); // 关闭底图可点动能
map.enableScrollWheelZoom(); // 鼠标滚动缩放
var point = new BMap.Point(117.051534, 36.660632);
map.centerAndZoom(point, 16);
var points = [];
var p4 = [{"lng": 117.035278, "lat": 36.666162, "count": 99}];
$.getJSON($SCRIPT_ROOT + '/jquery/all_loads_nodes', {}, function (data) {
var nodes = data.result['nodes'];
var loads = data.result['loads'];
loads.forEach(function (load) {
var start_id = load[0];
var end_id = load[1];
var start_lng = Number(nodes[start_id]['longitude']);
var start_lat = Number(nodes[start_id]['latitude']);
var end_lng = Number(nodes[end_id]['longitude']);
var end_lat = Number(nodes[end_id]['latitude']);
var k = (start_lat - end_lat) / (start_lng - end_lng);
var step = (start_lng - end_lng) / 10;
var flow = load[4];
for (var i = 0; i <= 2; i++) {
var point = {
"lng": Number((end_lng + i * step).toFixed(6)),
"lat": Number((k * i * step + end_lat).toFixed(6)),
"count": parseInt(flow / 150)
};
points.push(point);
}
});
show_heat_map();
});
function show_heat_map() {
heatmapOverlay = new BMapLib.HeatmapOverlay({"radius": 104});
map.addOverlay(heatmapOverlay);
heatmapOverlay.setDataSet({data: p4, max: 100});
heatmapOverlay.show();
}
</script>
1
maxiaoming OP 问题已经解决,链接如下: https://www.cnblogs.com/hqjma/p/3169556.html
|