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.

Hi I am currently exploring ARCGIS Javascript API. I have my own map services and feature services up on my local server. I would want to use the FeatuerLayer to select and highlight feature on the map. But when i add my feature service i get the following error.

TypeError: Unable to draw graphic (geometry:null, symbol:null): _14 is undefined**

I am not able to figure out what this could be. And I am not sure if the feature layer has been added to the map or not. How could I check if it has been added? I tried using a dojo.connect method with the FeatureLayer with an onClick event. But this doesn't seem to work. Have placed the code below

Code:

esri.config.defaults.io.proxyUrl = "proxy.ashx";
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("esri.map");
dojo.require("esri.layers.FeatureLayer");
dojo.require("esri.tasks.query");

var map;
var selectionToolbar;
var infoTemplate = new esri.InfoTemplate();
infoTemplate.setTitle("${ROADNAME}");
infoTemplate.setContent("<b>ROAD NAME: </b>${LINK_ID}<br/>" + "<b>CAT</b>${CAT}</b>");

function init() {
  try {
    var initExtent = new esri.geometry.Extent({
      "xmin": 103.55,
      "ymin": 1.13,
      "xmax": 104.16,
      "ymax": 1.56,
      "spatialReference": {
        "wkid": 4326
      }
    });

    map = new esri.Map("map", {
      extent: esri.geometry.geographicToWebMercator(initExtent)
    });

    var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");

    //my map service layer
    var basemap_sing = new esri.layers.ArcGISTiledMapServiceLayer("http://karthikpc:8399/arcgis/rest/services/Carriage_Mercantor/MapServer", {
      displayLevels: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
    });
    // my feature layer which i am not able to use              
    var featureLayer = new esri.layers.FeatureLayer("http://karthikpc:8399/arcgis/rest/services/Carriage_Mercantor/FeatureServer", {
      mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
      infoTemplate: infoTemplate,
      outFields: ["*"]
    });

    map.addLayer(basemap);
    map.addLayer(base_sing);
    map.addLayer(featureLayer);

    dojo.connect(map, "onLoad", initSelectToolbar);
    dojo.connect(featureLayer."onClick", helloworld);
  } catch (e) {
    alert('An error has occurred: ' + e.message);
  }

}

function helloworld() {
  alert("hello world");
}

dojo.addOnLoad(init);
share|improve this question

2 Answers 2

The URL passed to esri.layers.FeatureLayer needs to be for a specific layer. Your code points to the root of the feature service.

To fix this, append the layer index of the layer the URL. For instance, in this feature service, the rivers layer is layer 1. To create a feature layer using this layer, you would use this url: http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hydrography/Watershed173811/FeatureServer/1. This is shown in the ONDEMAND feature layer sample although the sample uses the map service. If you're only displaying data, you can use either the map service for the feature service. If you want to edit the data via the ArcGIS API for JavaScript, you have to use the feature service URL.

share|improve this answer
    
Thanks for your reply. I had tried it, I think the feature layer has been added. I checked using an onload event. But when i tried the onclick event on the feature layer it did not work out. Please suggest a best way to identify if a feature layer has been added and to make use of it. My goal of my application is to 1) highlight few features, 2) edit few features. From the samples i thought a feature layer would help. Please correct me if I am wrong. –  Karthik Bharadwaj May 2 '12 at 15:04
    
@KarthikBharadwaj please post a new question, the comments aren't the appropriate place for this type of discussion. –  Derek Swingley May 2 '12 at 15:34

A FeatureLayer ends with a digit, which is more of an array concept.

my/service/url/points/here

vs.

my/feature/url/points/here/0

The first url points to a service containing anywhere from 1 to X Features. Whereas the second url points to a specific Feature inside of that service.

Hope that helps...

share|improve this answer

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.