Angular 8/Ionic 5/Openlayers 6:Can't以地图为中心



我想将OL映射集中在一个特性上。类属性引用了此功能。

当我点击用于触发居中的按钮时,实际上会调用下面的方法,但地图不会移动。

我尝试过Firefox和Brave,但都没有成功。地图在FF中移动了一次,但我修改了一些内容,无法使其再次工作。

这是我的代码(注释行是我也尝试过的(

centerOnPosition() {
var point: Point = <Point>this.positionFeature.getGeometry();
console.log("Proj:", this.view.getProjection().getCode());
console.log("actual center", this.view.getCenter());
console.log("centering on pos", point.getCoordinates());

this.view.setCenter( point.getCoordinates());
// this.view.centerOn(point.getCoordinates(), this.map.getSize(),  [500, 500]);
// setTimeout(() => {
//   this.map.updateSize();
//   this.map.render();
// }, 1000);
//    this.map.getView().animate({
//     center: point.getCoordinates(),
//     duration: 1000
//  })
// this.map.updateSize();
// this.view.setCenter( fromLonLat( point.getCoordinates() , get("EPSG:3857")));
// this.map.render();
}

这是输出:

Proj: EPSG:3857 
actual center : Array [ 312807.60214986256, 5350017.244833869 ]
centering on pos : [ 6153873.7653989205, -2394513.7334693754 ]

编辑:更多信息。

我怀疑投影坐标不正确。我得到了我想以地理定位为中心的位置:

var geolocation = this.initGeolocation();
geolocation.setTracking(true);

initGeolocation() {
return new Geolocation({
trackingOptions: {
enableHighAccuracy: true,
},
projection: this.view.getProjection(),
});
}

因此,问题似乎是由组件构造函数中的一段代码引发的:如果用户没有经过身份验证,他将通过特定的路由转发到登录页面。(我试图在ngOnInit和ionViewWillEnter中进行此调用,但没有成功(。

我不完全明白问题出在哪里,我想第一次访问主页时的导航更改扰乱了地图构建。。。我很乐意接受一个能给我更多见解的答案。

这里是我现在必须评论的代码行:

if (!this.accountService.isAuthenticated()) {
console.log("not logged !!");
// this.router.navigateByUrl('/menu/login');
}    

最新更新