Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm interested in detecting when a user moves or pans a map so that I can run a new query on a database based on their location. However, the following code causes the panning and zooming controls to go crazy:"moveend", map, function(){              

If I comment out these lines, there appears to be no problem. If they are included, after two pans or zooms, the map suddenly jumps to half-way around the world (it looks similar to 0 lat, 0 long). I'm unsure what I am doing incorrectly.

The other problem I have regarding the pan/zooming is that the movend does not really seem to wait until the user has finished moving or panning. Queries seem to be fired off even as the map is being moved and panned. Again, I'm not sure if this is a problem with how I am detecting this but it does not seem to behave as I thought it would.

EDIT: Including getValues function also:

getValues = function(c){

    c.transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326") )
    console.log(, c.lon)

            type: "POST",
            url: "php/query.php" ,  
            data:{x:, y:c.lon},  
            async: true,
            success: function(r){

share|improve this question
up vote 2 down vote accepted

I see your problem. Try map.getCenter(). You are transforming the map center point which is likely the cause of your problem.

share|improve this answer
Yes, that does fix the 'thrashing'. However, on the third zoom/pan it throws the map to some random place in the world which stops when I comment out the piece as far as I can tell. – djq Aug 16 '12 at 20:14
Update the source in the question so I can see that you've replace with map.getCenter(). – ca0v Aug 16 '12 at 20:17
That fixed what was going on, thanks again. – djq Aug 19 '12 at 14:37

I've used this event successfully. A delay method similar to the one here can help any thrashing. The actual method looks like this:

delay: function( timeout, id, callback )
            this.delays = this.delays || [];
            var delay = this.delays[ id ];
            if ( delay )
                    clearTimeout ( delay );
            delay = setTimeout ( callback, timeout );
            this.delays[ id ] = delay;

Usage Example:

delay(1000, "uniqueId", function() {

I suspect your getValues method is modifying the map causing the moveend event to fire.

share|improve this answer
Thanks for the suggestion @ca0v. Do you place your example delay within the"moveend", map, function(){ ... }) function? I would be surprised if my getValues method moves the map. – djq Aug 16 '12 at 19:53
yes - register("moveend", map, function() { $.delay(...) }) where "$" is a reference to the object containing the delay function. This is necessary because of the this.delays references. – ca0v Aug 16 '12 at 20:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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