Wedge

Public area => The Pub => Off-topic => Topic started by: MultiformeIngegno on May 5th, 2013, 03:36 PM

Title: for(i=1;i<j;i++)
Post by: MultiformeIngegno on May 5th, 2013, 03:36 PM
What does this mean?

Code: [Select]
var i, j=mkArray.length-1;
// Keeping the first and last one
for(i=1;i<j;i++) {
  mk=mkArray[i];
  mk.setMap(null);

I have a map with 3 markers set at loadtime. Then I have a function to calculate a route (so in the map 2 new markers are set, with a total of 5). I'm trying to remove the first 3 markers to leave just the route markers when route is calculated. I first pushed markers in an array with mkArray.push(marker);. Then the code above should remove the 3 initial markers.

The code does something, you can see it here(http://ffio.it/test2.html) (to test you can enter "Ostia" in input box). As you can see  it removes the first marker when route is calculated. It's a starting point but I need to remove all markers except the 2 related to the route. :D
Title: Re: for(i=1;i<j;i++)
Post by: Nao on May 5th, 2013, 04:38 PM
It iterates through the array called mkArray, all items except for the first (1 to length-1).

I'll have a look at your code.
Posted: May 5th, 2013, 04:27 PM

Okay, so I had a look at your code... Didn't get it at first, ah ah.

Code: [Select]
for (var i = 1, j = mkArray.length - 2; i < j; i++)
  mkArray[i].setMap(null);

This should work, as I tested it in the console... If it doesn't, it means your code can't execute while loading, so you'll have to load it inside an onload event, or something.
e.g., document.body.onload = function () { ... }
Title: Re: for(i=1;i<j;i++)
Post by: MultiformeIngegno on May 5th, 2013, 06:09 PM
Uhm. I tried your code but no marker is removed.. :(

Original code: http://ffio.it/test2.html
Your code: http://ffio.it/test_nao.html

If you calc the route (typing for example "Ostia") with the first example you can see it removes (only) the first marker. Yours keeps all markers.. :(

EDIT: SInce the first example (at least) removes one marker this should mean it could execute the function while loading. :)
Title: Re: for(i=1;i<j;i++)
Post by: Nao on May 6th, 2013, 04:09 PM
Replace with length-1 instead of length-2 actually, because that's the only way it's going to do at least one pass.
What you're looking for, is code that removes ONE marker, right..? The one on the bottom left?
Title: Re: for(i=1;i<j;i++)
Post by: MultiformeIngegno on May 6th, 2013, 04:23 PM
I'm looking for code that removes all markers except the 2 that get created when route is calculated (start and end points). :)
Title: Re: for(i=1;i<j;i++)
Post by: Nao on May 6th, 2013, 04:51 PM
Well, then the one I gave you should work, as long as you replace the '2' with a '1'.

If it won't work, then it's a loading issue, really.
Title: Re: for(i=1;i<j;i++)
Post by: MultiformeIngegno on May 6th, 2013, 07:07 PM
I made some trials and this worked :P

Code: [Select]
for (var i = 0, j = mkArray.length - 0; i < j; i++)
  mkArray[i].setMap(null);
http://ffio.it/test_nao.html
Title: Re: for(i=1;i<j;i++)
Post by: Arantor on May 6th, 2013, 07:14 PM
So:
Code: [Select]
for (var i = 0, j = mkArray.length; i < j; i++)
  mkArray[i].setMap(null);

then... ;)
Title: Re: for(i=1;i<j;i++)
Post by: Nao on May 10th, 2013, 12:53 AM
IE10 doesn't remove any markers, BTW ;)

Okay, bed time...
Title: Re: for(i=1;i<j;i++)
Post by: MultiformeIngegno on May 10th, 2013, 01:30 AM
Quote from Nao on May 10th, 2013, 12:53 AM
IE10 doesn't remove any markers, BTW ;)
True! WTF? :o