基础标签和谷歌地图
Foundation tabs and Google Map
我把一个谷歌地图内的基础选项卡,它加载为灰色没有控制。如果我以任何方式调整浏览器的大小,那么地图将正确显示,但我不知道如何让它在选择特定选项卡时刷新/调整地图的大小。非常感谢所有的帮助。
<style>
#propertymap {
width: 100%;
height:480px;
}
</style>
<ul class="tabs" data-tab>
<li class="tab-title active"><a href="#panel1">Pictures</a></li>
<li class="tab-title"><a href="#panel2">Virtual Walkthrough</a></li>
<li class="tab-title"><a href="#panel3">Map</a></li>
</ul>
<div class="tabs-content">
<div class="content active" id="panel1">
<p>Pictures</p>
</div>
<div class="content" id="panel2">
<p>Virtual Walkthrough</p>
</div>
<div class="content" id="panel3">
<div id="propertymap"></div>
<script>
var latitude={tag_latitude}, //the tag is for the business catalyst web app
longitude={tag_longitude};
var marker;
function initMap() {
var map = new google.maps.Map(document.getElementById('propertymap'), {
center: {lat: latitude, lng: longitude},
zoom: 15
});
marker = new google.maps.Marker({
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
position: {lat: latitude, lng: longitude}
});
marker.addListener('click', toggleBounce);
}
function toggleBounce() {
if (marker.getAnimation() !== null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
</script>
<style>
#propertymap {
width: 100%;
height:480px;
}
</style>
<ul class="tabs" data-tab>
<li class="tab-title active"><a href="#panel1">Pictures</a></li>
<li class="tab-title"><a href="#panel2">Virtual Walkthrough</a></li>
<li class="tab-title"><a href="#panel3">Map</a></li>
</ul>
<div class="tabs-content">
<div class="content active" id="panel1">
<p>Pictures</p>
</div>
<div class="content" id="panel2">
<p>Virtual Walkthrough</p>
</div>
<div class="content" id="panel3">
<div id="propertymap"></div>
<script>
var latitude={tag_latitude}, //the tag is for the business catalyst web app
longitude={tag_longitude};
var marker;
function initMap() {
var map = new google.maps.Map(document.getElementById('propertymap'), {
center: {lat: latitude, lng: longitude},
zoom: 15
});
marker = new google.maps.Marker({
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
position: {lat: latitude, lng: longitude}
});
marker.addListener('click', toggleBounce);
}
function toggleBounce() {
if (marker.getAnimation() !== null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
</script>
</div>
</div>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&callback=initMap"></script>
</div>
</div>
http://vprintz.businesscatalyst.com/property-list/4-bay-meadows是它在网站上的显示方式
我以前有同样的问题,我通过添加这段代码来修复它
function initMap() {
var map = new google.maps.Map(document.getElementById('propertymap'), {
center: {lat: latitude, lng: longitude},
zoom: 15
});
marker = new google.maps.Marker({
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
position: {lat: latitude, lng: longitude}
});
marker.addListener('click', toggleBounce);
jQuery('document').ready(function(){
google.maps.event.trigger(map,'resize',{});
});
}
function toggleBounce() {
if (marker.getAnimation() !== null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
,最好将其放在脚本的末尾,但关键是在加载后触发组件上的resize事件,这将由该行完成。
这是我最终采用的解决方案:
<script>
var latitude={tag_latitude}, //the tag is for the business catalyst web app
longitude={tag_longitude};
var marker;
function initMap() {
var map = new google.maps.Map(document.getElementById('propertymap'), {
//change propertymap to your map id
center: {lat: latitude, lng: longitude},
zoom: 15 //set to preferred zoom level
});
marker = new google.maps.Marker({
map: map,
draggable: true,
animation: google.maps.Animation.DROP,
position: {lat: latitude, lng: longitude}
});
marker.addListener('click', toggleBounce); //for marker drop animation, can be removed
jQuery('#panel3').on('toggled', function(){ //change #panel3 to your tab id
var center = new google.maps.LatLng(latitude, longitude);
map.setCenter(center); //must recenter map after tab loads
google.maps.event.trigger(map,'resize',{});
});
}
function toggleBounce() { // for marker drop animation, can be removed
if (marker.getAnimation() !== null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
</script>
这就是我使用Foundation选项卡更改事件的方法:
var map = null;
$('[data-tabs]').on('change.zf.tabs', function () {
// check that user selected Map tab for the first time
// if yes then load and show Google map
// let's assume map is located in Tab#2, thus we need Tab with index of 1
if (!map && $('.tabs-title.is-active').index() == 1) { // change "1" to your tab# + 1
// create your map here
map = new google.maps.Map(document.getElementById('divMap'));
// add map markers and so on...
}
// optional: if you have Foundation equalizer plugin on the page
// then uncomment line below to reInit the plugin
// Foundation.reInit('equalizer');
});
我最近一直有这个问题。它帮助我在点击标签时只启动了一次谷歌地图;
$('#tabWithMap').one('click', function(){
//create map and markers etc.
});
相关文章:
- 当标记太多时,如何在谷歌地图上优化标记与标签
- 谷歌地图没有在标签2中和标签3中正确加载.如何创建刷新选项卡
- 你如何制作一个以具有特定标签的地址为中心的谷歌地图
- 谷歌地图与方向 - 我可以在没有表单标签的情况下做到这一点吗?
- 谷歌地图jquery标签未加载
- 谷歌地图API v3 - 不同缩放级别的不同标记/标签
- 谷歌地图调整大小并在标签系统中居中
- 带有标签的谷歌地图 API v3 标记
- 标记标签未显示 - 谷歌地图
- 谷歌地图JavaScript API在标签打开很长时间后未加载,并有403响应
- 谷歌地图 api javascript 标签未验证
- 谷歌地图地理给出 JSONP 错误意外的令牌:或无效的标签
- 棱角分明的谷歌地图标签覆盖了图标
- 如何格式化谷歌地图标记的标签
- 在GeoJson数据接收到的谷歌地图多边形上贴上标签
- 谷歌地图加载部分点击隐藏标签
- 在谷歌地图脚本标签中放置变量
- 按标签删除谷歌地图标记
- 无法将谷歌地图集成到标签组件中
- 换行不工作在javascript谷歌地图标签