Openlayers2卷帘功能的实现

概述:

在WebGIS开发中,经常会有用户提需求,要实现卷帘功能,卷帘功能主要是实现两张图之间的对比。在前文中,讲到了openlayers3以及Arcgis for js中卷帘的实现,在本文讲述如何在openlayers2中实现卷帘功能。

 

结果展示:

 

实现代码:

在此,扩展了一个名为Swipe的Control,Swipe的代码如下:

[javascript] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. /* 
  2.  * 
  3.  * @requires OpenLayers/Control.js 
  4.  */  
  5.   
  6. /* The following globals are for JSLint */  
  7. /* jslint browser: true, vars: true */  
  8. /* global OpenLayers, escape */  
  9.   
  10. /** api: (define) 
  11.  *  module =  OpenLayers.Control 
  12.  *  class = Swipe 
  13.  *  base_link = `OpenLayers.Control <http://dev.openlayers.org/apidocs/files/OpenLayers/Control-js.html>`_ 
  14.  */  
  15.   
  16. /** api: example 
  17.  *  Sample code to add a swipe control 
  18.  * 
  19.  *  .. code-block:: javascript 
  20.  * 
  21.  *     var map = new new OpenLayers.Map("mymap"); 
  22.  *     var Swipe = new OpenLayers.Control.Swipe({map: map}); 
  23.  *     map.addControls([swipe]); 
  24.  *     Swipe.activate(); 
  25.  * 
  26.  */  
  27.   
  28. /** api: constructor 
  29.  *  .. class:: Swipe(options) 
  30.  * 
  31.  *  :param options: ``Object`` options 
  32.  * 
  33.  *  :return:  ``OpenLayers.Control.Swipe`` 
  34.  * 
  35.  *  Add a swipe control in the map 
  36.  */  
  37. OpenLayers.Control.Swipe = OpenLayers.Class(OpenLayers.Control, {  
  38.   
  39.     /** api: config[map] 
  40.      *  ``OpenLayers.Map`` 
  41.      *  A `OpenLayers.Map <http://dev.openlayers.org/docs/files/OpenLayers/Map-js.html>`_ instance 
  42.      */  
  43.     map: null,  
  44.   
  45.     width: 32,  
  46.   
  47.     /** api: config[swipeRatio] 
  48.      *  ``Number`` 
  49.      *  A number between 0 and 1 defining the position of the swipe relative to the map (from right to left) 
  50.      */  
  51.     swipeRatio: null,  
  52.   
  53.     swipeLayer: null,  
  54.   
  55.     isTitleVisible: false,  
  56.   
  57.     isDragging: false,  
  58.   
  59.     mouseDragStart: null,  
  60.   
  61.   
  62.     /** 
  63.      * Property: divEvents 
  64.      * {<OpenLayers.Events>} 
  65.      */  
  66.     divEvents: null,  
  67.   
  68.     initialize: function (options) {  
  69.         "use strict";  
  70.         OpenLayers.Control.prototype.initialize.apply(  
  71.             this,  
  72.             arguments  
  73.         );  
  74.         // Manage position of swipe  
  75.         if (this.map && this.map.swipeRatio) {  
  76.             // Swipe ratio can be set in the map (in order to manage permalink)  
  77.             this.setSwipeRatio(this.map.swipeRatio);  
  78.         } else {  
  79.             if (!this.swipeRatio) {  
  80.                 // Default swipe ratio is 0.5  
  81.                 this.setSwipeRatio(0.5);  
  82.             } else {  
  83.                 // Swipe ratio can be set to the control  
  84.                 this.setSwipeRatio(this.swipeRatio);  
  85.             }  
  86.         }  
  87.     },  
  88.   
  89.     /** 
  90.      * Method: activate 
  91.      * Activates the control. 
  92.      * 
  93.      * Returns: 
  94.      * {Boolean} The control was effectively activated. 
  95.      */  
  96.     activate: function () {  
  97.         this.map.swipeActive = true;  
  98.         this.map.events.triggerEvent("changelayer", {  
  99.             layer: this.swipeLayer,  
  100.             property: "name"  
  101.         });  
  102.         OpenLayers.Control.prototype.activate.apply(this, arguments);  
  103.         this.map.events.on({  
  104.             "addlayer": this.handleAddLayer,  
  105.             "removelayer": this.handleRemoveLayer,  
  106.             "changelayer": this.handleChangeLayer,  
  107.             "updatesize": this.handleUpdateSize,  
  108.             "move": this.handleMove,  
  109.             "scope": this  
  110.         });  
  111.   
  112.         if (this.isLayersInLayerSwitcher()) {  
  113.             this.div.style.display = 'block';  
  114.             this.viewBigArrow();  
  115.         }  
  116.         this.resize();  
  117.   
  118.         return true;  
  119.     },  
  120.   
  121.     /** 
  122.      * Method: deactivate 
  123.      * Deactivates the control. 
  124.      * 
  125.      * Returns: 
  126.      * {Boolean} The control was effectively deactivated. 
  127.      */  
  128.     deactivate: function () {  
  129.         this.map.swipeActive = false;  
  130.         this.map.events.triggerEvent("changelayer", {  
  131.             layer: this.swipeLayer,  
  132.             property: "name"  
  133.         });  
  134.         this.map.events.un({  
  135.             "addlayer": this.handleAddLayer,  
  136.             "removelayer": this.handleRemoveLayer,  
  137.             "changelayer": this.handleChangeLayer,  
  138.             "updatesize": this.handleUpdateSize,  
  139.             "move": this.handleMove,  
  140.             "scope": this  
  141.         });  
  142.         this.hideBigArrow();  
  143.         this.hideLayerTitle();  
  144.         this.div.style.display = 'none';  
  145.         if (this.swipeLayer) {  
  146.             if (this.swipeLayer.layers) {  
  147.                 for (var i = this.swipeLayer.layers.length - 1; i >= 0; i--) {  
  148.                     var layer = this.swipeLayer.layers[i];  
  149.                     if (layer.div) {  
  150.                         layer.div.style.clip = 'auto';  
  151.                     }  
  152.                 }  
  153.             } else {  
  154.                 this.swipeLayer.div.style.clip = 'auto';  
  155.             }  
  156.             this.swipeLayer = null;  
  157.         }  
  158.   
  159.         return OpenLayers.Control.prototype.deactivate.apply(  
  160.             this, arguments  
  161.         );  
  162.     },  
  163.   
  164.     /** 
  165.      * Method: destroy 
  166.      * Destroy control. 
  167.      */  
  168.     destroy: function() {  
  169.         this.map.events.un({  
  170.             "addlayer": this.handleAddLayer,  
  171.             "removelayer": this.handleRemoveLayer,  
  172.             "changelayer": this.handleChangeLayer,  
  173.             "updatesize": this.handleUpdateSize,  
  174.             "scope": this  
  175.         });  
  176.         OpenLayers.Control.prototype.destroy.apply(this, arguments);  
  177.     },  
  178.   
  179.     /** 
  180.      * Method: draw 
  181.      * Initialize control. 
  182.      * 
  183.      * Returns: 
  184.      * {DOMElement} A reference to the DIV DOMElement containing the control 
  185.      */  
  186.     draw: function() {  
  187.         OpenLayers.Control.prototype.draw.apply(this, arguments);  
  188.   
  189.         this.elementLayer = document.createElement("div");  
  190.         this.div.appendChild(this.elementLayer);  
  191.         OpenLayers.Element.addClass(  
  192.             this.elementLayer,  
  193.             'olControlSwipeLayerHide'  
  194.         );  
  195.         this.elementLayerSpan = document.createElement("span");  
  196.         this.div.appendChild(this.elementLayerSpan);  
  197.         OpenLayers.Element.addClass(  
  198.             this.elementLayerSpan,  
  199.             'olControlSwipeLayerSpan'  
  200.         );  
  201.         this.elementLeft = document.createElement("div");  
  202.         this.div.appendChild(this.elementLeft);  
  203.         OpenLayers.Element.addClass(  
  204.             this.elementLeft,  
  205.             'olControlArrowLeft'  
  206.         );  
  207.   
  208.         this.elementRight = document.createElement("div");  
  209.         this.div.appendChild(this.elementRight);  
  210.         OpenLayers.Element.addClass(  
  211.             this.elementRight,  
  212.             'olControlArrowRight'  
  213.         );  
  214.   
  215.         OpenLayers.Control.prototype.draw.apply(this, arguments);  
  216.   
  217.         this.divEvents = new OpenLayers.Events(this, this.div, null, true, {includeXY: true});  
  218.   
  219.         this.divEvents.on({  
  220.             "touchstart": this.divDown,  
  221.             "touchmove": this.divDrag,  
  222.             "touchend": this.divUp,  
  223.             "mousedown": this.divDown,  
  224.             "mousemove": this.divDrag,  
  225.             "mouseup": this.divUp,  
  226.             "mouseover": this.divMouseOver,  
  227.             "mouseout": this.divMouseOut,  
  228.             scope: this  
  229.         });  
  230.   
  231.         return this.div;  
  232.     },  
  233.   
  234.     /* 
  235.      * Method: divMouseOver 
  236.      * event listener for onmouseover event 
  237.      * 
  238.      * Parameters: 
  239.      * evt - {<OpenLayers.Event>} 
  240.      */  
  241.     divMouseOver: function(ev) {  
  242.         OpenLayers.Element.addClass(  
  243.             this.div,  
  244.             'olControlSwipeHover'  
  245.         );  
  246.         //this.viewLayerTitle();  
  247.     },  
  248.   
  249.     hideBigArrow: function() {  
  250.         if (!this.isDragging) {  
  251.             this.elementLeft.style.display = "none";  
  252.             this.elementRight.style.display = "none";  
  253.         }  
  254.     },  
  255.   
  256.     viewBigArrow: function() {  
  257.         if (!this.isDragging) {  
  258.             this.elementLeft.style.display = "block";  
  259.             this.elementRight.style.display = "block";  
  260.         }  
  261.     },  
  262.   
  263.     /* 
  264.      * Method: divMouseOut 
  265.      * event listener for onmouseout event 
  266.      * 
  267.      * Parameters: 
  268.      * evt - {<OpenLayers.Event>} 
  269.      */  
  270.     divMouseOut: function(ev) {  
  271.         OpenLayers.Element.removeClass(  
  272.             this.div,  
  273.             'olControlSwipeHover'  
  274.         );  
  275.         this.hideLayerTitle();  
  276.         this.viewBigArrow();  
  277.     },  
  278.   
  279.     /** 
  280.      * Method: passEventToDiv 
  281.      * This function is used to pass events that happen on the map, 
  282.      * through to the div, which then does its moving thing. 
  283.      * 
  284.      * Parameters: 
  285.      * evt - {<OpenLayers.Event>} 
  286.      */  
  287.     passEventToDiv:function(evt) {  
  288.         this.divEvents.handleBrowserEvent(evt);  
  289.     },  
  290.   
  291.     /* 
  292.      * Method: divDown 
  293.      * event listener for clicks on the div 
  294.      * 
  295.      * Parameters: 
  296.      * evt - {<OpenLayers.Event>} 
  297.      */  
  298.     divDown:function(evt) {  
  299.         if (!OpenLayers.Event.isLeftClick(evt) && !OpenLayers.Event.isSingleTouch(evt)) {  
  300.             return;  
  301.         }  
  302.         this.map.events.on({  
  303.             "touchmove": this.passEventToDiv,  
  304.             "mousemove": this.passEventToDiv,  
  305.             "mouseup": this.passEventToDiv,  
  306.             scope: this  
  307.         });  
  308.         this.mouseDragStart = evt.xy.clone();  
  309.         OpenLayers.Event.stop(evt);  
  310.         //this.viewLayerTitle();  
  311.         this.hideBigArrow();  
  312.         this.isDragging = true;  
  313.         return false;  
  314.     },  
  315.   
  316.     /* 
  317.      * Method: divDrag 
  318.      * This is what happens when a click has occurred, and the client is 
  319.      * dragging.  Here we must ensure that the div doesn't go beyond the 
  320.      * bottom/top of the zoombar div, as well as moving the div to its new 
  321.      * visual location 
  322.      * 
  323.      * Parameters: 
  324.      * evt - {<OpenLayers.Event>} 
  325.      */  
  326.     divDrag:function(evt) {  
  327.         if (this.mouseDragStart && this.isDragging) {  
  328.             var deltaX = this.mouseDragStart.x - evt.xy.x;  
  329.             var left = parseInt(this.div.style.left, 10);  
  330.             if ((left - deltaX) >= 0 &&  
  331.                 (left - deltaX) <= (this.map.size.w - this.width)) {  
  332.                 var delta = 0;  
  333.                 if (OpenLayers.BROWSER_NAME === "msie" || OpenLayers.BROWSER_NAME === "safari") {  
  334.                     delta = -1;  
  335.                 }  
  336.                 this.setSwipeRatio((left - deltaX) / (this.map.size.w - this.width + delta));  
  337.                 this.moveTo(this.computePosition());  
  338.                 this.clipFirstLayer();  
  339.                 this.mouseDragStart = evt.xy.clone();  
  340.             }  
  341.             OpenLayers.Event.stop(evt);  
  342.         }  
  343.         return false;  
  344.     },  
  345.   
  346.     /* 
  347.      * Method: divUp 
  348.      * Perform cleanup when a mouseup event is received 
  349.      * 
  350.      * Parameters: 
  351.      * evt - {<OpenLayers.Event>} 
  352.      */  
  353.     divUp:function(evt) {  
  354.         this.map.events.un({  
  355.             "touchmove": this.passEventToDiv,  
  356.             "mousemove": this.passEventToDiv,  
  357.             "mouseup": this.passEventToDiv,  
  358.             scope: this  
  359.         });  
  360.         if (!OpenLayers.Event.isLeftClick(evt) && evt.type !== "touchend") {  
  361.             return;  
  362.         }  
  363.         if (this.mouseDragStart) {  
  364.             this.mouseDragStart = null;  
  365.         }  
  366.         this.isDragging = false;  
  367.         this.viewBigArrow();  
  368.         if (evt.type === "touchend") {  
  369.             this.hideLayerTitle();  
  370.         }  
  371.         OpenLayers.Event.stop(evt);  
  372.         return false;  
  373.     },  
  374.   
  375.     /* 
  376.      * Method: clipFirstLayer 
  377.      * Clip the first layer present in the layer switcher 
  378.      */  
  379.     clipFirstLayer: function() {  
  380.         var newFirstLayer = this.getFirstLayerInLayerSwitcher();  
  381.         if (this.swipeLayer) {  
  382.             if (newFirstLayer.id !== this.swipeLayer.id) {  
  383.                 if (this.swipeLayer.layers) {  
  384.                     for (var i = this.swipeLayer.layers.length - 1; i >= 0; i--) {  
  385.                         var layer = this.swipeLayer.layers[i];  
  386.                         if (layer.div) {  
  387.                             layer.div.style.clip = 'auto';  
  388.                         }  
  389.                     }  
  390.                 } else {  
  391.                     this.swipeLayer.div.style.clip = 'auto';  
  392.                 }  
  393.             }  
  394.         }  
  395.   
  396.         if (newFirstLayer) {  
  397.             var width = this.map.getCurrentSize().w;  
  398.             var height = this.map.getCurrentSize().h;  
  399.             // slider position in pixels  
  400.             var s = parseInt(width * this.getSwipeRatio() * ((this.map.getCurrentSize().w - this.width) / this.map.getCurrentSize().w), 10);  
  401.             // cliping rectangle  
  402.             var top = -this.map.layerContainerOriginPx.y;  
  403.             var bottom = top + height;  
  404.             var left = -this.map.layerContainerOriginPx.x;  
  405.             var right = left + s + Math.ceil((this.width - 1) / 2);  
  406.             //Syntax for clip "rect(top,right,bottom,left)"  
  407.             var clip = "rect(" + top + "px " + right + "px " + bottom + "px " + left + "px)";  
  408.             this.swipeLayer = newFirstLayer;  
  409.             if (this.swipeLayer.layers) {  
  410.                 for (var i = this.swipeLayer.layers.length - 1; i >= 0; i--) {  
  411.                     var layer = this.swipeLayer.layers[i];  
  412.                     if (layer.div) {  
  413.                         layer.div.style.clip = clip;  
  414.                     }  
  415.                 }  
  416.             } else {  
  417.                 this.swipeLayer.div.style.clip = clip;  
  418.             }  
  419.         }  
  420.   
  421.     },  
  422.   
  423.     /* 
  424.      * Method: handleAddLayer 
  425.      * Triggered when a new layer is added 
  426.      * 
  427.      * Parameters: 
  428.      * object - {<OpenLayers.Event>} 
  429.      */  
  430.     handleAddLayer: function (object) {  
  431.         if (this.isLayersInLayerSwitcher()) {  
  432.             this.div.style.display = 'block';  
  433.             this.moveTo(this.computePosition());  
  434.             this.clipFirstLayer();  
  435.         } else {  
  436.             this.div.style.display = 'none';  
  437.             this.swipeLayer = null;  
  438.         }  
  439.     },  
  440.   
  441.     viewLayerTitle: function() {  
  442.         if (!this.isTitleVisible && !this.isDragging) {  
  443.             if (this.swipeLayer) {  
  444.                 var content = "     " + this.swipeLayer.name;  
  445.                 this.elementLayer.innerHTML = content;  
  446.                 this.elementLayerSpan.innerHTML = content;  
  447.                 OpenLayers.Element.addClass(  
  448.                     this.elementLayer,  
  449.                     'olControlSwipeLayerView'  
  450.                 );  
  451.                 OpenLayers.Element.removeClass(  
  452.                     this.elementLayer,  
  453.                     'olControlSwipeLayerHide'  
  454.                 );  
  455.                 var width = parseInt(this.elementLayerSpan.offsetWidth) + 5;  
  456.                 this.elementLayer.style.width = width + "px";  
  457.                 this.elementLayer.style.marginLeft = "-" + width + "px";  
  458.   
  459.             }  
  460.   
  461.         }  
  462.         this.isTitleVisible = true;  
  463.     },  
  464.   
  465.     hideLayerTitle: function() {  
  466.         if (!this.isDragging) {  
  467.             this.elementLayer.innerHTML = '';  
  468.             this.isTitleVisible = false;  
  469.             OpenLayers.Element.addClass(  
  470.                 this.elementLayer,  
  471.                 'olControlSwipeLayerHide'  
  472.             );  
  473.             OpenLayers.Element.removeClass(  
  474.                 this.elementLayer,  
  475.                 'olControlSwipeLayerView'  
  476.             );  
  477.         }  
  478.     },  
  479.   
  480.     /* 
  481.      * Method: handleRemoveLayer 
  482.      * Triggered when a new layer is removed 
  483.      * 
  484.      * Parameters: 
  485.      * object - {<OpenLayers.Event>} 
  486.      */  
  487.     handleRemoveLayer: function (object) {  
  488.         if (this.isLayersInLayerSwitcher()) {  
  489.             this.div.style.display = 'block';  
  490.             this.moveTo(this.computePosition());  
  491.             this.clipFirstLayer();  
  492.         } else {  
  493.             this.div.style.display = 'none';  
  494.             this.swipeLayer = null;  
  495.         }  
  496.     },  
  497.   
  498.     /* 
  499.      * Method: handleChangeLayer 
  500.      * Triggered when the layer order is changed 
  501.      * 
  502.      * Parameters: 
  503.      * object - {<OpenLayers.Event>} 
  504.      */  
  505.     handleChangeLayer: function (object) {  
  506.         if (object.property === 'order') {  
  507.             if (this.isLayersInLayerSwitcher()) {  
  508.                 this.div.style.display = 'block';  
  509.                 this.moveTo(this.computePosition());  
  510.                 this.clipFirstLayer();  
  511.             } else {  
  512.                 this.div.style.display = 'none';  
  513.                 this.swipeLayer = null;  
  514.             }  
  515.         }  
  516.     },  
  517.   
  518.     /* 
  519.      * Method: handleUpdateSize 
  520.      * Triggered when the map size changed. In this case the swipe control is updated accordingly. 
  521.      * 
  522.      * Parameters: 
  523.      * object - {<OpenLayers.Event>} 
  524.      */  
  525.     handleUpdateSize: function (object) {  
  526.         //we have to delay this on Android devices  
  527.         if (navigator.userAgent.toLowerCase().indexOf("android") > 0) {  
  528.             var self = this;  
  529.             setTimeout(function() {  
  530.                 self.resize();  
  531.             }, 10);  
  532.         } else {  
  533.             this.resize();  
  534.         }  
  535.     },  
  536.   
  537.     /* 
  538.      * Method: handleMove 
  539.      * Triggered when the map is moved. In this case, the clip ares has to be updated 
  540.      * 
  541.      * Parameters: 
  542.      * object - {<OpenLayers.Event>} 
  543.      */  
  544.     handleMove: function (object) {  
  545.         this.clipFirstLayer();  
  546.     },  
  547.   
  548.     /* 
  549.      * Method: resize 
  550.      * Resize the swipe and update the first layer clipping 
  551.      */  
  552.     resize: function() {  
  553.         this.div.style.height = this.map.getCurrentSize().h + 'px';  
  554.         this.div.style.width = this.width + 'px';  
  555.         this.moveTo(this.computePosition());  
  556.         this.clipFirstLayer();  
  557.         var topPosition = (this.map.getCurrentSize().h / 2) - 32;  
  558.         this.elementLeft.style.marginTop = topPosition + 'px';  
  559.         this.elementRight.style.marginTop = topPosition + 'px';  
  560.     },  
  561.   
  562.     /* 
  563.      * Method: computePosition 
  564.      * Recompute the position of the swipe acording  to swipeRatio and the size of the map 
  565.      */  
  566.     computePosition: function() {  
  567.         var y = 0;  
  568.         var x = this.getSwipeRatio() * (this.map.size.w - this.width);  
  569.         return new OpenLayers.Pixel(x, y);  
  570.     },  
  571.   
  572.     /* 
  573.      * Method: getFirstLayerInLayerSwitcher 
  574.      * Get the first layer visible in the layer switcher 
  575.      */  
  576.     getFirstLayerInLayerSwitcher: function() {  
  577.         for (var i = this.map.layers.length - 1; i >= 0; i--) {  
  578.             var layer = this.map.layers[i];  
  579.             if (layer.displayInLayerSwitcher) {  
  580.                 return layer;  
  581.             }  
  582.         }  
  583.         return null;  
  584.     },  
  585.   
  586.     /* 
  587.      * Method: isLayersInLayerSwitcher 
  588.      * Check the presence of a layer in the layer switcher 
  589.      */  
  590.     isLayersInLayerSwitcher: function() {  
  591.         for (var i = 0, len = this.map.layers.length; i < len; i++) {  
  592.             var layer = this.map.layers[i];  
  593.             if (layer.displayInLayerSwitcher) {  
  594.                 return true;  
  595.             }  
  596.         }  
  597.         return false;  
  598.     },  
  599.   
  600.     setSwipeRatio: function(ratio) {  
  601.         this.map.events.triggerEvent("changelayer", {  
  602.             layer: this.swipeLayer,  
  603.             property: "name"  
  604.         });  
  605.         this.map.swipeRatio = ratio;  
  606.         this.map.swipeActive = this.active;  
  607.     },  
  608.   
  609.     getSwipeRatio: function() {  
  610.         return this.map.swipeRatio;  
  611.     },  
  612.   
  613.     /* 
  614.      * Method: updateRatio 
  615.      * Update the swipeRatio and update the swipe control accordingly 
  616.      */  
  617.     updateRatio: function(ratio) {  
  618.         this.setSwipeRatio(ratio);  
  619.         if (this.isLayersInLayerSwitcher()) {  
  620.             this.div.style.display = 'block';  
  621.             this.moveTo(this.computePosition());  
  622.             this.clipFirstLayer();  
  623.         } else {  
  624.             this.div.style.display = 'none';  
  625.             this.swipeLayer = null;  
  626.         }  
  627.     },  
  628.   
  629.     CLASS_NAME: "OpenLayers.Control.Swipe"  
  630. });  



[javascript] view plain copy print?在CODE上查看代码片派生到我的代码片
  1. <pre code_snippet_id="1644580" snippet_file_name="blog_20160413_1_9288680" name="code" class="javascript"><span style="font-family: Arial, Helvetica, sans-serif; rgb(255, 255, 255);">这个js文件里面引用到了一些样式,样式文件的内容如下:</span></pre>  
  1. .olControlSwipe {  
  2.     background:url("../img/line.png") repeat;  
  3.     display: none;  
  4. }  
  5.   
  6. .olControlSwipeHover {  
  7.     cursor: w-resize;  
  8. }  
  9.   
  10. .olControlSwipeLayerView {  
  11.     background-color: white;  
  12.     height: 16px;  
  13.     width: 220px;  
  14.     margin-top: 23px;  
  15.     margin-left: -230px;  
  16.     display: block;  
  17.     font-size: 11px;  
  18.     font-family: Tahoma, Arial;  
  19.     font-weight: 700;  
  20.     padding-top: 2px;  
  21.     background-image: url("../img/bigarrow_left.png");  
  22.     background-repeat: no-repeat;  
  23.     position: absolute;  
  24. }  
  25.   
  26. .olControlSwipeLayerSpan {  
  27.     visibility: hidden;  
  28.     font-size: 11px;  
  29.     font-family: Tahoma, Arial;  
  30.     font-weight: 700;  
  31.     white-space: pre;  
  32.     position: absolute;  
  33. }  
  34.   
  35. .olControlSwipeLayerHide {  
  36.     display: none;  
  37. }  
  38.   
  39. .olControlArrowLeft {  
  40.     width: 16px;  
  41.     height: 32px;  
  42.     margin-left: -1px;  
  43.     background-image: url("../img/bigarrow_left.png");  
  44.     background-repeat: no-repeat;  
  45.     position: absolute;  
  46. }  
  47. .olControlArrowRight {  
  48.     width: 16px;  
  49.     height: 32px;  
  50.     margin-left: 19px;  
  51.     background-image: url("../img/bigarrow_right.png");  
  52.     background-repeat: no-repeat;  
  53.     position: absolute;  
  54. }  

最后,调用展示,代用代码如下:

[javascript] view plain copy print?在CODE上查看代码片派生到我的代码片
    1. $("#swipebutton").on("click",function(){  
    2.     if(flag){  
    3.         swipe.deactivate();  
    4.         flag=false;  
    5.     }  
    6.     else{  
    7.         swipe.activate();  
    8.         flag=true;  
    9.     }  
    10. }); 
posted @ 2016-07-18 15:10  韩慧兵  阅读(720)  评论(0编辑  收藏  举报