var windowid;

//标注
function Label () {
	
}

//标注marker
Label.bzMarkerObj = {};

Label.getBzMarker = function(key){
	if (!Label.bzMarkerObj) {
		return null;
	}
	return Label.bzMarkerObj[key] || null;
}

Label.addBzMarker = function(key, value){
	if (!Label.bzMarkerObj) {
		Label.bzMarkerObj = {};
	}
	if (!key) {
		return;
	}
	Label.bzMarkerObj[key] = value;
}

Label.deleteBzMarker = function (key) {
	delete Label.bzMarkerObj[key];
}

//修改经纬度
Label.update = function () {
    var xh = $('#xh').val();
    if (!xh) {
    	$.showMsg('请选择摄像头！');
    	return;
    }
    var model={};
    model.jd = $('#updateLongitude').val();
    model.wd = $('#updateLatitude').val();
    model.sbbh = $('#sbbh').val();
    model.tdbh = $('#tdbh').val();
    model.XGTJxh = xh;
    var key = model.jd+ ',' + model.wd;
    $.ajax({
		type:'post',
		dataType : 'json',
		url:'szMapHttpAction!update_sbtd_jwd.do',
		data:model,
		success:function(data){
			if(data=="success"){
				var key = model.jd + ',' + model.wd;
				var bzMarker = Label.getBzMarker(key);
				bzMarker.closeInfoWindowHtml();
				MapAPI.removeOverlay(bzMarker);
				Label.deleteBzMarker(key);
				Label.addMarker();
			}else{
				$.showMsg("操作失败！");
			}
		}
	});	
}
//标注打点
Label.addMarker = function () {
	var model = {};
	model.sbbh = $('#sbbh').val();
    model.tdbh = $('#tdbh').val();
    model.page = "1";
    model.rows = "1";
    $.ajax({
		type:'post',
		dataType : 'json',
		url : 'sbtdspsrAction!listSbtdspsrByPage.do',
		data:model,
		success:function(data){
			if (data && data.rows && data.rows.length > 0) {
	    		var monitorLayer = MapMain.getLayer(MapConst.LAYER_MONITOR);
	    		monitorLayer.addMarker(data.rows[0]);
	    		$.showMsg("操作成功！");
	    	} else {
	    		$.showMsg("操作失败！");
	    	}
		}
	});	
}
//打开摄像头窗口
Label.tdmcClick = function (){
	windowid = top.$.createWin({
        title    :     '选择摄像头',
        width    :      800,
        height    :     500,
        url    :    top.sysUrl + '/szmap/business/main/Monitor.jsp',
        buttons: [{
            text:$.fn.textbox.defaults.ok,
            handler:function(){Label.load();}
        }]
    });    
}

//赋值
Label.load = function () {
	var frame    =    top.$("#"+windowid).children("iframe")[0];
    var win        =    frame.contentWindow||frame.window;
    var monitor = win.$('#monitor-tab-grid').datagrid('getSelected');
    if (monitor == null) {
    	$.showMsg('请先选择记录！');
    	return;
    }
    $('#tdmc').val(monitor.tdmc);
    $('#sbbh').val( monitor.sbbh);
    $('#tdbh').val( monitor.tdbh);
    $('#xh').val( monitor.xh);
    top.$('#'+windowid).dialog('close');
}

//取消
Label.cancle = function () {
	var longitude = $('#updateLongitude').val();
    var latitude = $('#updateLatitude').val();
    var key = longitude + ',' + latitude;
	var bzMarker = Label.getBzMarker(key);
	bzMarker.closeInfoWindowHtml();
	MapAPI.removeOverlay(bzMarker);
	Label.deleteBzMarker(key);
}
