Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have ArcGIS Server 9.3, and I'm trying to use the JS API. I successfully displayed the map, and I can locate and zoom to a feature based on ParcelID value. The problem is I can't highlight this parcel. I mean I tried to configure the symbol, but its not being displayed. Here's the code:

<script>

    dojo.require("esri.map");
    dojo.require("esri.layers.FeatureLayer");
    var map,featureLayer,query,sfs;

  function init() {
    map = new esri.Map("mapDiv", { 
      sliderOrientation: "horizontal"
    }); 


    var imageParameters = new esri.layers.ImageParameters();
    imageParameters.format = "PNG24";  //set the image type to PNG24, note default is PNG8.

    //Takes a URL to a non cached map service.
    var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://*******/*****/rest/services/****/MapServer", {
      "opacity":1, 
      "imageParameters":imageParameters
    });
    dynamicMapServiceLayer.setVisibleLayers([4,10,11,16]);
    map.addLayer(dynamicMapServiceLayer);


    //Locate Parcel--------
    sfs = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT,new dojo.Color([255,0,0]), 2),new dojo.Color([255,255,0,0.25]));

    featureLayer  = new esri.layers.FeatureLayer("http://*****/*****/rest/services/*****/MapServer/4", {
            outFields: ["*"],
            mode: esri.layers.FeatureLayer.MODE_SELECTION
        });
    featureLayer.setSelectionSymbol(sfs);
    map.addLayers([featureLayer]);

    query = new esri.tasks.Query();        
    query.where = "ParcelID_NS = '101010101'";

    var deferred = featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (selection) {
        var stateExtent = selection[0].geometry.getExtent().expand(3.0);
        map.setExtent(stateExtent);
    });
    //----------------------    
  }


  dojo.ready(init);

</script>

Any help? Thanks.

share|improve this question
    
Your code is almost correct –  Jagadesh May 23 '13 at 8:49
add comment

1 Answer

up vote 2 down vote accepted
 var deferred = featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (selection) {
    var stateExtent = selection[0].geometry.getExtent().expand(3.0);
    map.setExtent(stateExtent);

try this instead of

 featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);

You can get the selected features from featurelayer.FeatureSelection() method available which will return as Graphics from that you do getExtent().expand(3.0);

share|improve this answer
    
I can't see any deference ? –  Mathboy May 23 '13 at 10:09
    
Try the updated one once. For me its worked fine. –  Jagadesh May 23 '13 at 10:21
    
Is it worked for you –  Jagadesh May 24 '13 at 4:27
    
Yes , thank you –  Mathboy Jun 3 '13 at 6:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.