1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > Openlayers4.6.5根据坐标点集绘制多边形

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

时间:2018-07-02 17:41:34

相关推荐

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。嗯,后面就简单了。。。。​​​​

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。