[Google Maps API v3] fromContainerPixelToLatLng() and counterparts

2,165 views
Skip to first unread message

Pil

unread,
May 23, 2010, 12:08:53 PM5/23/10
to Google Maps JavaScript API v3
fromContainerPixelToLatLng()
fromDivPixelToLatLng()
fromLatLngToContainerPixel()
fromLatLngToDivPixel()


All these four methods are only accessible through
MapCanvasProjection. MapCanvasProjection is only accessible when an
overlay is used. So a redundant dummy overlay must be used to keep the
v3 API happy. At least these three things must be done to access one
of these methods finally:

1. Set a constructor function for a dummy object as followed

function Dummy(map) {
this.setMap(map);
}

2. Extend the dummy object by using OverlayView()

Dummy.prototype = new google.maps.OverlayView();

To avoid a script error an empty draw method should be added

Dummy.prototype.draw = function() {};

3, Initialize the dummy object early and in global scope so that it's
ready when needed.


In v2 there was (and still is) only one line necessary for this
procedure.

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

Chad Killingsworth

unread,
May 23, 2010, 4:15:01 PM5/23/10
to Google Maps JavaScript API v3
Your summary appears to be correct. Projections are not directly
available - at least partially due to the asynchronous nature of the
v3 API. Projections are only available after the map has initialized.

Did you have an actual question?

Chad Killingsworth

Ben Appleton

unread,
May 23, 2010, 9:26:54 PM5/23/10
to google-map...@googlegroups.com

Why do you need these methods, if not to overlay something on the map?

We do not arbitrarily make things difficult for developers.  This design allows us to delay-load the code for all projections, which speeds up every site that does not need these methods.

Pil

unread,
May 24, 2010, 1:53:03 AM5/24/10
to Google Maps JavaScript API v3


On May 24, 3:26 am, Ben Appleton <apple...@google.com> wrote:
> Why do you need these methods, if not to overlay something on the map?


Hmm, yes, but it could be that one of these methods is needed for
simple markers, polylines etc. or something like this

http://gmaps-samples-v3.googlecode.com/svn/trunk/latlng-to-coord-control/latlng-to-coord-control.html


And regarding the speed: I think you ignore the clients script code
(also a great speed factor), as I mentioned here

http://groups.google.com/group/google-maps-api/msg/000026a40d477776

Ben Appleton

unread,
May 25, 2010, 9:29:21 PM5/25/10
to google-map...@googlegroups.com
On Mon, May 24, 2010 at 3:53 PM, Pil <wol...@gmail.com> wrote:


On May 24, 3:26 am, Ben Appleton <apple...@google.com> wrote:
> Why do you need these methods, if not to overlay something on the map?


Hmm, yes, but it could be that one of these methods is needed for
simple markers, polylines etc. or something like this

http://gmaps-samples-v3.googlecode.com/svn/trunk/latlng-to-coord-control/latlng-to-coord-control.html

Why don't you just listen to Map event "mousemove"?  That returns the LatLng, which seems simpler than adding a dummy OverlayView only to access the projection.

And regarding the speed: I think you ignore the clients script code
(also a great speed factor), as I mentioned here

http://groups.google.com/group/google-maps-api/msg/000026a40d477776

We take performance very seriously, not just the time to load a map.  Your post does not claim poor performance though, it claims that markers are hard to use.  Can you suggest improvements to the marker tutorial?
 
Thanks
Ben

Pil

unread,
May 26, 2010, 1:53:58 AM5/26/10
to Google Maps JavaScript API v3

On May 26, 3:29 am, Ben Appleton <apple...@google.com> wrote:

>
> Why don't you just listen to Map event "mousemove"?  That returns the
> LatLng, which seems simpler than adding a dummy OverlayView only to access
> the projection.

I just want a static screen overlay (in v2 GScreenOverlay) that
doesn't move with the map or the mouse. To position the overlay
exactly within the map container a dummy overlay is needed. Seems you
haven't taken this into account.

Besides: Positioning of such a static overlay is very buggy - if not
unusable. I'll post a bug report and a demonstrator page later.


> We take performance very seriously, not just the time to load a map.  

Concerning performance: I've mentioned stuttering dragging of the map
earlier

http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/1f1b191ad0282b87#

Ben Appleton

unread,
May 26, 2010, 3:36:55 AM5/26/10
to google-map...@googlegroups.com
On Wed, May 26, 2010 at 3:53 PM, Pil <wol...@gmail.com> wrote:


On May 26, 3:29 am, Ben Appleton <apple...@google.com> wrote:

>
> Why don't you just listen to Map event "mousemove"?  That returns the
> LatLng, which seems simpler than adding a dummy OverlayView only to access
> the projection.

I just want a static screen overlay (in v2 GScreenOverlay) that
doesn't move with the map or the mouse. To position the overlay
exactly within the map container a dummy overlay is needed. Seems you
haven't taken this into account.

What you describe requires a custom control which can display text, not a GScreenOverlay which can only display an image.  Start with this example.

Besides: Positioning of such a static overlay is very buggy - if not
unusable. I'll post a bug report and a demonstrator page later.


> We take performance very seriously, not just the time to load a map.  

Concerning performance: I've mentioned stuttering dragging of the map
earlier

http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/1f1b191ad0282b87#

Yes, we've seen that page.  It works fine on my phone.  I haven't been able to reproduce the stuttering on a desktop browser, but my desktop is fast.  We're looking into it.

Pil

unread,
May 26, 2010, 4:10:11 AM5/26/10
to Google Maps JavaScript API v3

On May 26, 9:36 am, Ben Appleton <apple...@google.com> wrote:


> Start with this
> example<http://www.google.com/url?sa=D&q=http://code.google.com/apis/maps/documentation/javascript/examples/control-custom.html&usg=AFQjCNGfLl2g3bwispGh7F_BFnDCoBPFWg>

Thanks I've seen that. I want that the overlay should be positioned at
the center of the map or - for example - just underneath the map type
buttons.

This seems not possible with the restrichted possibilities of
ControlPosition.
Unfortunately it's not possible to turn off the "intelligent flowing".

Pil

unread,
May 26, 2010, 12:55:10 PM5/26/10
to Google Maps JavaScript API v3
Absolute positioning of controls doesn't seem to work generally in v3.
With absolute positioning I mean positioning independent of pre-
defined constants of ControlPosition.

In v2 GSize class was included in GControlPosition. That made it
possible to position everything absolute (independant of pre-defined
anchors of GControlPosition).

As it seems now, absolute positioning in v3 is only possible without
interference of a drag or zoom event when the constant BOTTOM_RIGHT is
used.

If that behaviour was not intended it can be called a bug.
If it was intended it's a unnecessary restriction.

To see what I mean I posted a report with a link to a demonstrator

http://code.google.com/p/gmaps-api-issues/issues/detail?id=2420&sort=-id&colspec=ID%20Type%20Status%20Introduced%20Fixed%20Summary%20Stars%20ApiType%20Internal

Ben Appleton

unread,
May 26, 2010, 6:31:23 PM5/26/10
to google-map...@googlegroups.com

If you need to absolutely position an element, I suggest .appendChild() the element inside the map div and set css position: absolute.


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScri...

Pil

unread,
May 27, 2010, 3:23:59 AM5/27/10
to Google Maps JavaScript API v3

On May 27, 12:31 am, Ben Appleton <apple...@google.com> wrote:
> If you need to absolutely position an element, I suggest .appendChild() the
> element inside the map div and set css position: absolute.

Yes, thanks. This would be possible in many cases but not generally.
For example not in this case:

If you look at the tiny icon that snaps to the polyline after creating
a route

http://www.marsrutai.info/directions


Ben Appleton

unread,
May 27, 2010, 3:35:55 AM5/27/10
to google-map...@googlegroups.com

I would call that tiny icon an OverlayView, no?

>
> --

Björn Brala

unread,
May 27, 2010, 3:37:25 AM5/27/10
to google-map...@googlegroups.com
The icon would be a marker indeed, in mt opinion also :X

2010/5/27 Ben Appleton <appl...@google.com>



--
Bjorn Brala
----------------
www.GeoStart.nl/english/ - Google maps - Swis Webdesign
www.twitter.com/bbrala

Pil

unread,
May 27, 2010, 5:22:58 AM5/27/10
to Google Maps JavaScript API v3
Regardless what it is. It cannot be positioned absolute and it can
also not be positioned using the "intelligent flowing" of
ControlPosition. A similar problem seems to appear here

http://www.wolfpil.de/map-in-a-box.html

The problem would be the icon at the bottom right.
Either I quit the whole maps stuff or a crude hack will be the result.

The possibilities of positioning a control in v3 are completely
inflexible compared to v2.

Ben Appleton

unread,
May 27, 2010, 6:06:24 AM5/27/10
to google-map...@googlegroups.com
On Thu, May 27, 2010 at 7:22 PM, Pil <wol...@gmail.com> wrote:
>
> Regardless what it is. It cannot be positioned absolute and it can
> also not be positioned using the "intelligent flowing" of
> ControlPosition.

It's simply not a control.  v3 controls do not support the display of
non-controls.

> A similar problem seems to appear here
>
> http://www.wolfpil.de/map-in-a-box.html
>
> The problem would be the icon at the bottom right.
> Either I quit the whole maps stuff or a crude hack will be the result.

Line 170 looks like a "crude hack" to me:

/* Move the 'Terms of Use' 25px to the left
* to make sure that it's fully readable
*/
var terms = container.childNodes[2];
terms.style.marginRight = "25px";

> The possibilities of positioning a control in v3 are completely
> inflexible compared to v2.

v2 only allowed to insert absolutely positioned divs. You can just do
that in the DOM if you like. v3 adds the possibility of flow control,
so your controls play nice with each other and with default controls.

Reply all
Reply to author
Forward
0 new messages