Mike Priven


Hi All,

I'd like to be able to center the map (or pan) only when a location being added (as a pushpin) would be placed on the part of the map that's currently not visible in the map window.

My application is such that it reads locations from a file and places pushpins as it reads. The time between reading each location is variable (chosen by a slider control). For example, it can be 20x, adding pushpins every 50 milliseconds. I tried calling SetCenter every time AddShape is called, but it just can't keep up and locks up the map window. (calling AddShape by itself that often is not an issue). So, I only want to re-center when the route moves off screen, which shouldn't be often.

I looked at the events of V5, but couldn't find a suitable solution.

Appreciate any suggestions.

\Mike




Re: How to call SetCenter only when AddShape is placed off-screen?

SoulSolutions


For every function except the routing there is a way not pan the map, typically the sample code you use includes a code line to ensure the sample makes sence, Find() for example has a property "setBestMapView" set to false won't change the map.

The routing seems a little outdated and as Derek pointed out in his recent article on viavirtualearth it appears to still be old V4 code.

Hopefully we will see something better in the next release.

John.







Re: How to call SetCenter only when AddShape is placed off-screen?

Mike Priven

John, from what I could find, only Find() has that property, and that won't work for me here. What I really need is a function that will tell me whether a particular location is inside the visible portion of the map. Or alternatively an event that'll fire when AddPin or AddShape adds a location that will be placed outside of the visible portion of the map. The idea is to pan or setcenter only when needed.





Re: How to call SetCenter only when AddShape is placed off-screen?

Derek Chan

Mike,

What you can do is use the map.PixelToLatLong method combined with the map.GetTop/GetLeft methods to calculate the co-ordinate box that your current window is in by converting the map <div> pixel boundaries. Then you can check to see if the latlong of the pixel added is within that box and if not, then recenter the map.

map.PixelToLatLong

http://msdn2.microsoft.com/en-us/library/bb429564.aspx

map.GetTop

http://msdn2.microsoft.com/en-us/library/bb412550.aspx

map.GetLeft

http://msdn2.microsoft.com/en-us/library/bb412534.aspx


Hope that helps,






Re: How to call SetCenter only when AddShape is placed off-screen?

Mike Priven

Perfect, thanks Derek!

This got me on the right track, and after further looking into the API I found that GetMapView() returns the upper-left and lower-right coordinates of the map which made things even easier - no need to do any pixel-to-latlon conversion, just checking if the new location fits within the mapview rectangle works like a charm.

\Mike