liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
widgets/legends/Widget.js
@@ -3,66 +3,154 @@
// 模块描述:显示坐标
///////////////////////////////////////////////////////////////////////////
define([
   'dojo/_base/declare',
   'dojo/_base/lang',
   'dojo/_base/array',
   'dojo/_base/html',
   'dojo/topic',
   'jimu/BaseWidget',
   'jimu/utils',
   'jimu/css!libs/zTree_v3/css/zTreeStyle/zTreeStyle.css',
   'libs/zTree_v3/js/jquery.ztree.all'
],
   function (declare,
      lang,
      array,
      html,
      topic,
      BaseWidget,
      aspect,
      string,
      utils
   ) {
      return declare([BaseWidget], {
         baseClass: 'jimu-widget-legends',
         name: 'legends',
         layers: {},
         startup: function () {
            // 暴露在外的接口
        'dojo/_base/declare',
        'dojo/_base/lang',
        'dojo/_base/array',
        'dojo/_base/html',
        'dojo/topic',
        'jimu/BaseWidget',
        'jimu/utils',
        'jimu/css!libs/zTree_v3/css/zTreeStyle/zTreeStyle.css',
        'libs/zTree_v3/js/jquery.ztree.all'
    ],
    function (declare,
        lang,
        array,
        html,
        topic,
        BaseWidget,
        aspect,
        string,
        utils
    ) {
        return declare([BaseWidget], {
            baseClass: 'jimu-widget-legends',
            name: 'legends',
            layers: {},
            startup: function () {
                // 暴露在外的接口
                topic.subscribe("getLegendsData", lang.hitch(this, this.onGetLegendsData));
                topic.subscribe("addLayersLegends", lang.hitch(this, this.addLayersLegends));
                topic.subscribe("removeLayersLegends", lang.hitch(this, this.removeLayersLegends));
         },
            },
            onGetLegendsData: function (item, data, imgurl, type) {
                if (item == this.name) {
         closeToolBox: function (item) {
         },
                    var domq = $("#legendsInquanjing");
                    domq.empty();
                    var liList = $(".jimu-widget-legends .layer-legends li");
                    if (data == "" && data.length == 0) {
                        if (liList.length == 0) {
                            $(".jimu-widget-legends").stop().hide();
                        }
                        return;
                    }
         onOpen: function () {
            //面板打开的时候触发 (when open this panel trigger)
         },
                    var onceData = {};
         onClose: function () {
            //面板关闭的时候触发 (when this panel is closed trigger)
         },
         onMinimize: function () {
            this.resize();
         },
                    for (var k in data) {
         onMaximize: function () {
            this.resize();
         },
                        if (type == "全景站点") {
         resize: function () {
                            onceData[data[k].protectArea] = onceData[data[k].protectArea] == undefined ? 1 : onceData[data[k].protectArea] += 1;
         },
         begin: function () {
         },
                        } else if (type == "监控站点") {
         destroy: function () {
            //销毁的时候触发
            //todo
            //do something before this func
            this.inherited(arguments);
         }
                            onceData[data[k].protectName] = onceData[data[k].protectName] == undefined ? 1 : onceData[data[k].protectName] += 1;
      });
   });
                        } else if (type == "监测站点") {
                            onceData[data[k].wetlandName_] = onceData[data[k].wetlandName_] == undefined ? 1 : onceData[data[k].wetlandName_] += 1;
                        }
                    }
                    var itemBox = $("<div class='m-init'> <i class='m-init-h'><img src='" + imgurl + "' /></i> " + type + " <i>(" + data.length + "个)</i> </div>")
                    var h = '';
                    for (var k in onceData) {
                        h += `<div class="m-init m-i-child"> <i></i> ${k}<i>(${onceData[k]}个)</i> </div>`;
                    }
                    domq.append(itemBox , h);
                    $(".jimu-widget-legends").stop().show();
                }
            },
            addLayersLegends: function (item, obj) {
                if (item == this.name) {
                    if (obj.attList && obj.attList.length > 0) {
                        for (var i = 0; i < obj.attList.length; i++) {
                            var list = $("<li class='m-init' itemid='" + obj.id + "'>" +
                                "<i class='m-init-h'><img src='" + obj.attList[i].uaOriginPath + "' /></i>" +
                                "<span title='" + obj.title + "'>" +
                                obj.title +
                                "</span>" +
                                "</li>")
                            $(".jimu-widget-legends .layer-legends").append(list);
                        }
                    }
                    var liList = $(".jimu-widget-legends .layer-legends li");
                    if (liList.length > 0 && $(".jimu-widget-legends").is(":hidden")) {
                        $(".jimu-widget-legends").stop().show();
                    }
                }
            },
            removeLayersLegends: function (item, obj) {
                // console.log(obj)
                if (item == this.name) {
                    var liList = $(".jimu-widget-legends .layer-legends li");
                    for (var i = 0; i < liList.length; i++) {
                        if ($(liList[i]).attr('itemid') && $(liList[i]).attr('itemid') == obj.id) {
                            $(liList[i]).remove();
                        }
                    }
                    var domq = $("#legendsInquanjing");
                    if ($(".jimu-widget-legends .layer-legends li").length == 0 && domq.text().trim() == "") {
                        $(".jimu-widget-legends").stop().hide();
                    }
                }
            },
            closeToolBox: function (item) {},
            onOpen: function () {
                //面板打开的时候触发 (when open this panel trigger)
                $(".jimu-widget-legends").stop().hide();
            },
            onClose: function () {
                //面板关闭的时候触发 (when this panel is closed trigger)
            },
            onMinimize: function () {
                this.resize();
            },
            onMaximize: function () {
                this.resize();
            },
            resize: function () {
            },
            begin: function () {},
            destroy: function () {
                //销毁的时候触发
                //todo
                //do something before this func
                this.inherited(arguments);
            }
        });
    });