gpt4 book ai didi

javascript - Leaflet 中的 Circle getBounds() 方法失败

转载 作者:行者123 更新时间:2023-12-05 04:55:07 26 4
gpt4 key购买 nike

我有:

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 上调用 getBounds() 失败了:

const bounds = circle.getBounds();

它在 Circle.js 中的 getBounds 函数内部失败,这是 Leaflet 代码,
Leaflet 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)));
}

尝试访问 this._map.layerPointToLatLng 失败
我得到的错误是 this._map 未定义
有什么想法吗?

============================================= ====

请注意:
我还定义了一个多边形,并在多边形上调用 getBounds() 可以顺利通过并正常工作,在 map 上正确显示。
=> 只有 Circle.getBounds() 失败了

最佳答案

在 map 上添加centerzoom

const map = L.map("map", {center:[47.6652642, -122.3161248], zoom: 16 ,preferCanvas: true});

关于javascript - Leaflet 中的 Circle getBounds() 方法失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65580408/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com