简体   繁体   English

如何使用dburles:google-maps流星包显示热图?

[英]How to display a heatmap using dburles:google-maps Meteor package?

UPDATE: Code below is fixed as per accepted answer and is confirmed to be working. 更新:下面的代码已根据接受的答案进行了修复,并被确认可以正常工作。

I'm a bit stuck with Meteor, please help me out. 我对流星有些困惑,请帮帮我。 I've installed the dburles:google-maps package and got the map to show markers just fine. 我已经安装了dburles:google-maps软件包,并让地图可以很好地显示标记。 Then I tried to display a heatmap and it's causing an error, I can't resolve - " Uncaught InvalidValueError: setMap: not an instance of Map(anonymous function) " 然后,我试图显示一个热图,并导致一个错误,但我无法解决-“ Uncaught InvalidValueError:setMap:不是Map(匿名函数)的实例

Console output can be seen here - http://improveit.meteor.com/map 控制台输出可以在这里看到-http: //improveit.meteor.com/map

 Template.map.helpers({ issueMapOptions: function() { // Make sure the maps API has loaded if (GoogleMaps.loaded()) { // Map initialization options return { zoom: 13, center: new google.maps.LatLng(37.774546, -122.433523), mapTypeId: google.maps.MapTypeId.SATELLITE, mapTypeControl: false, panControl: false, streetViewControl: false }; } } }); Template.map.onCreated(function() { // We can use the `ready` callback to interact with the map API once the map is ready. GoogleMaps.ready('issueMap', function(issueMap) { var issueData = [ new google.maps.LatLng(37.782551, -122.445368), new google.maps.LatLng(37.757676, -122.405118), new google.maps.LatLng(37.757039, -122.404346), new google.maps.LatLng(37.756335, -122.403719), new google.maps.LatLng(37.755503, -122.403406), new google.maps.LatLng(37.754665, -122.403242), new google.maps.LatLng(37.753837, -122.403172), new google.maps.LatLng(37.752986, -122.403112), new google.maps.LatLng(37.751266, -122.403355) ]; var issueArray = new google.maps.MVCArray(issueData); var heatMapLayer = new google.maps.visualization.HeatmapLayer({ data: issueArray, radius: 20 }); heatMapLayer.setMap(issueMap.instance); }); }); 
  <template name="map"> <h1>Issue heat map</h1> <p>This map will display issues and their severity</p> <div class="map-container"> {{> googleMap name="issueMap" options=issueMapOptions}} </div> </template> 

Change this line: 更改此行:

heatMapLayer.setMap(issueMap);

to

heatMapLayer.setMap(issueMap.instance);

The setMap method requires a google map instance. setMap方法需要一个Google地图实例。 the callback of .ready does not directly provide this as it also has an options object for extra convenience. .ready的回调不直接提供此回调,因为它还有一个options对象,以提供额外的便利。

I confirmed it works on your site: 我确认它可以在您的网站上运行:

在此处输入图片说明

 Template.map.helpers({ issueMapOptions: function() { // Make sure the maps API has loaded if (GoogleMaps.loaded()) { // Map initialization options return { zoom: 13, center: new google.maps.LatLng(37.774546, -122.433523), mapTypeId: google.maps.MapTypeId.SATELLITE, mapTypeControl: false, panControl: false, streetViewControl: false }; } } }); Template.map.onCreated(function() { // We can use the `ready` callback to interact with the map API once the map is ready. GoogleMaps.ready('issueMap', function(issueMap) { var issueData = [ new google.maps.LatLng(37.782551, -122.445368), new google.maps.LatLng(37.757676, -122.405118), new google.maps.LatLng(37.757039, -122.404346), new google.maps.LatLng(37.756335, -122.403719), new google.maps.LatLng(37.755503, -122.403406), new google.maps.LatLng(37.754665, -122.403242), new google.maps.LatLng(37.753837, -122.403172), new google.maps.LatLng(37.752986, -122.403112), new google.maps.LatLng(37.751266, -122.403355) ]; var issueArray = new google.maps.MVCArray(issueData); var heatMapLayer = new google.maps.visualization.HeatmapLayer({ data: issueArray, radius: 20 }); heatMapLayer.setMap(issueMap.instance); }); }); 
  <template name="map"> <h1>Issue heat map</h1> <p>This map will display issues and their severity</p> <div class="map-container"> {{> googleMap name="issueMap" options=issueMapOptions}} </div> </template> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM