2017-04-12 19 views
0

我使用angular2-google-map移谷歌地图的中心向右角2

我想转移中心映射到左。

它是什么,现在 What it is righ now

我想要什么 what I want

的HTML

<sebm-google-map [latitude]="center.lat" [longitude]="center.long"> 
    <sebm-google-map-marker *ngFor="let h of mapData?.list" [latitude]="h.lat" [longitude]="h.lang"> 
     <sebm-google-map-info-window [maxWidth]="300"> 
      <strong>{{h.info}}</strong> 
     </sebm-google-map-info-window> 
    </sebm-google-map-marker> 
</sebm-google-map> 

Component.ts文件

@Component({ 
    selector: 'google-map', 
    templateUrl: './google-map.component.html', 
    providers: [MapDataService] 
}) 

export class googleMapComponent implements OnInit, OnChanges { 
    center:any; 
    @Input() mapData: Array<Object>; 
    public constructor(private mapService: MapDataService) { 
     this.center = {}; 
     this.center['lat'] = 28.457523; 
     this.center['long'] = 77.026344; 
    } 
} 

感谢

注:图片是从This question具有相同的问题(但在简单的谷歌地图)

回答

2

简答采取:

ngOnInit() { 
    this.browserWidth = window.innerWidth; 
    this.lngDiff = this.browserWidth * .000335; 
} 

和更新:this.center['long'] = 77.026344;this.center['long'] = 77.026344+this.lngDiff;


龙答:

我必须做同样的事情,我必须弥补地图的权利(但保持它在浏览器的右半部分为中心)。为了做到这一点,我根据3种不同的浏览器宽度1920px, 1280px, and 790px,手动将地图集中在屏幕右侧所需的位置。

地图上的经度差异对于所有三点都不同。对于1920px需要偏离地图的经度为.651280px的差值为.43790px的差值为.26

然后,我做了一些数学计算出所有这三点有什么共同点(我必须解决x)。

1920 * x = .651280 * x = .43790 * x = .26

因为这些点并不完全是我正在寻找的中点,所以我对这些点的结果取平均值。我得到的是.000335这是你乘以浏览器宽度的数字。

您现在可以将this.lngDiff添加到您的经度以将地图偏移到左侧或减去以将地图偏移到右侧。

The result is this