2

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.

1 Answer 1

1

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

drag.draw();
map.addControl(drag);
drag.activate();

i hope it helps you...

4
  • 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.. Oct 30, 2012 at 9:40
  • it is the same as moveend method.
    – urcm
    Oct 30, 2012 at 9:42
  • Ok, you mean replace the moveend method with DragPan as a workaround? Oct 30, 2012 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 :) Oct 30, 2012 at 10:19

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.