【发布时间】:2017-09-09 11:43:13
【问题描述】:
我正在使用 NodeJS 和 AngularJS 开发一个 Web 应用程序。现在,我正在尝试使用 heatmapjs 和 gmap plugin 放置热图。
我已经用我的 API KEY 将脚本包含在 html 中(我也在使用 Chartjs):
<script src="/node_modules/chart.js/dist/Chart.js"></script>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=MY_APIKEY">
</script>
<script src="/node_modules/heatmap.js/build/heatmap.js"></script>
<script src="gmaps-heatmap.js"></script>
我已将the example 复制到我的角度控制器中:
// don't forget to add gmaps-heatmap.js
var myLatlng = new google.maps.LatLng(25.6586, -80.3568);
// map options,
var myOptions = {
zoom: 3,
center: myLatlng
};
// standard map
var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
// heatmap layer
var heatmap = new HeatmapOverlay(map,
{
// radius should be small ONLY if scaleRadius is true (or small radius is intended)
"radius": 2,
"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": true,
// 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"
valueField: 'count'
}
);
var testData = {
max: 8,
data: [{lat: 24.6408, lng:46.7728, count: 3},{lat: 50.75, lng:-1.55, count: 1}]
};
heatmap.setData(testData);
我把地图放在 HTML 中:
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<i class="fa fa-user" aria-hidden="true"></i> Mapita de calor
</div>
<canvas id="map-canvas"></canvas>
</div>
</div>
控制台没有错误,但没有出现映射到页面,为什么??
【问题讨论】:
-
谁知道呢。请张贴您的代码丹尼尔。或者甚至更好地发布一些代表您的问题的演示
-
@MaximShoustin 现在我已经实现了这篇文章。
标签: javascript angularjs heatmap gmaps.js