AnsweredAssumed Answered

Adding a HomeButton dijit to a page and manually specifying event handler...

Question asked by Pudnik on Apr 16, 2016
Latest reply on Apr 16, 2016 by Pudnik

I have tried to add a HomeButton dijit to my page. However, it won't work if I specify any event listeners on the map object. In other words, if I want to add BOTH a HomeButton, AND a task that specifies event listeners on the map object, like this:

  // for home button
        var objHome = new HomeButton({map: divMap}, "HomeButton");
        objHome.startup();
          // this is how you call 'on' style events in the API
        objMap.on("load", function()
        {
          // for coordinates display - event listeners
          objMap.on("mouse-move", showCoordinates);
          objMap.on("mouse-drag", showCoordinates);
          // for home button - when home event is fired, execute home() method - currently doesn't work
          objHome.on("home",objHome.home());
        });
                // for coordinates display
        function showCoordinates(evt)
          {
          //the map is in web mercator but display coordinates in geographic (lat, long)
          var mp = webMercatorUtils.webMercatorToGeographic(evt.mapPoint);
          //display mouse coordinates
          dom.byId("spanCoordinates").innerHTML = mp.x.toFixed(3) + ", " + mp.y.toFixed(3);
        }

...It won't work.

What do I need to modify here, to get the HomeButton to work with the showCoordinates code? Again, before you post the code on the HomeButton class definition page as a solution - that code WILL NOT WORK if you specify an 'on' function on the map object.

Thanx.

Outcomes