Part Time Australian


I am working on a mapping project that allows the user to draw polylines. It all seems to work when the user clicks points of the polyline. From there I save the gps coords to a database. When I then retrieve the coordinates and display the polyline it does crazy things. It initially displays correctly but when zooming in, the line sometimes disappears, or draws in incorrect locations. If it does draw in incorrect locations and you pan, the polyline constantly moves.

Can anyone please help, this problem is starting to drive me crazy.

I have included "some" of my code.

function loadMap()

{

mapDiv = document.getElementById("myMap");

new VEMap('myMap');

map.LoadMap();

map.HideDashboard();

map.ShowDisambiguationDialog(false);

map.AttachEvent('onmouseup', mapMouseUp);

//Check to see if the path needs to be reconstructed

if(hdnPath.value != "")

reloadPath();

if((hdnPath.value != ""))

viewByBoundingLocations();

}

function reloadPath()

{

pts = new Array();

var vals = hdnPath.value.split(',');

for(i = 0; i < vals.length; i++)

{

pts.push(new VELatLong(valsIdea, vals[i+1]));

i++

}

drawPolyline();

}

function drawPolyline() {

map.DeleteAllPolylines();

if (pts.length > 1)

{

var poly = new VEPolyline(1,pts);

poly.SetWidth(2);

poly.SetColor(new VEColor(255,0,0,1));

map.AddPolyline(poly);

}

}




Re: Polyline Craziness

SoulSolutions


Ah you sure thats your code

you appear to kick off with:

mapDiv = document.getElementById("myMap");
new VEMap('myMap');
map.LoadMap();

While most of us would do this:

map = new VEMap('myMap');
map.LoadMap();

John.







Re: Polyline Craziness

Part Time Australian

Sorry, copy/paste error.

The actual code does read

map = new VEMap('myMap');

I am grabbing the mapDiv for other reasons.






Re: Polyline Craziness

Derek Chan

I'm curious about when reloadpath() method is called. Have you checked your co-ordinates to make sure their correct when your drawing the polyline (A simple alert and printing them out/verify would work).




Re: Polyline Craziness

Part Time Australian

The co-ordinates are fine. It will actually render the Polyline correctly and then zoom to best view. However, when you zoom in to a point that not all points on the polyline are contained within the view, the polyline starts acting crazy. At first I thought something might be happening onendzoom or onendcontinuouspan, however I don't perform any function on these events.

Also, the polyline will render correctly if you zoom back out to at least a best fit view.

The actual behavior makes me think that Virtual Earth is having trouble plotting any points that aren't contained within the current view. If you zoom in on a point on the polyline, it will always be in the correct place, however the line drawn to the next point outside the view will constantly be moving when zooming and panning.





Re: Polyline Craziness

Derek Chan

whats going in this function

viewByBoundingLocations();




Re: Polyline Craziness

Part Time Australian

function viewByBoundingLocations()

{

var latlongArray = new Array();

for(i=0; i < pts.length; i++) //pts is an array of the points on the polyline

{

latlongArray.push(ptsIdea);

}

for(j=0; j < pp.length; j++) //pp is an array of any pushpins on the map

{

latlongArray.push(new VELatLong(pp[j], pp[j+1]));

j++;

}

map.SetMapView(latlongArray);

}





Re: Polyline Craziness

Derek Chan

 Part Time Australian wrote:

function viewByBoundingLocations()

{

var latlongArray = new Array();

for(i=0; i < pts.length; i++)                     //pts is an array of the points on the polyline

{

latlongArray.push(pts);

}

for(j=0; j < pp.length; j++)                   //pp is an array of any pushpins on the map

{

latlongArray.push(new VELatLong(pp[j], pp[j+1]));

j++;

}

map.SetMapView(latlongArray);

}



ah ha, maybe this is the problem.  This function is probably being fired when you zoom/pan, so your zoomed in and then the setmapview is trying to fit all the points in your array into your zoomed in map probably causing some erradic behaviour.  It would also explain why its working when your in best view but crashes when you zoom in + pan.  Try to comment this function out and see if it behaves normally.  Also just to make sure what browser are you using






Re: Polyline Craziness

Part Time Australian

Tried commenting it out, problem is still there.

I am using IE 7, but have tried it on IE 6 and FF 1.x

I have included a picture of what I see at

http://dev.accent-inc.com/mapping/polyline.jpg

You can see on the third image that when you zoom in the polyline inverts itself and draws a strait line at the top of the window. very odd.

fyi, I have tried both v3 and v4 of Virtual Earth.





Re: Polyline Craziness

Derek Chan

yeah that is very bizarre.




Re: Polyline Craziness

SpeedOfSPin

Hi,

You haven't got your Map DIV inside a table cell have you by any chance I had this problem when I had mine in a <TH> cell. When I changed it to a <TD> cell or took it out of the table completely the polgons were fine. Maybe try it with just the map div on its own on a page.

cheers,

Erik





Re: Polyline Craziness

Part Time Australian

Found the problem.

It turns out that if you pass string values to the VELatLong constructor you will get this behavior.

To fix it, I used parseFloat() and passed those values to the VELatLong constructor.

Not to sure why the Polyline was working at higher zoom levels and not when you zoomed in though. You would think by passing string values it would break altogether.





Re: Polyline Craziness

AvinashTheLearner

Right now iam using --

if( typeof( window.innerWidth ) == 'number' ) //Non IE

Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }

instead of writing if condition specially for Firefox( Ref -- http://www.viavirtualearth.com/Wiki/Firefox2.ashx link).

It is working fine in Opera9.2, mozilla . Right now iam facing some problem related to flcikering of polyline in Firefox. In netscape at present polylines are not coming. Iam working on it - i will share it, if get any solution.

Meanwhile if anybody else any solution, then pls mai at avinash1981@hotmail.com.

Thanks,

Avinash





Re: Polyline Craziness

AvinashTheLearner

Polylines instead of Plylines .

sorry for spelling error.





Re: Polyline Craziness

Derek Chan

AvinashTheLearner wrote:

Right now iam using --

if( typeof( window.innerWidth ) == 'number' ) //Non IE

Msn.Drawing.Graphic.CreateGraphic=function(f,b) { return new Msn.Drawing.SVGGraphic(f,b) }

instead of writing if condition specially for Firefox( Ref -- http://www.viavirtualearth.com/Wiki/Firefox2.ashx link).

It is working fine in Opera9.2, mozilla . Right now iam facing some problem related to flcikering of polyline in Firefox. In netscape at present polylines are not coming. Iam working on it - i will share it, if get any solution.

Meanwhile if anybody else any solution, then pls mai at avinash1981@hotmail.com.

Thanks,

Avinash



Where are you getting this error Is this some kind of VE app you've developed Can you give us sample code to reproduce or give us a URL to test