Feature Query Selection.

1808
1
01-31-2016 10:05 PM
NadirHussain
Occasional Contributor II

Dear all

on my page load event i create one circle graphic element.by using below code. in page load event

i add one feature layer.

           map.addLayers([myFeatureLayer]);

           map.on("layers-add-result", drawCircle(evt));

function drawCircle(evt){

               var ptLayer = evt.layers[0].layer;

                var pt = new Point("45.42", "23.24", map.SpatialReference);

                var selectQuery = new Query();

                 circle = new Circle({

                        center: pt,

                        geodesic: true,

                        radius: 500,

                        radiusUnit: "esriMiles"

                    });

                     map.graphics.clear();

                    var graphic = new Graphic(circle, circleSymb);

                    map.graphics.add(graphic);

                    var selectQuery= new Query();

                    selectQuery.geometry = circle.getExtent();

                    selectQuery.distance = 500;

                    selectQuery.units = "miles";

                    selectQuery.returnGeometry = true;

                     ptLayer .selectFeatures(selectQuery, FeatureLayer.SELECTION_NEW, function (features) {

                            if (features.length > 0) {

                                 updateFeature = features[0];

                                map.infoWindow.setTitle("Editor");

                                // map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));

                                map.infoWindow.show(pt, map.getInfoWindowAnchor(pt));

                            

                            }

                            else {

                                map.infoWindow.hide();

                            }

                        });

}

if i call this function on map click event it return features.But if i call this on page load event.no feature returns.what can be the reason.please help.i have to use this code my production part.

thanks once again.

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus

Nadir,

   Make sure you add the "on" event handler line before you add the layer and also make sure the map is loaded by listening to the load event on the map before you call your function. Your web console is likely giving you an error about what is going on.