| New file |
| | |
| | | define(["base/AppEvent", |
| | | "base/ConfigData", |
| | | "dojo/_base/declare", |
| | | "dojo/_base/lang", |
| | | "dojo/dom", |
| | | "dojo/dom-construct", |
| | | "dojo/dom-attr", |
| | | "dojo/dom-class", |
| | | "dojo/on", |
| | | "utils/LayerUtil", |
| | | "utils/ConfigUtil", |
| | | "controls/toolbar/tools/Map3DTool", |
| | | "controls/toolbar/tools/SwipeTool", |
| | | "controls/toolbar/tools/ZoomInTool", |
| | | "controls/toolbar/tools/ZoomOutTool", |
| | | "controls/toolbar/tools/PanTool", |
| | | "controls/toolbar/tools/FullScreenTool", |
| | | "controls/toolbar/tools/ScreenWindowTool", |
| | | "controls/toolbar/tools/StreetViewTool", |
| | | "controls/toolbar/tools/MeasureLineTool", |
| | | "controls/toolbar/tools/MeasurePolygonTool", |
| | | "controls/toolbar/tools/ErrCorrectTool", |
| | | "controls/toolbar/tools/ClearTool", |
| | | "controls/toolbar/tools/CityLayerTool", |
| | | "controls/toolbar/tools/LocationTool", |
| | | "dojo/dom-style", |
| | | "dojo/domReady!" |
| | | ], |
| | | function(AppEvent, |
| | | ConfigData, |
| | | declare, |
| | | lang, |
| | | dom, |
| | | domConstruct, |
| | | domAttr, |
| | | domClass, |
| | | on, |
| | | LayerUtil, |
| | | ConfigUtil, |
| | | Map3DTool, |
| | | SwipeTool, |
| | | ZoomInTool, |
| | | ZoomOutTool, |
| | | PanTool, |
| | | FullScreenTool, |
| | | ScreenWindowTool, |
| | | StreetViewTool, |
| | | MeasureLineTool, |
| | | MeasurePolygonTool, |
| | | ErrCorrectTool, |
| | | ClearTool, |
| | | CityLayerTool, |
| | | LocationTool, |
| | | domStyle) { |
| | | return declare("WidgetManager", null, { |
| | | //-------------------------------------------- |
| | | // 系统所有widget的配置 |
| | | //-------------------------------------------- |
| | | _widgetsConfig: [{ |
| | | "label": "分析研判", |
| | | "id": "AnalysisAndJudgment", |
| | | "widgetClass": "widgets/analysisAndJudgment/AnalysisAndJudgment", |
| | | "type": "sider", |
| | | "cssPath": "widgets/analysisAndJudgment/AnalysisAndJudgment.css", |
| | | "actived": false |
| | | }, |
| | | // { |
| | | // "label": "周界检测", |
| | | // "id": "PerimeterDetection", |
| | | // "widgetClass": "widgets/perimeterDetection/PerimeterDetection", |
| | | // "type": "sider", |
| | | // "cssPath": "widgets/perimeterDetection/PerimeterDetection.css", |
| | | // "actived": false |
| | | // }, |
| | | // { |
| | | // "label": "入口安检", |
| | | // "id": "EntranceSecurity", |
| | | // "widgetClass": "widgets/entranceSecurity/EntranceSecurity", |
| | | // "type": "sider", |
| | | // "cssPath": "widgets/entranceSecurity/EntranceSecurity.css", |
| | | // "actived": false |
| | | // }, |
| | | { |
| | | "label": "实时报警", |
| | | "id": "RealTimePolice", |
| | | "widgetClass": "widgets/realTimePolice/RealTimePolice", |
| | | "type": "sider", |
| | | "cssPath": "widgets/realTimePolice/RealTimePolice.css", |
| | | "actived": false |
| | | }, |
| | | { |
| | | "label": "客户管理", |
| | | "id": "ClientManagement", |
| | | "widgetClass": "widgets/clientManagement/ClientManagement", |
| | | "type": "sider", |
| | | "cssPath": "widgets/clientManagement/ClientManagement.css", |
| | | "actived": false |
| | | }, |
| | | { |
| | | "label": "设备管理", |
| | | "id": "equipment", |
| | | "widgetClass": "widgets/equipment/ClientManagement", |
| | | "type": "sider", |
| | | "cssPath": "widgets/equipment/ClientManagement.css", |
| | | "actived": false |
| | | }, |
| | | { |
| | | "label": "警情调度", |
| | | "id": "PoliceDispatching", |
| | | "widgetClass": "widgets/policeDispatching/PoliceDispatching", |
| | | "type": "sider", |
| | | "cssPath": "widgets/policeDispatching/PoliceDispatching.css", |
| | | "actived": false |
| | | }, |
| | | { |
| | | "label": "巡逻管理", |
| | | "id": "PatrolManagement", |
| | | "widgetClass": "widgets/patrolManagement/PatrolManagement", |
| | | "type": "sider", |
| | | "cssPath": "widgets/patrolManagement/PatrolManagement.css", |
| | | "actived": false |
| | | }, |
| | | { |
| | | "label": "出警队伍", |
| | | "id": "APoliceTeam", |
| | | "widgetClass": "widgets/aPoliceTeam/APoliceTeam", |
| | | "type": "sider", |
| | | "cssPath": "widgets/aPoliceTeam/APoliceTeam.css", |
| | | "actived": false |
| | | }, |
| | | { |
| | | "label": "处警队伍", |
| | | "id": "SecurityMap", |
| | | "widgetClass": "widgets/securityMap/SecurityMap", |
| | | "type": "sider", |
| | | "cssPath": "widgets/securityMap/SecurityMap.css", |
| | | "actived": false |
| | | }, |
| | | { |
| | | "label": "分发处置", |
| | | "id": "AlertSecurity", |
| | | "widgetClass": "widgets/alertSecurity/AlertSecurity", |
| | | "type": "sider", |
| | | "cssPath": "widgets/alertSecurity/AlertSecurity.css", |
| | | "actived": false |
| | | }, |
| | | { |
| | | "label": "抢单任务", |
| | | "id": "task", |
| | | "widgetClass": "widgets/task/task", |
| | | "type": "sider", |
| | | "cssPath": "widgets/task/task.css", |
| | | "actived": false |
| | | }, |
| | | { |
| | | "label": "轨迹查看", |
| | | "id": "trajectory", |
| | | "widgetClass": "widgets/trajectory/trajectory", |
| | | "type": "sider", |
| | | "cssPath": "widgets/trajectory/trajectory.css", |
| | | "actived": false |
| | | }, |
| | | { |
| | | "label": "地图模式", |
| | | "id": "SupervisoryMap", |
| | | "widgetClass": "widgets/supervisoryMap/SupervisoryMap", |
| | | "type": "sider", |
| | | "cssPath": "widgets/supervisoryMap/SupervisoryMap.css", |
| | | "actived": false |
| | | }, |
| | | { |
| | | "label": "卡片模式详情", |
| | | "id": "DetailMap", |
| | | "widgetClass": "widgets/detailMap/DetailMap", |
| | | "type": "sider", |
| | | "cssPath": "widgets/detailMap/DetailMap.css", |
| | | "actived": false |
| | | }, |
| | | { |
| | | "label": "洪水风险", |
| | | "id": "MapBrowseWidgetCopy", |
| | | "widgetClass": "widgets/mapBrowsecopy/MapBrowseWidgetCopy", |
| | | "type": "sider", |
| | | "cssPath": "widgets/mapBrowsecopy/MapBrowseWidgetCopy.css", |
| | | "actived": false |
| | | }, { |
| | | "label": "数据查询", |
| | | "id": "MapBrowseWidget", |
| | | "widgetClass": "widgets/mapBrowse/MapBrowseWidget", |
| | | "type": "sider", |
| | | "cssPath": "widgets/mapBrowse/MapBrowseWidget.css", |
| | | "actived": false |
| | | }, { |
| | | "label": "工具箱", |
| | | "id": "toolBoxWidget", |
| | | "widgetClass": "widgets/toolbox/toolBoxWidget", |
| | | "type": "cover", |
| | | "cssPath": "widgets/toolbox/toolBoxWidget.css", |
| | | "actived": false |
| | | } |
| | | ], |
| | | _map: null, |
| | | _bodyDom: null, |
| | | _mapContentDom: null, |
| | | /** |
| | | * 默认初始化显示在侧边栏的Widget |
| | | */ |
| | | _defaultActivedSiderWidgetId: null, |
| | | _topWidgetContainerDom: null, |
| | | _widgetsTable: {}, |
| | | _activedButton: null, |
| | | _widgetId2TabButtonIndex: {}, |
| | | constructor: function() { |
| | | AppEvent.addAppEventListener(AppEvent.CONFIG_LOADED, lang.hitch(this, this.onConfigLoaded)); |
| | | AppEvent.addAppEventListener(AppEvent.BASE_MAP_LAYER_LOADED, lang.hitch(this, this.onMapLoaded)); |
| | | AppEvent.addAppEventListener(AppEvent.RUN_WIDGET, lang.hitch(this, this.onRunWidgetHandler)); |
| | | AppEvent.addAppEventListener(AppEvent.CLOSE_WIDGET, lang.hitch(this, this.onCloseWidgetHandler)); |
| | | }, |
| | | onConfigLoaded: function() { |
| | | this._bodyDom = dom.byId("body"); |
| | | this._mapContentDom = dom.byId("mapcontentClass"); |
| | | this._topWidgetContainerDom = dom.byId("topWidgetContainer"); |
| | | }, |
| | | onMapLoaded: function(map) { |
| | | try { |
| | | this._map = map; |
| | | for (var i = 0; i < this._widgetsConfig.length; i++) { |
| | | var widgetCfg = this._widgetsConfig[i]; |
| | | switch (widgetCfg.type) { |
| | | case "sider": |
| | | this._parseSiderWidget(widgetCfg); |
| | | break; |
| | | case "top": |
| | | this._parseTopWidget(widgetCfg); |
| | | break; |
| | | case "cover": |
| | | this._parseCoverWidget(widgetCfg); |
| | | break; |
| | | |
| | | } |
| | | } |
| | | if (this._defaultActivedSiderWidgetId != null && this._activedButton != null) { |
| | | this._switchTab(this._defaultActivedSiderWidgetId); |
| | | domClass.add(this._activedButton, "tabbuttonbar-actived"); |
| | | } |
| | | this._tempAppendOthers(); |
| | | } catch (err) { |
| | | console.log(err); |
| | | } |
| | | |
| | | }, |
| | | /** |
| | | * 解析侧边栏的Widget |
| | | */ |
| | | _parseSiderWidget: function(widgetCfg) { |
| | | if (widgetCfg.inited) { |
| | | this._loadWidget(widgetCfg.widgetClass, widgetCfg.id, widgetCfg.cssPath, function(widget) { |
| | | domConstruct.place(widget.domNode, dom.byId("tabcontainer")); |
| | | widget.startup(); |
| | | widget.close(); |
| | | }); |
| | | } |
| | | // if (!widgetCfg.displaylabel) { |
| | | // |
| | | // return |
| | | // } |
| | | var tabButton = domConstruct.create("li", null, dom.byId("tabbuttonbar")); |
| | | on(tabButton, "click", dojo.hitch(this, this._onTabButtonClickHandler)); |
| | | domAttr.set(tabButton, "widgetid", widgetCfg.id); |
| | | if (widgetCfg.actived) { |
| | | this._defaultActivedSiderWidgetId = widgetCfg.id; |
| | | this._activedButton = tabButton; |
| | | } |
| | | tabButton.innerHTML = widgetCfg.label; |
| | | this._widgetId2TabButtonIndex[widgetCfg.id] = tabButton; |
| | | }, |
| | | /** |
| | | * 解析顶部位置的Widget |
| | | */ |
| | | _parseTopWidget: function(widgetCfg) { |
| | | if (widgetCfg.actived) { |
| | | this._loadWidget(widgetCfg.widgetClass, widgetCfg.id, widgetCfg.cssPath, lang.hitch(this, function() { |
| | | var widget = this._widgetsTable[widgetCfg.id]; |
| | | domConstruct.place(widget.domNode, this._topWidgetContainerDom); |
| | | widget.startup(); |
| | | widget.open(); |
| | | })); |
| | | } |
| | | }, |
| | | /** |
| | | * 解析浮动在地图显示区域上的Widget |
| | | */ |
| | | _parseCoverWidget: function(widgetCfg) { |
| | | if (widgetCfg.actived) { |
| | | this._loadWidget(widgetCfg.widgetClass, widgetCfg.id, widgetCfg.cssPath, lang.hitch(this, function() { |
| | | var widget = this._widgetsTable[widgetCfg.id]; |
| | | domConstruct.place(widget.domNode, this._mapContentDom); |
| | | widget.startup(); |
| | | })); |
| | | } |
| | | |
| | | }, |
| | | |
| | | onRunWidgetHandler: function(widgetId) { |
| | | var widgetCfg = this._getWidgetConfigById(widgetId); |
| | | if (!widgetCfg) { |
| | | alert("该模块不存在!"); |
| | | return; |
| | | } |
| | | var widget = this._widgetsTable[widgetId]; |
| | | if (widget == null) { |
| | | var content = { |
| | | thisObj: this, |
| | | widgetCfg: widgetCfg |
| | | }; |
| | | this._loadWidget(widgetCfg.widgetClass, widgetId, widgetCfg.cssPath, lang.hitch(content, function() { |
| | | var widget = this.thisObj._widgetsTable[this.widgetCfg.id]; |
| | | this.thisObj._runWidget(widget, this.widgetCfg); |
| | | })); |
| | | } else { |
| | | this._runWidget(widget, widgetCfg); |
| | | } |
| | | }, |
| | | onCloseWidgetHandler: function(widgetId) { |
| | | var widgetCfg = this._getWidgetConfigById(widgetId); |
| | | if (!widgetCfg) { |
| | | return; |
| | | } |
| | | var widget = this._widgetsTable[widgetId]; |
| | | if (!widget) { |
| | | return; |
| | | } |
| | | widget.close(); |
| | | }, |
| | | |
| | | /** |
| | | * 运行Widget |
| | | */ |
| | | _runWidget: function(widget, widgetCfg) { |
| | | switch (widgetCfg.type) { |
| | | case "sider": |
| | | if (this._activedButton) { |
| | | domClass.remove(this._activedButton, "tabbuttonbar-actived"); |
| | | } |
| | | this._switchTab(widgetCfg.id); |
| | | this._activedButton = null; |
| | | if (widgetCfg.displaylabel) { |
| | | this._activedButton = this._widgetId2TabButtonIndex[widgetCfg.id]; |
| | | domClass.add(this._activedButton, "tabbuttonbar-actived"); |
| | | } |
| | | break; |
| | | case "top": |
| | | this._parseTopWidget(widgetCfg); |
| | | if (widget.loaded() == false) { |
| | | widget.startup(); |
| | | } |
| | | widget.open(); |
| | | break; |
| | | case "cover": |
| | | //this._parseCoverWidget(widgetCfg); |
| | | domConstruct.place(widget.domNode, this._mapContentDom); |
| | | if (widget.loaded() == false) { |
| | | widget.startup(); |
| | | } |
| | | widget.open(); |
| | | break; |
| | | } |
| | | //会导致对sider widget派发RUNWIDGET事件时,widget.open()执行两次,故移入switch中 。 Edit by liuyl 2015/11/5 |
| | | // if (widget.loaded() == false) { |
| | | // widget.startup(); |
| | | // } |
| | | // widget.open(); |
| | | }, |
| | | /** |
| | | * 临时的实例化,因为还没有规划好怎么加载 |
| | | */ |
| | | _tempAppendOthers: function() { |
| | | return; |
| | | var map = this._map; |
| | | var mapDomNode = dom.byId(map.id); |
| | | //创建常用工具条 |
| | | dojo.create("link", { |
| | | href: 'controls/toolbar/toolbar.css', |
| | | type: 'text/css', |
| | | rel: 'stylesheet' |
| | | }, |
| | | document.getElementsByTagName('head')[0]); |
| | | var toolbarDom = domConstruct.create("div", { |
| | | id: "toolBarDiv", |
| | | "class": "toolbar" |
| | | }, dom.byId('mainMapWidget')); |
| | | //全屏 |
| | | /*var tool = new FullScreenTool({ |
| | | "map": this._map |
| | | }); |
| | | domConstruct.place(tool.domNode, toolbarDom); |
| | | AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, tool);*/ |
| | | //放大 |
| | | var tool = new ZoomInTool({ |
| | | "map": this._map |
| | | }); |
| | | domConstruct.place(tool.domNode, toolbarDom); |
| | | AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, { |
| | | tool: tool, |
| | | hockId: ConfigData.mapWidgetId |
| | | }); |
| | | //缩小 |
| | | var tool = new ZoomOutTool({ |
| | | "map": this._map |
| | | }); |
| | | domConstruct.place(tool.domNode, toolbarDom); |
| | | AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, { |
| | | tool: tool, |
| | | hockId: ConfigData.mapWidgetId |
| | | }); |
| | | //复位 |
| | | var tool = new LocationTool({ |
| | | "map": this._map |
| | | }); |
| | | domConstruct.place(tool.domNode, toolbarDom); |
| | | AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, { |
| | | tool: tool, |
| | | hockId: ConfigData.mapWidgetId |
| | | }); |
| | | //漫游 |
| | | /*var tool = new Map3DTool({ |
| | | "map": this._map |
| | | }); |
| | | domConstruct.place(tool.domNode, toolbarDom); |
| | | AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, { |
| | | tool: tool, |
| | | hockId: ConfigData.mapWidgetId |
| | | });*/ |
| | | //平移 |
| | | var tool = new PanTool({ |
| | | "map": this._map |
| | | }); |
| | | domConstruct.place(tool.domNode, toolbarDom); |
| | | AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, { |
| | | tool: tool, |
| | | hockId: ConfigData.mapWidgetId |
| | | }); |
| | | //量距离 |
| | | var tool = new MeasureLineTool({ |
| | | "map": this._map |
| | | }); |
| | | domConstruct.place(tool.domNode, toolbarDom); |
| | | AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, { |
| | | tool: tool, |
| | | hockId: ConfigData.mapWidgetId |
| | | }); |
| | | //;量面积 |
| | | var tool = new MeasurePolygonTool({ |
| | | "map": this._map |
| | | }); |
| | | domConstruct.place(tool.domNode, toolbarDom); |
| | | AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, { |
| | | tool: tool, |
| | | hockId: ConfigData.mapWidgetId |
| | | }); |
| | | //清除 |
| | | var tool = new ClearTool({ |
| | | "map": this._map |
| | | }); |
| | | domConstruct.place(tool.domNode, toolbarDom); |
| | | AppEvent.dispatchAppEvent(AppEvent.APPEND_TOOL, { |
| | | tool: tool, |
| | | hockId: ConfigData.mapWidgetId |
| | | }); |
| | | |
| | | }, |
| | | _onTabButtonClickHandler: function(evt) { |
| | | if (this._activedButton == evt.currentTarget) { |
| | | return; |
| | | } |
| | | var clickButton = evt.currentTarget; |
| | | var widgetId = domAttr.get(evt.currentTarget, "widgetid"); |
| | | var widget = this._widgetsTable[widgetId]; |
| | | if (widget == null) { |
| | | //Widget还未Load |
| | | var widgetCfg = this._getWidgetConfigById(widgetId); |
| | | this._loadWidget(widgetCfg.widgetClass, widgetId, widgetCfg.cssPath, lang.hitch(this, function() { |
| | | widget = this._widgetsTable[widgetId]; |
| | | //this._confirmUserRightForSiderWidget(widget) |
| | | if (this._activedButton) { |
| | | domClass.remove(this._activedButton, "tabbuttonbar-actived"); |
| | | } |
| | | this._switchTab(widget.widgetName); |
| | | this._activedButton = clickButton; |
| | | domClass.add(this._activedButton, "tabbuttonbar-actived"); |
| | | })); |
| | | } else { |
| | | //this._confirmUserRightForSiderWidget(widget) |
| | | if (this._activedButton) { |
| | | domClass.remove(this._activedButton, "tabbuttonbar-actived"); |
| | | } |
| | | this._switchTab(widget.widgetName); |
| | | this._activedButton = clickButton; |
| | | domClass.add(this._activedButton, "tabbuttonbar-actived"); |
| | | } |
| | | //var loadwidget = lang.hitch(this, this._confirmUserRightForSiderWidget(widget)); |
| | | }, |
| | | _switchTab: function(widgetId) { |
| | | var widget; |
| | | if (widgetId == this._defaultActivedSiderWidgetId) { |
| | | //第一次加载defaultWidget的时候,widget还未请求 |
| | | widget = this._widgetsTable[widgetId]; |
| | | if (widget != null) { |
| | | return; |
| | | } |
| | | //是第一次加载,先清除default,以可以走下面的判断 |
| | | this._defaultActivedSiderWidgetId = null; |
| | | } |
| | | if (this._defaultActivedSiderWidgetId != null) { |
| | | widget = this._widgetsTable[this._defaultActivedSiderWidgetId]; |
| | | widget.close(); |
| | | widget.domNode.parentNode.removeChild(widget.domNode); |
| | | } |
| | | widget = this._widgetsTable[widgetId]; |
| | | var loadfun = lang.hitch(this, function(widget, widgetId) { |
| | | this._defaultActivedSiderWidgetId = widgetId; |
| | | domConstruct.place(widget.domNode, dom.byId("tabcontainer")); |
| | | if (widget.loaded() == false) { |
| | | widget.startup(); |
| | | } |
| | | |
| | | widget.open(); |
| | | }); |
| | | if (widget == null) { |
| | | var widgetCfg = this._getWidgetConfigById(widgetId); |
| | | this._loadWidget(widgetCfg.widgetClass, widgetId, widgetCfg.cssPath, lang.hitch(this, function() { |
| | | widget = this._widgetsTable[widgetId]; |
| | | loadfun(widget, widgetId); |
| | | })); |
| | | } else { |
| | | loadfun(widget, widgetId); |
| | | } |
| | | |
| | | }, |
| | | _loadWidget: function(widgetUrl, widgetId, cssPath, callback) { |
| | | if (cssPath && cssPath != "") { |
| | | dojo.create("link", { |
| | | href: cssPath, |
| | | type: "text/css", |
| | | rel: "stylesheet" |
| | | }, |
| | | document.getElementsByTagName("head")[0]); |
| | | } |
| | | require([widgetUrl], lang.hitch(this, function(WidgetClass) { |
| | | var widget = new WidgetClass({ |
| | | map: this._map, |
| | | id: widgetId |
| | | }); |
| | | this._widgetsTable[widgetId] = widget; |
| | | if (callback) |
| | | callback(widget); |
| | | }), |
| | | function(err) { |
| | | console.log("load widget"); |
| | | console.log(err); |
| | | }); |
| | | }, |
| | | _getWidgetConfigById: function(widgetId) { |
| | | for (var i = 0; i < this._widgetsConfig.length; i++) { |
| | | if (this._widgetsConfig[i].id == widgetId) { |
| | | return this._widgetsConfig[i]; |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | }); |