一、样式
<style>
.box-map{width:736px;padding-bottom:9999px;margin-bottom:-9999px}
.gdmap{width:50%;height:400px;float:left;font-size:12px;border-radius:5px;margin:10px;} //地图大小
.button-group {position: fixed;bottom: 20px;right: 20px;font-size: 12px;padding: 10px;}
.button-group .button {height: 28px;line-height: 28px;background-color: #0D9BF2;color: #FFF;border: 0;
outline: none;padding-left: 5px;padding-right: 5px;border-radius: 3px;margin-bottom: 4px;cursor: pointer;}
.button-group .inputtext {height: 26px;line-height: 26px;border: 1px;outline: none;padding-left: 5px;padding-right: 5px;border-radius: 3px;
margin-bottom: 4px;cursor: pointer;}
#tip {background-color: #fff;padding-left: 10px;padding-right: 10px;position: absolute;font-size: 12px;right: 10px;top: 20px;border-radius: 3px;
border: 1px solid #ccc;line-height: 30px;}
.amap-info-content {font-size: 12px;}
#myPageTop {position: absolute;top: 5px;right: 10px;background: #fff none repeat scroll 0 0;border: 1px solid #ccc;margin: 10px auto;
padding:6px;font-family: "Microsoft Yahei", "微软雅黑", "Pinghei";font-size: 14px;}
#myPageTop label {margin: 0 20px 0 0;color: #666666;font-weight: normal;}
#myPageTop input {width: 170px;}
#myPageTop .column2{padding-left: 25px;}
.info {border: solid 1px silver;}
div.info-top {position: relative;background: none repeat scroll 0 0 #F9F9F9;border-bottom: 1px solid #CCC;border-radius: 5px 5px 0 0;}
div.info-top div {display: inline-block;color: #333333;font-size: 14px;font-weight: bold;line-height: 31px;padding: 0 10px;}
div.info-top img {position: absolute;top: 10px;right: 10px;transition-duration: 0.25s;}
div.info-top img:hover {box-shadow: 0px 0px 5px #000;}
div.info-middle {font-size: 12px;padding: 6px;line-height: 20px;}
div.info-bottom {height: 0px;width: 100%;clear: both;text-align: center;}
div.info-bottom img {position: relative;z-index: 104;}
span {margin-left: 0px;font-size: 11px;}
.info-middle img {float: left;margin-right: 6px;}
.cont_list{height:41px; margin-bottom:45px;}
.cont_l{float:left; height: 41px;margin-left:45px;width:100%;}
.cont_l p span{font-size:16px;color:#525050;font-family:微软雅黑; }
.cont_l p{font-size:13px;color:#000000;color:#94312B;}
</style>
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=XXXXXXXXXXXXXX"></script>
<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
<div class="container f-fix">
<div class="box_map f-fr" style="width:100%;">
<div id="container" class="gdmap"></div>
</div><!-- main -->
</div><!-- container -->
<script type="text/javascript">
//地图初始化时,在地图上添加一个marker标记,鼠标点击marker可弹出自定义的信息窗体
var map = new AMap.Map("container", {
resizeEnable: true,
center: [114.022706,22.536871],
zoom: 18
});
addMarker();
//添加marker标记
function addMarker() {
map.clearMap();
var marker = new AMap.Marker({
map: map,
position: [114.022706,22.536871]
});
//鼠标点击marker弹出自定义的信息窗体
AMap.event.addListener(marker, 'click', function() {
infoWindow.open(map, marker.getPosition());
});
}
//实例化信息窗体
var title = '<{$CONFIG.site.sitename}><span style="font-size:11px;color:#F00;"></span>',
content = [];
content.push("地址:<{$CONFIG.site.addr}>");
content.push("电话:<{$CONFIG.site.tel}>");
content.push("<a href='<{$CONFIG.site.host}>' target='_blank'>详细信息</a>");
var infoWindow = new AMap.InfoWindow({
isCustom: true, //使用自定义窗体
content: createInfoWindow(title, content.join("<br/>")),
offset: new AMap.Pixel(16, -45)
});
//构建自定义信息窗体
function createInfoWindow(title, content) {
var info = document.createElement("div");
info.className = "info";
//可以通过下面的方式修改自定义窗体的宽高
//info.style.width = "400px";
// 定义顶部标题
var top = document.createElement("div");
var titleD = document.createElement("div");
var closeX = document.createElement("img");
top.className = "info-top";
titleD.innerHTML = title;
closeX.src = "http://webapi.amap.com/images/close2.gif";
closeX.onclick = closeInfoWindow;
top.appendChild(titleD);
top.appendChild(closeX);
info.appendChild(top);
// 定义中部内容
var middle = document.createElement("div");
middle.className = "info-middle";
middle.style.backgroundColor = 'white';
middle.innerHTML = content;
info.appendChild(middle);
// 定义底部内容
var bottom = document.createElement("div");
bottom.className = "info-bottom";
bottom.style.position = 'relative';
bottom.style.top = '0px';
bottom.style.margin = '0 auto';
var sharp = document.createElement("img");
sharp.src = "http://webapi.amap.com/images/sharp.png";
bottom.appendChild(sharp);
info.appendChild(bottom);
return info;
}
//关闭信息窗体
function closeInfoWindow() {
map.clearInfoWindow();
}
</script>
网友评论