OpenLayers 5获取范围坐标

OpenLayers 5获取范围坐标,openlayers,openlayers-5,angular-openlayers,Openlayers,Openlayers 5,Angular Openlayers,我试图从OpenLayers 5中的一个区段创建一个多多边形 我通过dragBox的地图交互来获取范围 let extent = selectBox.getGeometry().getExtent(); myService.select(extent); select(extent){ let topLeft = extent.getTopLeft(); let topRight = extent.getTopRight(); let bottomLeft = extent.getBo

我试图从OpenLayers 5中的一个区段创建一个多多边形

我通过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不是一个函数”


任何帮助都将不胜感激

请使用类似的方法

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);
};
我的解决方案

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
您可以参考官方文件: