我正在尝试使用mapbox.js制作经度和纬度选择器,并且需要将此地图放在模态框中,在单击“选择位置”按钮时打开。但是当这个模态框打开时,地图没有完全呈现。
这是我的代码:
这是我的代码:
<div class="modal fade" id="chooseLocation" tabindex="-1" role="dialog" aria-labelledby="chooseLocation" aria-hidden="true">
<div class="Cadd-event-modal" style="width: 600px; margin: 0px auto; margin-top: 10%;">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title Cfont-1">Choose location</h4>
</div>
<div class="modal-body" style="width: 500px; margin: 0px auto;">
<div id='map'></div>
<div class='map-overlay'>
<label for='latitude'>latitude</label><br />
<input type='text' size='5' id='latitude' /><br />
<label for='longitude'>longitude</label><br />
<input type='text' size='5' id='longitude' />
</div>
</div>
<div class="model-footer"></div>
</div>
</div>
脚本
var map = L.mapbox.map('map', 'examples.map-9ijuk24y')
.setView([0, 0], 2);
// get the form inputs we want to update
var latitude = document.getElementById('latitude');
var longitude = document.getElementById('longitude');
var marker = L.marker([0, 0], {
draggable: true
}).addTo(map);
// every time the marker is dragged, update the form
marker.on('dragend', ondragend);
// set the initial values in the form
ondragend();
function ondragend() {
var ll = marker.getLatLng();
latitude.value = ll.lat;
longitude.value = ll.lng;
}
和按钮动作
$('#chooseLocation-btn').click(function(){
$('#chooseLocation').modal('show');
});
$('a[href="#Location"]').on('shown.bs.tab', function(e) {
,而是使用$('#chooseLocation').on('shown.bs.modal', function () {
来使其正常工作。不要忘记使用google.maps.visualRefresh = true;
。 - Ravimallya