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 { 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 に答える
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 に答える