[route-me] Prevent Map Dragging beyond Bounds

79 views
Skip to first unread message

wuf810

unread,
May 15, 2010, 8:00:44 PM5/15/10
to route-me
Again search through the archives and cannot find a definitive answer.

So the question, can I either :

1) specify a map bounds that prevents the user dragging a map beyond
these bounds OR

2) in beforeMapMove test whether map is dragged beyond bound and then
somehow stop the user dragging?

Really appreciate a response…even if the answer is no!

Thanks, Michael.

--
You received this message because you are subscribed to the Google Groups "route-me" group.
To post to this group, send email to route-...@googlegroups.com.
To unsubscribe from this group, send email to route-me-map...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/route-me-map?hl=en.

Anna Hentzel

unread,
May 15, 2010, 8:14:23 PM5/15/10
to route-...@googlegroups.com
I got this working in a somewhat hacky way and posted my RMMapContents here, you can read my post from then and check out the files - http://groups.google.com/group/route-me-map/browse_thread/thread/4f07179530ae3f94#

It checks the tile source bounds when you move the map, zoom to bounds, or jump to a point, and cancels the action if the center of the map will not be in the tile source bounds.

We've been using it for awhile now,  and it's been working well.

-Anna
--
Anna Hentzel
GaiaGPS.com
415-335-7447

wuf810

unread,
May 15, 2010, 8:47:06 PM5/15/10
to route-me
Anna,

Thank you so much, I check out your versions. Also I really appreciate
the quick reply…I was pulling my hair out following numerous dead end
threads!

Thanks again, Michael.

On May 16, 1:14 am, Anna Hentzel <wi...@gmail.com> wrote:
> I got this working in a somewhat hacky way and posted my RMMapContents here,
> you can read my post from then and check out the files -http://groups.google.com/group/route-me-map/browse_thread/thread/4f07...
>
> It checks the tile source bounds when you move the map, zoom to bounds, or
> jump to a point, and cancels the action if the center of the map will not be
> in the tile source bounds.
>
> We've been using it for awhile now,  and it's been working well.
>
> -Anna
>
>
>
>
>
> On Sat, May 15, 2010 at 5:00 PM, wuf810 <michaelk...@mac.com> wrote:
> > Again search through the archives and cannot find a definitive answer.
>
> > So the question, can I either :
>
> > 1) specify a map bounds that prevents the user dragging a map beyond
> > these bounds OR
>
> > 2) in beforeMapMove test whether map is dragged beyond bound and then
> > somehow stop the user dragging?
>
> > Really appreciate a response…even if the answer is no!
>
> > Thanks, Michael.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "route-me" group.
> > To post to this group, send email to route-...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > route-me-map...@googlegroups.com<route-me-map%2Bunsubscribe@google groups.com>
> > .

wuf810

unread,
May 17, 2010, 8:50:16 AM5/17/10
to route-me
Hi Anna,

I've implemented your code and all working really well.

I do have one issue in that the when the map is zoomed I seem to lose
more and more longitudinal dragging. It's as if the bounds are being
reduced somewhat and I sideways dragging stops well before the "edge"
of the map.

I noted in the other thread you spoke about irregular shaped maps. The
actual mapView I am using is rectangular. Could this be the cause of
the issue?

Any thoughts gratefully received

Thanks, Michael.

On May 16, 1:14 am, Anna Hentzel <wi...@gmail.com> wrote:
> I got this working in a somewhat hacky way and posted my RMMapContents here,
> you can read my post from then and check out the files -http://groups.google.com/group/route-me-map/browse_thread/thread/4f07...
>
> It checks the tile source bounds when you move the map, zoom to bounds, or
> jump to a point, and cancels the action if the center of the map will not be
> in the tile source bounds.
>
> We've been using it for awhile now,  and it's been working well.
>
> -Anna
>
>
>
>
>
> On Sat, May 15, 2010 at 5:00 PM, wuf810 <michaelk...@mac.com> wrote:
> > Again search through the archives and cannot find a definitive answer.
>
> > So the question, can I either :
>
> > 1) specify a map bounds that prevents the user dragging a map beyond
> > these bounds OR
>
> > 2) in beforeMapMove test whether map is dragged beyond bound and then
> > somehow stop the user dragging?
>
> > Really appreciate a response…even if the answer is no!
>
> > Thanks, Michael.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "route-me" group.
> > To post to this group, send email to route-...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > route-me-map...@googlegroups.com<route-me-map%2Bunsubscribe@google groups.com>
> > .

Anna Hentzel

unread,
May 17, 2010, 5:26:49 PM5/17/10
to route-...@googlegroups.com
What you might be seeing is that my constraint requires that the center of the map be within bounds, so if you center right on your bounds you can zoom all the way out and see way around the bounds, and just in general you'll be able to pan a little farther out at lower zooms. This works for how we're using it, since we wanted to be able to show the larger map and draw a line around the bounds of the area they can zoom in on for context.

It's also possible that the way I'm setting the bounds constraint is kind of messed up. I'm just setting the easting and northing bounds based on the projection when you set the tile source. I'll check it out if you don't think it's the centering thing.

-Anna

wuf810

unread,
May 17, 2010, 9:54:54 PM5/17/10
to route-me
Anna,

Thanks again for the reply.

Yes it sounds like in might be the centering constraint to me
(although I'm not sure why it is only affecting the longitudinal
axis?)

If this does sound like the centering restraint, any tips where I
should look to remove the constraint?

If not, I would be massively grateful if you could have a quick look
at your bounding code just in case something is not quite right.

Thanks & Regards, Michael.

Anna Hentzel

unread,
May 17, 2010, 10:03:40 PM5/17/10
to route-...@googlegroups.com
So if you want the constraint to keep the entire screen within bounds,
what you could do it look at everywhere I call the -
tileSourceBoundsContainProjectedPoint: function in RMMapContents, and
instead of calling it for the center of the source, compute the
corners of the map and call it for two of the opposite corners.

I'm not sure why it would only affect the longitudinal access, except
that maybe the shape of your region makes the longitude constraint
much more obvious.

-Anna

wuf810

unread,
May 18, 2010, 2:57:39 PM5/18/10
to route-me
Anna,

I'm really sorry but I'm just not getting it. Think half the problem
is my poor understanding of map projections.

So to confirm once again, I have a map that has a limit to its bounds
(imagine a map of a city).

What I need to do is to stop dragging beyond the bounds in all
directions.

You mentioned:

> tileSourceBoundsContainProjectedPoint: function in RMMapContents, and
> instead of calling it for the center of the source, compute the
> corners of the map and call it for two of the opposite corners.

In RMContents.m I find 5 references. One is the method and the other
call the method. The only one I see that is being called is :

- (void)moveBy: (CGSize) delta

In this method you do the following (I assume to get the centre):

RMProjectedPoint projCenter = [mercatorToScreenProjection
projectedCenter];
RMProjectedSize XYDelta = [mercatorToScreenProjection
projectScreenSizeToXY:delta];
projCenter.easting = projCenter.easting - XYDelta.width;
projCenter.northing = projCenter.northing - XYDelta.height;


So what Projected point do I need to define and pass to
tileSourceBoundsContainProjectedPoint? If I just pass in NE then how
do I determine I am dragging the opposite way? And what about up and
down?

Sorry if I sound like I have no idea what I'm doing, but I'm beginning
to think I don't!
> > For more options, visit this group athttp://groups.google.com/group/route-me-map?hl=en.

Anna Hentzel

unread,
May 18, 2010, 3:46:05 PM5/18/10
to route-...@googlegroups.com
Comment inline --
Sounds like you've almost got it. You'd have to call it twice, pass in
the NE and the SW and don't do the drag if either of them is False.

wuf810

unread,
May 19, 2010, 2:23:36 PM5/19/10
to route-me
Hi Anna,

Well I've spent the last 24 hours on this and going no where fast.

The problem I currently face is it that when my NE point is out of
bounds I return from the moveBy method so the map stops moving.
However I am already at that point and any further dragging just means
the point remains out of bounds (as the moveBy method will never allow
the drag).

I'm not really getting the logic of how once I hit the out of bounds,
I can then allow the user to drag back the other way.

You don't fancy a bit of paid consultancy via skype do you? Can't see
any other way I can get this going unless I have a eureka moment of
some sort :-)

Thanks, Michael.

Mo

unread,
Jun 10, 2010, 6:16:19 AM6/10/10
to route-me
Hi Anna and hi together,

for wich version is your implementation? I'd tried to use it, but i
receive so many errors.
Or is there something similar in the current version, what i can use,
to prevent that the user move out of bounds?

Moritz K.
> ...
>
> Erfahren Sie mehr »
Reply all
Reply to author
Forward
0 new messages