[英]How to make infowindows have tabs in Google Map?
How can I make the my infoWindows have tabbed content? 如何使infoWindows具有选项卡式内容? I tried things like:
我尝试过类似的事情:
google.maps.event.addListener(this, "domready", function(){ $("#info").tabs() });
* also tried to use infoWidnwow
, infowindow
, and iw
instead of this
keyword * 还试图用
infoWidnwow
, infowindow
和iw
,而不是this
关键字
and 和
.ready(function(){ $("#info").tabs();});
and 和
.bind('domready', function(){ $("#info").tabs(); });
None of these worked. 这些都不起作用。
Code for creating markers and infowindows: 用于创建标记和信息窗口的代码:
$('#map').gmap(mapOptions).bind('init', function(){
$.post('getmarkers.php', function(json){
var theMarkers = json;
$.each(theMarkers, function(i, element) {
$.each(element, function(object, attributes){
$('#map').gmap('addMarker', {
'position': new google.maps.LatLng(parseFloat(attributes.Lat), parseFloat(attributes.Lng)),
'bounds':true } ).click(function(){
$('#map').gmap('openInfoWindow', { 'content':'<div id="info"><ul><li><a href="#tab1">Tab1</li><li><a href="#tab2">Tab2</li></ul><div id="tab1"><h1>'+attributes.productName+'</h1></div><div id="tab2"><h2 style="color: grey"><h1>'+attributes.productPrice+'</h1></div></div>' }, this);
});
});
});
});
});
Somehow I need to tell this part: 我需要以某种方式告诉这一部分:
$('#map').gmap('openInfoWindow', { 'content':'<div id="info"><ul><li><a href="#tab1">Tab1</li><li><a href="#tab2">Tab2</li></ul><div id="tab1"><h1>'+attributes.productName+'</h1></div><div id="tab2"><h2 style="color: grey"><h1>'+attributes.productPrice+'</h1></div></div>' }, this);
To tab the content
that I pass to openInfoWindow
. 要制表我传递给
openInfoWindow
的content
。
There is a free jquery plugin that takes care of multiple tabs, positioning of each and styling i just found that has an intuitive interface for customization. 我有一个免费的jquery插件,可以处理多个选项卡,每个选项卡的位置和样式,我刚刚发现它们具有直观的自定义界面。 Here is a demo
这是一个演示
https://github.com/googlemaps/js-info-bubble/blob/gh-pages/examples/example.html https://github.com/googlemaps/js-info-bubble/blob/gh-pages/examples/example.html
Remove the first three snippets you posted and use this: 删除您发布的前三个代码片段,并使用此代码:
$('#map').gmap(mapOptions).bind('init', function() {
$.post('getmarkers.php', function(json) {
var theMarkers = json;
$.each(theMarkers, function(i, element) {
$.each(element, function(object, attributes) {
$('#map').gmap('addMarker', {
'position': new google.maps.LatLng(parseFloat(attributes.Lat), parseFloat(attributes.Lng)),
'bounds': true
}).click(function() {
var ts = $.now();
$('#map').gmap('openInfoWindow', {
"<div id='" + ts + "info'>... your tab content ..."
}, this);
$('#' + ts + 'info').tabs();
});
});
});
});
});
I created a unique string and used it to give the div a unique id, then used that to make the tabs. 我创建了一个唯一的字符串,并使用它为div赋予了唯一的ID,然后使用它来制作标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.