Select to view content in your preferred language

Simple FeatureLayer Selection not working

599
0
08-23-2013 10:26 AM
PremRadhakrishnan
Regular Contributor
Hello All,
Can someone please look at this code and tell me why the selection is not showing up ? All I am trying to do is select a parcel when the page loads .

The map zooms to the correct extent but does not highlight the parcel(s) . Sometimes it can return multiple results.

The code itself is a simplified modified version of the example here https://developers.arcgis.com/en/javascript/jssamples/exp_history.html
Thanks in advance.

<script>
var map;
var parcels;
require([
        "esri/map", "esri/layers/FeatureLayer",
        "esri/layers/ArcGISTiledMapServiceLayer", "esri/tasks/query",
        "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleLineSymbol",
        "esri/graphic", "esri/dijit/Popup", "esri/dijit/PopupTemplate",
        "esri/urlUtils", "esri/graphicsUtils",
        "dojo/_base/Color",
        "dojo/on", "dojo/query", "dojo/parser", "dojo/dom-construct",

        "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
      ], function(
        Map, FeatureLayer,
        ArcGISTiledMapServiceLayer, Query,
        SimpleFillSymbol, SimpleLineSymbol,
        Graphic, Popup, PopupTemplate,
        urlUtils, graphicsUtils,
        Color,
        on, query, parser, domConstruct
      ) {
   //apply a selection symbol that determines the symbology for the selected parcel
  
   var sfs = new SimpleFillSymbol(
     SimpleFillSymbol.STYLE_SOLID,
     new SimpleLineSymbol(
    SimpleLineSymbol.STYLE_SOLID,
    new Color([111, 0, 255]),
    2
     ),
     new Color([111, 0, 255, 0.15])
   );
 

   map = new Map("map", { slider:false, logo:false, basemap: "hybrid" , extent: new esri.geometry.Extent({"xmin":-9857930.663880095,"ymin":4551977.908437532,"xmax":-9408480.93756328,"ymax":5155524.683777255,"spatialReference":{"wkid":102100}}) });
   parcels = new FeatureLayer("MAP_SERVICE_URL",
          { outFields: ['PIN_18'], mode: FeatureLayer.MODE_SELECTION });
  
   parcels.setSelectionSymbol(sfs);
  
   map.on("layers-add-result", function (result) {
    var parcelid = "53-01-40-109-616.000-008";
    selectParcel(parcelid);
  
   });
  
   map.addLayers([parcels]);
   function selectParcel(parcelid) {
    var query = new Query();
    query.where = "PIN_18 = '"  + parcelid + "'";
    query.outSpatialReference = 102100;
    var deferred = parcels.selectFeatures(query, FeatureLayer.SELECTION_NEW,
    function (selection) {
     console.log(selection);
     //var center = graphicsUtils.graphicsExtent(selection).getCenter();
     var extent = graphicsUtils.graphicsExtent(selection).expand(5);
     // zoom to center and set extent
     //map.centerAt(center);
     map.setExtent(extent);
    
      
    });
   }
    });
0 Kudos
0 Replies