AnsweredAssumed Answered

Only Add Text to Map After Click Submit Button

Question asked by afrocodes on Feb 25, 2015
Latest reply on Apr 9, 2015 by afrocodes


I have a web map where users want to be able to add their own text to the map. But for some reason the code is ignoring my if statement that says only add text when button is clicked.


What it's currently doing:

-When user clicks on map, the default text entered in the Text Box displays on the map.

-When user presses the submit text button, clicks on the map, the text entered in the Text Box displays on the map.

-Text is added to the map even after the submit button was pressed once when user clicks on map.

-It conflicts with the other tools in the map like the measure tool.


What I want it to do:

-I only want the text in the text box to show after the submit button is pressed once not conflict with other tools.

[Ex., user presses the submit button, clicks on map, text is added to the map. User clicks on map again, no text is added to the map. If user wants text to be added to the map again, the user will have to click the submit button again.]


Background Info:

Level: newbie JS developer.

Using ESRI JavaScript API - ESRI's Public information web map template: Esri/public-information-map-template-js · GitHub

This code was added to the main.js file in the _init: function ().


The code is posted below. Suggestions appreciated.




if (this.config.enableAddText) {
     if (query("div#TextButton .dijitButton .dijitButtonNode").on('click', lang.hitch (this, function()
     {console.log("if query text button accessed")
     var map =;
     console.log("text button was clicked");

     query("div#mapDiv").on('click', lang.hitch (this, function (evt){

     var map =;
            new Graphic(
            new Point(evt.mapPoint.x, evt.mapPoint.y, new esri.SpatialReference({ wkid: 102100 })),
            new TextSymbol(dojo.byId("tsText").value).setColor(
                   new Color([0,0,0])).setAlign(esri.symbol.Font.ALIGN_START).setAngle(0).setOffset(0,0).setFont( 
                   new Font("12pt").setWeight(esri.symbol.Font.WEIGHT_BOLD))         
        console.log("added text graphic");