Maintain Aspect Ratio when editing a Rectangle

908 views
Skip to first unread message

gavin

unread,
Nov 15, 2011, 7:37:20 PM11/15/11
to google-map...@googlegroups.com
Any advice on how to maintain the aspect ratio when someone is editing an "editable" google.maps.Rectangle?
 
There's an example of an editable rectangle here:
(but without aspect ratio preserving)
 
Thanks in advance for any advice.
 
Cheers,
Gavin

Enoch Lau (Google Employee)

unread,
Nov 15, 2011, 9:20:11 PM11/15/11
to google-map...@googlegroups.com
That's currently not possible. Feel free to file a feature request, and note how you plan to use it. Is it preserving the aspect ratio on-screen, or preserving the lat-lng aspect ratio?

Enoch

gavin

unread,
Nov 16, 2011, 5:56:12 PM11/16/11
to google-map...@googlegroups.com
Hi Enoch,
 
Cheers for the reply.
 
The aspect ratio desired was for on-screen use. I plan to select an area of map for printing purposes (printing a custom topo map layer).
 
There's a beta version of the print functionality I've implemented at http://www.topomap.co.nz - I'm looking to replace my custom (and a little buggy at present) area selector with Google's more elegant editable rectangle.
 
I'll open a feature request as advised.
 
Cheers,
Gavin
Message has been deleted

Marcelo

unread,
Nov 16, 2011, 8:06:14 PM11/16/11
to Google Maps JavaScript API v3
On Nov 16, 3:56 pm, gavin <m...@gavinharriss.com> wrote:
>
> I'll open a feature request as advised.
>


It's quicker to do it yourself! :-)
http://maps.forum.nu/v3/gm_rectangle_preserve_aspect_ratio.html

The trouble is that the Rectangle object does not have a convenient
event to which to attach the resize function so, for this demo, I put
it on the mousemove event. This means that, after resizing the
rectangle, you need to move the mouse over it to restore the aspect
ratio.

--
Marcelo - http://maps.forum.nu
--

Previous post removed as it had the wrong URL.

gavin

unread,
Nov 16, 2011, 8:10:07 PM11/16/11
to Google Maps JavaScript API v3
Cheers Marcelo - thanks for the example - very much appreciated!

Some very handy exmaples you provide on your site Marcelo - I'm going
to have a deeper dig! ;)

On Nov 17, 2:06 pm, Marcelo <marcelo...@hotmail.com> wrote:
> On Nov 16, 3:56 pm, gavin <m...@gavinharriss.com> wrote:
>
>
>
> > I'll open a feature request as advised.
>
> It's quicker to do it yourself! :-)http://maps.forum.nu/v3/gm_rectangle_preserve_aspect_ratio.html
>
> The trouble is that the Rectangle object does not have a convenient
> event to which to attach the resize function so, for this demo, I put
> it on the mousemove event. This means that, after resizing the
> rectangle, you need to move the mouse over it to restore the aspect
> ratio.
>
> --
> Marcelo -http://maps.forum.nu

Enoch Lau (Google Employee)

unread,
Nov 16, 2011, 9:26:01 PM11/16/11
to google-map...@googlegroups.com
You could listen to bounds_changed.

Enoch

Marcelo

unread,
Nov 16, 2011, 9:54:38 PM11/16/11
to Google Maps JavaScript API v3
On Nov 16, 7:26 pm, "Enoch Lau (Google Employee)"
<enoch...@google.com> wrote:
> You could listen to bounds_changed.
>

Yes, that was my first thought, but that would create an endless loop,
so inside the listener function I'd have to remove the listener, do
the resize, and then attach the listener again, but that was too much
work for a simple demo. :-)
Events like 'resize' and 'resizeend', or 'drag' and 'dragend' might be
useful.

Enoch Lau (Google Employee)

unread,
Nov 17, 2011, 12:04:58 AM11/17/11
to google-map...@googlegroups.com
Yes. It might be simpler to write something like this:

var inBoundsChanged = false;

google.maps.event.addListener(rectangle, 'bounds_changed', function() {
  if (inBoundsChanged) return;

  inBoundsChanged = true;
  // change the rectangle's bounds.
  inBoundsChanged = false;
});

Tiby Ionescu

unread,
Nov 17, 2011, 3:25:02 AM11/17/11
to Google Maps JavaScript API v3
I haven't tested yet, but couldn't you use the map mousemove event,
something like:

var resizing = false;

// on marker dragstart
resizing = true

// on marker dragend
resizing = false

// on map mouse move
if (resizing) // calculate aspect ratio

I am using the map mousemove technique in my drawing application, and
it works very well. If you're using Chrome, chances are that it will
run very smoothly, also.

Probably you could do it with the marker drag event, but if you drag
in another direction, the cursor will not be on the marker anymore,
and I don't know what kind of creepy effects that would generate

On Nov 17, 7:04 am, "Enoch Lau (Google Employee)"

gavin

unread,
Nov 17, 2011, 2:22:26 PM11/17/11
to Google Maps JavaScript API v3
Cheers for the suggestions! I'm hoping to have a play next week.

Marvin

unread,
Feb 28, 2018, 5:35:02 PM2/28/18
to Google Maps JavaScript API v3
Hey,

any chance to get your code? I can't find any solution for keeping the aspect ratio...

Thanks.

Gavin Harriss

unread,
Feb 28, 2018, 6:33:05 PM2/28/18
to google-map...@googlegroups.com
Hi Marvin,

I never implemented a solution for maintaining aspect ratio in the end.

Best of luck,
Gavin

Gavin Harriss :: Web / Mobile / Software Developer
www.gavinharriss.com


--
You received this message because you are subscribed to a topic in the Google Groups "Google Maps JavaScript API v3" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-maps-js-api-v3/YaZq7fgdr3E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-maps-js-api-v3+unsub...@googlegroups.com.
To post to this group, send email to google-maps-js-api-v3@googlegroups.com.
Visit this group at https://groups.google.com/group/google-maps-js-api-v3.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages