Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: threads Bing
Hi,
 
I would like to understand how would it be possible to use threads with bing maps.
The task at hand is that of making a polygon (shape) blink and at the same time keep the browser responding for the user to navigate through the map.
 
At my attempt to make the polygon blink (using client side code [now I know that javascript is single threaded but I still can't figure out a solution]), I ended up freezing the whole browser.
 
Thanks for any help guys,
J
Posted 22-Jan-13 12:18pm
Jukatzu297

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

For a proper answer, you'd have to post what code you're using already. However, in general, you can avoid freezing the UI by using setTimeout, which you can read about here: http://ejohn.org/blog/how-javascript-timers-work/.
 
Basically, do a small bit of work, then call setTimeout so the UI can take control for a few milliseconds before you resume doing more work. Repeat that and you can simulate multiple threads.
 
EDIT: Here's an example (a number will increment every 30 milliseconds using a timeout rather than a loop):
<html>
<head>
  <title>Timer</title>
</head>
<body>
  <div id="info">0</div>
  <script type="text/javascript">
    // Do not pollute the global scope.
    (function() {
      var val = 0;
      var fnRepeat;
      fnRepeat = function() {
        val = val + 1;
        var infoElement = document.getElementById("info");
        infoElement.removeChild(infoElement.childNodes[0]);
        infoElement.appendChild(document.createTextNode(val.toString()));
        setTimeout(fnRepeat, 30);
      };
      fnRepeat();
    })();
  </script>
</body>
</html>
 
The same concept can be applied for any operation you would typically perform in a loop.
  Permalink  
v2
Comments
Jukatzu at 22-Jan-13 17:56pm
   
Thanks for the quick reply Sir.
 
I do not wish to include any code since this is a personal project. However, for you to understand me better, let me give an identical scenario. Let's say I want to make a circle move continuously on the map along the x-axis. At the same time I want to be able to travel around the world with my cursor and zoom, pan...whatever. If I put in a while loop for the circle to keep moving left, how would I be able to re-gain control over the map at the same time? I have seen the link you gave me, but that speaks of one process waiting for the other, whereas in my case I do not wish to wait. One process has to run infinitely whilst the other allows user control in real-time. Hopes this explains better.
 
Thanks again for your time!
AspDotNetDev at 22-Jan-13 18:18pm
   
I updated my answer to show you an example.
Jukatzu at 22-Jan-13 18:23pm
   
Thank you! I will apply it to my case and see what happens. I can see what you mean better now. Will get back to you soon.
 
Much obliged.
Jukatzu at 23-Jan-13 18:36pm
   
Worked exactly as intended.
Should have thought of using the function recursively stupid me.
However I am very grateful for your help.
AspDotNetDev at 23-Jan-13 19:12pm
   
I'm glad to hear it worked for you :-)
Jukatzu at 25-Jan-13 8:56am
   
Sir, is it normal that the setTimeout function deteriorates after some time? In the sense that at first the map is very responsive, and the more time goes by with the setTimeout running, the less responsive the map becomes until you are not able to move it. The code in the setTimeout function continues smoothly though. I was expecting the performance to be the same throughtout and not deteriorate exponentially by time. Am I missing something?
AspDotNetDev at 25-Jan-13 12:14pm
   
I have no idea. Post a new question about your issue and make sure to include some sample code. Make sure to include only the relevant code so your sample is as small as possible.
Jukatzu at 25-Jan-13 17:33pm
   
Solved it myself. Was re-creating a circle from another function every timeout so the browser was not capable of finishing before the next run; setting it back by a bit each time ;) Thanks sir
AspDotNetDev at 25-Jan-13 18:43pm
   
Awesome :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100