Angular 将openlayers范围与角度

Angular 将openlayers范围与角度,angular,openlayers,extent,Angular,Openlayers,Extent,我在openlayers 5.1.3中使用angular 6。我尝试组合两个矢量层的范围,然后拟合地图的视图 我做以下几点 import Extent from 'ol/interaction/Extent.js'; olextent: Extent; //then in ngOnInit ngOnInit() { this.olextent = new Extent(); } //then get the extent of the 2 layers let relatedext = t

我在openlayers 5.1.3中使用angular 6。我尝试组合两个矢量层的范围,然后拟合地图的视图

我做以下几点

import Extent from 'ol/interaction/Extent.js';
olextent: Extent;
//then in ngOnInit
ngOnInit() {
  this.olextent = new Extent();
}

//then get the extent of the 2 layers
let relatedext = this.relatedsource.getExtent();
let vectorext = this.vectorsource.getExtent(); 
//then create an empty extent and extent it with the layer extents

ext = this.olextent.createEmpty(); 
ext.extend(this.olextent, relatedext);
ext.extend(this.olextent, vectorext); 

//also create a size and use it with the extent to fit the map view

this.olmap.getView().fit(ext, {size:size, duration: 1500});
这段代码在我看来很正常,但是我得到了
This.olextent.createEmpty不是函数,它不工作


我怎样才能解决这个问题

我认为这就是您可能想要实现的目标(除非您的代码中其他地方有一些交互处理)


您从错误的模块导入。有关
createEmpty
extend
的正确导入和使用,请参见此示例。谢谢,但是如果我从
导入,请从“ol/extent.js”导入区段我收到一条警告
在'ol/extent.js
中找不到“导出”默认值(导入为“extent”)
谢谢Mike,代码简洁明了。它工作了。
import {createEmpty, extend} from 'ol/extent.js';

//then in ngOnInit
ngOnInit() {
  this.olextent = createEmpty();
}

//then get the extent of the 2 layers
let relatedext = this.relatedsource.getExtent();
let vectorext = this.vectorsource.getExtent(); 
//then extent empty extent with the layer extents

extend(this.olextent, relatedext);
extend(this.olextent, vectorext); 

//also create a size and use it with the extent to fit the map view

this.olmap.getView().fit(this.olextent, {size:size, duration: 1500});