您的位置:首页 > Web前端 > JavaScript

基于OpenLayer工具栏管理类的Javascript类定义

2014-03-27 23:20 363 查看
基于OpenLayer工具栏管理类的Javascript类定义

mapCwgisToolBarClass.js

//定义工具栏管理类
//mapCwgisToolBarClass.js
//vp:hsg
//create date:2013-07-31
//modify date:2013-08-01
//定义全局变量
var cmToolbar = null;
//插件调用方法cmToolbar.addItem(pluginCmdTool);
//定义工具栏管理类
mapCwgisToolBarClass = OpenLayers.Class(
{
//
m_ToolBarItems: null,
isScan: false,
//初始化函数
initialize: function () {
this.m_ToolBarItems = [];

},
//添加插件项
addItem: function (item) {
if (item != null) {
this.m_ToolBarItems.push(item);
}
},
//反激活插件集合
deactivateItems: function () {
//清除全局地图事件鼠标监听者
mapWrap.map.events.clearMouseListener();
//反激活所有全局工具
if (this.m_ToolBarItems == null) return;
for (var item in this.m_ToolBarItems) {
if (item != null) {
try {
this.m_ToolBarItems[item].dispose();
}
catch (e) { }
this.m_ToolBarItems[item].deactivate();
}
}
},
//启动扫描
startScan: function () {
this.isScan = true;
window.setInterval('loopScanItemEvent()', 1000); //1000为1秒钟,时间可以自己设
},
//循环扫描项事件
loopScanItemEvent: function () {
if (this.isScan == true) {
for (var item in this.m_ToolBarItems) {
if (this.isScan == false) break;
if (item != null) {
item.enabled;
}
}
}
},
//释放类
dispose: function () {
this.isScan = false;
this.deactivateItems();
this.m_ToolBarItems = null;
OpenLayers.Class.prototype.destroy.apply(this, arguments);
},
//类名称
CLASS_NAME: "mapCwgisToolBarClass"
});
//实例化一个全局工具条管理类
cmToolBar = new mapCwgisToolBarClass();

//定义插件Command基类  继承于OpenLayers.Class(OpenLayers.Control)
//基类抽象类名称:mapCwgisPluginCommand
mapCwgisPluginCommand = OpenLayers.Class(OpenLayers.Control,
{
//定义属性
mapWrap: null,
//定义类  初始化函数
init: function (p_mapCwgisClass) {
this.mapWrap = p_mapCwgisClass;
this.setMap(this.mapWrap.map);
},
initialize: function (p_mapCwgisClass, options) {
this.init(p_mapCwgisClass);
//
this.displayClass =
this.CLASS_NAME.replace("OpenLayers.", "ol").replace(/\./g, "");

OpenLayers.Util.extend(this, options);
//
this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES);
if (this.eventListeners instanceof Object) {
this.events.on(this.eventListeners);
}
if (this.id == null) {
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
}
},
//---------------------------------------------
/**
* Method: activate
* Activates the control.
*
* Returns:
* {Boolean} The control was effectively activated.
*/
activate: function () {
if (!this.active) {
for (var i in this.handlers) {
this.handlers[i].activate();
}
}
return OpenLayers.Control.prototype.activate.apply(
this, arguments
);
},

/**
* Method: deactivate
* Deactivates the control.
*
* Returns:
* {Boolean} The control was effectively deactivated.
*/
deactivate: function () {
if (this.active) {
for (var i in this.handlers) {
this.handlers[i].deactivate();
}
}
return OpenLayers.Control.prototype.deactivate.apply(
this, arguments
);
},
//---------------------------------------------
//释放类
dispose: function () {
this.deactivate();
},
//定义单击事件
onClick: function () {
if (cmToolBar != null) {
cmToolBar.deactivateItems();
}
this.activate(); //激活控件
},
//类名称
CLASS_NAME: "mapCwgisPluginCommand"
});

//定义插件Tool基类  继承于OpenLayers.Class(mapCwgisPluginCommand)
//基类抽象类名称:mapCwgisPluginTool
mapCwgisPluginTool = OpenLayers.Class(mapCwgisPluginCommand,
{
//定义属性
layer: null,
callbacks: null,
multi: false,
handlerOptions: null,
handlerClass: null,
//定义类  初始化函数
initialize: function (p_mapCwgisClass,handler,options) {
this.init(p_mapCwgisClass);
//定义 处理鼠标事件基础对象 (点)   /线/面etc...
this.handlerClass = handler;
//
var handlerAbsClass = this.handlerClass;
this.handlerOptions = handlerAbsClass;
//初始化基类OpenLayers.Control的初始化方法
OpenLayers.Control.prototype.initialize.apply(this, [this.handlerOptions]);
//定义一个回调函数
this.callbacks = OpenLayers.Util.extend(
{
done: function (geometry) { },
modify: function (vertex, feature) {
},
create: function (vertex, feature) {
}
},
this.callbacks
);
if (this.mapWrap.vlayer_drawFeature == null) {
this.mapWrap.vlayer_drawFeature = new OpenLayers.Layer.Vector();
this.mapWrap.map.addLayer(this.mapWrap.vlayer_drawFeature);
}
//定义一个临时绘制的图层
this.layer = this.mapWrap.vlayer_drawFeature;
//this.handlerOptions =OpenLayers.Handler.Point;// this.handlerOptions || {};
if (!("multi" in this.handlerOptions)) {
this.handlerOptions.multi = this.multi;
}
var sketchStyle = this.layer.styleMap && this.layer.styleMap.styles.select; //.temporary;
if (sketchStyle) {
this.handlerOptions.layerOptions = OpenLayers.Util.applyDefaults(
this.handlerOptions.layerOptions,
{ styleMap: new OpenLayers.StyleMap({ "default": sketchStyle }) }
);
}
//定义处理鼠标事件基础对象
this.handler = new handlerAbsClass(this, this.callbacks, this.handlerOptions);
},
//定义 鼠标处理事件集合
//定义鼠标按上事件
onMouseUp: function (e) {
},
//定义鼠标按下事件
onMouseDown: function (e) {
},
//定义鼠标移动事件
onMouseMove: function (e) {
},
//定义鼠标双击事件
onDoubleClick: function (e) {
},
//定义鼠标右键单击事件
onRightClick: function (e) {
},
//释放类鼠标移动事件
dispose: function () {
//
this.layer.destroyFeatures();
this.layer.redraw();
//选中地块清除操作
//this.mapWrap.layer_Highlight.destroyFeatures();
//this.mapWrap.layer_Highlight.redraw();
//
//反注册鼠标按上事件 mouseup
this.mapWrap.map.events.unregister("mouseup", this.mapWrap.map, this.onMouseUp);
//反注册鼠标按下事件 mousedown
this.mapWrap.map.events.unregister("mousedown", this.mapWrap.map, this.onMouseDown);
//反注册鼠标移动事件 mousemove
this.mapWrap.map.events.unregister("mousemove", this.mapWrap.map, this.onMouseMove);
//反注册鼠标双击事件 dblclick
this.mapWrap.map.events.unregister("dblclick", this.mapWrap.map, this.onDoubleClick);
//反注册鼠标右键单击事件 rightclick
this.mapWrap.map.events.unregister("rightclick", this.mapWrap.map, this.onRightClick);
//
this.deactivate();
},
//定义单击事件
onClick: function () {
if (cmToolBar != null) {
cmToolBar.deactivateItems();
}
//初始化事件处理对象
var handlerAbsClass = this.handlerClass;
this.handlerOptions = handlerAbsClass;
this.handler = new handlerAbsClass(this, this.callbacks, this.handlerOptions);
//
//注册鼠标按上事件 mouseup
this.mapWrap.map.events.unregister("mouseup", this.mapWrap.map, this.onMouseUp);
this.mapWrap.map.events.register("mouseup", this.mapWrap.map, this.onMouseUp);
//注册鼠标按下事件 mousedown
this.mapWrap.map.events.unregister("mousedown", this.mapWrap.map, this.onMouseDown);
this.mapWrap.map.events.register("mousedown", this.mapWrap.map, this.onMouseDown);
//注册鼠标移动事件 mousemove
this.mapWrap.map.events.unregister("mousemove", this.mapWrap.map, this.onMouseMove);
this.mapWrap.map.events.register("mousemove", this.mapWrap.map, this.onMouseMove);
//注册鼠标双击事件 dblclick
this.mapWrap.map.events.unregister("dblclick", this.mapWrap.map, this.onDoubleClick);
this.mapWrap.map.events.register("dblclick", this.mapWrap.map, this.onDoubleClick);
//注册鼠标右键单击事件 rightclick
this.mapWrap.map.events.unregister("rightclick", this.mapWrap.map, this.onRightClick);
this.mapWrap.map.events.register("rightclick", this.mapWrap.map, this.onRightClick);
//
this.activate(); //激活控件
},
//类名称
CLASS_NAME: "mapCwgisPluginTool"
});

//定义 地图平移插件命令功能
mapCwgisMapPanCmd = OpenLayers.Class(mapCwgisPluginCommand,
{
//定义单击事件
onClick: function () {
if (cmToolBar != null) {
cmToolBar.deactivateItems();
}
//激活控件
this.activate();
},
CLASS_NAME: "mapCwgisMapPanCmd"
//
});
//地图平移工具
var mapPanCmd = new mapCwgisMapPanCmd(mapWrap);
//向全局工具栏管理类注册
if (cmToolBar != null) {
cmToolBar.addItem(mapPanCmd);
}
//--
//定义 地图全屏显示插件命令功能
mapCwgisMapFullExtentCmd = OpenLayers.Class(mapCwgisPluginCommand,
{
//定义单击事件
onClick: function () {
if (cmToolBar != null) {
cmToolBar.deactivateItems();
}
if (this.mapWrap.map) {
this.mapWrap.map.zoomToMaxExtent();
}
//激活控件
this.activate();
},
CLASS_NAME: "mapCwgisMapFullExtentCmd"
//
});
//地图全屏显示工具
var mapFullExtentCmd = new mapCwgisMapFullExtentCmd(mapWrap);
//向全局工具栏管理类注册
if (cmToolBar != null) {
cmToolBar.addItem(mapFullExtentCmd);
}
//--



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: