Custom MapType with both custom tiles and standard Google tiles

80 views
Skip to first unread message

sdamb

unread,
Sep 23, 2011, 5:51:49 AM9/23/11
to google-map...@googlegroups.com
I'm developing a custom MapType but I've custom tiles only for a range of zoom levels.
But I need to provide all zoom level to the user, so I would show standard Google Maps tiles for some levels of zoom.

With API v.2 I solved this issue with a "getTile" function like this (overriding a GTileLayer object's method):

getTileUrl =  function(tile, zoom) {
                if (zoom < 10) {
                    return 'http://mytileserver/' + zoom + '/' + tile.x + '/' + tyle.y + '.png';
                } else {
                    return G_NORMAL_MAP.getTileLayers()[0].getTileUrl(tile, zoom);
                }
 };

How can I obtain same result with API V. 3 ?
I think this can be a common and very useful feature, so It's strange that cannot be implemented in V.3....

Nianwei Liu

unread,
Sep 24, 2011, 7:01:15 AM9/24/11
to Google Maps JavaScript API v3
Your chances are getTile(coord, zoom, ownerDoc) .

They are quite a few things are not well aligned between v2 & v3,
custom map type is one of them. In v3 maptype is simply a
specification/interface not a parent class the actual map types has to
inherit from, so there is no guarantee the standard map types will
follow same rule (method signature wise) as custom map types.

I have seem the getTile function exposed and un-obfuscated in the
standard map types, but it seems change during releases. If by any
chance you can see getTile function is exposed in standard map types
through firebug you can do something like:

MyMapType.prototype.getTile = function (coord, z, doc) {
if (z < 10){
var div = doc.createElement('img');
//do stuff to set background style or attach img node for tile url
} else {
// you need a reference to map first maybe in your constructor so
you have this.map_

var road = this.map_.mapTypes(google.maps.MapTypeId.ROADMAP);
return road.getTile(coord, z, doc);
}
}


The way accessing individual map types in map registry is tricky, and
can change from release to release, plus the availability of publicly
available getTile from standard map types are not reliable, you have
to work against a specific release to try out yourself.

good luck.

sdamb

unread,
Sep 28, 2011, 4:17:59 AM9/28/11
to Google Maps JavaScript API v3
Thank you for your analysis.

I tried, but at:

var road = this.map_.mapTypes(google.maps.MapTypeId.ROADMAP);

I get an error "this.map_ is undefined"
> >                     return 'http://mytileserver/'+zoom + '/' + tile.x +

Enoch Lau (Google Employee)

unread,
Sep 28, 2011, 5:25:53 AM9/28/11
to google-map...@googlegroups.com
It is now no longer possible to call getTile on the built-in Google map types.

Enoch
Reply all
Reply to author
Forward
0 new messages