1

我正在尝试从 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 不是函数”

任何帮助表示赞赏

4

2 回答 2

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);
};
于 2019-07-16T14:49:41.687 回答
1

我的解决方案...

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

于 2019-07-22T18:50:38.727 回答