| New file |
| | |
| | | /** |
| | | * 时间轴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; |
| | | }); |