Creating custom styles for Navigation

64 views
Skip to first unread message

Amir

unread,
Jul 14, 2009, 5:37:15 AM7/14/09
to Google Maps JavaScript API v3
Hi there,

I want to totally change all the button styles on the page (like
navigation style, or map type buttons (hybrid, satellite, ...) style).

It's about 2 hours that I'm searching about this but so far I haven't
found anything.

I've found this one http://code.google.com/apis/maps/documentation/controls.html#Custom_Controls
but it's for API version 2 and i can not use it in version 3.

so, any idea.

cheers,

Amir

unread,
Jul 14, 2009, 5:57:51 AM7/14/09
to Google Maps JavaScript API v3
I uploaded the file so you can have a better idea:
gmap.jpg

String

unread,
Jul 14, 2009, 8:36:36 AM7/14/09
to Google Maps JavaScript API v3
On Jul 14, 10:37 am, Amir <amirrezaa.farh...@gmail.com> wrote:

> I want to totally change all the button styles on the page (like
> navigation style, or map type buttons (hybrid, satellite, ...) style).

This feature isn't supported yet by v3. I'd suggest you file an
enhancement request:
http://code.google.com/p/gmaps-api-issues/issues/entry?template=Maps%20API%20v3%20-%20Feature%20Request

In the meanwhile, your best way forward is probably to put your
controls in a div placed over the map, and implement the functionality
(zoom, pan, etc) yourself in the various click events.

Or, stick with v2 for your app - is there a reason you need to use v3?

String

Bjornie

unread,
Jul 14, 2009, 8:41:09 AM7/14/09
to Google Maps JavaScript API v3
I'm working on custom navigation as well, but haven't come up with
something beautiful yet ( ;) ). However, I have managed to create a
custom navigator window (working in at least Firefox and Opera,
haven't had time to try them in any other browser). What I do is I
create a separate layer (div) and place it over the map, then placing
regular DOM objects (like images) in the div, and associate events to
these objects. I'm putting a screenshot among the images on the groups
front page.

I can give you a code snippet, and if you don't get it - ask me and I
will try to guide you more. As I'm using mootools for a bunch of
functionality on my site, my example below will be full of mootools
code. Hopefully you sort it out anyway.

var map = new google.maps.Map(document.getElementById
('YourGoogleMap'), {
zoom: 7,
position: YOUR_POSITION,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var controllers = new Element('div', {
'style': 'background-image: url(/path/to/background-image.png);
width: 500px; height: 35px; position: absolute; left: 0; top: 0; z-
index: 1001';
});
var zoomIn = new Element('img', {
'src': '/path/to/zoom-in-image.png',
'style': 'cursor: pointer'
});
var zoomOut = new Element('img', {
'src': '/path/to/zoom-out-image.png',
'style': 'cursor: pointer'
});

/* Above is probably the same as the following, new Element(...) is
mootools specific:
*
* var controllers = document.createElement('div');
* controllers.style.backgroundImage = 'url(...)';
* controllers.style.width = '500px';
* ...
*/

zoomIn.addEvent('click', function() {
map.set_zoom(map.get_zoom() + 1);
});
zoomOut.addEvent('click', function() {
map.set_zoom(map.get_zoom() - 1);
});
/* Above is probably the same as the following, if you're not using
mootools (addEvent is mootools specific):
*
* google.maps.event.addDomListener(zoomIn, 'click', function() {
* map.set_zoom(map.get_zoom() + 1);
* });
* ...
*/

zoomIn.inject(controllers);
zoomOut.inject(controllers);
controllers.inject(document.getElementById('YourGoogleMap'));
/* Above is probably the same as the following, since element.inject
() is mootools specific:
*
* controllers.appendChild(zoomIn);
* controllers.appendChild(zoomOut);
* document.getElementById('YourGoogleMap').appendChild(controllers);
*/

Bjornie

unread,
Jul 14, 2009, 8:45:27 AM7/14/09
to Google Maps JavaScript API v3
It's kind of hard to read code in these groups, so I put it on pastbin
as well: http://pastebin.com/m2d953e55

Amir

unread,
Jul 14, 2009, 9:52:41 AM7/14/09
to Google Maps JavaScript API v3
oom, cool, I'll try to use overlay div(s). BTW there isn't any reason
for using V 3.0, I just wanted to use the recent version.


On Jul 14, 4:36 pm, String <sterling.ud...@googlemail.com> wrote:
> On Jul 14, 10:37 am, Amir <amirrezaa.farh...@gmail.com> wrote:
>
> > I want to totally change all the button styles on the page (like
> > navigation style, or map type buttons (hybrid, satellite, ...) style).
>
> This feature isn't supported yet by v3. I'd suggest you file an
> enhancement request:http://code.google.com/p/gmaps-api-issues/issues/entry?template=Maps%...

Amir

unread,
Jul 14, 2009, 9:53:43 AM7/14/09
to Google Maps JavaScript API v3
Fantastic, lemme go through it and try this myself and if I face any
issues I'll ask you.
Thanks for this.

Bjornie

unread,
Jul 14, 2009, 3:15:36 PM7/14/09
to Google Maps JavaScript API v3
Ok, now I think I've got a pretty nice way to do this. I've created a
library for the custom navigation system, and it's pretty easy to use
now (of course it can always get better). I've uploaded the library
(custom-controllers-library.js) to the group files, along with a demo.
Everything is in the custom-controllers.zip archive.

This is how it can look (codewise that is ;)) : http://pastebin.com/f6c8def11

Anyone is free to use, change, improve or refuse these classes.

Link to the zip-file;
http://google-maps-js-api-v3.googlegroups.com/web/custom-controllers.zip

Amir

unread,
Jul 15, 2009, 7:03:14 AM7/15/09
to Google Maps JavaScript API v3
WOW, Bjornie, this is brilliant

I uploaded the file (gmap.zip), I changed some css's and I'm almost
created the thing that I was looking for (thanking you), but just I
can't figure out the PAN button. would you help me with this also.

Cheers,

Amir

unread,
Jul 15, 2009, 7:05:49 AM7/15/09
to Google Maps JavaScript API v3
aa, another thing, the slider is an image at the moment, I'll put a
real slider for that, in case anyone wants to use this file.

Esa

unread,
Jul 15, 2009, 5:31:27 PM7/15/09
to Google Maps JavaScript API v3
This reminds me of the times when Google Maps API was released at the
end of June 2005. An incredible new scifi-like possibility to create
totally new things that were not even imagined the day before.

The most noisy crowd was shouting that the default marker is ugly.

Amir

unread,
Jul 16, 2009, 3:53:42 AM7/16/09
to Google Maps JavaScript API v3
Hi Bjornie

can you gimme some hints about the function for pan?

On Jul 14, 11:15 pm, Bjornie <bjorn.wikst...@gmail.com> wrote:

Bjornie

unread,
Jul 16, 2009, 4:22:07 AM7/16/09
to Google Maps JavaScript API v3
ATM I don't have time to look into it, but hopefully later today or
maybe tomorrow. I'm occupied this weekend as well. Maybe I'm going to
implement the same functionality in my app (at work) - if I do, I will
post my findings here.

Amir

unread,
Jul 16, 2009, 5:32:03 AM7/16/09
to Google Maps JavaScript API v3
Cool, keep me posted.
Reply all
Reply to author
Forward
0 new messages