mmarcon / jhere

jHERE - Maps made easy
MIT License
255 stars 51 forks source link

center by route #20

Closed axeff closed 10 years ago

axeff commented 10 years ago

Hi,

is it possible to center a calculated route within it's bounding box?

mmarcon commented 10 years ago

I tried to do it quickly for you. Unfortunately I have an annoying race condition that I need to fix before releasing the feature.

However, if you initialize the map first, and later on after perhaps the user has done some actions this race condition probably does not matter for you. In this case you can get route.js directly from the feature branch zoomToRoute, commit sha is 93b8529b8462bc7885ee3ecd9c8824fb5f8c017f.

axeff commented 10 years ago

ha. did basicly the same stuff and send you a pull-request. https://github.com/mmarcon/jhere/pull/21

how could you produce the race condition?

mmarcon commented 10 years ago

If you look at my route example: https://github.com/mmarcon/jhere/blob/master/src/examples/example.route.html

I initialize the map and then I chain immediately the call to the route function. If you set the map to be, for instance, at zoom level 1 at the beginning, then you'd expect to zoom to the route bounding box. Often that does not happen.

It seems that for some reason the route callback is invoked before the map is fully initialized so the zoom set in the initialization is applied after the one from the route bounding box.

axeff commented 10 years ago

I tried to reproduce the exact same thing but in my case it always zoomed to the route like expected.

mmarcon commented 10 years ago

Ok, seems to work, so I merged. Maybe today my other computer was just acting funny. It could also be the network at work that perhaps slows down the map load therefore creating the race condition. I will probably have another look at this, closed for now.