angular - 使用带角度的openlayers范围
问题描述
我将 Angular 6 与 openlayers 5.1.3 一起使用。我尝试结合两个矢量图层的范围,然后适合地图的视图。
我执行以下操作
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
它不起作用。
我怎样才能解决这个问题?
解决方案
我认为这就是您可能想要实现的目标(除非您在代码的其他地方进行了一些交互处理)
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});
推荐阅读
- javascript - 我已经在我的三个 js 文件中添加了 GUI 代码,但它没有工作也没有引发任何错误
- java - 在子类中具有方法实现的实用程序类
- tensorflow - 用于训练数据集的 model.fit_generator 错误
- python - subprocess.call nohup & - 不在后台运行进程
- azure-logic-apps - Azure Logic App 在 Azure Api 管理中触发 REST Api
- php - 插入/更新多对多关系时无法让背包传递正确的值
- oracle - 在 Virtualbox 上导入 Oracle VM 失败
- javascript - 在 react-three-fiber 中通过 useFrame 使用外部数据的最佳方式
- r - 如何为R中的缺失值提取向量的索引
- python - 如果表单有其他字段,如何验证 django modelform