【问题标题】:OpenLayers 5 get extent coordinatesOpenLayers 5 获取范围坐标
【发布时间】:2019-07-16 14:34:21
【问题描述】:

我正在尝试从 OpenLayers 5 中的范围创建 MultiPolygon

我通过dragBox的地图交互来获取范围

let extent = selectBox.getGeometry().getExtent();
    myService.select(extent);

select(extent){
let topLeft = extent.getTopLeft();
let topRight = extent.getTopRight();
let bottomLeft = extent.getBottomLeft();
let bottomRight = extent.getBottomRight();
};

getter 似乎不起作用,我收到一条错误消息,例如:“extent.getTopLeft 不是函数”

感谢任何帮助

【问题讨论】:

    标签: openlayers openlayers-5 angular-openlayers


    【解决方案1】:

    使用类似的东西

    import * as olExtent from 'ol/extent';
    
    let extent = selectBox.getGeometry().getExtent();
        myService.select(extent);
    
    select(extent){
    let topLeft = olExtent.getTopLeft(extent);
    let topRight = olExtent.getTopRight(extent);
    let bottomLeft = olExtent.getBottomLeft(extent);
    let bottomRight = olExtent.getBottomRight(extent);
    };
    

    【讨论】:

      【解决方案2】:

      我的解决方案...

      import { getBottomLeft, getBottomRight, getTopLeft, getTopRight } from 'ol/extent';
      

      然后在您的事件/功能中使用所选功能:

      const bottomLeft = getBottomLeft(feature.getGeometry().getExtent());
      const bottomRight = getBottomRight(feature.getGeometry().getExtent());
      const topLeft = getTopLeft(feature.getGeometry().getExtent());
      const topRight = getTopRight(feature.getGeometry().getExtent());
      console.log(`bottomLeft = ${ bottomLeft }, bottomRight = ${ bottomRight }, topLeft = ${ topLeft }, topRight = ${ topRight }`);
      

      输出:

      bottomLeft = 961504.4946941067,5919028.71679848, bottomRight = 961504.4946941067,5919028.71679848, topLeft = 961504.4946941067,5919028.71679848, topRight = 961504.4946941067,5919028.71679848
      

      可以参考官方文档:https://openlayers.org/en/latest/apidoc/module-ol_extent.html

      【讨论】:

        猜你喜欢
        • 2018-12-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-08
        • 1970-01-01
        • 2019-08-03
        • 1970-01-01
        相关资源
        最近更新 更多