Google Maps API V3: Offset panTo() by x pixels

后端 未结 3 1609
感情败类
感情败类 2020-12-08 12:11

I have a some UI elements on the right of my map (sometimes), and I\'d like to offset my panTo() calls (sometimes).

So I figured:

  1. get the original latl
3条回答
  •  没有蜡笔的小新
    2020-12-08 12:16

    Answer by Dean looks a lot cleaner as said in some comments, but was looking a little complicated to me. This single line solution is looking more elegant to me.

    var map = $('#map_canvas').gmap3("get")
    map.panBy(-500,-500); // (x,y)
    

    Set center of map first. Then panyBy will shift the center in (x,y) direction. The more negative x, map will shift right. The more negative y, map will shift down.

提交回复
热议问题