MultiformeIngegno

  • Posts: 1,337
for(i=1;i<j;i++)
« 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 (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

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: for(i=1;i<j;i++)
« Reply #1, 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 () { ... }

MultiformeIngegno

  • Posts: 1,337
Re: for(i=1;i<j;i++)
« Reply #2, on May 5th, 2013, 06:09 PM »Last edited on May 5th, 2013, 06:35 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. :)

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: for(i=1;i<j;i++)
« Reply #3, 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?

MultiformeIngegno

  • Posts: 1,337
Re: for(i=1;i<j;i++)
« Reply #4, 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). :)

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: for(i=1;i<j;i++)
« Reply #5, 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.

MultiformeIngegno

  • Posts: 1,337

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: for(i=1;i<j;i++)
« Reply #7, 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... ;)
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Nao

  • Dadman with a boy
  • Posts: 16,079
Re: for(i=1;i<j;i++)
« Reply #8, on May 10th, 2013, 12:53 AM »
IE10 doesn't remove any markers, BTW ;)

Okay, bed time...

MultiformeIngegno

  • Posts: 1,337