javascript - 更改缩放时更改 Bing 热图圆圈的半径

标签 javascript bing-maps heatmap

我正在使用 Bing map 和热图。我成功显示了热图。我的问题有两个:

  1. 如果用户双击 map ,它会放大,但我的热图圆圈的半径不会改变。有办法改变吗?

  2. 如果用户选择控件上的+或-来放大或缩小,有没有办法捕获该事件,然后执行我在#1中要求的操作——更改半径的半径热图圆圈?v

这是我的 GetMap() 函数,它最初绘制 map 以及任何其他相关代码:

var map;
var heatmapLayer;

function GetMap(myData) {
  /** If this is the first time the myData will be null so get all data **/

  if(myData == null){
    var myData = [];
    myData = myData.concat(HighRisk);
    myData = myData.concat(Ombuds);
  }
  map = new Microsoft.Maps.Map(document.getElementById("divMap"),
       { credentials: 'BING_MAPS_KEY',
         center: new Microsoft.Maps.Location(36,-40),
         mapTypeId: Microsoft.Maps.MapTypeId.road,
         labelOverlay: Microsoft.Maps.LabelOverlay.visible,
         zoom: 1
        });

  // Register and load the Client Side HeatMap Module
  Microsoft.Maps.registerModule("HeatMapModule", "js/heatmap.js");
  Microsoft.Maps.loadModule("HeatMapModule", { callback: function() {
  Microsoft.Maps.Events.addHandler(map, 'click', displayEventInfo);
    // Once the module is loaded, create a customised heatmap
    // by passing in various options as third parameter
    var myRadius = 400000;  


    heatmapLayer = new HeatMapLayer(
      map,
      myData,
      { intensity: 0.50, // "heat" at centre of each point
        radius: myRadius, // radius of affected area
        unit: "meters", // unit in which radius is measured
        showMapTypeSelector: false,
        colourgradient: {
          0.0: 'green',
          0.5: 'blue',
          0.75: 'orange',
          1.0: 'red'
        }
      });
  }});
  Microsoft.Maps.Location.prototype.multiplier = 50;

}

function displayEventInfo(e) {
      if (e.targetType == "map") {
          var point = new Microsoft.Maps.Point(e.getX(), e.getY());
          var loc = e.target.tryPixelToLocation(point);
          var options = map.getOptions();
          alert(map.getTargetZoom());

      }
  }

最佳答案

将单位选项设置为“像素”。这会将圆圈的大小保持在指定的像素数。您需要将半径设置得更小,例如 40。

关于javascript - 更改缩放时更改 Bing 热图圆圈的半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27029930/

相关文章:

html - 为什么不在信息框中选择元素展开?

javascript - 窗口调整信息的 Angular

javascript - javascript内置split函数的大O

javascript - 可扩展应用程序的 CORS 问题

windows-phone-7 - wp7 应用程序内查看 map 中的方向

matlab - 缩放 MATLAB/Octave 图,以便正确打印所有标签

javascript - 透明文本区域中的光标

c# - UWP MapControl MapPolygon 描边设置不正确

不同比例的 gnuplot 热图

r - 根据未在 x、y、颜色映射/plot_ly 条件文本中使用的辅助子分组,有条件地为热图单元格分配颜色和标签