私は持っています:
const map = L.map("mapid", {preferCanvas: true});
//....
const circle = L.circle([47.6652642, -122.3161248], {
color: '#ea647f',
fillOpacity: 0.4,
radius: 30
}).addTo(map);
しかし、サークルでgetBounds()を呼び出すと失敗します:
const bounds = circle.getBounds();
関数内で失敗します
getBounds
にCircle.jsこれはリーフレットコードです、
リーフレットの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()を呼び出すと、問題なく通過し、正しく機能し、マップに正しく表示されます。
=>それは
Circle.getBounds()
それは失敗します
回答 2 件
マップの状態をで初期化する必要があります
setView()
または他のメカニズム。ザ・layerPointToLatLng
それ以外の場合、呼び出しは失敗します。
追加
center
そしてzoom
地図に。