Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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(){
     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...

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

 
discard

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.