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 have created a map that contains a two base layers (Google Street Map and Open Street Map). A moveend event listener is registered to listen for any map movement which would perform a function call to load in new data based on the bounds of the map view port. I realise that the function call is performed even when switching the base layer without causing any map movement. Is there a way to switch the base layer silently?

As requested, the code in brief:

var map;
var gmap_r = new OpenLayers.Layer.Google('Google Street Map');
var osm = new OpenLayers.Layer.OSM('Open Street Map');
var options = {
  layers: [gmap_r, osm, markers]
map = new OpenLayers.Map('map', options);'moveend', map, my_function);
//code above used for triggering a call to my_function upon a map pan or zoom event 

The change of base layer unfortunately triggers the above as well.

share|improve this question
up vote 1 down vote accepted

if you share your code, we can make a good point for you. addition to the moveend listener you can chek out OpenLayers.Control.DragPan method for your request.

function dragged(){'map dragged');

var drag = new OpenLayers.Control.DragPan({'map':map, 'panMapDone':dragged});


i hope it helps you...

share|improve this answer
I have edited my question to add in the relevant code, not sure if it this is what you want.. but I don't get what you are trying to achieve with by adding a DragPan control.. – Question Overflow Oct 30 '12 at 9:40
it is the same as moveend method. – Aragon Oct 30 '12 at 9:42
Ok, you mean replace the moveend method with DragPan as a workaround? – Question Overflow Oct 30 '12 at 9:50
I added another listener to listen for changebaselayer event and use that as a workaround. Think it solved now. Thanks for your help :) – Question Overflow Oct 30 '12 at 10:19

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.