<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="<?php echo $mymps_global[SiteUrl]?>/template/global/button.css">
<script language="javascript" src="<?php echo $mymps_global[SiteUrl]?>/template/global/noerr.js"></script>
<script type="text/javascript" language="javascript" src="<?php echo $mymps_global[mapapi]; ?>"></script>
<style>
body{font:Verdana, Arial, Helvetica, sans-serif; text-align:left;}
</style>
<script language="javascript">
function besuremark() {
    var point = document.getElementById("result_").value;
    if(point == ''){
        if(!confirm('您尚未标注地图\n\n确认保存吗?')) return false;
    } else {
        parent.document.getElementById('mappoint').value =point;
        alert('地理位置标注成功！');
    }
    parent.closeopendiv();
}
</script>
</head>
<body style="margin:10px; font-size:14px;">
		<?php if($action == 'markpoint'){?>
        搜索地址：<input id="text_" type="text" style="width:220px;" value=""/>
        <div id="searchResultPanel" style="border:1px solid #C0C0C0;height:auto; display:none;"></div>
        <font style="display:none">经纬度：<input id="result_" type="text"/></font>
        <input type="button" value="确认正确,点我标注" onclick="besuremark();"/>
        <?php }?>
        <div id="container" style="position: absolute;margin-top:10px; margin-bottom:10px; width: <?php echo $action == 'markpoint'? $width.'px' :'100%';?>; height: <?php echo $height; ?>px;overflow:hidden;"></div>
        
</body>
</html>



<script type="text/javascript">

function G(id) {
    return document.getElementById(id);
}
function showInfo(e){
    //alert(e.point.lng + ", " + e.point.lat);
}
function myFun(result){
    var cityName = result.name;
    map.setCenter(cityName);
}

var map = new BMap.Map("container");
var p1 = "<?php echo $p1; ?>";
var p2 = "<?php echo $p2; ?>";
var view_level = "<?php echo $level; ?>";

map.addControl(new BMap.NavigationControl());

if(p1 != "" && p2 != "") {
	var _initPoint = new BMap.Point(p1,p2);
	map.centerAndZoom(_initPoint,view_level);
	var marker = new BMap.Marker(_initPoint); 
	map.addOverlay(marker);              // 将标注添加到地图中
	marker.enableDragging();
	marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
} else {
	map.centerAndZoom(new BMap.Point(), view_level);
	var myCity = new BMap.LocalCity();
	myCity.get(myFun);
}

map.enableScrollWheelZoom(); 
map.enableContinuousZoom(); 

map.addControl(new BMap.NavigationControl());
map.addControl(new BMap.OverviewMapControl()); 
map.addControl(new BMap.OverviewMapControl({ isOpen: true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT }));

var localSearch = new BMap.LocalSearch(map);
localSearch.enableAutoViewport(); 


var ac = new BMap.Autocomplete(   
		{
			"input" : "text_",
			"location" : map
		}
);

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;   
		document.getElementById("result_").value = pp.lng + "," + pp.lat;

		map.centerAndZoom(pp,<?php echo $level; ?>);
		var marker = new BMap.Marker(pp);
		map.addOverlay(marker);

	}
	var local = new BMap.LocalSearch(map, { 
	  onSearchComplete: myFun
	});
	local.search(myValue);
} 
map.addEventListener("click", showInfo);

function searchByStationName() {
    map.clearOverlays();
    var keyword = document.getElementById("text_").value;
    localSearch.setSearchCompleteCallback(function (searchResult) {
        var poi = searchResult.getPoi(0);
        document.getElementById("result_").value = poi.point.lng + "," + poi.point.lat;
        map.centerAndZoom(poi.point, <?php echo $level; ?>);
        var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat)); 
        map.addOverlay(marker);
        var content = document.getElementById("text_").value + "<br/><br/>经度：" + poi.point.lng + "<br/>纬度：" + poi.point.lat+"<br/>如有误请输入详细的小区名称重新查询";
        var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" + content + "</p>");
        marker.openInfoWindow(infoWindow);

        marker.setAnimation(BMAP_ANIMATION_BOUNCE); 
    });
    localSearch.search(keyword);
} 
</script>