lit*_*ito 3 jquery google-maps
我正在使用谷歌地图 API 3 和自定义叠加层 (OverlayView) 我有以下代码:
请将鼠标悬停在制造商上以查看工具提示叠加层。
如何精确地将工具提示弹出窗口(黄色窗口)定位在标记附近?我的 X,Y 想法不起作用,因为它与地图相关,因此如果页面的布局是液体,我的解决方案 (X,Y) 就毫无价值。
有什么想法吗?
google.maps.event.addListener(marker, 'mouseover', function(event) {
var pixel = latLngToPixel.getProjection().fromLatLngToContainerPixel(event.latLng);
// Grab marker position
var pos = [ pixel.x, pixel.y ];
// Create the tooltip on a dummy div and store it on the marker
marker.tooltip = $('<div />').qtip({
content: {
text: 'I\'m a replacement tooltip for the regular google one<br />New line<br /> new line<br />Newer line',
title: {
text: 'aaa',
button: true
}
},
position: {
at: "right center",
my: "left center",
target: pos,
container: $('#map_canvas')
},
show: {
ready: true,
event: false,
solo: true
},
hide: {
event: 'mouseleave unfocus'
}
});
});
}
Run Code Online (Sandbox Code Playgroud)
以防万一有人正在寻找答案,我想这样做:
// getting marker x,y offset from left-top map
var pixel = latLngToPixel.getProjection().fromLatLngToContainerPixel(event.latLng);
// then get the map_canvas offset with jquery
var left = $('#map_canvas').offset().left;
var top = $('#map_canvas').offset().top;
// x,y position tooltip
var pos = [ pixel.x + left, pixel.y + top];
Run Code Online (Sandbox Code Playgroud)
我希望它对某人有帮助,这花了我相当长的时间