Select to view content in your preferred language

Moving between code and buttons

766
3
Jump to solution
06-27-2014 12:18 PM
jaykapalczynski
Honored Contributor
I have 4 Buttons...
the first two seems to work fine.
....The first one allows the user to draw a polygon
....The Second one allows the user to draw Freehand
I click the 3rd and it pauses the first 2 and a single click in the map highlights the Region

So far so good

After Clicking the 3rd button and doing a map selection
Go back and click one of the first 2 buttons to Draw....the drawing works fine BUT you can single Click and select a Region which was the code in the 3rd Button.

I still cant seem to figure out how to Stop that code from running on a Feature Map Click (from the third button)

Can anyone place their eyes on the source code of this page and see what I am doing wrong?

https://fwisweb1.dgif.virginia.gov/dgifmapping/DataExtract3.html
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
So where are you defining all the actions? Is this what you're trying to do? You have to add in a reference to "dojo/on"

            function RegionSelection() {                  if (action1 != undefined) {                     action1.pause();                 }                 if (action2 != undefined) {                     action2.pause();                 }                 if (action4 != undefined) {                     action4.pause();                 }                 if (action3 == undefined) {                     alert("RegionSelection7");                      map.graphics.clear();                      var highlightSymbol = new SimpleFillSymbol(                     SimpleFillSymbol.STYLE_SOLID,                     new SimpleLineSymbol(                     SimpleLineSymbol.STYLE_SOLID,                     new Color([255, 0, 0]), 1),                     new Color([125, 125, 125, 0.35]));                      action3 = on.pausable(petroFieldsFL2, "click", function (evt) {                         map.graphics.clear();                         highlightGraphic = new Graphic(evt.graphic.geometry, highlightSymbol);                         map.graphics.add(highlightGraphic);                          var query = new Query();                         query.geometry = highlightGraphic.geometry.getExtent();                     });                      //petroFieldsFL2.on("click", function (evt) {                     //    map.graphics.clear();                     //    highlightGraphic = new Graphic(evt.graphic.geometry, highlightSymbol);                     //    map.graphics.add(highlightGraphic);                      //    var query = new Query();                     //    query.geometry = highlightGraphic.geometry.getExtent();                     //})                  }                 else {                     action3.resume();                 }              } 

View solution in original post

0 Kudos
3 Replies
jaykapalczynski
Honored Contributor
I was able to trick it with the code in REd below....This is the only way I can figure out how to turn off the Feature Map Click in the Third Button...

I know this is not the right way...there has to be a more correct way.....Any thoughts?

    <button id="polygon"
            data-dojo-type="dijit/form/Button"
            data-dojo-props="iconClass:'polyIcon', showLabel:false">
              Polygon
    </button>
    <button id="freehandpolygon"
            data-dojo-type="dijit.form.Button"
            data-dojo-props="iconClass:'freehandIcon', showLabel:false">
              Freehand
    </button>
    <button id="RegionSelection"
            data-dojo-type="dijit.form.Button"
            data-dojo-props="iconClass:'freehandIcon', showLabel:false">
              RegionSelection
    </button>
    <button id="Buffer"
            data-dojo-type="dijit.form.Button"
            data-dojo-props="iconClass:'freehandIcon', showLabel:false">
              Buffer
     </button>


      var action1, action2;
      var action3, action4;


      registry.byId("polygon").on("click", function() {
        if (action1 != undefined) {
   action2.pause();
   action3.pause();
   action4.pause();
  }

  if (action1 == undefined) {
   petroFieldsFL2.on("click", function (evt) {
    map.graphics.clear();
   });
   activateTool(this.id);
  }
   else {
   action1.resume();
  }
       });

       registry.byId("freehandpolygon").on("click", function() {
        if (action1 != undefined) {
   action1.pause();
   action3.pause();
   action4.pause();
  }

  if (action2 == undefined) {
   //alert("Freehand");
   petroFieldsFL2.on("click", function (evt) {
    map.graphics.clear();
   });
   activateTool(this.id);
  }
  else {
   action2.resume();
  }
       });


     registry.byId("RegionSelection").on("click", function() {
        if (action1 != undefined) {
   action1.pause();
   action2.pause();
   action4.pause();
  }
         if (action3 == undefined) {
   action3 = RegionalSelectionMap(map);
  }
         else {
                     action3.resume();
         }
       });


     registry.byId("Buffer").on("click", function() {
  if (action1 != undefined) {
   action1.pause();
   action2.pause();
   action3.pause();
  }

  if (action4 == undefined) {
   map.graphics.clear();
   action3 = FourthButton(map);
  }
  else {
   action4.resume();
  }
       });


        function RegionalSelectionMap() {
  map.graphics.clear();
  selectionToolbar.deactivate();

  var highlightSymbol = new SimpleFillSymbol(
  SimpleFillSymbol.STYLE_SOLID,
  new SimpleLineSymbol(
  SimpleLineSymbol.STYLE_SOLID,
  new Color([255, 0, 0]), 1),
  new Color([125, 125, 125, 0.35]));

  petroFieldsFL2.on("click", function (evt) {
   map.graphics.clear();
   highlightGraphic = new Graphic(evt.graphic.geometry, highlightSymbol);
   map.graphics.add(highlightGraphic);

   var query = new Query();
          query.geometry = highlightGraphic.geometry.getExtent();
  });

        }

        function FourthButton() {
  map.graphics.clear();
  selectionToolbar.deactivate();

  petroFieldsFL2.on("click", function (evt) {
   map.graphics.clear();
  });
        }
0 Kudos
KenBuja
MVP Esteemed Contributor
So where are you defining all the actions? Is this what you're trying to do? You have to add in a reference to "dojo/on"

            function RegionSelection() {                  if (action1 != undefined) {                     action1.pause();                 }                 if (action2 != undefined) {                     action2.pause();                 }                 if (action4 != undefined) {                     action4.pause();                 }                 if (action3 == undefined) {                     alert("RegionSelection7");                      map.graphics.clear();                      var highlightSymbol = new SimpleFillSymbol(                     SimpleFillSymbol.STYLE_SOLID,                     new SimpleLineSymbol(                     SimpleLineSymbol.STYLE_SOLID,                     new Color([255, 0, 0]), 1),                     new Color([125, 125, 125, 0.35]));                      action3 = on.pausable(petroFieldsFL2, "click", function (evt) {                         map.graphics.clear();                         highlightGraphic = new Graphic(evt.graphic.geometry, highlightSymbol);                         map.graphics.add(highlightGraphic);                          var query = new Query();                         query.geometry = highlightGraphic.geometry.getExtent();                     });                      //petroFieldsFL2.on("click", function (evt) {                     //    map.graphics.clear();                     //    highlightGraphic = new Graphic(evt.graphic.geometry, highlightSymbol);                     //    map.graphics.add(highlightGraphic);                      //    var query = new Query();                     //    query.geometry = highlightGraphic.geometry.getExtent();                     //})                  }                 else {                     action3.resume();                 }              } 
0 Kudos
jaykapalczynski
Honored Contributor
The other two buttons work great....

MODIFY: THANKS...I was missing the Dojo/on


Exactly what I needed....Learning everyday....much appreciated.

      
     var action1, action2, action3;

      registry.byId("polygon").on("click", function() {
    if (action2 != undefined) {
                action2.pause();
            }
            if (action3 != undefined) {
                action3.pause();
            }
    if (action1 == undefined) {
  activateTool(this.id);
    }
    else {
         action1.resume();
    }
       });

       registry.byId("freehandpolygon").on("click", function() {
    if (action1 != undefined) {
                action1.pause();
            }
            if (action3 != undefined) {
                action3.pause();
            }
    if (action2 == undefined) {
  activateTool(this.id);
    }
    else {
     action2.resume();
    }
       });

       registry.byId("RegionSelection").on("click", function() {
   if (action1 != undefined) {
                action1.pause();
            }
            if (action2 != undefined) {
                action2.pause();
            }

         if (action3 == undefined) {

                    map.graphics.clear();

                    var highlightSymbol = new SimpleFillSymbol(
                    SimpleFillSymbol.STYLE_SOLID,
                    new SimpleLineSymbol(
                    SimpleLineSymbol.STYLE_SOLID,
                    new Color([255, 0, 0]), 1),
                    new Color([125, 125, 125, 0.35]));

                    action3 = on.pausable(petroFieldsFL2, "click", function(evt) {

                        map.graphics.clear();
                        highlightGraphic = new Graphic(evt.graphic.geometry, highlightSymbol);
                        map.graphics.add(highlightGraphic);

                        var query = new Query();
                        query.geometry = highlightGraphic.geometry.getExtent();
                    });
   }
         else {
             action3.resume();
         }
       });

        function activateTool(tool) {
          map.graphics.clear();
          // The draw.activate expects a string like "polygon" or "freehand_polygon".
          selectionToolbar.activate(tool);
        }
0 Kudos