<!DOCTYPE html>
<html>
<head>

<script src="<!--{$oapath}-->Ins/js/jquery-2.1.1.js" type="text/javascript" ></script>
 <script src="<!--{$oapath}-->Ins/js/layui/layui.js" type="text/javascript"></script>
<script src="<!--{$oapath}-->Ins/js/layer/layer.js" type="text/javascript"></script>
<link href="<!--{$oapath}-->Ins/js/layui/css/layui.css" type="text/css"  rel="stylesheet" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;hidden;margin:0;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=HApG6QKUwGzgpS0aEK6P5Xmt4eX1I6cI"></script>
<title>添加普通标注点</title>
</head>
<body>


 <a class="layui-btn layui-btn-danger  layui-btn-small"  id="juti" style="width:15%"; ><i
                                    class="ace-icon fa fa-pencil bigger-100"></i>选择当前位置</a>
	<div id="r-result">请输入:<input type="text" id="suggestId" size="20" value="百度" style="width:150px;" /></div>
	<div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>

    <div id="allmap"></div>
<input type="hidden" value="<!--{$sign_data.address}-->"  link="zhongwen">
<input type="hidden" value="<!--{$sign_data.jing}-->"  link="jing">
<input type="hidden" value="<!--{$sign_data.wei}-->"  link="wei">
</body>
</html>

<script type="text/javascript">



$("#juti").click(function(){
		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引	
	 var zhongwen=$("[link=zhongwen]").val();
	  var jing=$("[link=jing]").val();
	    var wei=$("[link=wei]").val();
	
		parent.$("[name=address]").val(zhongwen);
		 parent.$("[name=jing]").val(jing);
	        parent.$("[name=wei]").val(wei);
	   
	      parent.layer.close(index);
	
	
	});
	
    var name1="<!--{$sign_data.address}-->";
    if(name1==""){
        name1="北京市丰台区北京诺德中心";
    }
 // 百度地图API功能
    var map = new BMap.Map("allmap");
    map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_LEFT, type: BMAP_NAVIGATION_CONTROL_SMALL}));  //右上角，仅包含平移和缩放按钮。

	map.centerAndZoom(name1, 11);    //执法者所在城市名称
	map.addEventListener("load", doshow);
  
  
  
  

  function doshow(e){
	 var map = new BMap.Map("allmap");
             var jing="<!--{$sign_data.jing}-->";
            if(jing==""){
                jing="116.305191";
            }
                var wei="<!--{$sign_data.wei}-->";
            if(wei==""){
                wei="39.835519";
            }
	 var point = new BMap.Point(jing,wei);    //当前执法者中心点
	map.centerAndZoom(point, 11);		
	var geoc = new BMap.Geocoder(); 
    var marker = new BMap.Marker(point);  // 创建标注
	
		
	map.addOverlay(marker);  // 将标注添加到地图中


	marker.enableDragging();    //可拖拽
	map.enableScrollWheelZoom();//可以鼠标滚动 缩放比例尺
	
	
	
	   var p = marker.getPosition();//获取marker的位置
	
		var pt = e.point;
		geoc.getLocation(pt, function(rs){
                   
			var addComp = rs.addressComponents;
				if(addComp.province!=''){
				
				var l=addComp.province;
				}
				if(addComp.city!=''){
					
					 l+=","+addComp.city;
					}
					
					if(addComp.district!=''){
					
				 l+=","+addComp.district;
					}
					
					if(addComp.street!=''){
					
					 l+=","+addComp.street;
					}
					if(addComp.streetNumber!=''){
					
					l+=","+addComp.streetNumber;
					}
				
			
				$("[link=zhongwen]").val(l);
			
		
		}); 
		
		
		
		
		
		
		
		var o=(p.lng);
		var c=(p.lat);
		
	
	
 
			
			$("[link=jing]").val(o);
			$("[link=wei]").val(c);
	
		
		 
	
		
		

	marker.addEventListener("dragend",function(e){
    var p = marker.getPosition();//获取marker的位置
	
		var pt = e.point;
		geoc.getLocation(pt, function(rs){
                    // console.log(rs);
			var addComp = rs.addressComponents;
				if(addComp.province!=''){
				
				var l=addComp.province;
				}
				if(addComp.city!=''){
					
					 l+=","+addComp.city;
					}
					
					if(addComp.district!=''){
					
				 l+=","+addComp.district;
					}
					
					if(addComp.street!=''){
					
					 l+=","+addComp.street;
					}
					if(addComp.streetNumber!=''){
					
					l+=","+addComp.streetNumber;
					}
				
			
				$("[link=zhongwen]").val(l);
			
		
		}); 
		
		
		
		
		
		
		
		var o=(p.lng);
		var c=(p.lat);
		
	
	
	
			
			$("[link=jing]").val(o);
			$("[link=wei]").val(c);
	
		
		 
	
		
		
		
	});	
	
	

	
	
	// 百度地图API功能
	function G(id) {
		return document.getElementById(id);
	}

	//var map = new BMap.Map("allmap");
	//map.centerAndZoom("北京",12);                   // 初始化地图,设置城市和地图级别。

	var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
		{"input" : "suggestId"
		,"location" : map
	});
var index = parent.layer.getFrameIndex(window.name); //获取窗口索
	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();
	});

	function setPlace(){

		map.clearOverlays();    //清除地图上所有覆盖物
		function myFun(){
 
			var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
			



console.log(pp.lng);
			
var marker = new BMap.Marker(pp);  // 创建标注
map.centerAndZoom(pp, 18);
var geoc = new BMap.Geocoder(); 
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引	


map.addOverlay(marker);  // 将标注添加到地图中



                    marker.enableDragging();    //可拖拽
                    map.enableScrollWheelZoom();//可以鼠标滚动 缩放比例尺
                   var address= $("#suggestId").val();
                        $("[link=zhongwen]").val(address);
 			$("[link=jing]").val(pp.lng);
			$("[link=wei]").val(pp.lat);
			

			
		 
				

			//map.centerAndZoom(pp, 18);
			//map.addOverlay(new BMap.Marker(pp));    //添加标注
		}
		var local = new BMap.LocalSearch(map, { //智能搜索
		  onSearchComplete: myFun
		});
		local.search(myValue);
	}	
	
	
	
	
	}

</script>

