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')
        })

 

本文标签: 多个矩形缩放外接视角