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);
map.events.register('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.


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(){
     console.info('map dragged');

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


i hope it helps you...

  • 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 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.