Openlayers4.6.5根据坐标点集绘制多边形

废话不多说,直接上代码:

                   

console.info(“坐标位置”+coordinateArr);//arr元素为{lon:xxxx,lat:xxxxx}

var targetArr = new Array();

$.each(coordinateArr,function(index,obj){

//改变一下数据结构

var newArr = new Array();

      newArr.push(obj.lon);

      newArr.push(obj.lat);

     targetArr.push(newArr);

});

if(targetArr.length>0){

     var polygonArr = new Array();

     polygonArr.push(targetArr);

     var myPolygon = new ol.geom.Polygon(polygonArr);//绘制多边形(点集数组结构是[[[xxxx,xxxx],[   xxxx,xxxx],…..]])

//myPolygon.applyTransform(ol.proj.getTransform(‘EPSG:4326’, ‘EPSG:3857’));

var feature = new ol.Feature(myPolygon);

feature.setStyle(lineStyle)

zoneSource.addFeature(feature);

}

​总之就是:polygon封装到Feature –> feature添加到source。嗯,后面就简单了。。。。​​​​

转载自:https://blog.csdn.net/henrystern/article/details/81149015

You may also like...