You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jeremy Thomerson <je...@wickettraining.com> on 2008/10/28 02:43:32 UTC

GMap2 - GInfoWindow

I'm not sure who maintains GMap2 (Martin F?) - but I just created a class
that allows me to show an info window when a GMarker is clicked.  This could
actually be abstracted to allow other calls on a GMarker fairly easily.

Two questions:
1 - is there a better way already built in?  (I couldn't find one)
2 - can you use this class or a better method to include this functionality
in GMap2?

Thanks for the GMap2 contribution!!

(Class pasted below)

-- 
Jeremy Thomerson
http://www.wickettraining.com

public class GInfoWindow extends AbstractBehavior {
 private static final long serialVersionUID = 1L;

 private GMap2 mMap;
 private final IModel<String> mHtmlModel;
 private final GMarker mMarker;

 public GInfoWindow(GMarker marker, String html) {
  mMarker = marker;
  mHtmlModel = new Model<String>(html);
 }

 public GInfoWindow(GMarker marker, IModel<String> html) {
  mMarker = marker;
  mHtmlModel = html;
 }

 @Override
 public void bind(Component<?> component) {
  super.bind(component);

  if ((component instanceof GMap2) == false) {
   throw new IllegalStateException("must be added to a gmap2");
  }
  mMap = (GMap2) component;
 }

 @Override
 public void renderHead(IHeaderResponse response) {
  super.renderHead(response);
  CharSequence html = JavascriptUtils.escapeQuotes(mHtmlModel.getObject());
  String call = "overlays[" + mMarker.getId() + "].bindInfoWindowHtml('" +
html + "', null)";
  response.renderOnDomReadyJavascript(mMap.getJSinvoke(call));
 }
}

Re: GMap2 - GInfoWindow

Posted by Martin Funk <ma...@googlemail.com>.
Jeremy Thomerson wrote:
> I'm not sure who maintains GMap2 (Martin F?) 
I guess one could say that :-)
> - but I just created a class
> that allows me to show an info window when a GMarker is clicked.  This could
> actually be abstracted to allow other calls on a GMarker fairly easily.
>
> Two questions:
> 1 - is there a better way already built in?  (I couldn't find one)
>   
It's hard to say what way is better. Look at what we've done in
wicket.contrib.examples.gmap.top.HomePage
I think it pretty much implements the same as what you came up with.
But it does it in an ajax way, clicking a Marker sends an ajax call to 
the server, which generates what has to show up in the Infowindow and 
sends it back.
As I understand your code example the html for the InfoWindow has to be 
known by the time the marker is inserted in the map.
Which might suite your needs.

> 2 - can you use this class or a better method to include this functionality
> in GMap2?
>   
If you want your code to be preserved for others, come up with a patch 
for wicket-contrib-gmap2-examples.
And if you are desperate you could ask for commit rights on the 
userlist, and do it yourself.

Feel free & have fun,

Martin
> Thanks for the GMap2 contribution!!
>
> (Class pasted below)
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org