leaflet 画扇形

1.生成扇形点的方法

/**
 *
 * @param center 中心点 数组
 * @param radius 半径
 * @param startAngle 起始角度
 * @param endAngle 终止角度
 * @param pointNum 圆弧上点的个数
 */
function getPoints(center, radius, startAngle, endAngle,pointNum) {
    var sin;
    var cos;
    var x;
    var y;
    var angle;
    var points = new Array();
    points.push(center);
    for (var i = 0; i <= pointNum; i++) {
        angle = startAngle + (endAngle - startAngle) * i / pointNum;
        sin = Math.sin(angle * Math.PI / 180);
        cos = Math.cos(angle * Math.PI / 180);
        y = center[0] + radius * cos;
        x = center[1] + radius * sin;
        points[i] = [y, x];
        debugger
    }
    var point = points;
    point.push(center);
    return point;
}
2.调用leaflet中饿多边形生成扇形
var clon = 116.5;
var clat = 38;
var points = getPoints([clat, clon], 2, -90, 0, 500);
points[points.length] = points[0];
L.polygon(points).addTo(leafletMap).bindPopup("一个白痴");

你可能感兴趣的:(gis)