views:

31

answers:

2

My map has several hundred markers within a city. Usually no more than a 20 mile radius. I've read through the documentation and haven't found a way to set the init to automatically pan between every marker, no matter the distance. The default behavior is to pan if close, jump if far. I understand why they would do this since the map doesn't load the whole world at the selected zoom level and it could screw up if the distance was too great. However, I think it could handle 20 mile radius with minimal complaints.

If anyone has any ideas, I'd love to hear them. Thanks

+1  A: 

The threshold of the smooth panning does not depend on the distance between the current center and the new target. It depends on whether the change will require a full page scroll (horizontally and vertically) or not:

Quoting from the API Reference:

panTo(latLng:LatLng)

Changes the center of the map to the given LatLng. If the change is less than both the width and height of the map, the transition will be smoothly animated.

Therefore, as long as you are zoomed out such that your viewport is 20 miles in height and width, you should be guaranteed smooth panning for distances under 20 miles.

Daniel Vassallo
never the less, is there a way to overwrite this?
Kai Qing
@Kai: I don't think there is by using the API. You could implement the animation yourself, but that might not be worth the effort (it depends on how important is this feature).
Daniel Vassallo
I argue that this functionality is not important, but the client seems to think so. Since the navigation is also listed in an accordion menu to the side, the user can make the map jump all over by running down the list, and while doing so they may lose track of where the marker is in relation to familiar areas.
Kai Qing
@Kai: What if when the user clicks on an item from the accordian menu, the map zooms out a bit, pans to the new location, and zooms back in. If you zoom out just enough for both the start and destination to appear on the same viewport, you'd get smooth panning.
Daniel Vassallo
That may be an option. If it could zoom out, pan then zoom in. I'll see if I can do that.
Kai Qing
A: 

As Daniel has mentioned, the built-in panTo() function will not work for you if the two points are too far apart. You can manually animate it yourself if that's the case though: for each zoom level, figure out the distance covered by say 100 pixels. Now, when you have to pan to a point, you can use this information to figure out if the panTo() funciton will animate or jump. If the distance moved is so big that it will not animate, you should do the animation manually - compute some intermediate waypoints between your current map center and your destination, and pan to them in sequence.

levik
that's true but I was not looking to hack the system. I could calculate distance between points and set invisible markers at reasonable increments, then pan to each until the destination is met. However, that sounds like it is too much for the scope of my project, so I will not do this... If I had a fwe extra days to play with it then maybe. Thanks
Kai Qing