Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8661035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:23:57+00:00 2026-06-12T16:23:57+00:00

I am using a mapping app called Leaflet. Some of the code I use

  • 0

I am using a mapping app called Leaflet. Some of the code I use is below:

var layer1 =L.tileLayer('http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/7540/256/{z}/{x}/{y}.png', {
    attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
    maxZoom: 12

}).addTo(map);

// THE ABOVE CODE MERELY PLACES A BASE LAYER INSIDE A DIV TAG. But the key to this is the //addTo method.

I also am getting weather radar data from Aeris and create a layer on leaflet using this:

var radar_img_arr = createVariables();

and the createVariables() looks like this:

function createVariables(){
  var radar_images = [];

  for (var i = 0; i <= 99; ++i) {
      radar_images[i] = L.tileLayer('http://tile2.aerisapi.com/QjvmoFnKc1Wj94aDULEX_8Y7R8eagwQKlUusR5WZk6JTBdz6zlCm3KIP15CLG/radar/{z}/{x}/{y}/'+data.files[i].time +'.png', {opacity: 0.6, format: 'image/png',   maxZoom: 12,attribution: "FOSM"}).addTo(map).setZIndex(999);
  }

  return radar_images;
}

The above adds to the map all data to the map at once just to test.

What I really want is a loop which can remove a old layer from the map and replace it with a new layer.

The 2 important methods are below:
map.removeLayer(radar_img_arr[i]);
map.addLayer(radar_img_arr[i+1]);

I am trying to write a loop to do this and the timing is messed up. other weather sites use Flex or Flash to animate a radar loop but i want to try a Javascript solution.

Does anyone know how to create this loop in JS or jQuery?

Thanks,
Jim

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:23:58+00:00Added an answer on June 12, 2026 at 4:23 pm

    You should use set timeout to iterate over the loop… Something like:

    // function for setTimeout
    var updateImage = function() {
    
      //gets the current image & update place
      var img = radar_img_arr[place++] 
    
      // code to update display here.
      ...
    
      // call the function again in 1 second 
      setTimeout(updateImage, 1000)
    
      // reset place to 0 if need be
      if (step == radar_img_arr.length-1) 
        place = 0;
    
    }
    
    // variable to store where we are in the array.
    var place = 0
    
    // array of images
    var radar_img_arr = createVariables()
    
    //start the process in 1 second:
    setTimeout(updateImage, 1000)
    
    // or, start it right away:
    updateImage()
    

    I don’t like to use setInterval, which will automatically call your function over and over however many miliseconds you pass. Reason is, if your function takes longer to run than timer takes, you create a race condition, which in your case would cause the images to update strangely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm current drawing some tile (small square images) for a mapping app. I'm using
I am new to nHibernate. I understand how to use mapping using Fluent nHibernate.
I'm learning Fluent NHibernate (and by extension, NHibernate generally). I'm using auto-mapping with some
I'm using Pyamf as my backend for my Flex app and I'm seeing some
I'm new to Spring MVC framework, having some trouble with basic URL mapping using
I'm using xml-mapping within my ruby on rails app. I need to load xml
I'm using nhibernate to store some user settings for an app in a SQL
I'm developing a mapping app using Eclipse 3.5. I'm setting the minimum update period
I have some huge binary files which I'm currently reading using memory mapping on
Background: I've got a single-page knockout.js app using the mapping plugin. The data is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.