1
    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 ); 

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

    var county = new OpenLayers.Layer.WMS( 
            "AllenProject:county", 
            "http://localhost:8080/......./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.addLayer(county); 

    map.events.register('click', map, function (evt) { 
            alert('on');    
    }); 

    map.events.unregister('click', map, function (evt) { 
            alert('off'); 
    }); 

I don't understand this.

2

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){
    alert('on');
    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, privacy policy and cookie policy

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