<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>选择地点</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<style type="text/css">
		body, html{width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
		#allmap{height:500px;width:100%;}
		#r-result{width:100%; font-size:14px;}
	</style>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=loaxPeDrzZ6xgvSMwiI8M61I5mK6l8dB"></script>
	<title>城市名定位</title>
</head>
<body>
<div id="allmap"></div>
<div id="r-result">
	<%--<div class="col-sm-12">
	<form:form id="inputForm" modelAttribute="workAttendancePlace" method="post" class="form-horizontal">
		<form:hidden path="itude"/>
		<form:hidden  path="placeName"/>
	</form:form>
	</div>--%>
</div>

</body>
</html>
<script type="text/javascript">
    // 百度地图API功能
    var map = new BMap.Map("allmap");
    var city = '${city}';
    var point = new BMap.Point(116.331398,39.897445);
    var x = "${x}";
    var y = "${y}";
    map.centerAndZoom(point,12);
    map.enableScrollWheelZoom(true);
    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function(r){
        if(this.getStatus() == BMAP_STATUS_SUCCESS){
            if(x == null || x == '' || x == undefined || y == null || y == '' || y == undefined ){
                map.centerAndZoom(city,12);      // 用城市名设置地图中心点
            }else{
                var points = new BMap.Point(x,y);
                var mk = new BMap.Marker(points);
                map.addOverlay(mk);//标出所在地
                map.panTo(points);//地图中心移动
                map.centerAndZoom(points,19);      // 用城市名设置地图中心点
            }
        }else {
            alert('failed'+this.getStatus());
        }
    },{enableHighAccuracy: true})
    function changePlacesInfo(name,itude,address) {
        console.log(parent);
        for(var i=0;i<parent.window.length;i++){
            var pwin = parent.window[i];
            console.log("pwin:"+pwin.pathName);
            if("/a/workattendance/workAttendanceRule/form"==pwin.pathName){
                pwin.changePlaces(name,itude,address);
                return;
			}
		}
    }
    function showInfo(e){
        var name = '${name}';
        var index1 = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        top.layer.confirm('确认要选择当前为考勤地址么?', {icon: 1, title:'系统提示'}, function(index){
            var itude = e.point.lng + "," + e.point.lat;
            var address = "";
            var point = new BMap.Point(e.point.lng,e.point.lat);    //用所定位的经纬度查找所在地省市街道等信息
            var gc = new BMap.Geocoder();
            gc.getLocation(point, function(rs){
                //var addComp = rs.addressComponents;
                address = rs.address;
                changePlacesInfo(name,itude,address);
                top.layer.close(index);
                parent.layer.close(index1); //再执行关闭
            });

        });
    }
    map.addEventListener("click", showInfo);
</script>