# HG changeset patch # User nickolay # Date 1505842676 -10800 # Node ID 9c21e656cbec68893825a89eb055974f13f6788f # Parent 1eeae195b2341316b1ffe16933f0129b2b28c26b Разработка кнопки выбора координат с карт diff -r 1eeae195b234 -r 9c21e656cbec src/djol/CoordPickerTool.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/djol/CoordPickerTool.js Tue Sep 19 20:37:56 2017 +0300 @@ -0,0 +1,24 @@ +define (["dojo/_base/declare", "./_OneshotTool", "implab/safe", "dojo/when"] , function(declare, _OneshotTool, safe, when) { + return declare([_OneshotTool], { + _map : null, + _proj : null, + + constructor : function(opts) { + safe.argumentNotNull(opts && opts.map, "opts.map"); + + this._map = opts.map; + this._proj = opts.proj; + }, + + invoke : function() { + var me = this; + + return when(me._map.awaitMapEvent('singleclick'), function(evt){ + if (me._proj) { + // тут можно преобразовать проекции + } + return evt; + }); + } + }); +}); \ No newline at end of file diff -r 1eeae195b234 -r 9c21e656cbec src/djol/_OneshotTool.js --- a/src/djol/_OneshotTool.js Tue Sep 19 12:34:16 2017 +0300 +++ b/src/djol/_OneshotTool.js Tue Sep 19 20:37:56 2017 +0300 @@ -1,65 +1,63 @@ -define([ "dojo/_base/declare", "implab/safe", "implab/guard", "ol3/_ToolBase", "ol3/ToolType" ], +define(["dojo/_base/declare", "implab/safe", "implab/guard", "ol3/_ToolBase", "ol3/ToolType"], + + function (declare, safe, guard, _ToolBase, ToolType) { + return declare([_ToolBase], { + _pending: null, + + _lastResult: null, + + toolType: ToolType.Oneshot, + + invoke: function () { + }, -function(declare, safe, guard, _ToolBase, ToolType) { - return declare([ _ToolBase ], { - _pending : null, - - _lastResult : null, + onActivating: function () { + var me = this; + + // start the operation + me._lastResult = me._pending = guard(me, "invoke"); - toolType : ToolType.Oneshot, + return this.inherited(arguments); + }, - invoke : function() { - }, + onActivated: function () { + var me = this; + + // fire the activate event + this.inherited(arguments); - onActivating : function() { - var me = this; - - // start the operation - me._lastResult = me._pending = guard(me,"invoke"); - - return this.inherited(arguments); - }, - - onActivated : function() { - var me = this; - - // fire the activate event - this.inherited(arguments); - - me._pending.then(function() { - if (me._pending) { - me.log("Operation finished, deactivating."); - me._pending = null; - me.deactivate(); + me._pending.then(function () { + if (me._pending) { + me.log("Operation finished, deactivating."); + me._pending = null; + me.deactivate(); + } + }, function (ex) { + if (me._pending) { + me.error("Operation failed, deactivating: {0}", ex); + me._pending = null; + me.deactivate(); + } + }); + }, + + onDeactivated: function () { + var d = this._pending; + if (d) { + this.log("Cancelling pending operation"); + this._pending = null; + d.cancel(); } - }, function(ex) { - if (me._pending) { - me.error("Operation failed, deactivating: {0}", ex); - me._pending = null; - me.deactivate(); - } - }); - }, + + return this.inherited(arguments); + }, - onDeactivated : function() { - var d = this._pending; - if (d) { - this.log("Cancelling pending operation"); - this._pending = null; - d.cancel(); + run: function () { + var me = this; + + return me.activate().then(function () { + return me._lastResult; + }); } - - return this.inherited(arguments); - }, - - run : function() { - var me = this; - - return me.activate().then(function(success) { - if (success) - return me._lastResult; - throw new Error("Operation declined"); - }); - } - }); -}); \ No newline at end of file + }); + }); \ No newline at end of file diff -r 1eeae195b234 -r 9c21e656cbec src/djol/coordPickerTool.js --- a/src/djol/coordPickerTool.js Tue Sep 19 12:34:16 2017 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -define (["dojo/_base/declare", "./_OneshotTool", "implab/safe", "dojo/when"] , function(declare, _OneshotTool, safe, when) { - return declare([_OneshotTool], { - _map : null, - _proj : null, - - constructor : function(opts) { - safe.argumentNotNull(opts && opts.map, "opts.map"); - - this._map = opts.map; - this._proj = opts.proj; - }, - - invoke : function() { - var me = this; - - return when(me.awaitMapEvent('singleclick'), function(evt){ - if (me._proj) { - // тут можно преобразовать проекции - } - return evt; - }); - } - }); -}); \ No newline at end of file