JS API - Measurement widget in draw mode and disabling the InfoTemplate?

1264
9
Jump to solution
09-08-2017 10:22 AM
IanPeebles
Occasional Contributor III

I have a simple application where I am adding in a measure widget and I have a couple of InfoTemplates configured.  How can I simply disconnect the infoTemplate from popping up while I am in draw mode with the measurement widget.  The two tools are conflicting with eachother.

I have tried using a couple of functions and setting map.setInfoWindowOnClick(false); while the tool is in draw then setting it back to map.setInfoWindowOnClick(true); but I cannot seem to get it to work.  I checked the API reference, but cannot get it to work.  Here are a couple blocks of code, one for the measurement widget and the other for the info template:

// Map - Measurement Widget
measurement = new Measurement({
     map: map,
     defaultAreaUnit: Units.SQUARE_FEET,
     defaultLengthUnit: Units.FEET
 }, dom.byId("measurementDiv"));
 measurement.startup();

When the widget is activated, I need the popup to disconnect or map.setInfoWindowOnClick(false);

// Planimetrics - Building Footprints (0)
var bfInfoTemplate = new PopupTemplate({
     title: "Building Footprint",
     fieldInfos: [{
        fieldName: "SHAPE.area",
        label: "Square Footage:",
     format: { "places": 0, "digitSeparator": true },
        visible: true
     }]
});

I am wanting to achieve this without having to add in a button and set up event listeners.

Any ideas?

0 Kudos
1 Solution

Accepted Solutions
IanPeebles
Occasional Contributor III

There is an easier way to do this I found.  Here is the code:

// Map - Measurement Widget
measurement = new Measurement({
   map: map,
   defaultAreaUnit: Units.SQUARE_FEET,
   defaultLengthUnit: Units.FEET
}, dom.byId("measurementDiv"));
measurement.startup();

// Handle Click Events Between Popup and Measurement Tool
measurement.on("tool-change", toolname)
function toolname(evt)
{
    if (evt.toolName)
    {
        map.setInfoWindowOnClick(false);
    }
    else
    {
        map.setInfoWindowOnClick(true);
    }           
}

View solution in original post

0 Kudos
9 Replies
ThomasSolow
Occasional Contributor III

The measure dijit has 'measure-start' and 'measure-end' events.  I would try listening for those events and disabling/enabling infotemplates.

Something like:  

var measurement = new Measurement({
  map: map,
  defaultAreaUnit: Units.SQUARE_MILES,
  defaultLengthUnit: Units.KILOMETERS
}, dom.byId('measurement'));

measurement.on('measure-start', event => {
   // disable info templates
});

measurement.on('measure-end', event => {
   // enable info templates
});
IanPeebles
Occasional Contributor III

Thank you for the idea, but when I tried the following logic, it still does not work as desired. 

// Map - Measurement Widget
measurement = new Measurement({
  map: map,
  defaultAreaUnit: Units.SQUARE_FEET,
  defaultLengthUnit: Units.FEET
}, dom.byId("measurementDiv"));
measurement.startup();


measurement.on('measure-start', disableInfoTemplate);
measurement.on('measure-end', enableInfoTemplate);

function disableInfoTemplate() {
  map.setInfoWindowOnClick(false)
}

function enableInfoTemplate() {
  map.setInfoWindowOnClick(true)
}

0 Kudos
ThomasSolow
Occasional Contributor III

Can you check to see if the event is firing at all?  (Maybe by adding a console to log in there).

0 Kudos
IanPeebles
Occasional Contributor III

The event is firing.  I put a console log statement inside the function and it was returning back the statement following the click.

This is a tricky one without adding some buttons.

The popup needs to be on by default, but when the "area", "distance", or "location" buttons are clicked, the InfoTemplate needs to be disabled.  When the draw is completed for any of these tools, the InfoTemplate needs to be re-enabled again.

I thought that was what the functions would do in the code snippet above?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ian,

   Here is the code I use for that:

          this.own(aspect.after(measurement, 'setTool', lang.hitch(this, function() {
            if (measurement.activeTool) {
              disableWebMapPopup();
            } else {
              enableWebMapPopup();
            }
          })));

//And the disableWebMapPpopup function just does:
map.setInfoWindowOnClick(false);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

If you are using popups from a webmap then you need to be sure to use:

usePopupManager:true

IanPeebles
Occasional Contributor III

Robert,

As always, thank your for the feedback.  What classes do I need to include? esri/lang?

I will certainly give this a shot.  Thank you much!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

dojo/lang, dojo/aspect

IanPeebles
Occasional Contributor III

There is an easier way to do this I found.  Here is the code:

// Map - Measurement Widget
measurement = new Measurement({
   map: map,
   defaultAreaUnit: Units.SQUARE_FEET,
   defaultLengthUnit: Units.FEET
}, dom.byId("measurementDiv"));
measurement.startup();

// Handle Click Events Between Popup and Measurement Tool
measurement.on("tool-change", toolname)
function toolname(evt)
{
    if (evt.toolName)
    {
        map.setInfoWindowOnClick(false);
    }
    else
    {
        map.setInfoWindowOnClick(true);
    }           
}

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Don't forget to mark this question as answered by clicking on the "Correct Answer" link on the reply that answered your question.