1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| var map = new AMap.Map("container", { resizeEnable: true, center: [116.481181, 39.989792], zoom: 16 }); addMarker();
function addMarker() { map.clearMap(); var marker = new AMap.Marker({ map: map, position: [116.481181, 39.989792] }); AMap.event.addListener(marker, 'click', function () { infoWindow.open(map, marker.getPosition()); }); }
var title = '方恒假日酒店<span style="font-size:11px;color:#F00;">价格:318</span>', content = []; content.push("<img src='http://tpc.googlesyndication.com/simgad/5843493769827749134'>地址:北京市朝阳区阜通东大街6号院3号楼东北8.3公里"); content.push("电话:010-64733333"); content.push("<a href='https://ditu.amap.com/detail/B000A8URXB?citycode=110105'>详细信息</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 = "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(); }
|