2

尝试使用圆形运行 getBounds() 和 contains() 时出现以下错误。

leaflet.js:7 Uncaught TypeError: Cannot read property 'layerPointToLatLng' of undefined

我可以将它与其他形状一起使用,但圆圈很顽固。我从另一个问题尝试了这个解决方案,但没有成功。

这是我对多边形和矩形形状的代码:

drawnLayers.eachLayer(function(l) {
  if (type == 'circle') {

    // console.log(l.getBounds().contains(layer.getBounds()));

  } else {
    if (l.getBounds().contains(layer.getBounds())) {
      isDonut = true;

      l._latlngs.push(layer.getLatLngs());
      l.redraw();

      $('#map-info').append("<br>New Polygon: <pre>" +
        JSON.stringify(l.getLatLngs(), null, 2) + '</pre>');
    }
  }
});
4

1 回答 1

0
l.getBounds().contains(layer.getBounds())

getBounds()是一种仅适用于传单 0.7.x中的折线/多边形/矩形的方法

从 1.0.0 版开始,它已添加到圆形 - 请参阅传单参考版本

要解决问题,您有 2 个选项

  1. getRadius()如果形状包含其他形状,请对圆形使用其他方法并自行计算
  2. 升级您的传单库

就我个人而言,我会将传单库升级到 1.0.3(我做得非常简单,而且我的项目没有任何兼容性问题)

于 2017-04-25T10:56:26.187 回答