Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript loop; getting the current variable
    primarykey
    data
    text
    <p>I am trying to make a map with <a href="http://www.netzgesta.de/shiftzoom/" rel="nofollow">shiftzoom.js</a></p> <p>I have the following code snippet: </p> <pre><code>function selectall() { for (i in geodata['world']) { var q = getGeoPosition('world', i.toUpperCase(), 1654, 496, 1350, 407); shiftzoom.construct($('world'), [{ x: q.l, y: q.t, w: 40, h: 40, id: geodata['world'][i].lc, pos: 0, title: '', href: "javascript:get_lake(i); ", target: 'graphFrame', src: 'images/bullet.gif' }]); cvi_tip.add(cvi_tip.$(geodata['world'][i].lc), '&lt;small&gt;Province:&lt;/small&gt;&lt;br/&gt;&lt;big&gt;&lt;b&gt;&lt;u&gt;' + geodata['world'][i].ln + '&lt;/u&gt;&lt;/b&gt;&lt;/big&gt;&lt;br/&gt;&lt;small&gt;LAT/LONG:&lt;/small&gt;&lt;br/&gt;&lt;big&gt;&lt;b&gt;' + geodata['world'][i].coord + '&lt;/b&gt;&lt;/big&gt;&lt;br/&gt;&lt;small&gt;PROVINCE:&lt;/small&gt;&lt;br/&gt;&lt;big&gt;&lt;b&gt;&lt;i&gt;' + geodata['world'][i].pr + '&lt;/i&gt;&lt;/b&gt;&lt;/big&gt;'); } } </code></pre> <p>I am positioning dots to represent lakes on the map and I would like it to zoom in when the dot is clicked. This is what the function get_lake does, but every dot I click shows zooms in to the last value of "i". I have tried using closures like so:</p> <pre><code> href:"javascript:function(num){return function(){get_lake(num);};}(i);" </code></pre> <p>but I might not be using it properly since this code doesn't run. Does anyone know how to code it so that the function calls the current variable instead of the last one?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload