该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
点击infoWindw中的button按钮,无效果;
覆盖默认的dom结构html,
body,
#container {
width: 100%;
height: 100%;
margin: 0px;
}
p.my-desc {
margin: 5px 0;
line-height: 150%;
}
//创建地图
var map = new AMap.Map('container', {
zoom: 4
});
//覆盖默认的dom结构
AMapUI.defineTpl("ui/overlay/SimpleInfoWindow/tpl/container.html", [], function() {
return document.getElementById('my-infowin-tpl').innerHTML;
});
AMapUI.loadUI(['overlay/SimpleInfoWindow'], function(SimpleInfoWindow) {
var infoWindow = new SimpleInfoWindow({
infoTitle: '消息',
infoBody:' 呼叫',
//基点指向marker的头部位置
offset: new AMap.Pixel(0, -21)
});
//绑定的infoWindow中的按钮事件
infoWindow.get$InfoBody().on('click', ".mybtn01", function(e) {
alert('Click .mybtn of infoBody');
});
infoWindow.get$InfoTitle().on('click', ".mybtn02", function(e) {
alert('Click .mybtn of infoBody');
});
//绑定的marker事件函数
function openInfoWin(e) {
infoWindow.open(map, e.target.getPosition());
};
function ocloseInfoWin(e) {
infoWindow.close(map,e.target.getPosition());
}
//遍历的四个点
var lnglats=[
[121.355914,31.259884],
[121.583881,31.205281],
[121.561908,31.333226],
[121.754169,31.35551]
];
//遍历所需要的标注点,在地图上标记
for(var i= 0,marker;i
var marker=new AMap.Marker({
position:lnglats[i],
title:i,
map:map
});
//marker标注的事件绑定
marker.on('mouseover',openInfoWin);
marker.on('mouseout',ocloseInfoWin);
}
map.setFitView();
});