Javascript Circle getBounds()方法在传单中失败
我有: 但在圆上调用getBounds()失败:Javascript Circle getBounds()方法在传单中失败,javascript,leaflet,Javascript,Leaflet,我有: 但在圆上调用getBounds()失败: const map = L.map("mapid", {preferCanvas: true}); //.... const circle = L.circle([47.6652642, -122.3161248], { color: '#ea647f', fillOpacity: 0.4, radius: 30 }).addTo(map); 它在Circle.js中的函数getBounds中
const map = L.map("mapid", {preferCanvas: true});
//....
const circle = L.circle([47.6652642, -122.3161248], {
color: '#ea647f',
fillOpacity: 0.4,
radius: 30
}).addTo(map);
它在Circle.js中的函数getBounds
中失败,该函数是传单代码,传单getBounds方法代码为:
const bounds = circle.getBounds();
试图访问此。\u map.layerPointToLatLng失败我得到的错误是
这个。_map
未定义有什么想法吗 =================================================== 请注意:
我还定义了一个多边形, 在多边形上调用getBounds()可以很好地通过并正常工作,在地图上正确显示。
=>只有
Circle.getBounds()
失败将居中
和缩放
添加到地图
getBounds: function () {
var half = [this._radius, this._radiusY || this._radius];
return new LatLngBounds(
this._map.layerPointToLatLng(this._point.subtract(half)),
this._map.layerPointToLatLng(this._point.add(half)));
}
您需要使用
setView()
或其他机制初始化映射状态。layerPointToLatling
调用否则将失败。谢谢,这很有帮助,但是-FYI-我使用了center:[0,0]
和zoom:1
因为这并不重要,因为在我收集了所有需要显示的数据之后,我调用了map.fitBounds()
并覆盖了那些初始值!!我不知道该怎么解释,但至少按照您的建议初始化L.map
会使Circle.getBounds()
方法通过。。。
const map = L.map("map", {center:[47.6652642, -122.3161248], zoom: 16 ,preferCanvas: true});