/**
|
* 所有工具的基类,自定义工具必需继承于此。BaseTool定义了工具的所有必需方法,有必要时,请重写。
|
* @author 温杨彪 2015-9-12
|
**/
|
define([
|
"dojo",
|
"dojo/_base/declare",
|
"dijit/_WidgetBase",
|
"dijit/_TemplatedMixin",
|
"dojo/text!controls/toolbar/tools/template.html",
|
"dojo/dom-construct",
|
"dojo/dom-attr",
|
"dojo/dom-style",
|
"dojo/_base/lang",
|
"dojo/on",
|
"dojo/dom-class"
|
], function(
|
dojo,
|
declare,
|
_WidgetBase,
|
_TemplatedMixin,
|
template,
|
domConstruct,
|
domAttr,
|
domStyle,
|
lang,
|
on,
|
domClass
|
) {
|
var RL = declare([_WidgetBase, _TemplatedMixin], {
|
templateString: template,
|
_activated: false,
|
map: null,
|
_graphicsLayer: null,
|
_label: "",
|
_toolCursor: null,
|
/**
|
* 正常的样式类
|
*/
|
_normalClass: "toolbar-item-normal",
|
|
/**
|
* 正常的图标样式类
|
*/
|
_normalIconClass: "",
|
/**
|
* 鼠标上浮的图标样式类
|
*/
|
_overIconClass: "",
|
/**
|
* 鼠标上浮的样式类
|
*/
|
_overClass: "toolbar-item-over",
|
/**
|
* 工具激活的样式类
|
*/
|
_selectedClass: "toolbar-item-select",
|
/**
|
* 工具激活的图标样式类
|
*/
|
_selectedIconClass: "",
|
_config: null,
|
_status: "",
|
/**
|
* 工具不可用的样式类
|
*/
|
_disableClass: "",
|
_enable: true,
|
mapEvents: [],
|
/**
|
*
|
*/
|
constructor: function(args) {
|
if (args) {
|
declare.safeMixin(this, args);
|
}
|
this.tooltip = "工具"
|
},
|
postCreate: function() {
|
domClass.add(this.tool, this._normalClass);
|
domClass.add(this.toolicon, this._normalIconClass);
|
},
|
_onClick: function(evt) {
|
evt.stopPropagation();
|
if (!this._enable) {
|
return;
|
}
|
},
|
_onMouseOverHandler: function(evt) {
|
evt.stopPropagation();
|
if (this._enable && this._activated == false) {
|
domClass.add(this.tool, this._overClass);
|
domClass.add(this.toolicon, this._overIconClass);
|
}
|
},
|
_onMouseOutHandler: function(evt) {
|
evt.stopPropagation();
|
if (this._enable && this._activated == false) {
|
domClass.remove(this.tool, this._overClass);
|
domClass.remove(this.toolicon, this._overIconClass);
|
}
|
},
|
_onMouseDownHandler: function(evt) {
|
evt.stopPropagation();
|
if (!this._enable)
|
return;
|
if (this._activated) {
|
this.deactivate(null);
|
this.ondeactivate();
|
} else {
|
this.activate(null);
|
}
|
},
|
_onMouseUpHandler: function(evt) {
|
evt.stopPropagation();
|
if (!this._enable)
|
return;
|
if (!this._activated) {
|
domClass.remove(this.toolicon, this._selectedIconClass);
|
domClass.remove(this.tool, this._selectedClass);
|
}
|
domClass.add(this.toolicon, this._overIconClass);
|
domClass.add(this.tool, this._overClass);
|
},
|
disable:function(){
|
this._enable=false;
|
domStyle.set(this.domNode,"background-color","#DBDBDB");
|
},
|
enable:function(){
|
this._enable=true;
|
domStyle.set(this.domNode,"background-color","");
|
},
|
activate: function(args) {
|
if (this._activated || !this._enable)
|
return;
|
this._activated = true;
|
domClass.add(this.toolicon, this._selectedIconClass);
|
domClass.add(this.tool, this._selectedClass);
|
if (this.map != null) {
|
var map = this.map;
|
var events = this.mapEvents;
|
events.push(map.on("click", this._onMapClickHandler));
|
events.push(map.on("mouse-down", this._onMapMouseDownHandler));
|
events.push(map.on("mouse-up", this._onMapMouseUpHandler));
|
events.push(map.on("mouse-move", this._onMapMouseMoveHandler));
|
events.push(map.on("dbl-click", this._onMapDoubleClickHandler));
|
}
|
this.onactivate();
|
},
|
onactivate: function() {
|
return this;
|
},
|
ondeactivate: function() {
|
return this;
|
},
|
deactivate: function(args) {
|
if (!this._enable || !this._activated)
|
return;
|
this._activated = false;
|
domClass.remove(this.toolicon, this._selectedIconClass);
|
domClass.remove(this.tool, this._selectedClass);
|
domClass.remove(this.toolicon, this._overIconClass);
|
domClass.remove(this.tool, this._overClass);
|
if (this.map != null) {
|
var events = this.mapEvents;
|
for (var i = 0; i < events.length; i++) {
|
events[i].remove();
|
}
|
this.mapEvents = [];
|
}
|
this.ondeactivate();
|
},
|
_onMapClickHandler: function(evt) {},
|
_onMapMouseDownHandler: function(evt) {},
|
_onMapMouseUpHandler: function(evt) {},
|
_onMapMouseMoveHandler: function(evt) {},
|
_onMapDoubleClickHandler: function(evt) {},
|
_setNormalClassAttr: function(normalClass) {
|
this._normalClass = normalClass;
|
},
|
_getNormalClassAttr: function() {
|
return this._normalClass;
|
},
|
_setOverClassAttr: function(overClass) {
|
this._overClass = overClass;
|
},
|
_getOverClassAttr: function() {
|
return this._overClass;
|
},
|
_setSelectedClassAttr: function(selectedClass) {
|
this._selectedClass = _selectedClass;
|
},
|
_getSelectedClassAttr: function() {
|
return this._selectedClass;
|
},
|
_setDisableClassAttr: function(disableClass) {
|
this._disableClass = disableClass;
|
},
|
_getDisableClassAttr: function() {
|
return this._disableClass;
|
},
|
_getStatusAttr: function() {
|
return this._status;
|
},
|
_setStatusAttr: function(status) {
|
this._status = status;
|
},
|
_setLabelAttr: function(label) {
|
if (label !== undefined && label != "") {
|
domStyle.set(this.toollabel, "display", "inline-block");
|
this._label = label;
|
} else {
|
domStyle.set(this.toollabel, "display", "none");
|
this._label = "";
|
}
|
this.toollabel.innerHTML = this._label;
|
},
|
getLabelAttr: function() {
|
return this.label;
|
}
|
});
|
|
/**
|
* 用户激活工具
|
*/
|
RL.ACTIVATE_EVENT = "onactivate";
|
|
/**
|
* 用户用鼠标点击工具后的释放
|
**/
|
RL.DEACTIVATE_EVEN = "ondeactivate";
|
|
/**
|
* 工具自动释放事件。有的工具激活后只能使用一次就必须释放,比如测量、标注等
|
**/
|
RL.SELFDEACTIVATE_EVENT = "selfDeactivate";
|
|
return RL;
|
});
|