我正在尝试从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();
};
吸气剂似乎无法正常工作,例如,我收到一条错误消息:“ extent.getTopLeft不是函数”
感谢您的帮助
答案 0 :(得分:0)
使用类似这样的东西
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);
};
答案 1 :(得分:0)
他。我的解决方案...
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