Post new topic Reply to topic  [ 2 posts ] 

Board index : GWT-Ext Forums : GWT-Ext 2.x Help

Author Message
 Post subject: Click events on MapPanel
PostPosted: Wed Apr 30, 2008 3:13 pm 
Offline

Joined: Mon Feb 11, 2008 4:18 pm
Posts: 3
Hi,

How can I get the LatLonPoint from a map when a user clicks on the map ?? Any example would be nice :-)

-Martin


Back to top
 Profile  
 
 Post subject: Re: Click events on MapPanel
PostPosted: Thu May 01, 2008 8:29 am 
Offline

Joined: Mon Mar 10, 2008 7:21 am
Posts: 202
One way of doing this is as follows:
1. Add an interface with an execute method that accepts one argument
Code:
package com.maharana.gwtextmaps.client;

public interface OneArgFunction {
   public void execute(com.google.gwt.core.client.JavaScriptObject arg);
}

2. Override methods in MapPanel.java
Code:
mapPanel = new GoogleMap() {
   public void addEventListener(final String event, final OneArgFunction listener) {
      if (!this.isRendered()) {
         addListener(MAP_RENDERED_EVENT, new Function() {
            public void execute() {
               doAddEventListener(event, listener);
            }
         });
      } else {
         doAddEventListener(event, listener);
      }
   }

   private native void doAddEventListener(String event, OneArgFunction listener) /*-{
            var map = this.@com.gwtext.client.widgets.map.MapPanel::mapJS;
            map.addEventListener(event, function(llp) {
            listener.@com.maharana.gwtextmaps.client.OneArgFunction::execute(Lcom/google/gwt/core/client/JavaScriptObject;)(llp);
            });
   }-*/;

   // constructor - attach event listener
   {
      addEventListener("click", new OneArgFunction(){
         public void execute(JavaScriptObject arg) {
            LatLonPoint llp = new LatLonPoint(arg);
            mapPanel.setCenterAndZoom(llp, mapPanel.getZoom());
            mapPanel.addMarker(new Marker(llp));
            MessageBox.alert("Clicked Location", "Lat: " + llp.getLat() + "<br>Lon: " + llp.getLon());
         }
      });
   }
};

I have posted a blog entry on this at: http://abhijeetmaharana.com/blog/2008/0 ... dle-click/

Do let me know if you have suggestions / corrections. A simpler method should be there somewhere!

_________________
Gwt-Ext docs: http://gwt-ext.com/docs/2.0.4/
Your question may have been answered already: viewforum.php?f=9


Back to top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

Board index : GWT-Ext Forums : GWT-Ext 2.x Help


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Style by Midnight Phoenix & N.Design Studio
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.