簡體   English   中英

如何使用Google地圖調整滾動條上的疊加層

[英]How do you adjust overlay layer on scroll with Google Maps

滾動地圖時,我不知道如何從Google Maps獲取疊加層進行自我調整。

我正在做類似的事情

div = document.createElement('div')
div.style.position = 'absolute';
div.borderColor = "red";
this.getPanes().overlayLayer.appendChild(div)

當我滾動地圖時,我會在疊加層中看到地圖原始邊框所在的div的紅色框。 里面的所有內容都很好,但是如果我滾動后該覆蓋層之外還有新內容怎么辦? 如果每次邊界,縮放等發生變化時,我都可以讓覆蓋層進行自我調整,那就太好了。但是我看不出怎么做。

解決此問題的一種方法是調整附加到overlayLayer的任何子項的位置。 我可以在'bounds_changed'或某些此類事件上觸發繪制,然后在draw方法中觸發(假設@div是疊加層的子級):

bounds = @getMap().getBounds()
sw = overlayProjection.fromLatLngToDivPixel(bounds.getSouthWest());
ne = overlayProjection.fromLatLngToDivPixel(bounds.getNorthEast());
@div.style.left = sw.x + 'px';
@div.style.top = ne.y + 'px';
@div.style.width = (ne.x - sw.x) + 'px';
@div.style.height = (sw.y - ne.y) + 'px';

我想這還不錯,但是您必須不斷考慮偏移量,而且看起來還不算干凈。 我想這樣做可以,但是希望有一種更好的方法,使實際的overlayLayer移動以匹配地圖的窗口,而不是固定在初始視口上。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM