console
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>默认样式信息窗体</title>
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
<style>
html, body, #container {
height: 100%;
width: 100%;
}
.content-window-card {
position: relative;
box-shadow: none;
bottom: 0;
left: 0;
width: auto;
padding: 0;
}
.content-window-card p {
height: 2rem;
}
.custom-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: 10px 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: 5px;
font-size: 11px;
}
.info-middle img {
float: left;
margin-right: 6px;
}
</style>
</head>
<body>
<div id="container"></div>
<div class="info">
点击地图上的点标记,打开所添加的自定义信息窗体
</div>
<script type="text/javascript"
src="https://webapi.amap.com/maps?v=1.4.15&key= de4d556bab489ff008b3a0bb78a56a32"></script>
<script type="text/javascript">
var map = new AMap.Map("container", {
resizeEnable: true,
center: [114.309082, 30.599991],
zoom: 16
});
addMarker1();
addMarker2();
function addMarker1() {
var marker1 = new AMap.Marker({
map: map,
position: [114.309082, 30.599991]
});
AMap.event.addListener(marker1, 'click', function () {
infoWindow1.open(map, marker1.getPosition());
});
}
function addMarker2() {
var marker2 = new AMap.Marker({
map: map,
position: [114.304487, 30.597854]
});
AMap.event.addListener(marker2, 'click', function () {
infoWindow2.open(map, marker2.getPosition());
});
}
var title1 = '中国长江三峡集团<span style="font-size:11px;color:#F00;">',
content1 = [];
content1.push("<img src='https://wwjossaliyun.oss-cn-hangzhou.aliyuncs.com/typora-img/20220902155931.jpg'>地址:江岸区六合路1号");
content1.push("入园企业:");
content1.push("企业1<br/>企业2<br/>企业3");
var infoWindow1 = new AMap.InfoWindow({
isCustom: true,
content: createInfoWindow(title1, content1.join("<br/>")),
offset: new AMap.Pixel(16, -45)
});
var title2 = '中国武汉科创园<span style="font-size:11px;color:#F00;">',
content2 = [];
content2.push("<img src='http://tpc.googlesyndication.com/simgad/5843493769827749134'>地址:江岸区中山大道与三阳路交叉口东");
content2.push("入园企业:");
content2.push("企业1<br/>企业2<br/>企业3");
var infoWindow2 = new AMap.InfoWindow({
isCustom: true,
content: createInfoWindow(title2, content2.join("<br/>")),
offset: new AMap.Pixel(16, -45)
});
function createInfoWindow(title, content) {
var info = document.createElement("div");
info.className = "custom-info input-card content-window-card";
var top = document.createElement("div");
var titleD = document.createElement("div");
var closeX = document.createElement("img");
top.className = "info-top";
titleD.innerHTML = title;
closeX.src = "https://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 = "https://webapi.amap.com/images/sharp.png";
bottom.appendChild(sharp);
info.appendChild(bottom);
return info;
}
function closeInfoWindow() {
map.clearInfoWindow();
}
</script>
</body>
</html>