var marker, oDrag = document.getElementById("drag");
// 百度地图API功能
var map = new BMap.Map("allmap"); // 创建Map实例
map.enableScrollWheelZoom(true);
map.addControl(new BMap.ScaleControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT})); // 右下比例尺
map.setDefaultCursor("Default");
var ac = new BMap.Autocomplete( //建立一个自动完成的对象
{"input" : "cityName"
,"location" : map
});
map.addEventListener("click", showInfo);
function showInfo(e){
map.clearOverlays();
marker = new BMap.Marker(new BMap.Point(e.point.lng, e.point.lat)); // 创建标注
map.addOverlay(marker);
}
//获取经纬度
map.addEventListener("click",function(e){
var input = document.getElementById('wd');
var input2 = document.getElementById('jd');
input.value = e.point.lng;
input2.value= e.point.lat;
});
function show() {
map.centerAndZoom('海南', 13); // 初始化地图,设置城市和地图级别。
oDrag.style.display = "block";
}
// $('#ceshiaaa').on('click',function () {
// var aaa = $(this).prop('class');
// console.log(aaa);
// // trIndex = index; //索引
// // console.log(trIndex);
//
// })
// $('#ceshiaaa').click(function () {
//
// })
function peitaoShow(index,idIndex) {
trIndex = index;
if(idIndex > 0) {
trIndex = idIndex;
trNum.push(trIndex);
}
trNum.push(trIndex);
// console.log($(this));
map.centerAndZoom('海南', 13); // 初始化地图,设置城市和地图级别。
oDrag.style.display = "block";
}
function dhide(){
map.clearOverlays();
document.getElementById("lng").value = '';
document.getElementById("lat").value = '';
oDrag.style.display = "none";
}
// 确认添加经纬度
function showMap(){
oDrag.style.display = "none";
var jd=document.getElementById('jd').value;
var wd=document.getElementById('wd').value;
if(wd==""){
document.getElementById('jwd').value="";
}else {
document.getElementById('jwd').value=wd+','+jd;
}
}
//周边配套
function showMapPeitao(){
oDrag.style.display = "none";
var jd=document.getElementById('jd').value;
var wd=document.getElementById('wd').value;
$.each(trNum,function(v,l){
if(l == trIndex){
if(wd==""){
document.getElementById('jwd'+l).value="";
}else {
document.getElementById('jwd'+l).value=jd+','+wd;
}
}
})
}
var local = new BMap.LocalSearch(map, {
renderOptions:{map: map}
});
var cityList = new BMapLib.CityList({
container: 'container',
map: map
});
function theLocation(){ //查找地址
var city = document.getElementById("cityName").value;
if(city != ""){
local.search(city);
}
};
function KeyDown(e){ //回车查找
var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
if (event.keyCode==13){
theLocation()
}
}
ac.addEventListener("onhighlight", function(e) { //鼠标放在下拉列表上的事件
var str = "";
var _value = e.fromitem.value;
var value = "";
if (e.fromitem.index > -1) {
value = _value.province + _value.city + _value.district + _value.street + _value.business;
}
str = "FromItem
index = " + e.fromitem.index + "
value = " + value;
value = "";
if (e.toitem.index > -1) {
_value = e.toitem.value;
value = _value.province + _value.city + _value.district + _value.street + _value.business;
}
str += "
ToItem
index = " + e.toitem.index + "
value = " + value;
// G("searchResultPanel").innerHTML = str;
});
var myValue;
ac.addEventListener("onconfirm", function(e) { //鼠标点击下拉列表后的事件
var _value = e.item.value;
myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
// G("searchResultPanel").innerHTML ="onconfirm
index = " + e.item.index + "
myValue = " + myValue;
// setPlace();
theLocation()
});
function setPlace(){
map.clearOverlays(); //清除地图上所有覆盖物
function myFun(){
var pp = local.getResults().getPoi(0).point; //获取第一个智能搜索的结果
map.centerAndZoom(pp, 18);
map.addOverlay(new BMap.Marker(pp)); //添加标注
}
var local = new BMap.LocalSearch(map, { //智能搜索
onSearchComplete: myFun
});
local.search(myValue);
}
//地图弹出层居中
$(window).on("scroll resize",function(){
$("#drag").css({
top: ($(window).height()-$("#drag").outerHeight())/2+$(window).scrollTop(),
left: ($(window).width()-$("#drag").outerWidth())/2+$(window).scrollLeft()
});
});
//滚动输入框提示消失
$(window).on("scroll",function(){
$(".tangram-suggestion-main").hide()
});