Select to view content in your preferred language

Trigger Layer(s) Popup with Feature.Geometry

5693
16
Jump to solution
11-05-2014 08:48 AM
BrianO_keefe
Honored Contributor

The simple version of this question is...

Can I trigger a specific layers popup / click response using a feature.geometry point?

The more involved version is as follows...

I have some simple maps, MyWatershed, Council Districts, etc. Currently the user opens the map, enters their address, and then has to click on the map to find out what watershed or council district they are in. I would like to circumvent that. I want the user to enter their address and then wherever that dot / popup (titled "Location") shows up, instead of showing it... trigger a click event / popup for a specific layer at that point.

I found the place in the Geocoder widget where this event gets fired...

/widgets/Geocoder/Widget.js : line 238

        if (feature) {

          this.map.infoWindow.setTitle("Location");

          this.map.infoWindow.setContent(content || null);

          this.map.infoWindow.show(feature.geometry);

  

        } else if (extent) {

          this.map.setExtent(extent);

        }

I "believe" that I can interrupt the this.map.infoWindow.show command, and step in and fire off a click even at feature.geometry instead. Still researching but if anyone has a better direction, please advise!

16 Replies
RobertScheitlin__GISP
MVP Emeritus

Brian,

   Give me an address to test in your app that does this.

0 Kudos
BrianO_keefe
Honored Contributor

4901 East 5th Place South, Tulsa, Oklahoma

That is a border location.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Brian,

  Try this:

          console.info(content);

          // First thing we need to do is convert the feature.geometry to a "mapPoint" object         

          var mpPt = feature.geometry;

          console.log( "Map Point is set." );

          this.map.centerAndZoom(mpPt,16);

          console.log( "Center and Zoom" );

          // Once we have the "mapPoint" object we convert it to a "screenPoint" object

          setTimeout(lang.hitch(this, function(){

            var scrPt = map.toScreen(mpPt);

            this.map.emit("click", { bubbles: true, cancelable: true, screenPoint: scrPt, mapPoint: mpPt });

          }), 500);

BrianO_keefe
Honored Contributor

Working Code

// First thing we need to do is convert the feature.geometry to a "mapPoint" object         

var mpPt = feature.geometry;

// Then we want to zoom to the mapPoint location, 16 is an arbitrary number but close enough

this.map.centerAndZoom( mpPt, 16);

// Now we set a timeout for 1000 and then set our screenpoint and emit our click

setTimeout(lang.hitch(this, function(){ var scrPt = this.map.toScreen(mpPt); this.map.emit("click", { bubbles: true, cancelable: true, screenPoint: scrPt, mapPoint: mpPt }); }), 1000);

Ok. This is the closest yet.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Brain,

  OK, so wouldn't you say that this question has been answered?

0 Kudos
BrianO_keefe
Honored Contributor

This question is answered.

Thank you SO much.

I've literally been wanting this solution for a year... now with WAB and you I've got it.

Thanks Robert Scheitlin, GISP‌!

0 Kudos
BrianO_keefe
Honored Contributor

My Guess

I think the issue we are dealing with here is a combination of the Javascript rendering of the polygons combined with the current Zoom level.

For instance... if I am zoomed in to, let's say, Street Level. And I do an address search. Bingo. Works fine. However, if I am zoomed way out, and I try an address that is close to a borderline, then I get two Feature responses.

My co-worker noticed something. When he zoomed in to a certain level, and clicked on a polygon, the selection (light blue line) showed a polygon out that was fairly smooth. However, he zoomed out with his scroll button and the selection was still active. The smooth border was great, no worries. But once zoomed out, he tried to re-select and the polygon shape suddenly was "wonky" and nowhere NEAR as smooth. It had jagged edges that skewed the boundary.

The boundary...

I think we are dealing with an issue where the javascript rendering of these polygons trips up the screen point and the map point precision. I really think the code should zoom to feature.geometry and THEN create the map and screen points.

Just my guess.

0 Kudos