当前位置 : 主页 > 网络编程 > JavaScript >

改写zyxzWidget.js

来源:互联网 收集:自由互联 发布时间:2021-06-30
资源现状 /** *资源现状 * * @class ForeStar.App.zyxzWidget * @extends ForeStar.App.BizWidget */Forestar.App.zyxzWidget = Forestar.Class(Forestar.App.BizWidget, { zyxz_table: { 1: 'ZYXZ_LDTDGC_ND_TJB', 2: 'ZYXZ_XJJG_ND_TJB', 3: 'ZYXZ_
资源现状
/**
 *资源现状
 * 
 * @class ForeStar.App.zyxzWidget
 * @extends ForeStar.App.BizWidget
 */
Forestar.App.zyxzWidget = Forestar.Class(Forestar.App.BizWidget, {
  zyxz_table: {
    1: 'ZYXZ_LDTDGC_ND_TJB',
    2: 'ZYXZ_XJJG_ND_TJB',
    3: 'ZYXZ_QSJG_ND_TJB',
    4: 'ZYXZ_QYJG_ND_TJB',
    5: 'ZYXZ_SLLBJG_ND_TJB',
    6: '',
  },
  colors1: ['#D11F27', '#6C9F59', '#2FC0B0', '#149C88', '#F2AD52', '#FA7DAA', '#7CEFF0', '#ED952C', '#45ADDE', '#13CD13'], // 蓄积结构模块颜色
  colors_ZYXZ_LDTDGC_ND_TJB: ['#45ADDE', '#6C9F59', '#2FC0B0', '#9400D3', '#F2AD52', '#FA7DAA', '#7CEFF0', '#ADFF2F', '#D11F27'], // 土地构成饼图颜色
  colors_ZYXZ_QSJG_ND_TJB: ['#D11F27', '#6C9F59', '#2FC0B0'], // 权属结构饼图颜色
  colors_ZYXZ_QYJG_ND_TJB: ['#D11F27', '#6C9F59', '#2FC0B0'], // 起源结构饼图颜色
  colors_ZYXZ_SLLBJG_ND_TJB: ['#D11F27', '#6C9F59', '#2FC0B0'], // 森林类别饼图颜色
  dualTableName: null, // 当前所查询的表加_
  dualField: null, // 大柱状图所渲染的当前字段
  index: null, // 资源现状模块下标
  title: null, // 左侧导航所点击的名称
  ZYXZ_LDTDGC_ND_TJB: { 'DL1': '有林地', 'DL2': '疏林地', 'DL3': '灌木林地', 'DL4': '未成林地', 'DL5': '苗圃地', 'DL6': '无立木林地', 'DL7': '宜林地', 'DL8': '林业辅助生产用地', 'DL9': '非林地' },
  ZYXZ_QSJG_ND_TJB: { 'GUO_YOU_MJ': '国有面积', 'JI_TI_MJ': '集体面积', 'GE_REN_MJ': '个人面积' },
  ZYXZ_QYJG_ND_TJB: { 'TIAN_RAN_MJ': '天然面积', 'REN_GONG_MJ': '人工面积' },
  ZYXZ_SLLBJG_ND_TJB: { 'GJGYL_MJ': '国家公益林', 'SJGYL_MJ': '省级公益林', 'SPL_MJ': '商品林' },
  ZYXZ_LDTDGC_ND_TJB_DL1_zq: [], // 林地土地构成
  ZYXZ_LDTDGC_ND_TJB_DL2_zq: [],
  ZYXZ_LDTDGC_ND_TJB_DL3_zq: [],
  ZYXZ_LDTDGC_ND_TJB_DL4_zq: [],
  ZYXZ_LDTDGC_ND_TJB_DL5_zq: [],
  ZYXZ_LDTDGC_ND_TJB_DL6_zq: [],
  ZYXZ_LDTDGC_ND_TJB_DL7_zq: [],
  ZYXZ_LDTDGC_ND_TJB_DL8_zq: [],
  ZYXZ_LDTDGC_ND_TJB_DL9_zq: [],
  ZYXZ_LDTDGC_ND_TJB_DL1_zq_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL2_zq_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL3_zq_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL4_zq_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL5_zq_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL6_zq_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL7_zq_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL8_zq_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL9_zq_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL1_pm: [],
  ZYXZ_LDTDGC_ND_TJB_DL2_pm: [],
  ZYXZ_LDTDGC_ND_TJB_DL3_pm: [],
  ZYXZ_LDTDGC_ND_TJB_DL4_pm: [],
  ZYXZ_LDTDGC_ND_TJB_DL5_pm: [],
  ZYXZ_LDTDGC_ND_TJB_DL6_pm: [],
  ZYXZ_LDTDGC_ND_TJB_DL7_pm: [],
  ZYXZ_LDTDGC_ND_TJB_DL8_pm: [],
  ZYXZ_LDTDGC_ND_TJB_DL9_pm: [],
  ZYXZ_LDTDGC_ND_TJB_DL1_pm_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL2_pm_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL3_pm_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL4_pm_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL5_pm_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL6_pm_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL7_pm_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL8_pm_name: [],
  ZYXZ_LDTDGC_ND_TJB_DL9_pm_name: [],
  ZYXZ_QSJG_ND_TJB_GUO_YOU_MJ_zq: [], // 权属结构
  ZYXZ_QSJG_ND_TJB_JI_TI_MJ_zq: [],
  ZYXZ_QSJG_ND_TJB_GE_REN_MJ_zq: [],
  ZYXZ_QSJG_ND_TJB_GUO_YOU_MJ_zq_name: [],
  ZYXZ_QSJG_ND_TJB_JI_TI_MJ_zq_name: [],
  ZYXZ_QSJG_ND_TJB_GE_REN_MJ_zq_name: [],
  ZYXZ_QSJG_ND_TJB_GUO_YOU_MJ_pm: [],
  ZYXZ_QSJG_ND_TJB_JI_TI_MJ_pm: [],
  ZYXZ_QSJG_ND_TJB_GE_REN_MJ_pm: [],
  ZYXZ_QSJG_ND_TJB_GUO_YOU_MJ_pm_name: [],
  ZYXZ_QSJG_ND_TJB_JI_TI_MJ_pm_name: [],
  ZYXZ_QSJG_ND_TJB_GE_REN_MJ_pm_name: [],
  ZYXZ_QYJG_ND_TJB_TIAN_RAN_MJ_zq: [], // 起源结构
  ZYXZ_QYJG_ND_TJB_REN_GONG_MJ_zq: [],
  ZYXZ_QYJG_ND_TJB_TIAN_RAN_MJ_zq_name: [],
  ZYXZ_QYJG_ND_TJB_REN_GONG_MJ_zq_name: [],
  ZYXZ_QYJG_ND_TJB_TIAN_RAN_MJ_pm: [],
  ZYXZ_QYJG_ND_TJB_REN_GONG_MJ_pm: [],
  ZYXZ_QYJG_ND_TJB_TIAN_RAN_MJ_pm_name: [],
  ZYXZ_QYJG_ND_TJB_REN_GONG_MJ_pm_name: [],
  ZYXZ_SLLBJG_ND_TJB_GJGYL_MJ_zq: [], // 森林类别
  ZYXZ_SLLBJG_ND_TJB_SJGYL_MJ_zq: [],
  ZYXZ_SLLBJG_ND_TJB_SPL_MJ_zq: [],
  ZYXZ_SLLBJG_ND_TJB_GJGYL_MJ_zq_name: [],
  ZYXZ_SLLBJG_ND_TJB_SJGYL_MJ_zq_name: [],
  ZYXZ_SLLBJG_ND_TJB_SPL_MJ_zq_name: [],
  ZYXZ_SLLBJG_ND_TJB_GJGYL_MJ_pm: [],
  ZYXZ_SLLBJG_ND_TJB_SJGYL_MJ_pm: [],
  ZYXZ_SLLBJG_ND_TJB_SPL_MJ_pm: [],
  ZYXZ_SLLBJG_ND_TJB_GJGYL_MJ_pm_name: [],
  ZYXZ_SLLBJG_ND_TJB_SJGYL_MJ_pm_name: [],
  ZYXZ_SLLBJG_ND_TJB_SPL_MJ_pm_name: [],
  pie_data: [], // 饼图数据
  xAxisName: [], // 小柱状图x轴显示名称
  barData: [], // 小柱状图数据
  dataSheet: [], // 数据表数据
  tjdwmc: null, // 统计单位名称
  hlmxjZq_op: [], // 活立木蓄积政区数据
  hlmxjPm_op: [], // 活立木蓄积排名数据
  areaHlmxjZq: null, // 所属政区的活立木蓄积面积
  bar_xAxisName_hlmxj_zq: [], // 活立木蓄积柱状图中x轴名称
  bar_xAxisName_hlmxj_pm: [], // 活立木蓄积柱状图中x轴名称
  slxjZq_op: [], // 森林蓄积政区数据
  bar_xAxisName_slxj_zq: [],
  slxjPm_op: [], // 森林蓄积排名数据
  bar_xAxisName_slxj_pm: [],
  areaSlxjjZq: null, // 所属政区的森林蓄积面积
  bar_xAxisName_slxj: [], // 森林蓄积柱状图中x轴名称
  spxjZq_op: [], // 四旁蓄积政区数据
  bar_xAxisName_spxj_zq: [],
  spxjPm_op: [], // 四旁蓄积排名数据
  bar_xAxisName_spxj_pm: [],
  areaSpxjjZq: null, // 所属政区的四旁蓄积面积
  bar_xAxisName_spxj: [], // 四旁蓄积柱状图中x轴名称
  ssxjZq_op: [], // 散生蓄积政区数据
  bar_xAxisName_ssxj_zq: [],
  ssxjPm_op: [], // 散生蓄积排名数据
  bar_xAxisName_ssxj_pm: [],
  areaSsxjjZq: null, // 所属政区的散生蓄积面积
  bar_xAxisName_ssxj: [], // 散生蓄积柱状图中x轴名称
  columns: [ // 数据表表头
    { field: 'name', title: '地类', align: 'center', valign: 'middle' },
    { field: 'value', title: '面积', align: 'center', valign: 'middle' }
  ],

  /** 初始化 */
  initialize: function () {
    Forestar.App.BizWidget.prototype.initialize.apply(this,
      arguments)
    Forestar.App.zyxzWidget.instance = this;
    /**
    * 点击时时触发
    * 给资源现状下的专题绑定单机事件
    * @event Select#change
    */
    $('.thr-box .thr-item').click(function () {
      var that = Forestar.App.zyxzWidget.instance
      that.index = $(this).attr('index')
      that.title = $($(this).children().children()[0]).html(); // 点击地图时显示的模块名称
      that.dualTableName = that.zyxz_table[that.index] + '_';
      if (that.index != 0 && that.index != 2) {
        var zqcode = Config.zqdwObj.zqcode
        $('#hlmxjl_dom').removeClass('show');
        $('#slxj_dom').removeClass('show');
        $('#spxj_dom').removeClass('show');
        $('#ssxj_dom').removeClass('show');
        $('.zs-board-box').removeClass('show');
        $('#zs-quick-board-gjzb').hide();
        $('#zs-quick-board-xjjg').hide();
        $('.withBtns').removeClass('show');
        $('#ldgc_dom').addClass('show');
        $('#ldgc_dom').show();
        // 初始化林地土地构成模块数据
        Forestar.App.zyxzWidget.instance.getData(that.zyxz_table[that.index], zqcode);
        that.layerShowGjzb(false);
        that.layerShowTdgk(true);
      } else if (that.index == 0){
        $('#hlmxjl_dom').removeClass('show');
        $('#slxj_dom').removeClass('show');
        $('#spxj_dom').removeClass('show');
        $('#ssxj_dom').removeClass('show');
        $('.zy-slfgl').show();
        $('#zs-quick-board-xjjg').hide();
        $('#zs-quick-board-gjzb').show();
        $('#ldgc_dom').removeClass('show');
        that.layerShowGjzb(true);
        that.layerShowTdgk(false); // 隐藏土地概况图层
      } else if (that.index == 2) {
        var zqcode=Config.zqdwObj.zqcode;
        $(".zs-board-box").removeClass("show");
        $("#zs-quick-board-gjzb").hide();
        $(".withBtns").removeClass("show");
        $("#ldgc_dom").removeClass("show");
        $("#ldgc_dom").hide();
        $("#zs-quick-board-xjjg").show();
        Forestar.App.zyxzWidget.instance.getData(that.zyxz_table[that.index], zqcode); // 初始化起源结构数据
        that.layerShowGjzb(false);
        that.layerShowTdgk(false);
      }
    });

    /**
    * 点击时触发
    * 统计类型各个小图标的单机事件
    * @event Select#change
    */
    $('.zt_checkShowLx li').click(function () {
      var that = Forestar.App.zyxzWidget.instance;
      var index = that.index;
      $(this).addClass('selected').siblings().removeClass('selected');
      var id = $(this).attr('href');
      id = id.substr(1, id.length - 1);
      $('#' + id).show().siblings().hide();
    });

    /**
    * 点击时触发
    * 政区和排名按钮的单机事件
    * @event Select#change
    */
    $('#ldgc_dom .idTabs a').click(function () {
      var that = Forestar.App.zyxzWidget.instance;
      var table = that.dualTableName.substring(0, that.dualTableName.length - 1);
      var field = that.dualField;
      var name = $($(this)[0]).attr('name');
      that.createBigBar(table, field, name);
    });

    /**
    * 蓄积机构下政区和排名的单机事件
    */
    $('.zyxz_region_rank').click(function () {
      var that = Forestar.App.zyxzWidget.instance;
      var barName = $(this).attr('barname')
      var id = $(this).attr('val');
      var bar = echarts.init(document.getElementById(id));
      var op = $(this).attr('op');
      bar.setOption(getOption.creatBar1(that[barName], that[op], '亩')); // 加载柱状图
    });
  },

  /**
   * 获取数据
   * 
   * @param {object} zqcode 政区code
   * @param {object} table 表名
   * @param {object} index 点击模块的下标
   */
  getData: function (table, zqcode) {
    var that = Forestar.App.zyxzWidget.instance;
    this.code = zqcode;
    var qf = {}; // queryFilter
    if (zqcode.length <= 4) {
      qf.whereString = "(TJDW like'" + zqcode + "__' or TJDW='" + zqcode + "') and nd='2017' and ZQFZ_LX='10'";
    }
    else {
      qf.whereString = "(TJDW like'" + zqcode + "___' or TJDW='" + zqcode + "') and nd='2017' and ZQFZ_LX='10'";
    }
    qf.orderByString = " TJDW"
    FsService.getEntityList(table, qf, {
      callback: function (res) {
        if (res.length > 0) {
          // 对数据进行处理
          if (table == 'ZYXZ_XJJG_ND_TJB') {
            that.handDataXjjg(res, zqcode);
          } else {
            that.handDataTdgc(res, zqcode, table);
          }
        } else {

        }
      },
      exceptionHandler: function (e) {

      },
    });
  },

  /**
     * 回调函数,处理林地土地构成模块数据
     * 
     * @param {object} res 查询数据库后返回的数据
     * @param {object} zqcode 用户所在的政区code 
     */
  handDataTdgc: function (res, zqcode, table) {
    var that = Forestar.App.zyxzWidget.instance;
    var colors = 'colors_' + table; // 选择查询表所对应的渲染颜色
    var temp;
    var tjdw;
    var transTable = that[table]; // 所查表的字段翻译
    var gColor; // 每一个饼图颜色所生成的渐变色
    var k = 0; // 柱状图对应的颜色的起始下标  
    var colorRank; // 计算每个柱状图所对应颜色级别
    var barColor; // 每个柱状图所对应的颜色
    var field;
    var zqCodeNextLength;
    that.ZYXZ_LDTDGC_ND_TJB_DL1_zq = []; // 林地土地构成
    that.ZYXZ_LDTDGC_ND_TJB_DL2_zq = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL3_zq = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL4_zq = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL5_zq = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL6_zq = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL7_zq = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL8_zq = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL9_zq = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL1_zq_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL2_zq_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL3_zq_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL4_zq_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL5_zq_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL6_zq_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL7_zq_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL8_zq_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL9_zq_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL1_pm = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL2_pm = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL3_pm = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL4_pm = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL5_pm = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL6_pm = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL7_pm = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL8_pm = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL9_pm = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL1_pm_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL2_pm_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL3_pm_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL4_pm_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL5_pm_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL6_pm_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL7_pm_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL8_pm_name = [];
    that.ZYXZ_LDTDGC_ND_TJB_DL9_pm_name = [];
    that.ZYXZ_QSJG_ND_TJB_GUO_YOU_MJ_zq = []; // 权属结构
    that.ZYXZ_QSJG_ND_TJB_JI_TI_MJ_zq = [];
    that.ZYXZ_QSJG_ND_TJB_GE_REN_MJ_zq = [];
    that.ZYXZ_QSJG_ND_TJB_GUO_YOU_MJ_zq_name = [];
    that.ZYXZ_QSJG_ND_TJB_JI_TI_MJ_zq_name = [];
    that.ZYXZ_QSJG_ND_TJB_GE_REN_MJ_zq_name = [];
    that.ZYXZ_QSJG_ND_TJB_GUO_YOU_MJ_pm = [];
    that.ZYXZ_QSJG_ND_TJB_JI_TI_MJ_pm = [];
    that.ZYXZ_QSJG_ND_TJB_GE_REN_MJ_pm = [];
    that.ZYXZ_QSJG_ND_TJB_GUO_YOU_MJ_pm_name = [];
    that.ZYXZ_QSJG_ND_TJB_JI_TI_MJ_pm_name = [];
    that.ZYXZ_QSJG_ND_TJB_GE_REN_MJ_pm_name = [];
    that.ZYXZ_QYJG_ND_TJB_TIAN_RAN_MJ_zq = []; // 起源结构
    that.ZYXZ_QYJG_ND_TJB_REN_GONG_MJ_zq = [];
    that.ZYXZ_QYJG_ND_TJB_TIAN_RAN_MJ_zq_name = [];
    that.ZYXZ_QYJG_ND_TJB_REN_GONG_MJ_zq_name = [];
    that.ZYXZ_QYJG_ND_TJB_TIAN_RAN_MJ_pm = [];
    that.ZYXZ_QYJG_ND_TJB_REN_GONG_MJ_pm = [];
    that.ZYXZ_QYJG_ND_TJB_TIAN_RAN_MJ_pm_name = [];
    that.ZYXZ_QYJG_ND_TJB_REN_GONG_MJ_pm_name = [];
    that.ZYXZ_SLLBJG_ND_TJB_GJGYL_MJ_zq = []; // 森林类别
    that.ZYXZ_SLLBJG_ND_TJB_SJGYL_MJ_zq = [];
    that.ZYXZ_SLLBJG_ND_TJB_SPL_MJ_zq = [];
    that.ZYXZ_SLLBJG_ND_TJB_GJGYL_MJ_zq_name = [];
    that.ZYXZ_SLLBJG_ND_TJB_SJGYL_MJ_zq_name = [];
    that.ZYXZ_SLLBJG_ND_TJB_SPL_MJ_zq_name = [];
    that.ZYXZ_SLLBJG_ND_TJB_GJGYL_MJ_pm = [];
    that.ZYXZ_SLLBJG_ND_TJB_SJGYL_MJ_pm = [];
    that.ZYXZ_SLLBJG_ND_TJB_SPL_MJ_pm = [];
    that.ZYXZ_SLLBJG_ND_TJB_GJGYL_MJ_pm_name = [];
    that.ZYXZ_SLLBJG_ND_TJB_SJGYL_MJ_pm_name = [];
    that.ZYXZ_SLLBJG_ND_TJB_SPL_MJ_pm_name = [];
    that.pie_data = []; // 清空数据
    that.xAxisName = [];
    that.barData = [];
    that.dataSheet = [];
    if (zqcode.length < 6) {
      zqCodeNextLength = zqcode.length + 2;
    } else {
      zqCodeNextLength = zqcode.length + 3;
    }
    for (var i = 0; i < res.length; i++) {
      tjdw = res[i].originalObjects.TJDW;
      if (tjdw == zqcode) { // 获取所点击政区的林地数据
        that.tjdwmc = res[i].originalObjects.TJDWMC;
        for (key in transTable) { // 构建饼图数据
          that.pie_data.push({
            name: transTable[key],
            value: res[0].originalObjects[key],
            field:key
          });
        }
        break;
      }
    }
    // 构建大柱状图数据
    for (key in transTable) {
      field = key; // 每一个模块的最后一个字段
      // 生成渐变色 (每个模块所对应)gradientColor  gradientColor
      gColor = gradientColor(that[colors][k],'#FFFFFF',10);
      for (var i = 0; i < res.length; i++) {
        tjdw = res[i].originalObjects.TJDW;
        if (tjdw.toString().length == zqCodeNextLength) {
          colorRank = ((res[i].originalObjects[key] / that.pie_data[k].value) * 100).toFixed(2);
          barColor = Forestar.App.zyxzWidget.instance.getColor(colorRank, gColor);  
          // 生成饼状图每一部分所对应的柱状图  
          that[table + '_' + key + '_zq'].push({ value: res[i].originalObjects[key], tjdwmc:res[i].originalObjects.TJDWMC, tjdw:res[i].originalObjects.TJDW, itemStyle: { normal: { color: barColor } } }); 
          that[table + '_' + key + '_zq'+ '_name'].push(res[i].originalObjects.TJDWMC);
        }
      }
      that[table + '_' + key + '_pm'] = Forestar.App.zyxzWidget.instance.sortArr(that[table + '_' + key + '_zq']);//按面积大小排序的数据
      for (var m = 0; m < that[table + '_' + key + '_pm'].length; m++) {
        that[table + '_' + key + '_pm' + '_name'].push(that[table + '_' + key + '_pm'][m].tjdwmc);
      }
      k++;
    }
    // 构建数据表和柱状图数据
    for (var i = 0; i < that.pie_data.length; i++) {
      that.xAxisName.push(that.pie_data[i].name);
      that.barData.push({
        TJDWMC: that.pie_data[i].name,
        value: that.pie_data[i].value,
        field: that.pie_data[i].field,
        itemStyle: { normal: { color: that[colors][i] } } });
      temp = {
        name: that.pie_data[i].name,
        value: that.pie_data[i].value,
        field: that.pie_data[i].field,
        color:that[colors][i]
      };
      that.dataSheet.push(temp);
    }
    // 加载简介
    that.getTxt();
    var zyxzPieShow = echarts.init(document.getElementById("pie_boxldgc")); // 获取饼状图容器
    var zyxzBar = echarts.init(document.getElementById("ldgclRight_bar")); // 加载左侧小柱状图容器
    zyxzPieShow.setOption(getOption.createPie(that.pie_data, that[colors]));
    zyxzPieShow.on('click', function (params) { // 饼状图的单击事件
      Forestar.App.zyxzWidget.instance.onClickBarOrPie(params, table);
    });
    zyxzBar.setOption(getOption.creatBar(that.xAxisName, that.barData, '亩')); // 加载柱状图
    zyxzBar.on('click', function (params) {
      //that.callBackBar_tdgc(params, table);
      Forestar.App.zyxzWidget.instance.onClickBarOrPie(params, table);
    });
    that.createSheet(that.dataSheet, that.columns, table);
    that.judgeWhichButtonIsSelected(table, field, that[colors][that[colors].length - 1]);
  },

  /**
   * 根据政区和排名所选中的按钮渲染数据
   * @param  {} table 表名
   * @param  {} field 表中最后一个字段名
   */
  judgeWhichButtonIsSelected: function (table, field, color) {
    var that = Forestar.App.zyxzWidget.instance;
    var name;
    that.dualField = field; // 将渲染的字段传递到公共变量中,供点击政区或排名按钮使用
    $('#ldgc_dom .btns a' ).each(function () { // 判断页面政区和排名哪个按钮被选中,然后渲染数据
      if ($(this).hasClass("selected")) {
        name = $(this).attr('name');
        that.createBigBar(table, field, name);
      }
    });
    var colorMap = gradientColor(color, '#FFFFFF', 10); // 地图渲染所用渐变色
    Forestar.App.zyxzWidget.instance.addLayers(that[table + '_' + field + '_' + name], '亩', that.title, createMapGradientColor(colorMap)); // 渲染地图
  },

  /**
   * 生成大柱状图
   * @param  {} table 表名
   * @param  {} field 表中最后一个字段名
   */
  createBigBar: function (table, field, name) {
    var that = Forestar.App.zyxzWidget.instance;
    var zyxz_bigBar = echarts.init(document.getElementById("ldgc_bar_ld"));//获取大柱状图容器
    zyxz_bigBar.setOption(getOption.creatBar1(that[table + '_' + field + '_' + name + '_name'], that[table + '_' + field + '_' + name], '亩')); // 加载大柱状图
  },

  /**
   * 点击饼图或是柱状图的单机事件
   * @param  {} params 图形所传递的参数
   * @param  {} table 表名
   */
  onClickBarOrPie: function (params, table) {
    var fieldName = params.data.field;
    var color = params.color;
    Forestar.App.zyxzWidget.instance.judgeWhichButtonIsSelected(table, fieldName, color);
  },

  /**
     * 用bootstrap生成数据表格
     * @param {object} data 生成表格的数据
     * @param {object} columns 表头文字
     * @date 
     */
  createSheet: function (data, columns, table) {
    $('#ldgc_table').bootstrapTable('destroy').bootstrapTable({
      method: 'get',
      cache: false,
      height: 200,
      width: 300,
      striped: false, // 是否显示行间隔色设置为 true 会有隔行变色效果
      pageSize: 5, // 如果设置了分页,页面数据条数
      pageNumber: 1, // 如果设置了分页,首页页码
      uniqueId: '', // Indicate an unique identifier for each row
      exportOptions: {
        fileName: '统计表', // 文件名称设置  
        worksheetName: 'sheet1', // 表格工作区名称  
        tableName: '统计表'
      },
      columns: columns,
      onClickRow: function (row, field) {
        var that = Forestar.App.zyxzWidget.instance;
        that.dataSheetOnClick_zyxz(row, table);
      },
      onCheck: function (row) { // 当用户点击一行的时候,单行最前面的checkbox被选中
        if (row.ZQCODE) {
          this.exportDataType = "selected";
        }
      },
      onUncheck: function (row, ele) { // 单行最前面的checkbox被取消
        this.exportDataType = "all";
      },
      onCheckAll: function (arg1, arg2) { // 最顶上的checkbox被选中
        this.exportDataType = "basic";
      },
      onUncheckAll: function (arg1, arg2) { // 最顶上的checkbox被取消
        this.exportDataType = "all";
      },
      data: data
    });
  },

  /**
   * 显示关键指标图层
   */
  layerShowGjzb:function (falseOrTrue) {
    var gjzbLayer=Forestar.App.combineMap._map2D.getLayer('g_layer'); // 获取关键指标渲染图层
    if (gjzbLayer) {
      gjzbLayer.setVisibility(falseOrTrue); // 设置该图层可见
    }
  },

  /**
   * 显示土地概况图层
   * 
   */
  layerShowTdgk: function (falseOrTrue){
    var tdgkLayer=Forestar.App.combineMap._map2D.getLayer('tdgc_layer'); // 获取土地概况渲染图层
    if (tdgkLayer) {
      tdgkLayer.setVisibility(falseOrTrue); // 设置该图层不可见
    }
  },

  /**
   * 资源现状数据表格的单击事件
   * @param  {} row 行的属性信息
   * @param  {} field 字段的属性信息
   */
  dataSheetOnClick_zyxz: function (row, table) {
    Forestar.App.zyxzWidget.instance.judgeWhichButtonIsSelected(table, row.field, row.color);
  },

  /**
   * 林地土地构成模块简介
   */
  getTxt: function () {
    var that = Forestar.App.zyxzWidget.instance;
    var html = '';
    html = that.tjdwmc;
    for (var i = 0; i < that.pie_data.length; i++) {
      html += that.pie_data[i].name + "面积为" + "" + that.pie_data[i].value + "" + "亩,"
    }
    var htmls = html.substring(0, html.length - 1) + '。';
    $('#ldgc-texts').html('');
    $('#ldgc-texts').html(htmls);
  },

  /**
   * 蓄积结构模块简介
   */
  getTxt_xjjg: function () {
    var that = Forestar.App.zyxzWidget.instance;
    var html = '';
    html = that.tjdwmcXjjg + "活立木蓄积面积为" + "" + that.areaHlmxjZq + "" + "公顷," + "森林蓄积面积为" + "" + that.areaSlxjjZq + "" + "公顷,"
    + "四旁蓄积面积为" + "" +that.areaSpxjjZq + "" + "公顷," + "散生蓄积面积为" + "" + that.areaSsxjjZq+ "" + "公顷。"
    //清空简介
    $("#txt-hlm-hlmxjl").html("");
    $("#txt-hlm-slxj").html("");
    $("#txt-hlm-spxj").html("");
    $("#txt-hlm-ssxj").html("");
    //添加简介
    $("#txt-hlm-hlmxjl").html(html);
    $("#txt-hlm-slxj").html(html);
    $("#txt-hlm-spxj").html(html);
    $("#txt-hlm-ssxj").html(html);
  },

  /**
   *  回调函数,处理蓄积结构模块数据
   * @param  {} res 查询数据库后返回的数据
   * @param  {} zqcode用户所在的政区code
   */
  handDataXjjg: function (res, zqcode) {
	var that = Forestar.App.zyxzWidget.instance;
	var hlmxjArea = 0, slxjArea = 0, spxjArea = 0, ssxjArea = 0;
	var barColor_hlmxj, barColor_slxj, barColor_spxj, barColor_ssxj;
	var tjdw;
	//清空数据
	that.spxjZq_op = [];
	that.spxjPm_op = [];
	that.ssxjZq_op = [];
	that.ssxjPm_op = [];
	that.bar_xAxisName_hlmxj = [];
	that.bar_xAxisName_slxj = [];
	that.bar_xAxisName_spxj = [];
	that.bar_xAxisName_ssxj = [];
	that.areaHlmxjZq = 0;
	that.areaSlxjjZq = 0;
	that.areaSpxjjZq = 0;
	that.areaSsxjjZq = 0;
	var sortData_hlmxj = [];//排序后的活立木蓄积数据
	var sortData_slxj = [];//排序后的森林蓄积数据
	var sortData_spxj = [];//排序后的四旁蓄积数据
	var sortData_ssxj = [];//排序后的散生蓄积数据
	for (var i = 0; i < res.length; i++) {
	  if (res[i].originalObjects.TJDW == zqcode) {
		that.tjdwmcXjjg = res[i].originalObjects.TJDWMC;
		that.areaHlmxjZq = res[i].originalObjects.HUO_LM_XJ;
		that.areaSlxjjZq = res[i].originalObjects.SEN_LIN_XJ;
		that.areaSpxjjZq = res[i].originalObjects.SI_PANG_XJ;
		that.areaSsxjjZq = res[i].originalObjects.SAN_S_XJ;
		if (that.areaSpxjjZq == undefined) {
          that.areaSpxjjZq = 0;
		}
		if (that.areaHlmxjZq == undefined) {
          that.areaHlmxjZq = 0;
		}
		if (that.areaSlxjjZq == undefined) {
          that.areaSlxjjZq = 0;
		}
	    if (that.areaSsxjjZq == undefined ) {
          that.areaSsxjjZq = 0;
		}
	  }
	  break;
	}
	that.hlmxjZq_op = [];
	that.bar_xAxisName_hlmxj_zq = [];
	that.hlmxjPm_op = [];
	that.bar_xAxisName_hlmxj_pm = [];
	that.slxjZq_op = [];
	that.bar_xAxisName_slxj_zq = [];
	that.slxjPm_op = [];
	that.bar_xAxisName_slxj_pm = [];
	for (var i = 0; i < res.length; i++) {
	  tjdw = res[i].originalObjects.TJDW;
	  if (tjdw.toString().length != zqcode.length) {
		var obj = res[i].originalObjects;
		hlmxjArea = obj.HUO_LM_XJ;
		slxjArea = obj.SEN_LIN_XJ;
		spxjArea = obj.SI_PANG_XJ;
		ssxjArea = obj.SAN_S_XJ;
		  if (hlmxjArea == undefined) {
			hlmxjArea = 0;
		  }
		  else if (slxjArea == undefined) {
			slxjArea = 0;
		  }
		  else if (spxjArea == undefined) {
			spxjArea = 0;
		  }
		  else if (ssxjArea == undefined) {
			ssxjArea = 0;
		  }
          barColor_hlmxj = Forestar.App.zyxzWidget.instance.getColorByValue(hlmxjArea);
          // 构建活立木蓄积柱状图数据
          that.hlmxjZq_op.push({ "tjdw": obj.TJDW, "TJDWMC": obj.TJDWMC, "value": hlmxjArea, itemStyle: { normal: { color: barColor_hlmxj } } });
          that.bar_xAxisName_hlmxj_zq.push(obj.TJDWMC);
          // 构建森林蓄积柱状图数据
		  barColor_slxj = Forestar.App.zyxzWidget.instance.getColorByValue(slxjArea);
		  that.slxjZq_op.push({ "tjdw": obj.TJDW, "TJDWMC": obj.TJDWMC, "value": slxjArea, itemStyle: { normal: { color: barColor_slxj } } });
          that.bar_xAxisName_slxj_zq.push(obj.TJDWMC);
          // 构建四旁蓄积柱状图数据
          barColor_spxj = Forestar.App.zyxzWidget.instance.getColorByValue(spxjArea);
		  that.spxjZq_op.push({ "tjdw": obj.TJDW, "TJDWMC": obj.TJDWMC, "value": spxjArea, itemStyle: { normal: { color: barColor_spxj } } });
          that.bar_xAxisName_spxj_zq.push(obj.TJDWMC);
          // 构建散生蓄积柱状图数据
          barColor_ssxj = Forestar.App.zyxzWidget.instance.getColorByValue(ssxjArea);
		  that.ssxjZq_op.push({ "tjdw": obj.TJDW, "TJDWMC": obj.TJDWMC, "value": ssxjArea, itemStyle: { normal: { color: barColor_ssxj } } });
          that.bar_xAxisName_ssxj_zq.push(obj.TJDWMC);
        }
	}
	// 对活立木蓄积数据进行排序
	sortData_hlmxj = Forestar.App.zyxzWidget.instance.sortArr(that.hlmxjZq_op);//按面积大小排序的数据
	// 构建活立木蓄积排序后的柱状图数据
	for(var i = 0; i < sortData_hlmxj.length; i++){
	  that.bar_xAxisName_hlmxj_pm.push(sortData_hlmxj[i].TJDWMC);
	  that.hlmxjPm_op.push({ "value": sortData_hlmxj[i].value, tjdw:sortData_hlmxj[i].tjdw, itemStyle:  sortData_hlmxj[i].itemStyle });
	}
	// 对森林蓄积数据进行排序
	sortData_slxj = Forestar.App.zyxzWidget.instance.sortArr(that.slxjZq_op); // 按面积大小排序的数据
	// 构建森林蓄积排序后的柱状图数据
	for(var i = 0; i < sortData_slxj.length; i++){
	  that.bar_xAxisName_slxj_pm.push(sortData_slxj[i].TJDWMC);
	  that.slxjPm_op.push({ "value": sortData_slxj[i].value, tjdw:sortData_slxj[i].tjdw, itemStyle:  sortData_slxj[i].itemStyle });
	}
	// 对四旁蓄积数据进行排序
	sortData_spxj = Forestar.App.zyxzWidget.instance.sortArr(that.spxjZq_op); // 按面积大小排序的数据
	// 构建四旁蓄积排序后的柱状图数据
	for(var i = 0; i < sortData_spxj.length; i++){
	  that.bar_xAxisName_spxj_pm.push(sortData_spxj[i].TJDWMC);
	  that.spxjPm_op.push({ "value": sortData_spxj[i].value, tjdw:sortData_spxj[i].tjdw, itemStyle: sortData_spxj[i].itemStyle });
	}
	// 对散生蓄积数据进行排序
	sortData_ssxj = Forestar.App.zyxzWidget.instance.sortArr(that.ssxjZq_op); // 按面积大小排序的数据
	// 构建散生蓄积排序后的柱状图数据
	for(var i = 0; i < sortData_ssxj.length; i++){
	  that.bar_xAxisName_ssxj_pm.push(sortData_ssxj[i].TJDWMC);
	  that.ssxjPm_op.push({ "value": sortData_ssxj[i].value, tjdw:sortData_ssxj[i].tjdw, itemStyle:  sortData_ssxj[i].itemStyle });
	}
	that.getBar();
	that.getTxt_xjjg();
  },    

  /**
   * 按比例获取柱状图的颜色
   * @param  {} value 每一个柱子的值占所有柱子值的比例
   */
  getColor: function (value, colors) {
    var color;

    if (value <= 10) {
      color = colors[0];
    } else if (value <= 20) {
      color = colors[1];
    } else if (value <= 30) {
      color = colors[2];
    } else if (value <= 40) {
      color = colors[3];
    } else if (value <= 50) {
      color = colors[4];
    } else if (value <= 60) {
      color = colors[5];
    } else if (value <= 70) {
      color = colors[6];
    } else if (value <= 80) {
      color = colors[7];
    } else if (value <= 90) {
      color = colors[8];
    } else if (value <= 100) {
      color = colors[9];
    }
    return color;
  },

  /**
   * 通过值的大小获取柱状图的颜色
   * @param  {} value
   */
  getColorByValue: function (value) {
    var color;
    var that = Forestar.App.zyxzWidget.instance;
    if (135000 < value) {
      color = that.colors1[0];
    } else if (120000 < value <= 135000) {
      color = that.colors1[1];
    } else if (105000 < value <= 120000) {
      color = that.colors1[2];
    } else if (90000 < value <= 105000) {
      color = that.colors1[3];
    } else if (750000 < value <= 90000) {
      color = that.colors1[4];
    } else if (60000 < value <= 75000) {
      color = that.colors1[5];
    } else if (45000 < value <= 60000) {
      color = that.colors1[6];
    } else if (30000 < value <= 45000) {
      color = that.colors1[7];
    } else if (15000 < value <= 30000) {
      color = that.colors1[8];
    } else if (value <= 15000) {
      color = that.colors1[9];
    }
    return color;
  },

  /**
   * 生成蓄积结构柱状图
  */
  getBar: function () {
    var that = Forestar.App.zyxzWidget.instance;
    var colors1Map = createMapGradientColor(that.colors1);
    $("#zs-quick-board-xjjg a").each(function () {
      $(".hideInXjjg").removeClass("show");
      if ($(this).hasClass("selected")) {
        var id = $(this).attr("name");
        var title = $(this).html();
        $("#" + id).addClass("show");
        $("#" + id + " .btns a").each(function () {
          if ($(this).hasClass("selected")) {
            var barName = $(this).attr("barname")
            var ids = $(this).attr("val");
            var bar = echarts.init(document.getElementById(ids));
            var op = $(this).attr("op");
            bar.setOption(getOption.creatBar1(that[barName], that[op], "亩"));//加载柱状图
			// 地图渲染
			Forestar.App.zyxzWidget.instance.addLayers(that[op], '亩', title, colors1Map);
          }
        })
      }
    });
    $("#zs-quick-board-xjjg a").click(function () {
      $(".hideInXjjg").removeClass("show");
      if ($(this).hasClass("selected")) {
        var id = $(this).attr("name");
        var title = $(this).html();
        $("#" + id).addClass("show");
        $("#" + id + " .btns a").each(function () {
          if ($(this).hasClass("selected")) {
            var barName = $(this).attr("barname")
            var ids = $(this).attr("val");
            var bar = echarts.init(document.getElementById(ids));
            var op = $(this).attr("op");
            bar.setOption(getOption.creatBar1(that[barName], that[op], "亩"));//加载柱状图
			// 地图渲染
			Forestar.App.zyxzWidget.instance.addLayers(that[op], '亩', title, colors1Map);
          }
        })
      }
    });
  },

  /**
    * 对获取到的数据按值大小进行排序
    * @param {object} arr 需要排序的数组
    */
  sortArr: function (arr) {
    //这个排序方法 生成新的数组  不改变原来的数组
    var arr1 = [];
    for (var i = 0; i < arr.length; i++) {
      arr1.push(arr[i]);
    }
    arr1.sort(function (a, b) {
      return b.value - a.value;
    });
    return arr1;
  },
    
  /**
   * 加载自定义的图层
   * @param  {} dataArr 柱状图数据
   * @param  {} dw 单位
   * @param  {} name 
   * @param  {} mapLayer 自定义图层
   */
  addLayers: function (dataArr, dw, name, mapLayer) {
    var that = Forestar.App.zyxzWidget.instance;
    var map = Forestar.App.combineMap._map2D;
    var tdgcLayer;
    var layer = Forestar.App.combineMap._map2D.getLayer("tdgc_layer");
    if (layer) {
      layer.clear();
      tdgcLayer = layer;
    } else {
      tdgcLayer = new esri.layers.GraphicsLayer({ "id": "tdgc_layer" });
    }
    tdgcLayer.graphics = [];
    var outlineSyml = new esri.symbol.SimpleLineSymbol(
      esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([
        255, 255, 255, 0.5
      ]), 1);
    var colors = mapLayer;
    var color = colors["#C7FDC7"];
    var url = "js/json";
    if (that.code.length == 2) {
      url += "/shi.json";
    } else if (that.code.length == 4) {
      url += "/xian/" + that.code + ".json";
    } else {
      url += "/xian/" + that.code.substring(0, 4) + ".json";
    }
    $.get(url, null, function (result) {
      var res = JSON.stringify(result);
      res = eval("(" + res + ")");
      var jsonf = geoJsonConverter();
      var json = jsonf.toEsri(result);
      var features = json.features;
      for (var i = 0; i < features.length; i++) {
        var feature = features[i].geometry;
        var shiN = features[i].attributes.SHI_Name;
        var m = 0;
        if (feature.rings.length > 1) {
          for (var j = 1; j < feature.rings.length; j++) {
            if (feature.rings[j].length >= feature.rings[m].length) {
              m = j;
            }
          }
          var arr = feature.rings[m];
          feature.rings = [];
          feature.rings[0] = arr;
        }
        var attr = features[i].attributes;
        if (dataArr) {
          if (that.code.length == 2) {
            var code = "";
            if (attr.SHI.length == 2) {
              code = attr.SHENG + attr.SHI;
            } else {
              code = attr.SHENG + "0" + attr.SHI;
            }
            for (var k = 0; k < dataArr.length; k++) {
              if (dataArr[k].tjdw == code) {
                attr.value = dataArr[k].value;
                attr.tjdwmc = dataArr[k].TJDWMC;
                color = colors[dataArr[k].itemStyle.normal.color];
              }
            }
          } else if (that.code.length == 4) {
            for (var k = 0; k < dataArr.length; k++) {
              if (dataArr[k].tjdw == code) {
                attr.value = dataArr[k].value;
                attr.tjdwmc = dataArr[k].TJDWMC;
                color = colors[dataArr[k].itemStyle.normal.color];
              }
            }
          }
        }
        var infoTemplate = new esri.InfoTemplate("简介", "政区:${tjdwmc}" + name + ":${value}" + dw);
        var myPolygon = {
            "geometry": feature, "attributes": attr, "infoTemplate": infoTemplate,
            "symbol": {
                "color": color, "outline": {
                    "color": [255, 255, 255, 255],
                    "width": 1, "type": "esriSLS", "style": "esriSLSSolid"
                },
                "type": "esriSFS", "style": "esriSFSSolid"
            }
        };
        var graphic = new esri.Graphic(myPolygon);
         tdgcLayer.add(graphic);
      }
      map.addLayer(tdgcLayer);
    });
  },
  CLASS_NAME: "Forestar.App.zyxzWidget"
});
Forestar.App.zyxzWidget.instance = null;
网友评论