zengh
2022-05-16 63ad2c3598400370dd7da5534659fd7e768a0a4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
 * 时间轴widget
 * @author Liuyl
 * @date 2015/10/15
 */
define([
    "dojo/_base/declare", "dojo/_base/array", "dojo/_base/lang",
    "dojo/dom", "dojo/dom-style", "dojo/dom-class", "dojo/dom-attr", "dojo/dom-construct",
    "dojo/topic",
    "dijit/_WidgetBase", "dijit/_TemplatedMixin",
    "dojo/text!controls/timeslider/TimeSliderControl.html",
    "base/BaseControl", "base/AppEvent",
    "utils/LayerUtil",
    "controls/timeslider/js/jquery.ui.timeslider"
], function(
    declare, arrayUtil, lang,
    dom, domStyle, domClass, domAttr, domConstruct,
    topic,
    _WidgetBase, _TemplatedMixin,
    template,
    BaseControl, AppEvent,
    LayerUtil
) {
    var Widget = declare("TimeSliderControl", [BaseControl], {
        templateString: template,
        baseClass: "timeslider-base",
        constructor: function(options) {
            this.index = {};
 
            AppEvent.addAppEventListener(AppEvent.SWITCH_BASEMAP, lang.hitch(this, function(evt) {
                if(this.id == evt.sender){
                    return;
                }
                if (evt.hockId != this.hockId)
                    return;
                if (this.curGroupId == evt.grouplayer && this.curSetId == evt.setlayer) {
                    return;
                }
                var groupid = evt.grouplayer;
                
                if(evt.setlayer){
                    setid = evt.setlayer;
                }else{
                    //根据时间查找Group中的layerset是否有时间,没有的话设为默认
                    setid = this.index[groupid]["defaultset"];
                    arrayUtil.forEach(Object.keys(this.index[groupid]), lang.hitch(this, function(key) {
                        if(key!="defaultset"&&key!="slider"&&setid==this.index[groupid][key]){
                            this.index[groupid].slider.timeslider("setCurrent", parseInt(key));
                        }
                    }));
                    
                    arrayUtil.forEach(Object.keys(this.index[groupid]), lang.hitch(this, function(key) {
                        if (key!="defaultset"&&key!="slider"&&this._parseResult.groups[groupid].layerset[this.index[groupid][key]].label == this._parseResult.groups[this.curGroupId].layerset[this.curSetId].label) {
                            this.index[groupid].slider.timeslider("setCurrent", parseInt(key));
                            setid = this.index[groupid][key];
                        }
                        
                    }));
                }
                domStyle.set(this.index[this.curGroupId].slider[0], "display", "none");
                domStyle.set(this.index[groupid].slider[0], "display", "block");
                var curIndex = this.index[groupid].slider.timeslider("getCurrent");
//                if (this.index[groupid][curIndex] != setid) {
//                    arrayUtil.forEach(Object.keys(this.index[groupid]), lang.hitch(this, function(key) {
//                        if (key!="defaultset"&&this.index[groupid][key] == setid) {
//                            this.index[groupid].slider.timeslider("setCurrent", parseInt(key));
//                        }
//                    }));
//                }
 
                this.curGroupId = groupid;
                this.curSetId = this.index[groupid][curIndex];
 
            }));
        },
        startup: function() {
            try {
                this.inherited(arguments);
                this.curGroupId = this.visibleGroupLayerId;
                this.curSetId = this.visibleSetLayerId;
                this._parseResult = LayerUtil.parseGroups(this.grouplayersConfig);
                this.groups = this._parseResult.groupsInOrder;
                arrayUtil.forEach(this.groups, lang.hitch(this, function(group, index) {
                    this.index[group] = {};
                    var sliderDom = domConstruct.create("div", {
                        "groupid": group,
                        className: "timeslider_container"
                    }, this.domNode);
                    domStyle.set(sliderDom, "display", "none");
                    var timeset = [];
                    //var setCount = this._parseResult.groups[group].layersetInOrder.length;
                    var curIndex = 0;
                    arrayUtil.forEach(this._parseResult.groups[group].layersetInOrder, lang.hitch(this, function(set, index) {
                        var layerset=this._parseResult.groups[group].layerset[set];
                        timeset[index] = layerset.label;
                        this.index[group][index] = layerset.id;
                        if (this.curSetId == layerset.id) {
                            curIndex = index;
                        }
                    }));
                    $(sliderDom).timeslider({
                        groupName:this._parseResult.groups[group].label,
                        timeset: timeset,
                        max: timeset.length,
                        min: 0,
                        reverse: true,
                        timeChangeHandler: lang.hitch(this, function(index) {
                            var setid = this.index[this.curGroupId][index];
                            this.curSetId = setid;
                            AppEvent.dispatchAppEvent(AppEvent.SWITCH_BASEMAP, {
                                hockId: this.hockId,
                                grouplayer: this.curGroupId,
                                setlayer: setid,
                                sender:this.id
                            });
                        })
                    });
                    this.index[group].slider = $(sliderDom);
                    this.index[group].defaultset = this._parseResult.groups[group].defaultset;
                    $(sliderDom).timeslider("setCurrent", curIndex);
                }));
                domStyle.set(this.index[this.curGroupId].slider[0], "display", "block");
            } catch (err) {
                console.log(err);
            }
        },
        show: function() {
            domStyle.set(this.domNode, "display", "block");
        },
        hide: function() {
            domStyle.set(this.domNode, "display", "none");
        }
    });
    return Widget;
});