基於OpenLayer工具列管理類的Javascript類定義__Java

來源:互聯網
上載者:User

基於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)//基類抽象類別名稱:mapCwgisPluginCommandmapCwgisPluginCommand = 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)//基類抽象類別名稱:mapCwgisPluginToolmapCwgisPluginTool = 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);}//--

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.