Hide popup on polygon vertice click

316
16
Jump to solution
05-11-2020 12:35 AM
rsharma
Occasional Contributor III

Hi

A default popup appear when i click on vertice of polygon. As i m also using markers with popup in my app, but they also appear on my vertices with default body.

The line in bold shows my popup, but it should not work for polygon vertices.


        // This function is called when a user clicks on the view.
        function setUpGraphicClickHandler() {
          view.on("click", function(event) {
            view.hitTest(event).then(function(response) {
              var results = response.results;
            if(results.length === 0){
              sketchViewModel.complete();
               markersketchViewModel.complete();
            }
              // Check if the new development graphic and temp graphics with attribute named newDevelopment was clicked and pass
              // the graphic to sketchViewModel.update() with reshape tool.
              results.forEach(function(result) {
                if (
                  result.graphic.layer === sketchViewModel.layer &&
                  result.graphic.attributes &&
                  result.graphic.attributes.newDevelopment
                ) {
                  sketchViewModel.update([result.graphic], { tool: "reshape" });
                } else if(
                  result.graphic.layer === markersketchViewModel.layer &&
                  result.graphic.attributes &&
                  result.graphic.attributes.newDevelopment){
                 markersketchViewModel.update([result.graphic], { tool: "reshape" });
                }
                else if(sketchViewModel.state !== 'active'){
                  sketchViewModel.cancel();
                 // view.popup.open({features: [result.graphic], location: result.graphic.geometry});
                }  else if(markersketchViewModel!== 'active' ){
                   markersketchViewModel.cancel();
                  view.popup.open({features: [result.graphic], location: result.graphic.geometry});

                }
              });
            });
          });
        }//End setUpGraphicClickHandler

0 Kudos
1 Solution

Accepted Solutions
rsharma
Occasional Contributor III

Well your code blocked my markers also, so i did some minor editing, and now it works fine.

else if(sketchViewModel.state !== 'active'){
sketchViewModel.cancel();
//view.popup.open({features: [result.graphic], location: result.graphic.geometry});
} else if(markersketchViewModel.state!== 'active'){
markersketchViewModel.cancel();
if( result.graphic.attributes &&
result.graphic.attributes.newDevelopment){
view.popup.open({features: [result.graphic], location: result.graphic.geometry});
}
}

View solution in original post

0 Kudos
16 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Rajni,

   The popup is appearing because you are telling it to in your code.

                }  else if(markersketchViewModel!== 'active' ){
                   markersketchViewModel.cancel();
                  view.popup.open({features: [result.graphic], location: result.graphic.geometry});

                }

You have markersketchViewModel!== 'active' . Well markersketchViewModel is never going to equal a string of active... Maybe you mean markersketchViewModel.state !== 'active'.

rsharma
Occasional Contributor III

Ok, but the the problem still persists, default popup still appears on vertices

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Your next issue is that you are not checking the state of your default sketchviewmodel.

rsharma
Occasional Contributor III

Sir

I am checking its state here

else if(sketchViewModel.state !== 'active'){
                  sketchViewModel.cancel();
                 // view.popup.open({features: [result.graphic], location: result.graphic.geometry});
                } 

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Rajni,

  Hmm. is that code from a different area of your code?

I was envisioning something like this:

                }  else if(markersketchViewModel.state !== 'active'  && sketchViewModel.state !== 'active'){
                   markersketchViewModel.cancel();
                  view.popup.open({features: [result.graphic], location: result.graphic.geometry});

                }

rsharma
Occasional Contributor III

No sir

I have sketchviewmodel for property boundaries and markersketchviewmodel to create marker with polygons. So i have 2 sketchview models iin my code,

but markersketchview model default popup appear for vertices of sketchviewmodel.

Now i m confused!!!

function setUpGraphicClickHandler() {
          view.on("click", function(event) {
            view.hitTest(event).then(function(response) {
              var results = response.results;
            if(results.length === 0){
              sketchViewModel.complete();
               markersketchViewModel.complete();
            }
              // Check if the new development graphic and temp graphics with attribute named newDevelopment was clicked and pass
              // the graphic to sketchViewModel.update() with reshape tool.
              results.forEach(function(result) {
                if (
                  result.graphic.layer === sketchViewModel.layer &&
                  result.graphic.attributes &&
                  result.graphic.attributes.newDevelopment
                ) {
                  sketchViewModel.update([result.graphic], { tool: "reshape" });
                } else if(
                  result.graphic.layer === markersketchViewModel.layer &&
                  result.graphic.attributes &&
                  result.graphic.attributes.newDevelopment){
                 markersketchViewModel.update([result.graphic], { tool: "reshape" });
                }
                else if(sketchViewModel.state !== 'active'){
                  sketchViewModel.cancel();
                  //view.popup.open({features: [result.graphic], location: result.graphic.geometry});
                }  else if(markersketchViewModel.state!== 'active'){
                   markersketchViewModel.cancel();
                  view.popup.open({features: [result.graphic], location: result.graphic.geometry});

                }
              });
            });
          });
        }//End setUpGraphicClickHandler

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Well you have me confused too. Why in the world do you have two different sketchview models? You do not not need a different on just to draw points/markers, that just complicates your code...

0 Kudos
rsharma
Occasional Contributor III

Well markersketchviewmodel draw boundaries also with different color and attributes you can say zones on the person properties to separate them like areas in property with low signal  areas of property or high signal, ie the idea, so they must be used and act differently alot.

So to separate basic property polygon from their numerous areas of it

0 Kudos
rsharma
Occasional Contributor III

and their graphic layer iss also differnt. to make layers working more comfortable for zones and basic properties

0 Kudos