17
|
1 define(["dojo/_base/declare", "implab/safe", "implab/guard", "ol3/_ToolBase", "ol3/ToolType"],
|
|
2
|
|
3 function (declare, safe, guard, _ToolBase, ToolType) {
|
|
4 return declare([_ToolBase], {
|
|
5 _pending: null,
|
|
6
|
|
7 _lastResult: null,
|
|
8
|
|
9 toolType: ToolType.Oneshot,
|
|
10
|
|
11 invoke: function () {
|
|
12 },
|
8
|
13
|
17
|
14 onActivating: function () {
|
|
15 var me = this;
|
|
16
|
|
17 // start the operation
|
|
18 me._lastResult = me._pending = guard(me, "invoke");
|
8
|
19
|
17
|
20 return this.inherited(arguments);
|
|
21 },
|
8
|
22
|
17
|
23 onActivated: function () {
|
|
24 var me = this;
|
|
25
|
|
26 // fire the activate event
|
|
27 this.inherited(arguments);
|
8
|
28
|
17
|
29 me._pending.then(function () {
|
|
30 if (me._pending) {
|
|
31 me.log("Operation finished, deactivating.");
|
|
32 me._pending = null;
|
|
33 me.deactivate();
|
|
34 }
|
|
35 }, function (ex) {
|
|
36 if (me._pending) {
|
|
37 me.error("Operation failed, deactivating: {0}", ex);
|
|
38 me._pending = null;
|
|
39 me.deactivate();
|
|
40 }
|
|
41 });
|
|
42 },
|
|
43
|
|
44 onDeactivated: function () {
|
|
45 var d = this._pending;
|
|
46 if (d) {
|
|
47 this.log("Cancelling pending operation");
|
|
48 this._pending = null;
|
|
49 d.cancel();
|
8
|
50 }
|
17
|
51
|
|
52 return this.inherited(arguments);
|
|
53 },
|
8
|
54
|
17
|
55 run: function () {
|
|
56 var me = this;
|
|
57
|
|
58 return me.activate().then(function () {
|
|
59 return me._lastResult;
|
|
60 });
|
8
|
61 }
|
17
|
62 });
|
|
63 }); |