Button

1044
11
Jump to solution
03-25-2014 04:28 AM
jaykapalczynski
Frequent Contributor
Looking to create a simple button that runs some code like IDENTIFY. 
I am looking for two scenarios:
1.  The button must be pressed each time you want to run the code
2.  The code runs until you select another button

Anyone of an example for each...Appreciated.
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
See this example here.  This should help you get going in the right direction.

View solution in original post

0 Kudos
11 Replies
PaulVepraskas
Occasional Contributor
This should work for either one...

Create a global variable

var buttonclick;


Then create the function the button calls

function buttoncall() {
    buttonclick = dojo.connect(map, "onClick" resultFunction);
}

function resultFunction() {
    dojo.disconnect(buttonclick);
    alert("test");
}


Give it a shot
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Hi Jay,

Here is an example that sets the infoTemplate each time the button is clicked.
0 Kudos
jaykapalczynski
Frequent Contributor
Is there anything that I need in the

 require([

    ], function(

    ) {
0 Kudos
jaykapalczynski
Frequent Contributor
Hi Jay,

Here is an example that sets the infoTemplate each time the button is clicked.



I am doing to below....I the map and nothing....the way I want it.  I then click the button and then click a feature...it grabs the attrbiute  info and displays in a pane on the left.

The issue is that it allows the user to continue clicking in the map....I want to create this where it jumps out after each map click.

Cancel the functionality after a single click...so no longer call the Function
AND OR cancel the Function call if another button is pressed...

Say I have 2 buttons...Click one and it allows me to select and do what my code is doing below....UNTIL I click the other button

<input type="button" id="button" value="Identify" />

    on(dom.byId("button"), "click", function () {
        featureLayer.setInfoTemplate(template);
 initializeSidebar(app.map);
        on(app.map.infoWindow, "show", function () {
            featureLayer.setInfoTemplate(null);
        })
    })

    function initializeSidebar(map){
        var popup = map.infoWindow;

        //when the selection changes update the side panel to display the popup info for the
        //currently selected feature.
        connect.connect(popup, "onSelectionChange", function(){
            displayPopupContent(popup.getSelectedFeature());
        });

        //when the selection is cleared remove the popup content from the side panel.
        connect.connect(popup, "onClearFeatures", function(){
           //dom.byId replaces dojo.byId
           dom.byId("featureCount").innerHTML = "Click to select feature(s)";
           //registry.byId replaces dijit.byId
           registry.byId("leftPane").set("content", "");
           domUtils.hide(dom.byId("pager"));
        });

        //When features are associated with the map's info window update the sidebar with the new content.
        connect.connect(popup, "onSetFeatures", function(){
           displayPopupContent(popup.getSelectedFeature());
           dom.byId("featureCount").innerHTML = popup.features.length + " feature(s) selected";

       //enable navigation if more than one feature is selected
       popup.features.length > 1 ? domUtils.show(dom.byId("pager")) : domUtils.hide(dom.byId("pager"));
         });
       }

    function displayPopupContent(feature){
       if(feature){
           var content = feature.getContent();
           registry.byId("leftPane").set("content", content);
       }
    }
0 Kudos
JakeSkinner
Esri Esteemed Contributor
See this example here.  This should help you get going in the right direction.
0 Kudos
jaykapalczynski
Frequent Contributor
Thanks Jake..that worked great...

Still trying to dig into this one though...its nice and streamlined and seems to shut down after each click in the map...would be nice to get this one going as well....

Do you still have to define the button in HTML?

var buttonclick;

function buttoncall() {
    buttonclick = dojo.connect(map, "onClick" resultFunction);
}

function resultFunction() {
    dojo.disconnect(buttonclick);
    alert("test");
}
0 Kudos
jaykapalczynski
Frequent Contributor
This should work for either one...

Create a global variable

var buttonclick;


Then create the function the button calls

function buttoncall() {
    buttonclick = dojo.connect(map, "onClick" resultFunction);
}

function resultFunction() {
    dojo.disconnect(buttonclick);
    alert("test");
}


Give it a shot



Do i have to define anything in HTML?
Do I have to define anything in the REQUIRE?

I really like this approach....just cant seem to get it working...is there something i am missing?
Thanks
0 Kudos
PaulVepraskas
Occasional Contributor
In the HTML create a button that calls the function buttoncall

<a href="javascript:buttoncall()" id="button1" ><img alt="button1IMG" id="button1IMG" style="bottom:10px; left: 10px; width:36px; position:absolute; z-index:22;  border:none;" src="images/Button.png"/></a>


The map onClick will then stay activate until in your code you set it disconnect

dojo.disconnect(buttonclick);
0 Kudos
PaulVepraskas
Occasional Contributor
Sorry I missed a coma....

 buttonclick = dojo.connect(map, "onClick", resultFunction);
0 Kudos