OpenLayers OpenLayers

Changeset 5797

Show
Ignore:
Timestamp:
01/17/08 11:37:26 (1 year ago)
Author:
enjahova
Message:

cleaned up identify, switch and zoomout controls

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/enjahova/openlayers/examples/more-controls.html

    r5378 r5797  
    1616    <title>More Controls Demo</title> 
    1717    <script src="../lib/OpenLayers.js"></script> 
     18    <script type="text/javascript" src="../lib/openlayers/lib/OpenLayers/Control/ZoomOut.js"></script> 
     19    <script type="text/javascript" src="../lib/openlayers/lib/OpenLayers/Control/Identify.js"></script> 
     20    <script type="text/javascript" src="../lib/openlayers/lib/OpenLayers/Control/Switch.js"></script> 
    1821    <script type="text/javascript"> 
    1922        var lon = 5; 
     
    2427        function identify(pos) 
    2528        { 
    26            alert("user identify: pos = (" + pos.lat + ", " + pos.lon + ")"); 
     29           alert("user identify: pos = (" + pos.x + ", " + pos.y + ")"); 
     30        } 
     31 
     32        function on() 
     33        { 
     34            alert("user turned switch on"); 
     35        } 
     36         
     37        function off() 
     38        { 
     39            alert("user turned switch off"); 
    2740        } 
    2841 
    2942        function init() { 
    3043            var nt = new OpenLayers.Control.NavToolbar({'div':OpenLayers.Util.getElement('paneldiv')}); 
    31             nt.addControls(new OpenLayers.Control.ZoomOut()) 
    32             nt.addControls(new OpenLayers.Control.ZoomToMaxExtent()) 
    33             nt.addControls(new OpenLayers.Control.ZoomToLastExtent()) 
    34             nt.addControls(new OpenLayers.Control.Identify(identify)) 
     44            nt.addControls(new OpenLayers.Control.ZoomOut()); 
     45            nt.addControls(new OpenLayers.Control.Identify(identify)); 
     46            nt.addControls(new OpenLayers.Control.Switch(on,off)); 
    3547            map = new OpenLayers.Map('map', { controls: [nt], theme: null }); 
    3648     
     
    4658    <h3 id="title">More Controls Demo</h3> 
    4759    <p id="shortdesc"> 
    48        Demo the ZoomOut, ZoomToLastExtent, and Identify Controls. 
     60       Demo the ZoomOut, Identify and Switch Controls. 
    4961       (Using modified famfamfam.com icons) 
    5062    </p>  
  • sandbox/enjahova/openlayers/lib/OpenLayers.js

    r5787 r5797  
    131131            "OpenLayers/Control/ZoomBox.js", 
    132132            "OpenLayers/Control/Identify.js", 
    133             "OpenLayers/Control/Email.js", 
    134133            "OpenLayers/Control/ZoomOut.js", 
    135134            "OpenLayers/Control/ZoomToMaxExtent.js", 
    136             "OpenLayers/Control/ZoomToLastExtent.js", 
    137135            "OpenLayers/Control/DragPan.js", 
    138136            "OpenLayers/Control/Navigation.js", 
  • sandbox/enjahova/openlayers/lib/OpenLayers/Control/Identify.js

    r5497 r5797  
    55/** 
    66 * @requires OpenLayers/Control.js 
    7  * @requires OpenLayers/Handler/Drag.js 
     7 * @requires OpenLayers/Handler/Click.js 
    88 * 
    99 * Class: OpenLayers.Control.Identify 
     
    2424     * 
    2525     * Parameters: 
    26      * options - {func} An optional object whose properties will be used 
     26     * options - {userFunction} An optional object whose properties will be used 
    2727     *     to extend the control. 
    2828     */ 
    29     initialize: function(func, options) { 
     29    initialize: function(userFunction, options) { 
    3030        OpenLayers.Control.prototype.initialize.apply(this, [options]); 
    31         this.userFunction = func
     31        this.userFunc = userFunction
    3232    }, 
    3333 
     
    3737     */     
    3838    draw: function() { 
    39         this.handler = new OpenLayers.Handler.Drag( this, 
    40                             {"up": this.identify}, {keyMask: this.keyMask} ); 
     39        this.handler = new OpenLayers.Handler.Click( this,  
     40                            {"click": this.identify}, {keyMask: this.keyMask} ); 
    4141    }, 
    4242 
    4343    /** 
    4444     * Method: identify 
     45     * Placeholder for user defined identify function 
    4546     * 
    4647     * Parameters: 
    47      * position - {<OpenLayers.Pixel>} 
     48     * evt - {Click Event} 
     49     * 
    4850     */ 
    49     identify: function (position) { 
    50         //var pos = this.map.getLonLatFromPixel(position) 
    51         this.userFunction(position); 
     51    identify: function (evt) { 
     52        var position = evt.xy; 
     53        this.userFunc(position); 
    5254    }, 
    5355     
    54     /** 
    55      * Method: userFunction 
    56      * placeholder for the userdefined function that will handle the identify 
    57      */ 
    58     userFunction: function(pos){ 
    59     }, 
    60  
    6156    CLASS_NAME: "OpenLayers.Control.Identify" 
    6257}); 
  • sandbox/enjahova/openlayers/lib/OpenLayers/Control/Switch.js

    r5787 r5797  
    55/** 
    66 * @requires OpenLayers/Control.js 
    7  * @requires OpenLayers/Handler/Drag.js 
    87 * 
    9  * Class: OpenLayers.Control.Identify 
     8 * Class: OpenLayers.Control.Switch 
    109 * 
    1110 * Inherits from: 
     
    2019     
    2120    /** 
    22      * Constructor: OpenLayers.Control.Identify  
    23      * Fires a user defined function with the mouse position 
     21     * Constructor: OpenLayers.Control.Switch  
     22     * Fires a user defined function when toggled on/off 
    2423     * 
    2524     * Parameters: 
     
    3231        this.userOff = off; 
    3332    }, 
    34  
     33     
     34    /** 
     35     * Method: activate 
     36     * Override OpenLayers.Control.activate to call user defined "on" function 
     37     */ 
    3538    activate: function () { 
    3639        if (this.active) { 
     
    4548    }, 
    4649      
     50    /** 
     51     * Method: deactivate 
     52     * Override OpenLayers.Control.deactivate to call user defined "off" function 
     53     */  
    4754    deactivate: function () { 
    4855        if (this.active) { 
     
    5966     
    6067    /** 
    61      * Method: userFunctio
    62      * placeholder for the userdefined function that will handle the identify 
     68     * Method: userO
     69     * placeholder for the user defined function that will be fired when Switch is activated 
    6370     */ 
    6471    userOn: function(){ 
    6572    }, 
    66  
     73    /** 
     74     * Method: userOn 
     75     * placeholder for the user defined function that will be fired when Switch is activated 
     76     */ 
    6777    userOff: function(){ 
    6878    }, 
  • sandbox/enjahova/openlayers/lib/OpenLayers/Control/ZoomOut.js

    r5374 r5797  
    55/** 
    66 * @requires OpenLayers/Control.js 
    7  * @requires OpenLayers/Handler/Box.js 
     7 * @requires OpenLayers/Handler/Click.js 
    88 * 
    9  * Class: OpenLayers.Control.ZoomIn 
     9 * Class: OpenLayers.Control.ZoomOut 
    1010 * 
    1111 * Inherits from: 
     
    2323     */     
    2424    draw: function() { 
    25         this.handler = new OpenLayers.Handler.Drag( this, 
    26                             {"down": this.zoomOut}, {keyMask: this.keyMask} ); 
     25        this.handler = new OpenLayers.Handler.Click( this,  
     26                            {"click": this.zoomOut}, {keyMask: this.keyMask} ); 
    2727    }, 
    2828 
     
    3131     * 
    3232     * Parameters: 
    33      * position - {<OpenLayers.Pixel>} 
     33     * evt - {<Click Event>} 
    3434     */ 
    35     zoomOut: function (position) { 
     35    zoomOut: function (evt) { 
     36        var position = evt.xy; 
    3637        this.map.setCenter(this.map.getLonLatFromPixel(position), 
    3738                           this.map.getZoom() - 1); 
  • sandbox/enjahova/openlayers/lib/OpenLayers/Map.js

    r5719 r5797  
    142142     */ 
    143143    viewRequestID: 0, 
    144  
    145     /** 
    146      * Property extents 
    147      * {Array} Used to store a history of the extents 
    148      */ 
    149     extents: [], 
    150144 
    151145  // Options 
     
    400394        OpenLayers.Event.observe(window, 'unload', this.unloadDestroy); 
    401395         
    402         //keep track of previous extents so we can "undo" them Used by ZoomToLastExtent 
    403         var func = function () {  
    404             //console.log(this.getExtent()); 
    405             //console.log(this.getScale()); 
    406             this.extents.push(this.getExtent()); 
    407         } 
    408         this.events.register("moveend", map, func ); 
    409396    }, 
    410397 
     
    16971684    }, 
    16981685 
    1699     /**  
    1700      * APIMethod: zoomToLastExtent 
    1701      * Zoom to the full extent and recenter. 
    1702      */ 
    1703     zoomToLastExtent: function() { 
    1704         //maybe not the cleanest way to do this (no 'redo') but it works 
    1705         if(this.extents.length > 1) 
    1706         { 
    1707             var tmp = this.extents.pop(); 
    1708             var last_extent = this.extents.pop(); 
    1709             this.zoomToExtent(last_extent); 
    1710         } 
    1711         else 
    1712         { 
    1713             this.zoomToMaxExtent(); 
    1714             this.extents.pop();this.extents.pop();//original extent should leave extents empty 
    1715         } 
    1716     }, 
    1717  
    17181686    /**  
    17191687     * APIMethod: zoomToScale 
  • sandbox/enjahova/openlayers/tests/list-tests.html

    r5719 r5797  
    8989    <li>Control/test_Identify.html</li> 
    9090    <li>Control/test_SelectFeature.html</li> 
     91    <li>Control/test_Switch.html</li> 
    9192    <li>test_Handler.html</li> 
    9293    <li>Handler/test_Click.html</li>