【问题标题】:Use openlayers extent with angular使用带角度的openlayers范围
【发布时间】:2018-11-20 21:35:06
【问题描述】:

我在 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,但它不起作用。

我该如何解决这个问题?

【问题讨论】:

  • 您从错误的模块导入。有关createEmptyextend 的正确导入和使用,请参阅此示例openlayers.org/en/latest/examples/earthquake-clusters.html
  • 谢谢,但如果我从 import extent from 'ol/extent.js'; 导入,我会收到警告 "export 'default' (imported as 'extent') was not found in 'ol/extent.js

标签: angular openlayers extent


【解决方案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});

【讨论】:

  • 感谢 Mike,代码简洁明了。它奏效了。
猜你喜欢
  • 1970-01-01
  • 2017-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多