0
votes

I have a problem. I have a map and added ClickHandler, but after pushing a button I want to remove it. I know that there's some HandlerRegistration but I don't know how to use it. part of my code:

map.addMapClickHandler(new MapClickHandler()

        {
            public void onClick(MapClickEvent e) 
            {
                 ...
                }
        });

can anyone help me?

2
in the map is google map in which you can add points - john

2 Answers

0
votes

MapWidget#addMapClickHandler() doesn't return a HandlerRegistration, but the MapWidget class defines a removeMapClickHandler() method:

map.addMapClickHandler(new MapClickHandler() {
  @Override
  public void onClick(MapClickEvent event) {
    // Make sure map is visible to this inner class. It needs
    // either to be a member of the enclosing class or final.
    map.removeMapClickHandler(this);
  }
});
0
votes

In case you still need this, it took me a while to figure out the solution

final Set<HandlerRegistration> hack = new HashSet<HandlerRegistration>();
hack.add(map.addMapClickHandler(new MapClickHandler() {
    public void onClick(MapClickEvent e) {
        ...
        // remove handler here
        for (HandlerRegistration hr : hack) {
            hr.removeHandler();
        }
    }
}));