AnsweredAssumed Answered

get Extent from Feature Layer after Definition Expression

Question asked by royarturo on Apr 8, 2014
Latest reply on Apr 8, 2014 by royarturo
Hello

I want to be able to type a state name in a

[HTML]<input type="text" id = "statename"></input>[/HTML]

and when I click a submit button, two things happen

1 - draw the state in the map ---> I already did this.

2 - zoom to the state extent. (I don't want to use the infoTemplate and then the Zoom to function. I want to be able to call this Zoom to function when I click the submit button)


the code:


var map, geocoder, extent, sr, currentExtent, censusdef, featureLayer, loadStates, renderer, selected_state;
require(["esri/map", "esri/layers/FeatureLayer", "esri/InfoTemplate",
    "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol",
    "esri/renderers/SimpleRenderer", "esri/tasks/query",
    "dojo/parser", "dojo/_base/Color",
    "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"],
function(Map, FeatureLayer, InfoTemplate,
    SimpleLineSymbol, SimpleFillSymbol,
    SimpleRenderer,
    parser, Color, Query) {
    map = new esri.Map("map", {
        center: [-96.24, 38.1],
        zoom: 4,
        basemap: "hybrid"
    });
    sr = new esri.SpatialReference({wkid:4326});
    currentExtent = new esri.geometry.Extent();


    var symbol = new SimpleFillSymbol().setColor(new Color([255,0,0,0.4]));
    var renderer = new SimpleRenderer(symbol);
    featureLayer = new esri.layers.FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/2", {
        //infoTemplate: new InfoTemplate(" ", "${state_name}"),
        mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
        displayOnPan: true,
        styling: true
    });
    var b = document.getElementById('showstate');
    var selected_state = document.getElementById('statename').value;
    featureLayer.setDefinitionExpression("state_name = '"+selected_state+"'");
    featureLayer.setRenderer(renderer);

    b.addEventListener('click', function (){       
            var b = document.getElementById('showstate');
            var selected_state = document.getElementById('statename').value;
            //featureLayer.setDefinitionExpression("state_name = '"+selected_state+"'");
            featureLayer.setRenderer(renderer);
            map.addLayer(featureLayer);
        }, false);

});



is there anyway to access to the extent of the selected featureLayer? not the entire featurelayer, but only the result after the DefinitionExpression. Something like FeatureLayer.getExtent();

thanks!

Outcomes