引导旋转木马内谷歌地图信息框
Bootstrap carousel inside Google Maps Infobox
我在我的网站上使用Bootstrap,我使用谷歌地图api v3 (javascript)创建了一个带有多个标记的地图。我想在每个标记的信息窗口有一个图像旋转木马。为了能够控制信息窗口的样式,我使用了Infobox插件。
问题是carousel不能在Infobox中工作。请查看这个演示:
http://liveweave.com/MourQl你能帮我修这个吗?JQuery和Infobox之间是否存在某种不兼容?
下面是创建地图的js代码:<script type="text/javascript">
function initialize() {
var locations = [
['<h4>Bondi Beach</h4>', -33.890542, 151.274856],
['<h4>Maroubra Beach</h4>', -33.950198, 151.259302]
];
var content = [
['<div id="carousel-example-1" class="carousel slide" data-ride="carousel" data-interval="false"><div class="carousel-inner"><div class="item active"><img src="http://i60.tinypic.com/25g70g9.jpg" alt=""></div><div class="item"><img src="http://i57.tinypic.com/ddgoia.jpg" alt="..."></div><div class="item"><img src="http://i58.tinypic.com/b3ws5c.jpg" alt="..."></div></div><a class="prev carousel-control" href="#carousel-example-1" role="button" data-slide="prev"></a><a class="next carousel-control" href="#carousel-example-1" role="button" data-slide="next"></a></div>'],
['<div id="carousel-example-2" class="carousel slide" data-ride="carousel" data-interval="false"><div class="carousel-inner"><div class="item active"><img src="http://i60.tinypic.com/25g70g9.jpg" alt=""></div><div class="item"><img src="http://i57.tinypic.com/ddgoia.jpg" alt="..."></div><div class="item"><img src="http://i58.tinypic.com/b3ws5c.jpg" alt="..."></div></div><a class="prev carousel-control" href="#carousel-example-2" role="button" data-slide="prev"></a><a class="next carousel-control" href="#carousel-example-2" role="button" data-slide="next"></a></div>']
];
var map = new google.maps.Map(document.getElementById('map-container'), {
zoom: 10,
center: new google.maps.LatLng(-37.92, 151.25),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false,
panControl: false,
zoomControlOptions: {
position: google.maps.ControlPosition.LEFT_BOTTOM
}
});
var markers = new Array();
//var iconCounter = 0;
var markerImg = 'http://i58.tinypic.com/dr9o5j.png';
var activeMarkerImg = 'http://i58.tinypic.com/w6ph7c.png';
// Add the markers and infowindows to the map
for (var i = 0; i < locations.length; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: markerImg
});
markers.push(marker);
var myOptions = {
content: content[i][0]
,disableAutoPan: false
,maxWidth: 0
,pixelOffset: new google.maps.Size(-125, -250)
,zIndex: null
,boxStyle: {
width: "250px"
}
,closeBoxMargin: "0"
,closeBoxURL: ""
,infoBoxClearance: new google.maps.Size(1, 1)
,isHidden: false
,pane: "floatPane"
,enableEventPropagation: false
};
var ib = new InfoBox(myOptions);
google.maps.event.addListener(marker, "click", function (e) {
jQuery('.carousel').carousel();
ib.open(map, this);
jQuery('.carousel').carousel();
});
google.maps.event.addListener(ib, 'domready', function() {
jQuery('.carousel').carousel();
});
//ib.open(map, marker);
}
google.maps.event.addListener(map, 'click', function() {ib.close();});
function AutoCenter() {
// Create a new viewpoint bound
var bounds = new google.maps.LatLngBounds();
// Go through each...
$.each(markers, function (index, marker) {
bounds.extend(marker.position);
});
// Fit these bounds to the map
map.fitBounds(bounds);
}
AutoCenter();
}
</script>
<script type="text/javascript">
jQuery(window).on('load', function () {
//map initialize
initialize();
});
</script>
我不确定您是否仍然有这个问题,但是对于其他遇到麻烦的人来说,似乎信息框禁用了子事件。加载信息框后,需要单独添加事件。
infoWindow: function(content, map, marker) {
google.maps.event.addListener(marker, 'click', function() {
// If there is an open infobox on the screen, close it out
if (ib) {
ib.close();
}
ib.setContent($('.unitInfoBox').clone().html());
ib.open(map, marker);
// Once the infobox is fully loaded, add your events here
ib.addListener('domready', function() {
// Set up the carousel for images
$('#unitImageContainer').carousel({
interval: false
});
// Specify what you want the carousel to do when the .carousel-indicator is clicked
$('.carousel-indicators li').click(function() {
$('#unitImageContainer').carousel(parseInt($(this).attr('data-slide-to')));
});
});
});
}
只是一个小的编辑,使工作也旋转箭头:
infoWindow: function(content, map, marker) {
google.maps.event.addListener(marker, 'click', function() {
// If there is an open infobox on the screen, close it out
if (ib) {
ib.close();
}
ib.setContent($('.unitInfoBox').clone().html());
ib.open(map, marker);
// Once the infobox is fully loaded, add your events here
ib.addListener('domready', function() {
// Set up the carousel for images
$('#unitImageContainer').carousel({
interval: false
});
// Specify what you want the carousel to do when the .carousel-indicator is clicked
$('.carousel-indicators li').click(function() {
$('#unitImageContainer').carousel(parseInt($(this).attr('data-slide-to')));
});
// Arrows fix
$('.carousel-control').click(function() {
$('.map-thumbs').carousel($(this).attr('data-slide'));
});
});
});
}
相关文章:
- 谷歌地图点击潜水触发信息窗口
- 将FlowPlayer嵌入谷歌地图信息窗口
- 当我浏览回页面时,谷歌地图信息窗口不会弹出
- 谷歌地图信息窗口Z索引
- 谷歌地图-数据库中的标记只显示最后一行的信息
- 谷歌地图信息窗口为每个标记显示相同的内容
- 为位于路线上的谷歌地图标记(起点和终点)设置一个信息窗口
- 信息窗口谷歌地图点击事件给出错误
- Javascript谷歌地图每个信息窗口
- 更新打开的谷歌地图信息窗口
- 谷歌地图/SQL-添加链接到信息面板中的字段
- 在谷歌地图的信息窗口内点击按钮
- 谷歌地图API-信息窗口显示谷歌位置API信息
- 谷歌地图API-获取信息窗口打开时,点击一个圆圈
- 谷歌地图 API - 指向地点详细信息页面的链接
- 信息寡妇与不同的信息在折线谷歌地图 API v3
- 谷歌地图API:强制地图不处理信息框内的点击
- 如何在谷歌地图中设置多个信息窗口,但使用这种特定的JavaScript方法
- 为标记添加唯一的信息窗口,并更新数据库以存储信息(谷歌地图api)
- 访问大学建筑信息谷歌地图api