1

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.

  • Your code is almost correct – Jagadesh May 23 '13 at 8:49
2
 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);

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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