How to create a non-default GMarker with GoogleMapsGWT?

16 views
Skip to first unread message

dennis...@qwest.com

unread,
Jun 4, 2007, 3:36:48 PM6/4/07
to Google Web Toolkit
We use the GoogleMaps-GWT 2.1.4 package to develop a GeoMap
application. It needs to place a different marker on an address with a
trouble ticket. How can we create a non-default GMarker using
GoogleMaps-GWT?

I use the following code to try to create different GMarkers

GMarker marker = new GMarker(latLng); // Use the G_DEFAULT_ICON
if (addr.getTicketCount() > 0) {
marker.getIcon().setImage("http://www.google.com/mapfiles/
markerT.png");
}

But, after the setImage(url) statement is executed, all markers shown
on GoogleMap are globally changed to the "T" marker.

Any suggestion?

Thanks,
Dennis

krispy

unread,
Jun 4, 2007, 3:56:08 PM6/4/07
to Google Web Toolkit
Call marker.setImage(String url) - calling the icon.setImage(String)
function changes the icon's foreground URL globally. Change this
line:

marker.getIcon().setImage("http://www.google.com/mapfiles/
markerT.png");

to this line:

marker.setImage("http://www.google.com/mapfiles/markerT.png");

-krispy

On Jun 4, 3:36 pm, "dennis.ji...@qwest.com" <dennis.ji...@qwest.com>
wrote:

dennis...@qwest.com

unread,
Jun 4, 2007, 4:53:47 PM6/4/07
to Google Web Toolkit
I used the Java com.mapitz.gwt.googleMaps.client.GMarker class of
GoogleMapsGwt-2.1.4 instead of JavaScript GMarker from Google Maps
API. I just checked the com.mapitz.gwt.googleMaps.client.GMarker of
GoogleMapsGwt-2.2.1 in Java does not provide the
GMarker.setImage(String url) method.

- Dennis

On Jun 4, 1:56 pm, krispy <cplum...@integrity-apps.com> wrote:
> Callmarker.setImage(String url) - calling the icon.setImage(String)


> function changes the icon's foreground URL globally. Change this
> line:
>
> marker.getIcon().setImage("http://www.google.com/mapfiles/
> markerT.png");
>
> to this line:
>
> marker.setImage("http://www.google.com/mapfiles/markerT.png");
>
> -krispy
>
> On Jun 4, 3:36 pm, "dennis.ji...@qwest.com" <dennis.ji...@qwest.com>
> wrote:
>
>
>

> > We use the GoogleMaps-GWT2.1.4 package to develop a GeoMap
> > application. It needs to place a differentmarkeron an address with a
> > trouble ticket. How can wecreateanon-defaultGMarker using


> > GoogleMaps-GWT?
>
> > I use the following code to try tocreatedifferent GMarkers
>

> > GMarkermarker= new GMarker(latLng); // Use the G_DEFAULT_ICON


> > if (addr.getTicketCount() > 0) {
> > marker.getIcon().setImage("http://www.google.com/mapfiles/
> > markerT.png");
> > }
>
> > But, after the setImage(url) statement is executed, all markers shown
> > on GoogleMap are globally changed to the "T"marker.
>
> > Any suggestion?
>
> > Thanks,

> > Dennis- Hide quoted text -
>
> - Show quoted text -

krispy

unread,
Jun 4, 2007, 5:01:43 PM6/4/07
to Google Web Toolkit
Oh - that's right. It's in the newer versions of the API, but those
will only work with 1.4RC. It's actually incredibly simple to fix -
just add a JSNI method that takes in the GMarker's JSObject and calls
the setImage function on it. So, unless you can migrate to 1.4,
you'll have to write that quick fix for it. Aglaforge made a 2.1.5
beta with the fix in it, but never released it on sourceforge ... oh,
well. HTH!

-krispy

On Jun 4, 4:53 pm, "dennis.ji...@qwest.com" <dennis.ji...@qwest.com>
wrote:

krispy

unread,
Jun 4, 2007, 5:07:17 PM6/4/07
to Google Web Toolkit
Wait a second - you said you looked in the 2.2.1 JAR and didn't see
the GMarker.setImage() function? If you're looking at 2.1.4, it won't
be there - but 2.2.1 definitely has it. I'm looking at it as I type!
You must be mistaken about version numbers.

-krispy

dennis...@qwest.com

unread,
Jun 4, 2007, 7:46:56 PM6/4/07
to Google Web Toolkit
The GWTGoogleMaps2JavaDocs.zip at http://sourceforge.net/project/showfiles.php?group_id=169331
does not match the 2.2.1 jar. So does googlemaps_gwt_2_2_1.jar require
GWT 1.4?

-Dennis

> > > > - Show quoted text -- Hide quoted text -

aglaforge

unread,
Jun 5, 2007, 12:00:57 AM6/5/07
to Google Web Toolkit
Pretty straight forward:

1.) Create a new GIcon class referencing your images
2.) Create a GMarkerOptions class (and set the GIcon you created in
the step before in that)
3.) When you create your GMarkers... pass the GLatLng and the
GMarkerOptions class you just created.

Cheers,

Aglaforge

On Jun 4, 12:36 pm, "dennis.ji...@qwest.com" <dennis.ji...@qwest.com>
wrote:

krispy

unread,
Jun 5, 2007, 10:28:45 AM6/5/07
to Google Web Toolkit
GWTGoogleMaps2JavaDocs.zip - this is JavaDocs! Documentation, not
source code.
googlemaps_gwt_2_2_1.jar - this is the source. It contains the
GMarker class with the setImage() function.

You could copy the setImage(String) implementation into your current
version of googlemaps_gwt (if you want to stay with GWT 1.3) or just
migrate to GWT 1.4 and use the newest 2.2.1 jar file. I believe that
2.2.1 requires GWT 1.4 only b/c of the constructors to
JavaScriptObject (which have no parameters in GWT 1.4, but use to have
an int parameter in GWT 1.3). That's the scoop.

Or, you could do what Aglaforge says and just create new icons for
each marker : ) Probably that's just simpler - you wouldn't have to
change any of the source code or do crazy things like what I'm
saying. But you would get the additional overhead of a new GIcon
object for each marker.

Put simply, either you have to give each GMarker a new GIcon with the
right image URL, or you'd have to call setImage(String) on each of the
markers.

-krispy

On Jun 4, 7:46 pm, "dennis.ji...@qwest.com" <dennis.ji...@qwest.com>
wrote:
> The GWTGoogleMaps2JavaDocs.zip athttp://sourceforge.net/project/showfiles.php?group_id=169331

dennis...@qwest.com

unread,
Jun 8, 2007, 12:26:28 PM6/8/07
to Google Web Toolkit
I wrote the following method and called it with

GLatLng latLng = new GLatLng(gAddr.getLatitude(),
gAddr.getLongitude());
if (gAddr.getTicketCount() > 0)
marker = createGMarker(latLng, "http://www.google.com/mapfiles/
markerT.png");
else
marker = new GMarker(latLng);
.......

public GMarker createGMarker(GLatLng point, String iconUrl) {
GIcon icon = new GIcon(new GIcon(), iconUrl);
GMarkerOptions opt = new GMarkerOptions();
opt.setIcon(icon);
GMarker marker = new GMarker(point, opt);
return marker;
}

......

But, nothing was displayed on the GoogleMap for those gAddr whose
TicketCount > 0.

Any suggestions?

Thanks,
Dennis


On Jun 4, 10:00 pm, aglaforge <aglafo...@gmail.com> wrote:
> Pretty straight forward:
>
> 1.) Create a new GIcon class referencing your images
> 2.) Create a GMarkerOptions class (and set the GIcon you created in
> the step before in that)
> 3.) When you create your GMarkers... pass the GLatLng and the
> GMarkerOptions class you just created.
>
> Cheers,
>
> Aglaforge
>
> On Jun 4, 12:36 pm, "dennis.ji...@qwest.com" <dennis.ji...@qwest.com>
> wrote:
>
>
>
> > We use the GoogleMaps-GWT 2.1.4 package to develop a GeoMap
> > application. It needs to place a different marker on an address with a
> > trouble ticket. How can we create a non-default GMarker using
> > GoogleMaps-GWT?
>
> > I use the following code to try to create different GMarkers
>
> > GMarker marker = new GMarker(latLng); // Use the G_DEFAULT_ICON
> > if (addr.getTicketCount() > 0) {
> > marker.getIcon().setImage("http://www.google.com/mapfiles/
> > markerT.png");
> > }
>

> > But, after thesetImage(url) statement is executed, all markers shown


> > on GoogleMap are globally changed to the "T" marker.
>
> > Any suggestion?
>
> > Thanks,

krispy

unread,
Jun 8, 2007, 1:51:27 PM6/8/07
to Google Web Toolkit
Sorry I didn't realize this before - but when you create a new GIcon,
you have to specify all of its properties (shadow url, shadow size,
info window anchors, transparent images, blah blah blah). Instead of
doing it yourself, you should initialize the GIcon with the properties
of the default icon by calling:

new GIcon(new GIcon().G_DEFAULT_ICON(), iconUrl);

I think that should cause your markers to show up.

-krispy

P.S. Enhancement request to Aglaforge! Could you please create a
static method:

public static GIcon G_DEFAULT_ICON()
{
return GIcon.narrowToGIcon(GIconImpl.G_DEFAULT_ICON());
}

so that we don't have to create an empty icon just to get the default
one.

On Jun 8, 12:26 pm, "dennis.ji...@qwest.com" <dennis.ji...@qwest.com>
wrote:

dennis...@qwest.com

unread,
Jun 8, 2007, 2:38:51 PM6/8/07
to Google Web Toolkit
This solves the problem. Thank you!

> > > - Show quoted text -- Hide quoted text -

Reply all
Reply to author
Forward
0 new messages