项目需求
1、实现打开地图就能定位到中心显示标注点
2、点击标注显示保利可爱岛的详细信息
3、实现导航功能
<!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%;
}
.custom-input-card {
width: 22rem;
}
.custom-input-card .btn {
margin-right: 1rem;
}
.custom-input-card .btn:last-child {
margin-right: 0;
}
.info-title {
color: white;
font-size: 14px;
background-color: #25A5F7;
line-height: 26px;
padding: 0px 0 0 6px;
font-weight: lighter;
letter-spacing: 1px
}
.info-content {
font: 12px Helvetica, 'Hiragino Sans GB', 'Microsoft Yahei', '微软雅黑', Arial;
padding: 4px;
color: #666666;
line-height: 23px;
}
.info-content img {
float: left;
margin: 3px;
}
.amap-info-combo .keyword-input{
height: 25px;
border-radius: 2px 0 0 2px;
}
</style>
</head>
<body>
<div id="container"></div>
<div class="input-card custom-input-card">
<!-- <div class="input-item">
<input type="button" class="btn" value="信息窗体" onClick="infowindow1.open(map,lnglat)"/>
</div> -->
</div>
<script type="text/javascript"
src="https://webapi.amap.com/maps?v=1.4.14&key=你自己key值&plugin=AMap.AdvancedInfoWindow"></script>
<script type="text/javascript">
//第一步、初始化marker参数,标注出marker地址
var lnglat = [106.469344,29.497171];
var map = new AMap.Map('container', {
resizeEnable: true,
center: lnglat,
zoom: 16
});
var marker = new AMap.Marker({
position: lnglat
});
marker.setMap(map);
/第三步、绑定点击事件
marker.on('click',function(){
infowindow1.open(map,lnglat);
});
//第二步、设置点样式和内容
var content = '<div class="info-title">保利可爱岛</div><div class="info-content">' +
'<img src="img/baoli.jpg">' +
'19年央企品牌积淀,24座城市布局,用心构筑西城浪漫理想国。<br/>' /* +
'<a target="_blank" href = "https://mobile.amap.com/">点击下载高德地图</a></div>' */;
var infowindow1 = new AMap.AdvancedInfoWindow({
content: content,
offset: new AMap.Pixel(0, -30)
});
</script>
</body>
</html>