Yuki Chen


Hello everyone,

I found map.DeleteAllPushpins(); removes the flags and numbers on the route path, is there any way I can prevent it

Yuki



Re: map.GetRoute flags and numbers

SoulSolutions


Call it before you add your route

Someone else was looking at custom direction popups on this forum, I beleive they stored the data from the route request an put there own pins down, you could do something similar.

Or keep track of your other pins ID and just delete those

John.







Re: map.GetRoute flags and numbers

Yuki Chen

Thanks John ,

I call map.DeleteAllPushpins(); on the attach event onendzoom, as map.GetRoute zoom to the route, the pins on the route are deleted when map is zooming to the route. And I have a lot of other pins, I cant keeptrack of each of them and delete them one by one .. because it'll slow down a lot.

And I also found that with map.DeleteAllPushpins(); onendzoom, if the view needs to zoom to show the route .. then the turning points are removed .. but if the view is good to show route .. then the pins are looking good .. but when you do map.DeleteRoute();, the turning points are not removed .. ... I have copied some sample code below .. after the map is loaded with a broken route .. you can click on add route, and then remove route.. you will see what I mean ..


<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script>
<link rel="stylesheet" type="text/css" href="pins.css">
<script>
var map;

function MyOnload()
{
map = new VEMap('mymap');
map.LoadMap();
addRoute();
map.AttachEvent('onendzoom', myEventTester); //change to your event
}

function myEventTester(e)
{
map.DeleteAllPushpins();
}

function addRoute()
{
map.GetRoute("Space Needle", "Microsoft");
}

var pinID=1;
function AddPin()
{
var pin = new VEPushpin(pinID, map.GetCenter(),null, 'My pushpin', 'This is pushpin number '+pinID);
map.AddPushpin(pin);
pinID++;
}

function deleteRoute()
{
try
{
map.DeleteRoute();
}
catch (err)
{
alert(err.message);
}
}
</script>
</head>
<body onload="MyOnload()">
<div id='mymap' style="position:relative; width:600px; height:400px;"></div>
<a href="#" onclick="AddPin();">Add Pin</a> |
<a href="#" onclick="deleteRoute();">Remove Route</a> |
<a href="#" onclick="addRoute();">Add Route</a> |

</body>
</html>


Thank you very much
yuki





Re: map.GetRoute flags and numbers

Derek Chan

Yuki Chen wrote:
Thanks John ,

I call map.DeleteAllPushpins(); on the attach event onendzoom, as map.GetRoute zoom to the route, the pins on the route are deleted when map is zooming to the route. And I have a lot of other pins, I cant keeptrack of each of them and delete them one by one .. because it'll slow down a lot.

And I also found that with map.DeleteAllPushpins(); onendzoom, if the view needs to zoom to show the route .. then the turning points are removed .. but if the view is good to show route .. then the pins are looking good .. but when you do map.DeleteRoute();, the turning points are not removed .. ... I have copied some sample code below .. after the map is loaded with a broken route .. you can click on add route, and then remove route.. you will see what I mean ..


<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://dev.virtualearth.net/mapcontrol/v4/mapcontrol.js"></script>
<link rel="stylesheet" type="text/css" href="pins.css">
<script>
var map;

function MyOnload()
{
map = new VEMap('mymap');
map.LoadMap();
addRoute();
map.AttachEvent('onendzoom', myEventTester); //change to your event
}

function myEventTester(e)
{
map.DeleteAllPushpins();
}

function addRoute()
{
map.GetRoute("Space Needle", "Microsoft");
}

var pinID=1;
function AddPin()
{
var pin = new VEPushpin(pinID, map.GetCenter(),null, 'My pushpin', 'This is pushpin number '+pinID);
map.AddPushpin(pin);
pinID++;
}

function deleteRoute()
{
try
{
map.DeleteRoute();
}
catch (err)
{
alert(err.message);
}
}
</script>
</head>
<body onload="MyOnload()">
<div id='mymap' style="position:relative; width:600px; height:400px;"></div>
<a href="#" onclick="AddPin();">Add Pin</a> |
<a href="#" onclick="deleteRoute();">Remove Route</a> |
<a href="#" onclick="addRoute();">Add Route</a> |

</body>
</html>


Thank you very much
yuki


Okay, this post is quite confusing. Anyhow the reason why your map zooms to add the route, and everything is disappeared except for the route is because the onendzoom event was fired and then you deleted all your pushpins.

Deleteroute is doing what it is suppose to: Deleting the routesegments, thats all. It's not suppose to remove the pushpins/flags it placed on the map.






Re: map.GetRoute flags and numbers

Yuki Chen

Thanks Derek,

From my understanding .. deleteRoute() is suppose to delect the flags and numbers on the path . because if you remove the onendzoom event. it deletes everything on the route .

but with
the event , as you said all the flags are disappeared because the map zoomed and the function to delete all pins, now you DONT move the map, and click on add route, the flags would appear, and then you click on remove route.. the pins are not removed. and you will see what I'm talking about .

I know this is confusing, sorry for this...
yuki





Re: map.GetRoute flags and numbers

Derek Chan

 Yuki Chen wrote:
Thanks Derek,

From my understanding .. deleteRoute() is suppose to delect the flags and numbers on the path . because if you remove the onendzoom event. it deletes everything on the route .

but with
the event , as you said all the flags are disappeared because the map zoomed and the function to delete all pins, now  you DONT move the map, and click on add route,  the flags would appear, and then you click on remove route.. the pins are not removed. and you will see what I'm talking about .

I know this is confusing, sorry for this...
yuki



Okay, I see the problem and think I know why now:

Whenever you make a call to getroute, it automatically zooms.  Therefore, map.DeleteAllPushpins is being fired during a getroute is being called (important).  This causes the strange behaviour when you delete the route, because it probably assumed that the pins were deleted already.

If you want to prevent the zoom from actually happening, theres a thread on that issue somewhere on the forums or you would have to hack the API to disable the zooming.





Re: map.GetRoute flags and numbers

Yuki Chen

Thanks Derek,

heheh ... the thing is I need the auto zooming on the route .. and as well as DeleteAllPushpins onendzoom .. this is realy giving me lots of headache ..

do you know if there is anyway to find out the pinIDs on the route so I can manualy remove the pins.. I can't call DeleteAllPushpins here.. because I have many other pins on the map I don't want to remove..

or set getRoute not to show the pins by defualt .. so I can put my own pins down

wish my question didn't give you headache!
Thank you

Yuki




Re: map.GetRoute flags and numbers

Derek Chan

 Yuki Chen wrote:
Thanks Derek,

heheh ... the thing is I need the auto zooming on the route .. and as well as DeleteAllPushpins onendzoom .. this is realy giving me lots of headache ..

do you know if there is anyway to find out the pinIDs on the route so I can manualy remove the pins.. I can't call DeleteAllPushpins here.. because I have many other pins on the map I don't want to remove..

or set getRoute not to show the pins by defualt .. so I can put my own pins down

wish my question didn't give you headache!
Thank you

Yuki


There's no way to stop getRoute from showing the pins by default but see if you can do a deleteallpins() on the map onchangeview event handler and then add your own custom pins




Re: map.GetRoute flags and numbers

Yuki Chen

ok .. so there is no way for me to find out the element ID for the pins on the route

Yuki




Re: map.GetRoute flags and numbers

Derek Chan

Thats why we'd recommend storing the ID's somewhere after their stuck on the map