a3f5fd629045dbf53a6afd978bac5df0687eedd0.svn-base 6.58 KB
/*---------------------系统框架设计------------------------------*/
var map, layer ;
var pix;
// 地图初始化函数
function init() {
	pix = $("#tmpath").val() + "/gis/";
	var slideNav = new OpenLayers.Control.TouchNavigation({
		dragPanOptions : { //惯性滑动,
			enableKinetic : { //enableKinetic,可以设为bool,也可设为object,设为object时,object会考到{<OpenLayers.Kinetic> 的构造函数中
				deceleration : 0.0055
			//地图滑动的速率
			}
		}
	});

	////初始化地图容器,确定地图文档范围,显示级数分辨力等
	map = new OpenLayers.Map("map", {
		numZoomLevels : 16,
		maxExtent : new OpenLayers.Bounds(36405240.72123657, 3657662.159452337,36412330.04323516, 3667618.137449153),
		maxResolution : 7,
		controls : [ new OpenLayers.Control.Navigation(), slideNav ],
		theme : null
	});
	//初始化图层,确定数据名称,地址等
	layer = new Zondy.Map.Doc("MapGIS IGS MapDocLayer", "testhz", {
		ip : "101.200.140.90",
		port : "8089"
	});
	//给容器添加图层
	map.addLayers([ layer ]);
	map.setCenter(new OpenLayers.LonLat(0, 0), 1);
	//单击的标志位
	startClick = 1;
	initLogo();
	initStartBtn();
	initToolBar();
	get_JSON();
}

function initStartBtn() {
	var initStartFlag = 0;
	// start按钮事件
	$("#start").hide();
	$("#startBtn").click(function() {
		startClick = startFun(startClick);
		if (initStartFlag == 0) {
			initStartFlag = 1;
		} else
			return;
	});
}

function initToolBar() {
	//放大
	$("#toolbar ul").find('#zoomIn').click(zondy.setOperZoomIn);
	//缩小
	$("#toolbar ul").find('#zoomOut').click(zondy.setOperZoomOut);
	//移动
	$("#toolbar ul").find('#pan').click(zondy.setOperDrag);
	//复位
	$("#toolbar ul").find('#restore').click(function() {
		map.zoomToMaxExtent();
		zondy.setOperDrag();
		map.setCenter(new OpenLayers.LonLat(0, 0), 1);
	});
}

function initLogo() {
	// logo显示隐藏事件
	var logoClick = 0;
	$("#logoBtn").click(function() {
		if (logoClick == 0) {
			$("#logoText").hide('drop', null, 500, null);
			$(this).find(".logoBtn").attr("title", "显示标题");
			logoClick = 1;
		} else {
			$("#logoText").show('drop', null, 500, null);
			$(this).find(".logoBtn").attr("title", "隐藏标题");
			logoClick = 0;
		}
	});
}

//start显示或隐藏函数
function startFun(clickNum) {
	if (clickNum == 0) {
		$("#start").show('explode', null, 500, null);
		$("#startBtn").find(".operator").removeClass("opStart");
		$("#startBtn").find(".operator").addClass("opDown");
		return 1;
	} else {
		$("#start").hide('explode', null, 500, null);
		$("#startBtn").find(".operator").removeClass("opDown");
		$("#startBtn").find(".operator").addClass("opStart");
		return 0;
	}
}

/*---------------------读取配置文件(json)创建功能插件标签---------*/
var toolID;
function get_JSON() {
	$.ajax({
        type: "GET",
        url: pix + "$$framework$$.json?1",
        dataType: "text",
        success: function (data) {

            var json = eval("(" + data + ")");
            var tools = json.tools;
            var len = tools.length;
            var z = len/10;
            for (var i = 0; i < len; i++) {
                var divID;
                if (i == 0 || i % 10 == 0) {
                    divID = "contPanel" + i / 10; //margin: 5px 10px 0px 0px;
                    var d = ' <div class="contPanel" id="' + divID + '" style="padding-top:15px;margin: 5px 10px 0px 0px; height: 222px; width: 443px;background-image:url(lib/img/menuBg/48.jpg);left: 0px;z-index:"'+z+'">';
                    if((i/10)>1){
                    	d = '<div class="contPanel" id="' + divID + '" style="padding-top:15px;margin: 5px 10px 0px 0px; height: 222px; width: 443px;background-image:url(lib/img/menuBg/48.jpg);left: 443px;z-index:"'+z+'">';
                    }
                    $("#featured").append(d);
                    var s = $("#featured");
                    z--;
                }
                toolID = tools[i].id;
                CreateUI(divID, tools[i].imgSrc, tools[i].imgFun, tools[i].name, tools[i].id);
                //tools[i].js为插件js文件路径
                if (tools[i].jsPage != "" && tools[i].jsPage != undefined) {
                    loadjscssfile(tools[i].jsPage, "js", toolID);
                }
            }
            $('#featured').orbit({
                bullets: true, 					// true or false to activate the bullet navigation
                bulletThumbs: true, 			// thumbnails for the bullets 
                directionalNav: false,
                timer: false,
                animationSpeed: 500
            });
        }
    });
}

////动态加载js文件
function loadjscssfile(path, filetype, id) {
	var fileSrc = pix +'$$tools$$/' + id;
	fileSrc += path;
	fileSrc += "?toolId=" + id;
	if (filetype == "js") { //判断文件类型 
		var fileref = document.createElement('script'); //创建标签 
		fileref.setAttribute("type", "text/javascript"); //定义属性type的值为text/javascript 
		fileref.setAttribute("src", fileSrc); //文件的地址 
	} else if (filetype == "css") { //判断文件类型 
		var fileref = document.createElement("link");
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", fileSrc);
	}
	if (typeof fileref != "undefined")
		document.getElementsByTagName("head")[0].appendChild(fileref);
}

function CreateUI(divID, imgSrc, imgFun, name, id) {
	var Menu = $("#" + divID);
	var src = pix+'$$tools$$/' + id + imgSrc;
	var plusDOM = '<div class="funRegion">';
	plusDOM += '<img id="'+ id + '" style="width:48px;height:48px;" class="startMenu" src="'+src+'"  /><br />';
	plusDOM += name + '</div>';
	Menu.append(plusDOM);
	$("#" + id).click(function() {
		CallWorkFlow(imgFun, "", id);
	});
}

//jsfunction:插件是div层,调用的方法
//page:页面,调用的html
function CallWorkFlow(jsfunction, page, id) {
	if (jsfunction != "") {
		eval(jsfunction + '()');
	} else {
		page = pix+"$$tools$$/" + id + page; //add by lf :20130702
		window.open(page);
	}
}

function loadNETfile(path, filetype) {
	var fileSrc = path;
	if (filetype == "js") { //判断文件类型 
		var fileref = document.createElement('script'); //创建标签 
		fileref.setAttribute("type", "text/javascript"); //定义属性type的值为text/javascript 
		fileref.setAttribute("src", fileSrc); //文件的地址 
	} else if (filetype == "css") { //判断文件类型 
		var fileref = document.createElement("link");
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", fileSrc);
	}
	if (typeof fileref != "undefined")
		document.getElementsByTagName("head")[0].appendChild(fileref);
}