나는 가지고있다:
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();
기능 내부에서 실패합니다.
getBounds
에Circle.js리플릿 코드입니다.
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 ()를 호출하면 제대로 전달되고 올바르게 작동하며지도에 올바르게 표시됩니다.
=>그것은
Circle.getBounds()
실패
-
답변 # 1
-
답변 # 2
다음을 사용하여지도 상태를 초기화해야합니다.
setView()
또는 다른 메커니즘. 그만큼layerPointToLatLng
그렇지 않으면 호출이 실패합니다.
더하다
center
과zoom
지도에.