admin管理员组文章数量:1650774
开发gis系统的时候需要点击一个工程然后打开openlayers地图并且将该工程的线条缩放到合适的区域,对这个问题的解决方案:
1.旋转卡壳法求点集的最小覆盖矩形面积以及周长
https://wwwblogs/mypsq/p/4348243.html
2.计算最小最大经纬度获取外接矩形
https://blog.csdn/lihefei_coder/article/details/104997663
本文介绍一种另类的思路来解决这一方式,openlayer提供了feature的getExtent()来获取一个,但是如何获取多个呢?
(多亏公司的前辈给了提示,还是经验最重要!)方法是将多个feature当作一个feature来计算
代码:
// 计算外接矩形
let str = "http://192.168.0.188:9100/geoserver/szygis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=szygis:pm_spatial_design_pipeline&outputFormat=application%2Fjson&PROPERTYNAME=shape,tenantid,linename,devicemodel,pointlength,depth,projectid,sectionid,jobid,createtime,createuid,color&CQL_FILTER=tenantid=1 and projectid='09f2d433-7772-499b-a7ca-ae9e002471c6'";
this.$http.get(str).then(res=>{
let vectorSource = new VectorSource({
format: new GeoJSON()
})
let readFeatures = vectorSource.getFormat().readFeatures(res)
let cords = [];
for(let i=0;i<readFeatures.length;i++) {
let coordinates = readFeatures[i].getGeometry().getCoordinates()
cords = cords.concat(coordinates);
}
let testFeature = new Feature(
{
geometry: new LineString(cords)
}
);
let extent = testFeature.getGeometry().getExtent()
let ex1 = [extent[0],extent[1]]
let ex2 = [extent[2],extent[3]]
// 将4326转换为3857
ex1 = transform(ex1, 'EPSG:4326', 'EPSG:3857')
ex2 = transform(ex2, 'EPSG:4326', 'EPSG:3857')
extent = [ex1[0],ex1[1],ex2[0],ex2[1]]
storemit('setExtent',extent)
this.$router.push('/openLayersMap')
})
版权声明:本文标题:Openlayer 计算多个feature的外接矩形,并且缩放到合适的视角显示 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1729534163a1205199.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论