在 Leaflet 上,给定中心和半径,我可以轻松创建一个新圆:
// Circle
var radius = 500; // [metres]
var circleLocation = new L.LatLng(centreLat, centreLon);
var circleOptions = {
color: 'red',
fillColor: '#f03',
fillOpacity: 0.5
};
var circle = new L.Circle(circleLocation, radius, circleOptions);
map.addLayer(circle);
Run Code Online (Sandbox Code Playgroud)
上面的圆是创建和绘制的,没有问题,就这样了。
但是,如果我现在想创建并绘制一个包围圆的矩形,则它不起作用。这是我所做的:
// Rectangle
var halfside = radius; // It was 500 metres as reported above
// convert from latlng to a point (<-- I think the problem is here!)
var centre_point = map.latLngToContainerPoint([newCentreLat, newCentreLon]);
// Compute SouthWest and NorthEast points
var sw_point = …Run Code Online (Sandbox Code Playgroud) javascript latitude-longitude leaflet angular-leaflet-directive