Disable popups while drawing/sketching graphics (js api 4.6)

3335
6
Jump to solution
01-30-2018 02:02 PM
BlakeTerhune
MVP Regular Contributor

I've got one FeatureLayer with a popup in the map. I'm trying to use the SketchViewModel sample for sketching temporary geometries. How can I disable popups while the sketching is active so clicking on a feature in the FeatureLayer doesn't open the popup?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Blake,

   OK, it seems that the point draw-complete is fired before the mapView hittest is returned.

Here is the fix:

        sketchViewModel.on("draw-complete", function(evt) {
          setTimeout(function(){
            myFeatureLayer.popupEnabled = true;
          },200);

View solution in original post

0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus

Blake,

 Just disable the layers popup before you start sketching using the layers popupEnabled property.

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#popupEna... 

0 Kudos
BlakeTerhune
MVP Regular Contributor

Hi Robert,

Not quite sure where would be the best place to represent "stert sketching." I added the FeatureLayer popupEnabled = false to the onclick functions of each button in that SketchViewModel example. Then I change popupEnabled back to true in the on draw-complete function. It seems to work for line and polygon but isn't working for points.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Blake,


   Are you placing your code at the beginning of the onclick functions?

0 Kudos
BlakeTerhune
MVP Regular Contributor

Yes, for example:

// *************************************
// activate the sketch to create a point
// *************************************
var drawPointButton = document.getElementById("pointButton");
drawPointButton.onclick = function() {
  myFeatureLayer.popupEnabled = false;
  // set the sketch to create a point geometry
  sketchViewModel.create("point");
  setActiveButton(this);
};‍‍‍‍‍‍‍‍‍‍

Then I set it back to true in the on draw-complete function:

sketchViewModel.on("draw-complete", function(evt) {
  myFeatureLayer.popupEnabled = true;
  // add the graphic to the graphics layer
  tempGraphicsLayer.add(evt.graphic);
  setActiveButton();
});
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Blake,

   OK, it seems that the point draw-complete is fired before the mapView hittest is returned.

Here is the fix:

        sketchViewModel.on("draw-complete", function(evt) {
          setTimeout(function(){
            myFeatureLayer.popupEnabled = true;
          },200);
0 Kudos
BlakeTerhune
MVP Regular Contributor

That does it. Thanks!

0 Kudos