﻿// JScript 文件  

var oNorthPanel = null;
var oNavigationPanel = null;
var oResultPanel = null;
var oToolBarPanel = null
var oMapPanel = null;
var oSouthPanel = null;

var wHeight;
var wWidth;

//获取页面高度
function windowHeight() {
    var de = document.documentElement;
    return self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
}

function resize() {
    var panel = $("map-div");
    if(panel==null||panel=='undefine')
        return;
    panel.style.width = "100%";
    panel.style.height = windowHeight() - 120;
}

function fnInitPage() {
    wHeight = document.body.clientHeight;
    wWidth = document.body.clientWidth;

    fnCreateNorthFrame();
    fnCreateResultFrame();
    fnCreateNavigationFrame();
    fnCreateToolBarFrame();
    fnCreateMapFrame();
    fnCreateSouthFrame();

    var viewport = new Ext.Viewport({
        layout: 'border',
        items: [
            oNorthPanel,
            oSouthPanel,
            oResultPanel
            , {
                region: 'center',
                split: true,
                border: true,
                width: wWidth - 230,
                height: windowHeight(),
                tbar: oToolBarPanel,
                items: [oMapPanel]
            }
        ]
    });
}

function fnCreateNorthFrame() {
    oNorthPanel = new Ext.Panel({
        region: 'north',
        id: 'oNorthPanel',
        contentEl: 'north-div',
        split: false,
        frame: false,
        border: false,
        collapsible: false,
        height: 60,
        minSize: 60,
        maxSize: 60
    });
}

function fnCreateNavigationFrame() {
    oNavigationPanel = new Ext.TabPanel({
        renderTo: 'navigation-div',
        id: 'oNavigationPanel',
        activeTab: 0,
        autoScroll: true,
        split: true,
        plain: true,
        border: false,
        width: 650,
        height: 27,
        items: [
                {
                    title: '地名查询',
                    listeners: { activate: setTabActive }
                }
              ,
              {
                  title: '小区查询',
                  listeners: { activate: setTabActive }
              }
              ,
              {
                  title: '道路查询',
                  listeners: { activate: setTabActive }
              }      
              ,
              {
                  title: '楼门牌查询',
                  listeners: { activate: setTabActive }
              }
              ,
              {
                  title: '驾车导航',
                  listeners: { activate: setTabActive }
              }
              ,
              {
                  title: '公交换乘',
                  listeners: { activate: setTabActive }
              }
              ,
              {
                  title: '站点查询',
                  listeners: { activate: setTabActive }
              }
              ,
              {
                  title: '线路查询',
                  listeners: { activate: setTabActive }
              }
              ,
              {
                  title: '周边查询',
                  listeners: { activate: setTabActive }
              }
        ]
    });
}

function fnCreateResultFrame() {
    oResultPanel = new Ext.Panel({
        title: '查询结果',
        id: 'oResultPanel',
        region: 'west',
        margins: '0 0 0 3',
        contentEl: 'result-div',
        split: true,
        collapsible: true,
        autoScroll: true,
        width: 220,
        frame: false,
        boder: false,
        minSize: 220,
        maxSize: 220,
        collapseFirst: false,
        collapsed: true,
        titleCollapse: true
    });

    oResultPanel.on('collapse', function() {
        if (oMapPanel != null) {
            resize();
        }
    })

    oResultPanel.on('expand', function() {
        if (oMapPanel != null) {
            resize();
        }
    });
}

function fnCreateToolBarFrame() {
    oToolBarPanel = new Ext.Panel({
        contentEl: 'toolbar-div',
        frame: false,
        border: false
    });

    var tb = new Ext.Toolbar();
    tb.render('toolbar-div');
    tb.add(
            {
                text: '放大',
                icon: 'images/1.gif',
                cls: 'x-btn-text-icon',
                tooltip: '<span>地图放大</span>',
                handler: function() {
                    map.setCurOper(1001);
                }
            }
            ,
            {
                text: '缩小',
                icon: 'images/2.gif',
                cls: 'x-btn-text-icon',
                tooltip: '<span>地图缩小</span>',
                handler: function() {
                    map.setCurOper(1002);
                }
            }
            ,
            {
                text: '移动',
                icon: 'images/mov.gif',
                cls: 'x-btn-text-icon',
                tooltip: '<span>地图移动</span>',
                handler: function() {
                    map.setCurOper(1003);
                }
            }
            ,
            {
                text: '全图',
                icon: 'images/resetmap.gif',
                cls: 'x-btn-text-icon',
                tooltip: '<span>地图复位</span>',
                handler: function() {
                    map.setCurOper(1004);
                }
            }
            ,
            {
                text: '测距离',
                icon: 'images/measure.gif',
                cls: 'x-btn-text-icon',
                tooltip: '<span>图上测量距离</span>',
                handler: function() {
                    map.setCurOper(3001);
                }
            }
             ,
            {
                text: '测面积',
                icon: 'images/area_s.gif',
                cls: 'x-btn-text-icon',
                tooltip: '<span>图上测量面积</span>',
                handler: function() {
                    map.setCurOper(3002);
                }
            }
            ,
            {
                text: '鹰眼',
                icon: 'images/open_eye.gif',
                cls: 'x-btn-text-icon',
                tooltip: '<span>鹰眼定位</span>',
                handler: function() {
                    EagleDisplay();
                }
            }
            ,
            {
                text: '放大镜',
                icon: 'images/7.gif',
                cls: 'x-btn-text-icon',
                tooltip: '<span>放大镜</span>',
                handler: function() {
                    map.setCurOper(3003);
                }
            }
             ,
            {
                text: '拉框查询',
                icon: 'images/rect.gif',
                cls: 'x-btn-text-icon',
                tooltip: '<span>拉框查询</span>',
                handler: function() {
                    map.setCurOper(IMSOperType.SelectByRect);
                }
            }
            ,
            {
                text: '画圆查询',
                icon: 'images/circle.gif',
                cls: 'x-btn-text-icon',
                tooltip: '<span>画圆查询</span>',
                handler: function() {
                    map.setCurOper(IMSOperType.SelectByCircle);
                }
            }
            ,
            {
                text: '多边形查询',
                icon: 'images/polygon.gif',
                cls: 'x-btn-text-icon',
                tooltip: '<span>多边形查询</span>',
                handler: function() {
                    map.setCurOper(IMSOperType.SelectByPolygon);
                }
            }
           ,
            {
                text: '清除',
                icon: 'images/v4.gif',
                cls: 'x-btn-text-icon',
                tooltip: '<span>地图标注</span>',
                handler: function() {
                 oResultPanel.collapse();
                 ClaeaMap();
                }
            } 
             ,
            {
                text: '地图标注',
                icon: 'images/v3.gif',
                cls: 'x-btn-text-icon',
                tooltip: '<span>地图标注</span>',
                handler: function() {
                    //map.setCurOper(IMSOperType.AddLabel);
                    if(document.all.USERID.value!="")
                     {
                        map.setCurOper(3006);
                     }
                     else
                     {
                        alert("请先登陆再标记");
                     }
                }
            }
        );
}

function fnCreateMapFrame() {
    oMapPanel = new Ext.Panel({
        contentEl: 'map-div',
        frame: false,
        border: false,
        autoHeight: true,
        autoWidth: true
    });
}

function fnCreateSouthFrame() {
    oSouthPanel = new Ext.Panel({
        region: 'south',
        id: 'oSouthPanel',
        contentEl: 'south-div',
        split: true,
        frame: false,
        border: true,
        collapsible: false,
        height: 22,
        minSize: 22,
        maxSize: 22
    });
}

function setTabActive(tab) {
    oResultPanel.setTitle(tab.title);
    var tabActive;
    switch (tab.title) {
        case "地名查询":
            tabActive = 0;
            break;
        case "小区查询":
            tabActive = 1;
            break;
       case "道路查询":
            tabActive = 2;
            break;      
        case "楼门牌查询":
            tabActive = 3;
            break;
        case "驾车导航":
            tabActive = 4;
            break;
        case "公交换乘":
            tabActive = 5;
            break;
        case "站点查询":
            tabActive = 6;
            break;
        case "线路查询":
            tabActive = 7;
            break;
        case "周边查询":
            tabActive = 8;
            break;
    }
    for (var i = 0; i < 9; i++) {
        var am = $("tab-div" + i);
        if(am ==null)
            return;
        if (i == tabActive) {
            am.style.display = "block";
            if(i==1)
            {
              UpdateMap("1");
            }
            if(i==2)
            { 
              UpdateMap("2");
            }
        }
        else {
            am.style.display = "none";
        }
    }
}

function clickTabActive(name,type) {
    for (var i = 0; i < 9; i++) {
        var am = $("tab-div" + i);
        am.style.display = "none";
    }
    switch (type) {
        case "1":
            $("txt_bs_start").value = name;
            $("txt_bs_end").value = '';
            $("tab-div4").style.display = "block";
            break;
        case "2":
            $("txt_bs_start").value = '';
            $("txt_bs_end").value = name;
            $("tab-div4").style.display = "block";
            break;
        case "3":
            $("txt_center").value = name;
            $("txt_periphery").value = '';
            $("tab-div7").style.display = "block";
            break;
    }
}
