map.events.register('click', map, fucntion(e){alert('on')} ); 
    map.events.unregister('click', map, fucntion(e){alert('off')} ); 

Looks easy enough but un-registering just won't trigger. I try nesting unregistering inside register function call back but still nothing.

Here is how I created my map..

    var bounds = new OpenLayers.Bounds( 
            146501.328125, 2420230.75, 
            352670.46875, 2801126.25 
    var options = { 
            controls: [], 
            maxExtent: bounds, 
            maxResolution: 1487.873046875, 
            projection: "EPSG:3826", 
            unit: 'm' 
    format = "image/png"; 
    map = new OpenLayers.Map( 'MapPage_map-canvas2', options ); 

    event = map.events.register('move', map, function (evt) { 
            document.getElementById('map-url').innerHTML = map.getCenter(); 

    var county = new OpenLayers.Layer.WMS( 
                    LAYERS: 'AllenProject:county', 
                    STYLES: 'AllenProject_BlackBorder_GreyBackground', 
                    format: format, 
                    tiled: true, 
                    transparent: true, 
                    //tilesOrigin : map.maxExtent.left + ',' + map.maxExtent.bottom 
                    buffer: 0, 
                    //displayOutsideMaxExtent: true, 
                    transitionEffect: null, //'resize', 
                    isBaseLayer: true 

    map.events.register('click', map, function (evt) { 

    map.events.unregister('click', map, function (evt) { 

I don't understand this.

1 Answer 1


Solved... the problem with this is that register and unregister's call back has to be the same function. My way above is basically two different functions. To fix it this is what I did:

function doSomething(evt){
    map.events.unregister('move', map, doSomething);
map.events.register('move', map, doSomething);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.