//侧边栏 var d_s = '' ; var d_d = '' ; $('.ok').click(function(){ //d_s = 市名 d_z = 区id d_d = 区名 if(!d_s){ layer.msg('请选择市'); }else if(!d_d){ layer.msg('请选择区'); }else{ map.clearoverlays(); map.centerandzoom(d_d, 13); var status = '1'; $.post('index.php?s=/index/jm_ajax',{city:d_z,status:status},function(data){ for (var i = 0; i < data.list.length; i++) { var point = new bmap.point(data.list[i].longitude,data.list[i].latitude); var scontent = "
" + "" + "

" + data.list[i].address + "

" + "

电话:" + data.list[i].phone + "

" + "" + "
"; var infobox = new bmaplib.infobox(map,scontent,{offset:new bmap.size(0,10),closeiconurl:'public/home/images/v_ion12a.png',align:infobox_at_top}); infobox_a(point,infobox); }; },'json'); } }) var map = new bmap.map("mapcontainer"); // 创建地图实例 map.centerandzoom('温州', 13); // 初始化地图,设置中心点坐标和地图级别 map.addcontrol(new bmap.navigationcontrol()); map.addcontrol(new bmap.scalecontrol()); map.addcontrol(new bmap.overviewmapcontrol()); map.addcontrol(new bmap.maptypecontrol()); //地图主题 changemapstyle('grayscale') function changemapstyle(style){ map.setmapstyle({style:style}); } //地图select 市 $('.adrcity').on('click','.tagadr',function(){ $(this).next().show(); }) $('.adrcity').on('mouseleave','.select',function(){ $(this).hide(); }) $('.adrcity').on('click','.select span',function(){ $(this).addclass('active').siblings().removeclass('active'); $(this).parent().prev().html($(this).text()); $(this).parent().hide(); $('.adrcity').addclass('cheacked'); d_s = $(this).text(); var id = $(this).attr('id'); $.post(address_ajax,{id:id},function(d){ if(d.status == 1 ){ $(".add_1").empty(); var add_1 = "选择区"; $(".add_1").append(add_1); $(".add_2").empty(); for (var s = 0; s < d.list.length; s++) { var add = "" + d.list[s].name +"" $(".add_2").append(add); } } },'json'); }) //区 $('.adrarea').on('click','.tagadr',function(){ var flag=$('.adrcity').hasclass('cheacked'); $('.adrcity').find('.select').hide() console.log(flag) if(flag){ $(this).next().show(); } }) $('.adrarea').on('mouseleave','.select',function(){ $(this).hide(); }) $('.adrarea').on('click','.select span',function(){ $(this).addclass('active').siblings().removeclass('active'); $(this).parent().prev().html($(this).text()); $(this).parent().hide(); d_z = $(this).attr('id'); d_d = $(this).text(); console.log($(this).text()); }) function jm(city){ if(!city){ city = '0' ; } var status = '1' ; $.post('index.php?s=/index/jm_ajax',{city:city,status:status},function(data){ for (var i = 0; i < data.list.length; i++) { var point = new bmap.point(data.list[i].longitude,data.list[i].latitude); var scontent = "
" + "" + "

" + data.list[i].address + "

" + "

电话:" + data.list[i].phone + "

" + "" + "
"; var infobox = new bmaplib.infobox(map,scontent,{offset:new bmap.size(0,10),closeiconurl:'public/home/images/v_ion12a.png',align:infobox_at_top}); infobox_a(point,infobox); }; },'json'); } window.onload=jm(); //加载infobox var infoboxtemp = null; function infobox_a(point,infobox){ var marker = new bmap.marker(point,{icon:myicon}); infobox.enableautopan(); marker.addeventlistener("click", function(){ //打开一个infobox,关闭另一个。只能存在一个 if(infoboxtemp){ infoboxtemp.close(); } infoboxtemp = infobox; infobox.open(marker); }); map.addoverlay(marker); } //鼠标点击事件,e.overlay 判断点击的是地图还是覆盖物 map.addeventlistener("click", function(e){ if(!e.overlay){ infoboxtemp.close(); } }) //更改自定义图标 var myicon = new bmap.icon("public/home/images/tb.png", new bmap.size(24,32),{ anchor:new bmap.size(12,32), //图标中心点 imageoffset:new bmap.size(0,0) }); //加载infowindow function addmarker(point,infowindow){ var marker = new bmap.marker(point,{icon:myicon}); marker.addeventlistener("click", function(){ this.openinfowindow(infowindow); //图片加载完毕重绘infowindow document.getelementbyid('img').onload = function (){ infowindow.redraw(); //防止在网速较慢,图片未加载时,生成的信息框高度比图片的总高度小,导致图片部分被隐藏 } }); map.addoverlay(marker); } //定位模式 $('.mask').on('click','.maskclose',function(){ $('.mask').hide() }) $('.posilist').on('click','.posiitem',function(){ var title = $(this).attr('title'); var add = $(this).attr('add'); var phone = $(this).attr('phone'); $('.title').empty(); $('.add').empty(); $('.phone').empty(); $('.title').html(title); $('.add').html(add); $('.phone').html(phone); map.clearoverlays(); var longitude = $(this).attr('longitude'); var latitude = $(this).attr('latitude'); var point = new bmap.point(longitude,latitude); map.centerandzoom(point, 16); map.panby(527, 230);//中心点偏移多少像素(width,height)为div 宽高的1/2; var marker = new bmap.marker(point,{icon:myicon}); // 创建标注 map.addoverlay(marker); // 将标注添加到地图中 $('.mask').show(); })