<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>位置信息服务平台</title>
        
<style type="text/css">
.dingzhi_yiji_wrap{width:520px; margin:0 auto; margin-top:20px; position:absolute; z-index:1000; margin-left:80px;}
.dingzhi_yiji_search_input{padding-left:10px; width:290px; height: 33px;
  padding-top: 10px; float:left; background:#fff; border:1px solid #aaacab;}
.dingzhi_yiji_main{overflow:hidden;}
.dingzhi_button_shangchuan{display:block; float:left; width:110px; height:45px; line-height:45px; font-size:14px; color:#ffffff; text-align:center; background:#3087ff; margin-right:1px; border:none}
.dingzhi_button_shangchuan:hover{background:#3fa3ff;}
.loading{text-align:center;font-size:14px;}
.loading img{margin-bottom:20px;}
.shuju_jieguo{position: absolute; width: 250px; height: 100%; display: block; background: #fff; z-index: 2000; top: 0px; right: 0px; border: 1px solid #ccc; overflow: auto;}
.shuju_jieguo h3{font-size:14px; height:30px; line-height:30px; margin:10px; margin-bottom:0px;}
#progress_{font-size:12px;  padding:10px; display:block; padding-top:0px;}
</style>
<style type="text/css">
		body, html,#map {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
</style>
        
        <script type="text/javascript"
			src="<%=path%>/gpsonline/js/jquery-1.8.3.js"></script>
		<script type="text/javascript"
			src="<%=path%>/gpsonline/js/ajaxfileupload.js"></script>
		<script type="text/javascript"
			src="<%=path%>/gpsonline/js/json2.js"></script>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=xeq7fKv93DyyuEPG1RAsmQB9"></script>
    <script type="text/javascript">
    var map;
    var myGeo;
    
	function map(){
			
			map = new BMap.Map("map");
			var point = new BMap.Point(116.331398,39.897445);
			map.centerAndZoom(point,12);
			// 创建地址解析器实例
			map.addControl(new BMap.NavigationControl());  //缩放轴
			map.addControl(new BMap.OverviewMapControl());    //缩略图
			 
			myGeo = new BMap.Geocoder();
			map.enableScrollWheelZoom(); //启用滚轮放大缩小
			map.addControl(new BMap.ScaleControl());   // 添加默认比例尺控件
			map.setMinZoom(5);
    }
	function addUserMarker(title,lat,lng,index,text){
		$.ajax({
		       type: "POST",
		       dataType: "json",
		       url: "../../../json/markerAction_addOrUpdateUserMarker.action",
		       data: {
				share_type:1,
				title:title,
				"text":text,
				lat:lat,
				lng:lng,
				groupid:0,
				icon:"http://mapday.exlive.cn/mi/p/b/1/green.gif"
		       },
		       success: function(json){
		    	   if(json.flag==true){
		    		   $("#progress_").html($("#progress_").html()+"</br><font color='green' >"+title+" 标注 添加成功</font></br>")
		    		   parent.addImportMarker(json);
			       }else{
				       if(json.msg==10001){
				    	   $("#progress_").html($("#progress_").html()+"</br><font color='red' >"+title+" , 地址重复 ，标注  添加失败</font></br>")
						   
					   }else{
						   $("#progress_").html($("#progress_").html()+"</br><font color='red' >"+title+" 标注  添加失败</font></br>")
						   
					   }
			    	}
		       },
	   		   error: function() {
	       		   
		       }
		});
	}
    function ajaxFileUpload()
    {
        	/*
        	$("#loading")
            .ajaxStart(function(){
                $(this).show();
            })//开始上传文件时显示一个图片
            .ajaxComplete(function(){
               // $(this).hide();
            });//文件上传完成将图片隐藏起来
            */
            $.ajaxFileUpload
            (
                {
                    url:'../../../upload/fileUploadAction_fileUpload.action',//用于文件上传的服务器端请求地址
                    secureuri:false,//一般设置为false
                    fileElementId:'file',//文件上传空间的id属性  <input type="file" id="file" name="file" />
                    dataType:"JSON",//返回值类型 一般设置为json
                    success: function (data,status)  //服务器成功响应处理函数
                    {
                     
                     	data=data.substring(0,data.length-2);
                     	data = JSON.parse(data);
                     	
                        if(data.flag==true){
                            if(data.data.length>0){
                            	$("#msg").html("文件以导入，正在添加标注...")
                            	for(var i =0;i<data.data.length;i++){
									if(data.data[i].address != ""){
										 var index = i;
										
										 addressResolution(data.data[i].address,data.data[i].contacts+" "+data.data[i].phone,index)
									}
                                }
                            }
                        }else{
                            alert(data.msg);
                        }
                     	
                    },
                    error: function (data, status, e)//服务器响应失败处理函数
                    {
                        alert(e);
                    }
                }
            )
            return false;
    }
    function chushihua(){
    	$("#progress_").html("");
		$("#msg").html("");
		map.clearOverlays();
    }
   
    function addressResolution(address,text,index)
    {
    	myGeo.getPoint(address, function(point){
    		if (point) {
    			var p = new BMap.Point(point.lng, point.lat);
    			var now = new Date(); 
    			var nowStr = now.format("hh:mm:ss"); 
				addMarker(p,new BMap.Label(address,{offset:new BMap.Size(20,-10)}));
				var obj = baiduToGoogle(point.lng,point.lat);
				var ADDRESS = address.substring(address.indexOf('区')+1,address.length);
/*
				if(ADDRESS.length>25){
					ADDRESS=ADDRESS.substring(0,24);
				}
				*/
				addUserMarker(ADDRESS,obj.lng,obj.lat,index,text)
				
    			$("#progress_").html($("#progress_").html()+"</br><font color='green' >"+address+"  解析成功</font></br>")
    		}else{
    			$("#progress_").html($("#progress_").html()+"</br><font color='red' >"+address+"  地址没有解析到结果</font>")
    		}
    	}, "北京市");
    	index++;
    }

    function addMarker(point,label){
		var marker = new BMap.Marker(point);
		map.addOverlay(marker);
		marker.setLabel(label);
		map.centerAndZoom(point, 16);
	}
    function baiduToGoogle(blng,blat) {

    	var x_pi = 3.14159265358979324 * 3000.0 / 180.0;
    	var lng=blng;
    	var lat=blat;
    	var x = lng - 0.0065, y = lat - 0.006;
    	var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
    	var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
    	lng = z * Math.cos(theta);
    	lat = z * Math.sin(theta);
    	var obj=new Object();
    	obj.lng=lng;
    	obj.lat=lat;
    	return obj;
    }
    Date.prototype.format = function(format){ 
    	var o = { 
    	"M+" : this.getMonth()+1, //month 
    	"d+" : this.getDate(), //day 
    	"h+" : this.getHours(), //hour 
    	"m+" : this.getMinutes(), //minute 
    	"s+" : this.getSeconds(), //second 
    	"q+" : Math.floor((this.getMonth()+3)/3), //quarter 
    	"S" : this.getMilliseconds() //millisecond 
    	} 

    	if(/(y+)/.test(format)) { 
    	format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
    	} 

    	for(var k in o) { 
    	if(new RegExp("("+ k +")").test(format)) { 
    	format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); 
    	} 
    	} 
    	return format; 
    	} 
    </script>
    </head>
    <body onload="map();">
    <div class="dingzhi_yiji_wrap">
		<div  id="loading" class="loading" style="display:none">
			<img src="load.gif" /><br />
			<span id="msg">正在上传，请稍后...</span>
		</div>
		<div class="dingzhi_yiji_main">
			 <input type="file" id="file" name="file"  class="dingzhi_yiji_search_input" />
			<input type="button" value="上传" onclick="return ajaxFileUpload();" class="dingzhi_button_shangchuan" />
		</div>
		
		
	</div>
    <div  id="map" style=""> </div>   
    <div class="shuju_jieguo">
	<h3>上传数据结果</h3>
	<span id="progress_">
	
	</span>
</div>
    </body>
</html>