Blogger Information
Blog 175
fans 1
comment 0
visits 386186
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
百度地图JavaScript API
dxp2tq的博客
Original
997 people have browsed it

百度地图JavaScript API注意事项

两种地图点击弹窗的区别:

① 自定义复杂覆盖物(以下方法不能获取pro_point)

//初始化重新地位后项目新地图
var pro_map_new = new BMap.Map("allmap");
var pro_point_new = new BMap.Point(lngCurrent,latCurrent);
pro_map_new.centerAndZoom(pro_point_new,15);
//定位后,生成新地图 全局新地图pro_map_new
window.pro_map_new = pro_map_new;

myCompOverlay.addEventListener("click",function(e){
   openInfo(content,e);
});

function openInfo(content,e){
   var p = e.target;
   var pro_point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
   var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象
   pro_map_new.openInfoWindow(infoWindow,pro_point); //开启信息窗口
}

② 标注(以下方法能获取pro_point)

//初始化重新地位后项目新地图
var pro_map_new = new BMap.Map("allmap");
var pro_point_new = new BMap.Point(lngCurrent,latCurrent);
pro_map_new.centerAndZoom(pro_point_new,15);
//定位后,生成新地图 全局新地图pro_map_new
window.pro_map_new = pro_map_new;

var myIcon = new BMap.Icon("http://www.yantiansf.cn/mapImage/1.gif", new BMap.Size(48,48),{
   anchor:new BMap.Size(13,15),
   imageOffset:new BMap.Size(0,0)
});
var pro_mk_new = new BMap.Marker(pro_point_new,{icon:myIcon});  // 创建标注

pro_mk_new.addEventListener("click",function(e){
   openInfo(content,e);
});

function openInfo(content,e){
   var p = e.target;
   var pro_point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
   var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象
   pro_map_new.openInfoWindow(infoWindow,pro_point); //开启信息窗口
}

总结: 自定义覆盖物不能绑定点击事件

           自定义marker能绑定点击事件

           若要实现自定义覆盖物实现点击,可将marker绑定到自定义覆盖物上。。。(经验之谈)


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post