How to use google closure library extend google.maps.Map class ?

153 views
Skip to first unread message

xzhang

unread,
Jul 12, 2011, 6:05:37 PM7/12/11
to Google Maps JavaScript API v3
Hello:
I am trying to use closure-library inherits google.maps.Map class to
make my own subclass. But seems google.maps.Map doesn't have a
constructor.
Here is what I do:

goog.provide('MyMap');

MyMap = function(mapDiv, opts){
goog.base(this, mapDiv, opts);
}
goog.inherits(MyMap, google.maps.Map);
var myMap = new MyMap(div, opts);

But this doesn't give me right result, myMap have the right inherits
prototype but doesn't have any field and constructor.
I try to step into goog.base and goog.inherits to see what it does,
it seems google.maps.Map doesn't have a constructor, so when goog.base
try to call superClass_.constructor, it got noting.

So is there any way I can inherits from google.maps.Map ? or this is
not the right way to use google map api ? Or I should post this
question to closure library ?

Thanks for read my question
xzhang

xzhang

unread,
Jul 12, 2011, 6:55:12 PM7/12/11
to Google Maps JavaScript API v3
Forget to attach the example page:
http://www.howlworld.com/

In this page the <div id="map"/> should be the map container, but in
test.js line 18, it has not been create correct.

Esa

unread,
Jul 12, 2011, 7:09:45 PM7/12/11
to Google Maps JavaScript API v3

I'm not sure if you are searching for Google Maps API v3 Closure
extern files. They used to be here
http://closure-compiler.googlecode.com/svn/trunk/contrib/externs/google_maps_api_v3.js
but just noticed that they are not.

Luke Mahé

unread,
Jul 12, 2011, 7:22:13 PM7/12/11
to google-map...@googlegroups.com
http://closure-compiler.googlecode.com/svn/trunk/contrib/externs/maps/google_maps_api_v3.js is the correct url

-- Luke



--
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.


xzhang

unread,
Jul 12, 2011, 9:34:46 PM7/12/11
to Google Maps JavaScript API v3
Seems that doesn't fix my problem, although it is a very useful tool.
I haven't start compile my code yet, just try to find a way to extent
the Map class.

On Jul 12, 5:09 pm, Esa <esa.ilm...@gmail.com> wrote:
> I'm not sure if you are searching for Google Maps API v3 Closure
> extern files. They used to be herehttp://closure-compiler.googlecode.com/svn/trunk/contrib/externs/goog...

xzhang

unread,
Jul 13, 2011, 1:30:40 PM7/13/11
to Google Maps JavaScript API v3
For more information,
This will work if I add constructor for google.maps.Map by myself.
Change the above code to:

goog.provide('MyMap');
MyMap = function(mapDiv, opts){
this.constructor.superClass_.constructor = google.maps.Map;
goog.base(this, mapDiv, opts);
}
goog.inherits(MyMap, google.maps.Map);
var myMap = new MyMap(div, opts);

This will working correct, but it doen't look like the right way to do
things.
Is there any reason we don't assign constructor for google.maps.Map at
first place ?

Enoch Lau

unread,
Jul 13, 2011, 6:47:26 PM7/13/11
to google-map...@googlegroups.com
It may be helpful to explain the end result you're trying to achieve by subclassing Map.

xzhang

unread,
Jul 13, 2011, 7:26:47 PM7/13/11
to Google Maps JavaScript API v3
Thank for reply my question, Their is noting really require me
subclassing Map, I just trying to find a way to manage my project.

I have many picture and xml format text data corresponding with them.
So I want show certain text, base on the coordinator of current image.

I already finish all task by define my own custom map type.
But now I have many similar type of pictures, so I hope I can define
their behavior in object oriented pattern.
For example: they all need loadXML(), but may have different way to
getText().

I still have other way to avoid subclassing Map directly, but I still
interesting to know why google.maps.Map.prototype.constructor is an
empty function.
Reply all
Reply to author
Forward
0 new messages