$(document).ready(function() {
init();
$(".exit").click(function() {
$("#waiMap").hide();
});
});
//显示地图
function showMap(obj) {
$("#waiMap").show();
var content = $(obj).find("span").text();
init(content);
var y = $(obj).position().top; //获取元素相对的距离顶端的高度
var y2 = $(obj).offset().top; //获取元素绝对的距离顶端的高度
// var x1 = x - Math.floor($("#waiMap").width() / 2);
// var y1 = y - $("#waiMap").height();
var y1 = y + 70;
// alert(y1 );
$("#waiMap").css({ "top": y1 });
//如果地图绝对高度大于190,则滚动条要向下滚动,以确保地图居中
if (y2 > 190) {
// $(window).scrollTop = y1 - 190;
$('html,body').stop(true, true).delay(0).animate({ scrollTop: y2 - 190 }, "slow");
}
}
//加载地图并初始化
function init(content) {
var point = "";
var showContent="";
if (content == undefined) {
// point = new BMap.Point(106.44064, 29.859629); //重庆
point = new soso.maps.LatLng(29.859629, 106.44064);//纬度在前,经度在后
}
else {
var arrs = content.split(',');
point = new soso.maps.LatLng(arrs[3], arrs[4]);
showContent = '<div id="info"> ';
showContent += ' <ul> ';
showContent += '<li>' + arrs[0] + '</li> ';
showContent += '<li>' + arrs[1] + '</li> ';
showContent += '<li>' + arrs[2] + '</li> ';
showContent += '<li style="margin-top:10px;"><a href=\"http://map.soso.com/?type=nav&tocoord=' + arrs[4] + "," + arrs[3] + "&c=" + arrs[4] + "," + arrs[3] + '&l=13\"' + ' id=\"destion\" target=\"_blank\">公交或驾车去这里</a></li>';
showContent += '</div>';
}
var map = new soso.maps.Map(document.getElementById("allmap"), {
// 地图的中心地理坐标。
center: point,
zoom: 13
});
var maptypectrl = new soso.maps.MapTypeControl({
map: map,
align: soso.maps.ALIGN.BOTTOM_RIGHT
}); //地图类型控件
//地图导航控件
var navControl = new soso.maps.NavigationControl({
align: soso.maps.ALIGN.TOP_LEFT,
margin: new soso.maps.Size(5, 15),
map: map
});
//地图标记
var marker = new soso.maps.Marker({
position: point,
map: map
});
//信息窗口
var infoWin = new soso.maps.InfoWindow({
map: map
});
//
soso.maps.event.addListener(marker, 'click', function() {
infoWin.open();
infoWin.setContent(showContent );
infoWin.setPosition(marker);
infoWin.setZIndex = 100000;
});
}