我在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 is not a function
,但它不起作用。
我该如何解决?
答案 0 :(得分:1)
我认为这是您可能要实现的目标(除非您在代码的其他位置进行了交互处理)
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});