我试图在twitter引导程序的模式窗口内动态添加地图,但似乎无法工作。在twitter引导模式下动态加载谷歌地图
<!DOCTYPE html>
<html lang="en">
<head>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
#map-canvas {
margin: 0;
padding: 0;
height: 100%;
}
#map-canvas {
width:100%;
height:400px;
}
</style>
</head>
<body >
<h1 class="">Lazy Load Google Map</h1>
<a href="javascript:;" class="view" data-lat="23, 18.33">Launch Map Modal</a>
<div class="modal fade" id="myMapModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<div class="container">
<div class="row">
<div id="map-canvas" class=""></div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<script type='text/javascript' src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type='text/javascript' src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script type='text/javascript' src="http://maps.googleapis.com/maps/api/js?sensor=false&extension=.js&output=embed"></script>
<script type='text/javascript'>
$(".view").click(function(){
var element = $(this);
var map;
var myCenter=new google.maps.LatLng(element.attr("data-lat"));
var marker=new google.maps.Marker({
position:myCenter
});
$('#myMapModal').modal('show');
function initialize() {
var mapProp = {
center:myCenter,
zoom: 14,
draggable: false,
scrollwheel: false,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map=new google.maps.Map(document.getElementById("map-canvas"),mapProp);
marker.setMap(map);
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(contentString);
infowindow.open(map, marker);
});
};
google.maps.event.addDomListener(window, 'load', initialize);
google.maps.event.addDomListener(window, "resize", resizingMap());
$('#myMapModal').on('show.bs.modal', function() {
//Must wait until the render of the modal appear, thats why we use the resizeMap and NOT resizingMap!! ;-)
resizeMap();
})
function resizeMap() {
if(typeof map =="undefined") return;
setTimeout(function(){resizingMap();} , 400);
}
function resizingMap() {
if(typeof map =="undefined") return;
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
}
});
</script>
</body>
</html>
请帮我一把。
看看这个例子:http://www.bootply.com/zhqU9Vhu4k – ZimSystem 2014-10-16 17:33:16
我已经看到它了,事情是我想通过适当的链接从位置列表中动态地加载地图 – 2014-10-17 02:59:15