Javascript class definition based on the OpenLayer toolbar management class

Source: Internet
Author: User

Javascript class definition based on the OpenLayer toolbar management class

MapCwgisToolBarClass. js

// Define the toolbar management class // mapCwgisToolBarClass. js // vp: hsg // create date: 2013-07-31 // modify date: 2013-08-01 // defines the global variable var cmToolbar = null; // plug-in call method cmToolbar. addItem (pluginCmdTool); // defines the toolbar management class mapCwgisToolBarClass = OpenLayers. class ({// m_ToolBarItems: null, isScan: false, // initialization function initialize: function () {this. m_ToolBarItems = [];}, // Add the plug-in item addItem: function (item) {if (item! = Null) {this. m_ToolBarItems.push (item) ;}}, // deactivateItems: function () {// clear global map event mouse listener mapWrap. map. events. clearMouseListener (); // Reactivate all global tools 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 () ;}}, // start scanning startScan: function () {this. isScan = true; window. setInterval ('loopscanitemevent () ', 1000); // 1000 is 1 second, you can set the time by yourself}, // loopScanItemEvent: function () {if (this. isScan = true) {for (var item in this. m_ToolBarItems) {if (this. isScan = false) break; if (item! = Null) {item. enabled ;}}}, // release class dispose: function () {this. isScan = false; this. deactivateItems (); this. m_ToolBarItems = null; OpenLayers. class. prototype. destroy. apply (this, arguments) ;}, // class name CLASS_NAME: "mapCwgisToolBarClass"}); // instantiate a global toolbar management class cmToolBar = new mapCwgisToolBarClass (); // define the Command base class of the plug-in to inherit from OpenLayers. class (OpenLayers. control) // base class abstract class name: mapCwgisPluginCommandmapCwgisPluginCommand = OpenLayers. class (OpenLayers. control, {// defines the property mapWrap: null, // defines the class initialization function 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 = ne W 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 implements tively 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 inclutively deactivated. */deactivate: function () {if (this. active) {for (var I in this. handlers) {this. handlers [I]. deactivate ();} return OpenLayer S. control. prototype. deactivate. apply (this, arguments) ;}, // ----------------------------------------------- // release class dispose: function () {this. deactivate () ;}, // defines the onClick event: function () {if (cmToolBar! = Null) {cmToolBar. deactivateItems ();} this. activate (); // Activation Control}, // class name CLASS_NAME: "mapCwgisPluginCommand"}); // defines the plug-in Tool base class inherited from OpenLayers. class (mapCwgisPluginCommand) // base Class abstract Class name: mapcwgisplugintoolmapcwgisplug#ol = OpenLayers. class (mapCwgisPluginCommand, {// defines the attribute layer: null, callbacks: null, multi: false, handlerOptions: null, handlerClass: null, // defines the Class initialization function initialize: function (p_mapCwgisClass, h Andler, options) {this. init (p_mapCwgisClass); // defines the basic object (point)/line/surface etc for processing mouse events... this. handlerClass = handler; // var handlerAbsClass = this. handlerClass; this. handlerOptions = handlerAbsClass; // initialize the base class OpenLayers. control initialization method OpenLayers. control. prototype. initialize. apply (this, [this. handlerOptions]); // defines a callback function 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);} // defines a layer temporarily drawn. 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});} // defines the basic object for processing mouse events this. handler = new handlerAb SClass (this, this. callbacks, this. handlerOptions) ;}, // define the set of mouse processing events // define the mouse over the event onMouseUp: function (e) {}, // define the mouse to press the event onMouseDown: function (e) {}, // define the mouse movement event onMouseMove: function (e) {}, // define the mouse double-click event onDoubleClick: function (e ){}, // right-click the event onRightClick: function (e) {}, // release the class mouse movement event dispose: function () {// this. layer. destroyFeatures (); this. layer. redraw (); // clear the selected plot // this. mapWrap. laye R_Highlight.destroyFeatures (); // this. mapWrap. layer_Highlight.redraw (); /// click the event mouseup this when you unregister the mouse. mapWrap. map. events. unregister ("mouseup", this. mapWrap. map, this. onMouseUp); // re-register the mouse and press the event mousedown this. mapWrap. map. events. unregister ("mousedown", this. mapWrap. map, this. onMouseDown); // re-register the mouse movement event mousemove this. mapWrap. map. events. unregister ("mousemove", this. mapWrap. map, this. onMouseMove); // double-click the unregistered mouse Pieces dblclick this. mapWrap. map. events. unregister ("dblclick", this. mapWrap. map, this. onDoubleClick); // re-register, right-click the event, and click rightclick this. mapWrap. map. events. unregister ("rightclick", this. mapWrap. map, this. onRightClick); // this. deactivate () ;}, // defines the onClick event: function () {if (cmToolBar! = Null) {cmToolBar. deactivateItems ();} // initialize the event processing object var handlerAbsClass = this. handlerClass; this. handlerOptions = handlerAbsClass; this. handler = new handlerAbsClass (this, this. callbacks, this. handlerOptions); // register the mouse and press the event mouseup this. mapWrap. map. events. unregister ("mouseup", this. mapWrap. map, this. onMouseUp); this. mapWrap. map. events. register ("mouseup", this. mapWrap. map, this. onMouseUp); // register the mouse and press The following event is mousedown this. mapWrap. map. events. unregister ("mousedown", this. mapWrap. map, this. onMouseDown); this. mapWrap. map. events. register ("mousedown", this. mapWrap. map, this. onMouseDown); // registers the mouse movement event mousemove this. mapWrap. map. events. unregister ("mousemove", this. mapWrap. map, this. onMouseMove); this. mapWrap. map. events. register ("mousemove", this. mapWrap. map, this. onMouseMove); // register the mouse double-click event dblclick this. mapW Rap. map. events. unregister ("dblclick", this. mapWrap. map, this. onDoubleClick); this. mapWrap. map. events. register ("dblclick", this. mapWrap. map, this. onDoubleClick); // register and right-click the event and choose 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 (); // activate control}, // class name CLASS_N AME: "mapcwgisplugintointool"}); // defines the map translation plug-in command function mapCwgisMapPanCmd = OpenLayers. Class (mapCwgisPluginCommand, {// defines the onClick event: function () {if (cmToolBar! = Null) {cmToolBar. deactivateItems ();} // activate the control this. activate () ;}, CLASS_NAME: "mapCwgisMapPanCmd" //}); // map translation tool var mapPanCmd = new mapCwgisMapPanCmd (mapWrap ); // register if (cmToolBar! = Null) {cmToolBar. addItem (mapPanCmd);} // -- // defines the map full-screen display plug-in command function mapCwgisMapFullExtentCmd = OpenLayers. class (mapCwgisPluginCommand, {// defines the onClick event: function () {if (cmToolBar! = Null) {cmToolBar. deactivateItems ();} if (this. mapWrap. map) {this. mapWrap. map. zoomToMaxExtent ();} // activate the control this. activate () ;}, CLASS_NAME: "mapCwgisMapFullExtentCmd" //}); // map full screen display tool var mapFullExtentCmd = new mapCwgisMapFullExtentCmd (mapWrap ); // register if (cmToolBar! = Null) {cmToolBar. addItem (mapFullExtentCmd );}//--

Zookeeper

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.