|
|
|
|
|
<!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%;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.amap-icon img,
|
|
|
|
|
|
.amap-marker-content img {
|
|
|
|
|
|
width: 25px;
|
|
|
|
|
|
height: 34px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.marker {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: -20px;
|
|
|
|
|
|
right: -118px;
|
|
|
|
|
|
color: #fff;
|
|
|
|
|
|
padding: 4px 10px;
|
|
|
|
|
|
box-shadow: 1px 1px 1px rgba(10, 10, 10, .2);
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
font-family: "";
|
|
|
|
|
|
background-color: #25A5F7;
|
|
|
|
|
|
border-radius: 3px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.input-card {
|
|
|
|
|
|
width: 18rem;
|
|
|
|
|
|
z-index: 170;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.input-card .btn {
|
|
|
|
|
|
margin-right: .8rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.input-card .btn:last-child {
|
|
|
|
|
|
margin-right: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.masn{
|
|
|
|
|
|
width: 120px;
|
|
|
|
|
|
max-height: 90px;
|
|
|
|
|
|
padding: 10px;
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
background: #fff;
|
|
|
|
|
|
line-height: 1.4;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
left: -53px;
|
|
|
|
|
|
top: -51px;
|
|
|
|
|
|
z-index: 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
.ma-title{
|
|
|
|
|
|
height: 20px;
|
|
|
|
|
|
line-height: 20px;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
font-weight: 700;
|
|
|
|
|
|
width: 220px;
|
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
word-break: break-all;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
.ma-desc{
|
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
|
min-height: 40px;
|
|
|
|
|
|
line-height: 20px;
|
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
|
color: #6f6f6f;
|
|
|
|
|
|
}
|
|
|
|
|
|
.masn-img{
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
top: 34px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.amap-info-sharp {
|
|
|
|
|
|
top: 39px;
|
|
|
|
|
|
left: 50%;
|
|
|
|
|
|
margin-left: 5px;
|
|
|
|
|
|
border-left: 8px solid transparent;
|
|
|
|
|
|
border-right: 8px solid transparent;
|
|
|
|
|
|
border-top: 8px solid #fff;
|
|
|
|
|
|
}
|
|
|
|
|
|
.g_ell_1{
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
display: -webkit-box;
|
|
|
|
|
|
-webkit-line-clamp: 1;
|
|
|
|
|
|
-webkit-box-orient: vertical;
|
|
|
|
|
|
word-break: break-all;
|
|
|
|
|
|
}
|
|
|
|
|
|
.g_ell_2{
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
display: -webkit-box;
|
|
|
|
|
|
-webkit-line-clamp: 2;
|
|
|
|
|
|
-webkit-box-orient: vertical;
|
|
|
|
|
|
word-break: break-all;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|
|
|
|
|
|
</head>
|
|
|
|
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
<div id="container"></div>
|
|
|
|
|
|
<script src="https://webapi.amap.com/maps?v=2.0&key=b07c4f869f1abf510e59a94bd50699d8&&plugin=AMap.Scale,AMap.HawkEye,AMap.ToolBar,AMap.ControlBar" type="text/javascript" >
|
|
|
|
|
|
</script>
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
var marker, map;
|
|
|
|
|
|
|
|
|
|
|
|
// 实例化点标记
|
|
|
|
|
|
function addMarker($data) {
|
|
|
|
|
|
if (!marker) {
|
|
|
|
|
|
console.log('指定坐标的map信息:',$data)
|
|
|
|
|
|
map = new AMap.Map("container", {
|
|
|
|
|
|
resizeEnable: true,
|
|
|
|
|
|
center:[Number($data.lng),Number($data.lat)],
|
|
|
|
|
|
zoom: 12
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var scale = new AMap.Scale(),
|
|
|
|
|
|
toolBar = new AMap.ToolBar({
|
|
|
|
|
|
position: {
|
|
|
|
|
|
top: '110px',
|
|
|
|
|
|
right: '40px'
|
|
|
|
|
|
}
|
|
|
|
|
|
}),
|
|
|
|
|
|
controlBar = new AMap.ControlBar({
|
|
|
|
|
|
position: {
|
|
|
|
|
|
top: '10px',
|
|
|
|
|
|
right: '10px',
|
|
|
|
|
|
}
|
|
|
|
|
|
}),
|
|
|
|
|
|
overView = new AMap.HawkEye({
|
|
|
|
|
|
opened: false
|
|
|
|
|
|
});
|
|
|
|
|
|
map.addControl(scale);
|
|
|
|
|
|
// 点标记显示内容,HTML要素字符串
|
|
|
|
|
|
var markerContent = '' +
|
|
|
|
|
|
'<div class="custom-content-marker">' +
|
|
|
|
|
|
' <div class="masn">' +
|
|
|
|
|
|
' <div class="ma-title g_ell_1" title=' + $data.name + '>' + $data.name + '</div>' +
|
|
|
|
|
|
' <div class="ma-desc g_ell_2" title=' + $data.address + '>' + $data.address + '</div>' +
|
|
|
|
|
|
' </div>' +
|
|
|
|
|
|
' <div>' +
|
|
|
|
|
|
' <img class="masn-img" src="//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png" style="width:28px;height:auto;">' +
|
|
|
|
|
|
' </div>' +
|
|
|
|
|
|
' <div class="amap-info-sharp"></div>'
|
|
|
|
|
|
'</div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
marker = new AMap.Marker({
|
|
|
|
|
|
icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-red.png",
|
|
|
|
|
|
position: [Number($data.lng),Number($data.lat)],
|
|
|
|
|
|
zoom: 12,
|
|
|
|
|
|
offset: new AMap.Pixel(-13, -30),
|
|
|
|
|
|
content: markerContent,
|
|
|
|
|
|
});
|
|
|
|
|
|
marker.setMap(map);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
window.addEventListener(
|
|
|
|
|
|
"message",
|
|
|
|
|
|
function (event) {
|
|
|
|
|
|
addMarker(event.data);
|
|
|
|
|
|
},
|
|
|
|
|
|
"*"
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 清除 marker
|
|
|
|
|
|
function clearMarker() {
|
|
|
|
|
|
if (marker) {
|
|
|
|
|
|
marker.setMap(null);
|
|
|
|
|
|
marker = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
|
|
|
|
|
|
|
|
|
</html>
|