comparison src/djol/_OneshotTool.js @ 8:f0035923ff3e

добавлена библиотека для работы с openlayers 3+
author cin
date Mon, 21 Aug 2017 17:47:00 +0300
parents
children 9c21e656cbec
comparison
equal deleted inserted replaced
7:9c0943c68a90 8:f0035923ff3e
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 },
13
14 onActivating : function() {
15 var me = this;
16
17 // start the operation
18 me._lastResult = me._pending = guard(me,"invoke");
19
20 return this.inherited(arguments);
21 },
22
23 onActivated : function() {
24 var me = this;
25
26 // fire the activate event
27 this.inherited(arguments);
28
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();
50 }
51
52 return this.inherited(arguments);
53 },
54
55 run : function() {
56 var me = this;
57
58 return me.activate().then(function(success) {
59 if (success)
60 return me._lastResult;
61 throw new Error("Operation declined");
62 });
63 }
64 });
65 });