Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is an issue of variable scoping.</p> <p>Think of "L" conceptually as a namespace. L exposes methods to you, such as map, L.map().</p> <p>Looks like you want to expose your "current_map" variable. In your map_global.js file, current_map is currently a local variable - because you declared it with <strong>var</strong>. So anything outside of the map_global.js scope, can NOT access current_map.</p> <p>If you want a quick and dirty way to access current_map in map_individual.js, you can expose it by setting the global window.current_map to L.map(map_id), so change the scope of your current_map variable.</p> <p>This of course leads to polluting the global scope, so one thing you can explore is how to achieve "modular" client side javascript. A simple way of doing this, is by implementing your own namespacing. E.g. in map_global.js, you can expose just one 'object' - your own namespace - and attach that to window. You can use your namespace to access current_map and setup_map(), if you attach those methods and vars to that 'object', instead of attaching all your methods and variables directly to the window - global namespace - which could get out of hand quickly.</p> <pre><code> function setup_map(){ ...} var current_map; window.my_lib = { setup_map = setup_map, current_map = current_map } </code></pre> <p>so <strong>my_lib.setup_map()</strong>, and <strong>my_lib.current_map</strong> could be accessed later in this way then, since you only make <strong>my_lib</strong> a global. Imagine if my_lib exposed a dozen functions, the idea is that this would be more organized, as opposed to attaching all dozen functions to the window - global namespace. This comes in handy later when you have different files/"modules" which have functions that are named the same. This way, you can have my_lib.render() and say, client_lib.render(), without overwriting one another, and maintain that separation, as a way of reducing the risk that you overwrite what is already in the global namespace.</p> <p>Note that the order in which you import scripts matters as well! There are also libraries such as RequireJS, CommonJS, just to name a few that try to deal with the dependency side of this whole modularity thing which can be worth exploring. So tread carefully and hope this helps!</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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