I patched the code (my local checkout, although I'd like to see this
contributed) as follows:
/**
* Add an overlay to this map.
*
* @see GOverlay
* @see GMarker
*
* @param overlay
*/
public void addOverlay(GOverlay overlay)
{
overlay.setGMap2(this);
overlays.add(overlay);
}
/**
* Remove an overlay from this map.
*
* @see GOverlay
* @see GMarker
*
* @param overlay
*/
public void removeOverlay(GOverlay overlay)
{
overlays.remove(overlay);
}
(I added the removeOverlay method)
Then, I was able to do this, which works great:
mapPanel.addClickListener(new ClickListener() {
private static final long serialVersionUID =
-7743409010362331350L;
@Override
public void clickPerformed(ClickEvent clickEvent,
AjaxRequestTarget target) {
double lat = clickEvent.getPoint().getLat();
double lng = clickEvent.getPoint().getLng();
latLbl.setModelObject(lat);
lngLbl.setModelObject(lng);
map.removeOverlay(mMarker);
// when they click, it should remove the old one, and add
the new one in the clicked location
GLatLng point = new GLatLng(lat, lng);
map.addOverlay(mMarker = new GMarker(point));
map.setCenter(point);
if (target != null) {
target.addComponent(latLbl);
target.addComponent(lngLbl);
target.addComponent(mapPanel);
}
}
});
Jeremy Thomerson
On 6/18/07, Jeremy Thomerson <[EMAIL PROTECTED]> wrote:
With GMap2, how do I remove an overlay in a click event?
I need to be able to do this:
mapPanel.addClickListener(new ClickListener() {
private static final long serialVersionUID =
-7743409010362331350L;
@Override
public void clickPerformed(ClickEvent clickEvent,
AjaxRequestTarget target) {
double lat = clickEvent.getPoint().getLat();
double lng = clickEvent.getPoint ().getLng();
latLbl.setModelObject(lat);
lngLbl.setModelObject(lng);
//map.removeOverlay(memberDot); // this is the GMarker in
it's original location
// when they click, it should remove the old one, and add
the new one in the clicked location
map.addOverlay(new GMarker(new GLatLng(lat, lng)));
if (target != null) {
target.addComponent(latLbl);
target.addComponent(lngLbl);
target.addComponent(mapPanel);
}
}
});
Thank you!
Jeremy Thomerson
On 6/13/07, Martin Funk < [EMAIL PROTECTED]> wrote:
>
> Hi,
>
> may I draw your attention to a little project I was allowed to add to
> the wicket-stuff svn repository yesterday.
>
> Being highly inspired by Julians and Nicos wicket-contrib-gmap I got
> exited enough to try to create a project that does the same and a little
> bit more with a little different approach. Kinda bold, since I haven't
> looked into JavaScript before. Julian and Nico I hope you don't mind
> that I tried to invent the wheel a second time, but if your project
> wouldn't have been around I probably never would have tried. So thank
> you for that.
>
> Features:
> There can be more than one GMap on a page, I think there can be many, at
> least I succeeded with two.
>
> Components may become controls of the GMap. Any Component capable of
> firing events can become a controller. The controls are executed
> whenever the named event is fired by the Component. Currently ZooOut,
> ZoomIn, PanDirection, AddOverlay and OpenInfoWindow are implemented.
>
> Listeners may be added to the GMap. These are called whenever the GMap
> fires the corresponding Events. So far a ClickListener and a
> MoveEndListener are implemented. This allows to dynamically update any
> Component and the GMap itself.
>
> The events and the controls always do a round trip from the browser to
> the server and back, this way any call can be intercepted and controlled
> on the server side. The network traffic is kept down, since all needed
> JavaScript functions are defined in a js-file. So only arguments have to
>
> be transfered.
>
> Status:
> Is best described by, consolidating. As I said, being a JavaScript
> newbie and a Java mediocre, it was sort of bold to start this. The
> features in mind I basically cut right through any API ahead of me
> without taking care of any design principles. So if you ever find the
> time to look into the code, give feedback! And I fear this project is in
> need for a lot of feedback.
>
> Last but not least: Installation.
> There is no release currently planed. The code compiles against the
> current HEAD of wicket. So get get wicket from svn as described in
> http://incubator.apache.org/wicket/building-from-svn.html first.
> This project relies on the well maintained structure of wickets pom.xml
> files. It needs to be checked out into wicket jdk-1.5 folder:
>
> cd <wickets-jdk-1.5-folder>
> svn co
>
>
https://wicket-stuff.svn.sourceforge.net/svnroot/wicket-stuff/trunk/wicket-contrib-gmap2
> svn co
>
https://wicket-stuff.svn.sourceforge.net/svnroot/wicket-stuff/trunk/wicket-contrib-gmap2-examples
>
>
> This should do the install and get a jetty started for the examples:
> mvn -f wicket-contrib-gmap2/pom.xml install
> mvn -f wicket-contrib-gmap2-examples/pom.xml jetty:run
>
> Now browse to:
> http://localhost:8080/wicket-contrib-gmap2-examples/gmap/
> and click around.
>
>
> Have fun,
>
> Martin
>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
>
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user