123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- 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<br />index = " + e.fromitem.index + "<br />value = " + value;
- value = "";
- if (e.toitem.index > -1) {
- _value = e.toitem.value;
- value = _value.province + _value.city + _value.district + _value.street + _value.business;
- }
- str += "<br />ToItem<br />index = " + e.toitem.index + "<br />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<br />index = " + e.item.index + "<br />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()
- });
|