Mercurial > pub > ImplabJs
comparison src/djol/IdentificationTool.js @ 34:27e8e9e38e07 default tip
Слияние
author | nickolay |
---|---|
date | Wed, 05 Jun 2019 20:44:15 +0300 |
parents | 8af8e840dd49 1dc2fd263b90 |
children |
comparison
equal
deleted
inserted
replaced
33:8af8e840dd49 | 34:27e8e9e38e07 |
---|---|
1 define([ | |
2 "dijit/layout/ContentPane", | |
3 "dojo/_base/declare", | |
4 "dojo/Deferred", | |
5 "dojo/dom-construct", | |
6 "dojo/dom-class", | |
7 "dojo/on", | |
8 "dojo/promise/all", | |
9 "dojo/when", | |
10 "implab/safe", | |
11 "ol", | |
12 "./listen", | |
13 "./IdentifyGroup", | |
14 "./_ToolBase", | |
15 "./PopupContainer" | |
16 ], | |
17 | |
18 function ( | |
19 ContentPane, | |
20 declare, | |
21 Deffered, | |
22 domConstruct, | |
23 domClass, | |
24 on, | |
25 promiseAll, | |
26 when, | |
27 safe, | |
28 ol, | |
29 listen, | |
30 IdentifyGroup, | |
31 _ToolBase, | |
32 PopupContainer) { | |
33 return declare([_ToolBase], { | |
34 /** | |
35 * массив обработчиков openLayers, которые необходимо удалить при | |
36 * деактивации | |
37 */ | |
38 _handlers: null, | |
39 /** | |
40 * widget карты | |
41 */ | |
42 _map: null, | |
43 /** | |
44 * openLayers map | |
45 */ | |
46 _olMap: null, | |
47 /** | |
48 * Массив overlays содержащих popupContainers | |
49 */ | |
50 _popupOverlays: null, | |
51 /** | |
52 * Массив popups контейнеров | |
53 */ | |
54 _popupContainers: null, | |
55 /** | |
56 * Режим работы инструмента идентификации | |
57 * | |
58 * @value {String} "single"||"multiple" | |
59 */ | |
60 mode: null, | |
61 /** | |
62 * Режимы | |
63 */ | |
64 appManager: null, | |
65 | |
66 constructor: function (options) { | |
67 safe.argumentNotNull(options, "options"); | |
68 safe.argumentNotNull(options.map, "options.map"); | |
69 safe.argumentNotNull(options.appManager, "options.appManager"); | |
70 | |
71 this._map = options.map; | |
72 this._olMap = options.map.olMap; | |
73 this._popupContainers = []; | |
74 this._popupOverlays = []; | |
75 this._handlers = []; | |
76 | |
77 this.appManager = options.appManager; | |
78 this.mode = options.mode || "single"; | |
79 }, | |
80 /** | |
81 */ | |
82 createPopupContent: function (groupWidgets) { | |
83 var contentWidget = new ContentPane(); | |
84 groupWidgets.forEach(function (groupWidget) { | |
85 if (groupWidget && !groupWidget.isEmpty()) { | |
86 contentWidget.addChild(groupWidget); | |
87 } | |
88 }); | |
89 return contentWidget; | |
90 }, | |
91 | |
92 /** | |
93 * Возвращает обещание на получение объекта с результатом идентификации | |
94 * по всем видимым режимам и информационным слоям @ options {Object} @ pixel | |
95 * {Object} - информация о точке идентификации @ coordinate {Array} - | |
96 * координаты точки иденификации | |
97 */ | |
98 getGroupsFromVisibleModules: function (options) { | |
99 var promises = []; | |
100 var modules = this.appManager.getVisibleModules(); | |
101 modules.forEach(function (module) { | |
102 promises.push.apply(promises, module | |
103 .getIdentifyResult(options)); | |
104 }); | |
105 | |
106 return promiseAll(promises).then( | |
107 function (results) { | |
108 console.log("promise all groups = ", results); | |
109 return results; | |
110 }); | |
111 }, | |
112 | |
113 identifyPosition: function (position) { | |
114 var me = this, i; | |
115 var popupContainer = null, | |
116 popupOverlay = null; | |
117 if (me.mode == "multiple") { | |
118 // TODO: создать popupContainer и popupOverlay | |
119 popupContainer = new PopupContainer({ | |
120 map: me._olMap | |
121 }); | |
122 on(popupContainer, "close", function () { | |
123 var index = me._popupContainers.indexOf(me); | |
124 me._popupContainers.splice(index, 1); | |
125 | |
126 }); | |
127 me._popupContainers.push(popupContainer); | |
128 | |
129 popupOverlay = new ol.Overlay({ | |
130 element: popupContainer.domNode, | |
131 autoPan: true, | |
132 autoPanAnimation: { | |
133 duration: 250 | |
134 } | |
135 }); | |
136 me._popupOverlays.push(popupOverlay); | |
137 me._olMap.addOverlay(popupOverlay); | |
138 | |
139 } else { | |
140 if (me._popupContainers.length > 0) { | |
141 // Берем первый | |
142 popupContainer = me._popupContainers[0]; | |
143 // Все остальные удалить | |
144 if (me._popupContainers.length > 1) { | |
145 for (i = 1; i < me._popupContainers.length; i++) { | |
146 me._popupContainers[i].destroyRecursive(); | |
147 } | |
148 me._popupContainers.splice( | |
149 1, | |
150 me._popupContainers.length - 1); | |
151 } | |
152 } else { | |
153 // Создаем новый | |
154 popupContainer = new PopupContainer({ | |
155 map: me._olMap | |
156 }); | |
157 on(popupContainer, "close", function () { | |
158 var index = me._popupContainers.indexOf(me); | |
159 me._popupContainers.splice(index, 1); | |
160 | |
161 }); | |
162 me._popupContainers.push(popupContainer); | |
163 } | |
164 if (me._popupOverlays.length > 0) { | |
165 // Берем первый и помещаем в него popup | |
166 popupOverlay = me._popupOverlays[0]; | |
167 popupOverlay.setElement(popupContainer.domNode); | |
168 // Все остальные удалить | |
169 if (me._popupOverlays.length > 1) { | |
170 for (i = 1; i < me._popupOverlays.length; i++) { | |
171 me._olMap.removeOverlay(me._popupOverlays[i]); | |
172 } | |
173 me._popupOverlays.splice( | |
174 1, | |
175 me._popupOverlays.length - 1) | |
176 } | |
177 } else { | |
178 // Создаем новый и помещаем в него popup | |
179 popupOverlay = new ol.Overlay({ | |
180 element: popupContainer.domNode, | |
181 autoPan: true, | |
182 autoPanAnimation: { | |
183 duration: 250 | |
184 } | |
185 }); | |
186 me._popupOverlays.push(popupOverlay); | |
187 me._olMap.addOverlay(popupOverlay); | |
188 } | |
189 } | |
190 | |
191 popupContainer.destroyDescendants(); | |
192 | |
193 popupOverlay.setPosition(position.coordinate); | |
194 | |
195 popupContainer.showOverlay(); | |
196 | |
197 when(me.getGroupsFromVisibleModules(position), function (data) { | |
198 var contentWidget = me.createPopupContent(data); | |
199 popupContainer.show(contentWidget, "only"); | |
200 popupContainer.hideOverlay(); | |
201 }); | |
202 }, | |
203 /** | |
204 * Скрыть все popups | |
205 */ | |
206 hideAllPopups: function () { | |
207 var me = this, i; | |
208 for (i = 0; i < this._popupContainers.length; i++) { | |
209 this._popupContainers[i].destroyRecursive(); | |
210 } | |
211 this._popupContainers.splice(0, this._popupContainers.length); | |
212 | |
213 for (i = 0; i < this._popupOverlays.length; i++) { | |
214 this._olMap.removeOverlay(this._popupOverlays[i]); | |
215 } | |
216 this._popupOverlays.splice(0, this._popupOverlays.length) | |
217 }, | |
218 | |
219 onActivating: function () { | |
220 var me = this; | |
221 // Обработчик для события "singleclick" по карте | |
222 var handler = listen(this._olMap, 'singleclick', function (evt) { | |
223 if (evt.originalEvent.ctrlKey) { | |
224 me.mode = "multiple"; | |
225 } else { | |
226 me.mode = "single"; | |
227 } | |
228 me.identifyPosition({ | |
229 pixel: evt.pixel, | |
230 coordinate: evt.coordinate | |
231 }); | |
232 }); | |
233 this._handlers.push(handler); | |
234 }, | |
235 | |
236 onDeactivating: function () { | |
237 var me = this; | |
238 me._handlers.forEach(function (handler) { | |
239 if (handler.remove) | |
240 handler.remove(); | |
241 | |
242 }); | |
243 this.hideAllPopups(); | |
244 }, | |
245 }) | |
246 }); |