var map = new BMap.Map("map"); // 创建地图实例
var point = new BMap.Point(116.404, 39.915); // 创建点坐标
map.centerAndZoom(point, 15); // 初始化地图,设置中心点坐标和地图级别
map.enableScrollWheelZoom(true);
var baidukey='wnDAXmHr845e6o05d37mvpQM';
$("[name='pro']").change(function(){
$("[name='city']>option:gt(0)").remove();
var nowpro=$(this).val();
yiyuanr.forEach(function(e,i){
if(e.pro==nowpro){
if($("[name='city']>option[value='"+e.city+"']").length<1)
$("[name='city']").append("<option value='"+e.city+"'>"+e.city+"</option>");
}
});
});
$("[name='city']").change(function(){
$("[name='yiyuan']>option:gt(0)").remove();
var nowcity=$(this).val();
yiyuanr.forEach(function(e,i){
if(e.city==nowcity){
$("[name='yiyuan']").append("<option value='"+e.titleurl+"'>"+e.title+"</option>");
}
});
jhcopen($("[name='yiyuan']"));
});
$("[name='yiyuan']").change(function(){
var nowyiyuan=$(this).val();
if(nowyiyuan!='0'){
var yydizhi=$(this).find("option:selected").text();
var city=$("[name='city']").val();
//newYiYuan(yydizhi,$("[name='city']").val());
// 创建地址解析器实例
var myGeo = new BMap.Geocoder();
// 将地址解析结果显示在地图上,并调整地图视野
myGeo.getPoint(yydizhi, function(point){
if (point) {
map.centerAndZoom(point, 16);
var marker = new BMap.Marker(point); // 创建标注
map.addOverlay(marker); // 将标注添加到地图中
var opts = {
position : point, // 指定文本标注所在的地理位置
offset : new BMap.Size(30, -30) //设置文本偏移量
}
var label = new BMap.Label(yydizhi, opts); // 创建文本标注对象
label.setStyle({
color : "red",
fontSize : "12px",
height : "20px",
lineHeight : "20px",
fontFamily:"微软雅黑"
});
map.addOverlay(label);
$('label.BMapLabel').css('max-width','5000px');
marker.addEventListener("click",gotourl);
label.addEventListener("click",gotourl);
}else{
alert("您选择地址没有解析到结果!");
}
}, city);
}
});
function gotourl(){
var myurl=$("[name='yiyuan']").val();
window.open(myurl);
}
function jhcopen(elem) {
if (document.createEvent) {
var e = document.createEvent("MouseEvents");
e.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
//e.initMouseEvent("mousedown") //据说不要参知数也可道以
elem[0].dispatchEvent(e);
} else if (element.fireEvent) {
elem[0].fireEvent("onmousedown");
}
}
var yiyuanr=new Array();
//yiyuandata
yiyuanr[1]={pro:'北京市',city:'朝阳区',titleurl:'/map/5.html',title:'北京润美玉之光整形美容门诊部'};
|