<{import file="index/header_shop.html" title="门店位置"}>
<style type="text/css">
.lbox{ padding-bottom:100px; float:left;}
.map{ width:910px; height:500px; float:left;}
.map .name{ width:908px; background:#fff; border:1px solid #efefef; margin:0 0 10px 0; height:36px; padding:6px 0 0 0; float:left;}
.map .name span{padding:0 10px 0 10px; }
.map .name .aname{ padding:0 10px 0 10px; float:left;}
.map .name .aname span{ padding:7px 10px 0 10px; float:left; }
.map .name .aname input.btn{ padding:7px; } 
.map .name input#save_location{ background:#0188E0; border:none; color:#fff; padding:7px 10px 6px; margin-left:10px; }

.map #allmap {width: 100% ;height: 100%; overflow: hidden; margin:0; } 
#l-map{height:500px; width:100%;}
#r-result{width:100%;}
</style> 
<div class="tab_name"><span>门店位置</span></div>
<div class="lbox"> 
	<div class="map">
		<form action="#" method="post">
			<div class="name">
				<{if $row.lng == ''&& $row.lat== ''}><span>当前定位：<span></span> </span><{/if}> 
				<div class="aname"><span>经度：</span> <input type="text" size="10" value="<{$row.lng}>" name="lng" class="btn"/></div>
				<div class="aname"><span>纬度：</span><input type="text" size="10" value="<{$row.lat}>" name="lat" class="btn"/></div>
				<input type="button" name="save_pst" id="save_location" value="保存定位"/> 
			</div>
		</form> 
		<div id="allmap"></div>  
		<div id="r-result"></div>
	</div>  
</div>
<{include file="index/footer.html"}> 
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=3156edd4b77ad33ca5547f5fa86a2cf0"></script> 
<script type="text/javascript">
$(function(){
	$("#save_location").click(function(){
		var lng = $(".map .name input[name=lng]").val();
		var lat = $(".map .name input[name=lat]").val(); 
		$.post('?m=shop&a=ajax_map',{lng:lng, lat:lat},function(result){ 
			data = jQuery.parseJSON(result); 
			if(data.error == '0'){
				$.alert('保存成功');
			}else{ 
				$.alert(data.msg);
			}
		}); 	
	});
});
// 百度地图API功能
var map = new BMap.Map("allmap");  
<{if ($row.lng == '') && ($row.lat== '')}>
	var point = new BMap.Point(116.331398,39.897445);
	map.centerAndZoom(point,13);
	var myCity = new BMap.LocalCity();
	myCity.get(myFun);
	
	function myFun(result){
		var cityName = result.name; 
		map.setCenter(cityName);
		
		var myCity = new BMap.LocalCity(); 
		$('.map .name span').html(cityName); 
	}
<{else}>
	var sContent ="<{$row.name}>";
	var point = new BMap.Point(<{$row.lng}>, <{$row.lat}>);
	map.centerAndZoom(point, 20);
	var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象
	map.openInfoWindow(infoWindow,point); 		
<{/if}> 
map.enableScrollWheelZoom();   //启用滚轮放大缩小，默认禁用
map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用 
map.addEventListener("click",function(e){
	//alert(e.point.lng + "," + e.point.lat);
	$(".map .name input[name=lng]").val(e.point.lng);
	$(".map .name input[name=lat]").val(e.point.lat); 
	getNewArea(e);
});
function getNewArea(e){
	var sContent ="<{$row.name}>";
	var point = new BMap.Point(e.point.lng, e.point.lat);
	map.centerAndZoom(point, 20);
	var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象
	map.openInfoWindow(infoWindow,point); 			//开启信息窗口 
} 
</script>
