d219973396d25096d5618605330782f88274a616.svn-base 5.71 KB
var IsAddMLCCtrl = false;
function InitMLCCtrl() {
    if (!IsAddMLCCtrl) {
        if ($("#MLCdialog").attr("id") == undefined)
            BuildMLCAlert();
        else {
            $.parser.parse($("#MLCdialog")); //局部重新渲染
            $("#MLCdialog").dialog("open");
        }
        IsAddMLCCtrl = true;
    } else {
        $("#MLCdialog").dialog("close");
    }
}

function moveToPoint() {
	var bh = $("#addressCode").val();
	//if(isNaN(bh)){
	//    alert('非正确的宗地编号!');
	 //   return;
	//}
	
	var x = 0;
	var y = 0;
	
	switch(bh){
		case '610702009200GB00003':
			x = 36406584.17574;
			y = 3666485.5731947;
			break;
		case '610702009223GB00004':
			x = 36410889.17574;
			y = 3663076.5731947;
			break;
		case '610702009223JB00024':
			x = 36408114.514741;
			y = 3660008.0621932;
			break;
		default:
			x = 36407201.524239;
			y = 3661882.7404462;
			break;
	}
    // 跳转到某一级某个位置
    map.moveTo(new OpenLayers.LonLat(x, y), 3); //通过moveTo方法定位到某一级别地图的某一点
	var datas = [ {
		bh : '610702009200GB00003',
		x : 36406584.17574,
		y : 3666485.5731947
	}, {
		bh : '610702009223GB00004',
		x : 36410889.17574,
		y : 3663076.5731947
	}, {
		bh : '610702009223JB00024',
		x : 36408114.514741,
		y : 3660008.0621932
	}, {
		bh : '610702009223GA00007',
		x : 36407201.524239,
		y : 3661882.7404462
	} ];
    createMark(datas);
}

function createMark(datas){
	
	var vectorLayer = new OpenLayers.Layer.Vector("points");  
	 map.addLayer(vectorLayer);  
	 
	var markers = new OpenLayers.Layer.Markers( "Markers" );  
    var imageUrl = pix + 'lib/img/marker.png';
    
    var size = new OpenLayers.Size(21,25);  
    var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);  
    var jz = new OpenLayers.Icon(imageUrl,size,offset);  
    for(var i=0;i<datas.length;i++) {  
    	 var point = new OpenLayers.Geometry.Point(Number(datas[i].x), Number(datas[i].y));  
    	 var style_point = {  
                 strokeColor: '#000000',  
                 strokeWidth: 1,  
                 strokeDashstyle: "solid",  
                 pointRadius: 1,  
                 strokeOpacity: 0.8,  
                 fillOpacity: 0.8,  
                 label:datas[i].value,  
                 fontSize:'12px',  
                 fontFamily:'宋体',  
                 labelXOffset:0,  
                 labelYOffset:-15,  
                 labelAlign:'m',  
                 //fillColor: '#000000'  
            };  
    	  var pointFeature = new OpenLayers.Feature.Vector(point, null, style_point);  
          vectorLayer.addFeatures([pointFeature]);  
    	 
        //图片显示  
        var marker = new OpenLayers.Marker(new OpenLayers.LonLat(datas[i].x,datas[i].y),jz.clone());  
        markers.addMarker(marker);  
        map.addLayer(markers);  
        createPopup(marker, datas[i]);  
    }
    
    if(!map.getCenter()){  
        map.zoomToMaxExtent();  
    }  
}

//弹窗  
function createPopup(marker, data) {  
    //鼠标悬浮到图标上的事件  
	var popup1;
     marker.events.register("mouseover", marker, function(evt){  
	     var html="<b>&nbsp;&nbsp;宗地"+data.bh+"</b>";  
	     popup1 = new OpenLayers.Popup("popup1", new OpenLayers.LonLat(data.x,data.y),   new OpenLayers.Size(200,50),  html,  true);  
	     popup1.setBackgroundColor("#ffffff");  
	     popup1.setOpacity(12);  
	     popup1.setBorder("1px solid #d91f12");  
	     map.addPopup(popup1);  
    });  
     
     //鼠标移开事件  
    marker.events.register("mouseout", marker, function(evt){  
      popup1.hide();  
    });  
}  


function panToPoint() {
	var bh = $("#addressCode").val();
	//if(isNaN(bh)){
	 //   alert('非正确的宗地编号!');
	 //   return;
	//}
	
	var x = 0;
	var y = 0;
	
	switch(bh){
	case '610702009200GB00003':
		x = 36406584.17574;
		y = 3666485.5731947;
		break;
	case '610702009223GB00004':
		x = 36410889.17574;
		y = 3663076.5731947;
		break;
	case '610702009223JB00024':
		x = 36408114.514741;
		y = 3660008.0621932;
		break;
	default:
		x = 36407201.524239;
		y = 3661882.7404462;
		break;
}
    //放大到某一级
    map.zoomTo(2);
    //跳转到某个位置
    map.panTo(new OpenLayers.LonLat(x, y)); //通过panTo方法定位到当前级别地图的某一点
}

function BuildMLCAlert() {
    var sb = '<div id="MLCdialog" class="easyui-dialog" title="地图定位" style="left:800px;top:65px;width: 260px; height: 280px;padding:5px" resizable="true">' +
    '<div id="toolspanelMLC" class="itembox">' +
        '<div>' +
         '<label>提示:请选择宗地编号</label><select id="addressCode" > <option value=""></option><option value="610702009200GB00003">610702009200GB00003</option> <option value="610702009223GB00004">610702009223GB00004</option><option value="610702009223JB00024">610702009223JB00024</option> <option value="610702009223GA00007">610702009223GA00007</option></select>  ' +
        '</div>'+
         '<div style="margin-bottom:5px;">' +
          '<button  class="functionButton" style="background-color:white;width:90px;margin-left:50px;" id="Button1" title="定位到地图第5级的汉中红圈" onclick="moveToPoint()" >moveTo定位 </button>' +
          '</div>'+
         '<div style="padding-top:10px;border-top:1px dotted #A7C0DC;">' +
          '<label>提示:(123)定位到红圈的位置</label>' +
        '</div>' +
          '<div >' +
          '<button  class="functionButton"  style="background-color:white;width:90px;margin-left:50px;" id="Button2" title="定位到当前地图级别下的红圈" onclick="panToPoint()">panTo定位 </button>' +
          '</div>' +
     '</div>' +
    '</div>';
    $("#main").append(sb);
    $("#MLCdialog").dialog({ closed: false, onClose: function () { closeMLC(); } });
}

function closeMLC() {
    IsAddMLCCtrl = false;
}