locked
Programmed zoom-in wrong behaviour versus SDK version 7 after panning RRS feed

  • Question

  • Hi,

    After a panning, if a zoom increase is done programmatically, the zoomed-in map is afterwards centered on the location BEFORE the panning...

    Hereafter please find the used custom zoom:

    function setZoom(){
     var zl=parseInt(document.getElementById('zfs').value);
     var options=map.getOptions();
     options.zoom=zl;
     map.setView(options);
    }
    
    function populateZoomFactors(){
     zfs=document.getElementById('zfs');
     while(zfs.options.length){
      zfs.removeChild(zfs.options[0]);
     }
     var factors=map.getZoomRange().max;
     var zf=parseInt(map.getZoom()+0.5);
     for(var i=".$zoo.";factors>=i;++i){
      var option=document.createElement('option');
      option.value=i;
      option.appendChild(document.createTextNode(i*5+'%'));
      if(i==zf){
       option.selected=true;
      }
      zfs.appendChild(option);
     }
    }
    

    Thanks in advance for your appreciated help,

    Germain

    Sunday, October 16, 2016 10:35 AM

Answers

  • Without looking at your code I tried to reproduce the scenario you mentioned by setting a timeout to change the zoom level programmatically after a few seconds so that I had time to manually pan the map. Doing this the zoom worked as expected and zoomed into the center of the new area I had panned to.

    Looking at your code I see a few issues. The first is that you are getting map options using getOptions, adding a zoom property and then passing this into the setView function. Two issues here. The first is that getOptions returns map options, not view options which are completely different. The second is that you don't and shouldn't grab the current map options, change one then pass them all into the setView function. This may result in additional recalculations or processing for things that don't need recalculating or processing. All you need to do is this:

    map.setView({zoom: zl});

    Not sure what the code in the populateZoomFactors function is meant to do, but there is some odd looking code in there. Like, "var zf=parseInt(map.getZoom()+0.5);", unless this function is called while the map is being zoomed this will always be the same as map.getZoom(), as the map always snaps to an integer zoom level.


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Monday, October 17, 2016 6:21 PM
    • Marked as answer by VEHICALL Monday, October 17, 2016 6:47 PM
    Monday, October 17, 2016 6:21 PM

All replies

  • Without looking at your code I tried to reproduce the scenario you mentioned by setting a timeout to change the zoom level programmatically after a few seconds so that I had time to manually pan the map. Doing this the zoom worked as expected and zoomed into the center of the new area I had panned to.

    Looking at your code I see a few issues. The first is that you are getting map options using getOptions, adding a zoom property and then passing this into the setView function. Two issues here. The first is that getOptions returns map options, not view options which are completely different. The second is that you don't and shouldn't grab the current map options, change one then pass them all into the setView function. This may result in additional recalculations or processing for things that don't need recalculating or processing. All you need to do is this:

    map.setView({zoom: zl});

    Not sure what the code in the populateZoomFactors function is meant to do, but there is some odd looking code in there. Like, "var zf=parseInt(map.getZoom()+0.5);", unless this function is called while the map is being zoomed this will always be the same as map.getZoom(), as the map always snaps to an integer zoom level.


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Monday, October 17, 2016 6:21 PM
    • Marked as answer by VEHICALL Monday, October 17, 2016 6:47 PM
    Monday, October 17, 2016 6:21 PM
  • Thank you a lot Ricky !

    You are totally right and I apologize: I've changed my code accordingly and it works now :-)

    I took it without any change from the V7 version of http://ADtlas.com on which it is working but I will have a look into it too.

    Warm thanks again and cheers,

    Germain

    Monday, October 17, 2016 6:46 PM