Select to view content in your preferred language

Programmatically trigger a click to a specific layer

4965
1
11-06-2014 03:52 PM
BrianO_keefe
Honored Contributor

Alright...

So Robert Scheitlin, GISP‌ helped me figure out how to fire a click event and re-route the Geocoder. Now I am able to have users enter an address and instead of the fairly worthless (in my humble opinion) popup that says, "Here's you address at this address" and puts a dot on the map as... now when the user enters their address and hits enter it fires a click event on the map which pops up the various popups configured for that map.

Trigger Layer(s) Popup with Feature.Geometry

So now I am looking for bigger and better things. Now I want to have it target just specific layers. If I have a map point and a screen point, how can I target a click (or popup) for just specific layers?

Any ideas?

1 Reply
RobertScheitlin__GISP
MVP Emeritus

Brain,

    Here is how you fire the popup for a specific layer featureLayer in this snippet (you have to figure out how to get the specific layer in the widget).

        on(geocoder, "find-results", function(results){

          var mpPt = results.results.results[0].feature.geometry;

          var scrPt = map.toScreen(mpPt);

          featureLayer.graphics.some(function(graphic, index, array){

            if (graphic.geometry.getExtent().contains(mpPt)){

              if (graphic.geometry.contains(mpPt)){

                map.infoWindow.setFeatures([graphic]);

                map.infoWindow.show(mpPt);

                return true;

              }

            }

            return false;

          });

          map.centerAndZoom(mpPt,16);

        });

Don't forget to require "dojo/_base/array"