openlayers画扇形

function addSector(coord, dir) {
                //var origi_point = ol.proj.transform(coord, 'EPSG:4326', 'EPSG:3857');//根据经纬度生成圆点
                //调用自定义的写好的生成扇形的 方法          //圆心    半径     边数 弧度 方向角(以y周围0)(可以自定义自己的x周一样)
                //var points = createRegularPolygonCurve(origi_point, 1000000, 100, 30, dir);
                var points = createRegularPolygonCurve(coord, circleRadius, 1, 30, dir);
                var iconFeatureXX = new ol.Feature({
                    geometry: points,
                    population: 5000,
                    //rainfall: 500
                });
                var iconStyleXX = new ol.style.Style({
                    stroke: new ol.style.Stroke({
                        color: 'red',
                        lineDash: [0],
                        width: 2
                    }),
                    fill: new ol.style.Fill({
                        color: 'rgba(0, 0, 255, 0.2)'
                    })
                });
                //iconStyle.getImage().setScale(0.3);
                iconFeatureXX.setStyle(iconStyleXX);
                var vectorSourceXX = new ol.source.Vector({
                    features: [iconFeatureXX]
                });
                var vectorLayerXX = new ol.layer.Vector({
                    source: vectorSourceXX
                });
                map.addLayer(vectorLayerXX);
                //return { feature: iconFeatureXX, layer: vectorLayerXX, sourceVector: vectorSourceXX, point: coord };
            }                                   //圆心    半径  边数  弧度  方向角
            function createRegularPolygonCurve(origin, radius, sides, r, angle) {
                console.log("createRegularPolygonCurve");
                var points = [];
                points.push(origin);
                var angle = angle; //可疑目标方位角度
                var angleStep = 10; //目标区域步长
                var minAngel = angle - angleStep < 0 ? 0 : angle - angleStep; //可疑区域最小角度
                var maxAngel = angle + angleStep > 360 ? 360 : angle + angleStep; //可疑区域的最大角度
                console.log("值是多少-----" + circleRadius);
                for (var j = minAngel; j <= maxAngel; j++) {
                    points.push(destination(origin[0], origin[1], j, 5000));
                }
                console.log(points);
                //var rotation = 360 - r;
                ////var angle = Math.PI * ((1 / sides) - (1 / 2));
                //if (rotation) {
                //    angle += (rotation / 180) * Math.PI;
                //}
                //var rotatedAngle, x, y;
                //var points = [];
                //for (var i = 0; i < sides; ++i) {
                //    var an = i * ((360 - rotation) / 360);
                //    rotatedAngle = angle+ (an * 2 * Math.PI / sides);
                //    x = origin[0] + (radius * Math.cos(rotatedAngle));
                //    y = origin[1] + (radius * Math.sin(rotatedAngle));
                //    points.push([x, y]);
                //}
                //console.log(points);
                //if (rotation != 0) {
                //    points.push(origin);
                //}
                var ring = new ol.geom.LinearRing(points);
                //ring.rotate(Math.PI - ((angel - r / 2) / 180) * Math.PI, origin);
                var poy = new ol.geom.Polygon([points]);
                var a = ring.A;
                poy.A = a;

                return poy;
            }

 

posted @ 2021-05-21 13:49  武向前  阅读(852)  评论(1)    收藏  举报