Select to view content in your preferred language

Adding FeatureLayer issue

963
2
05-01-2012 08:14 PM
karthik_BharadwajT
Emerging Contributor
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

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( "ROAD NAME: ${LINK_ID}
" + "CAT${CAT}");

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);
0 Kudos
2 Replies
StephenLead
Honored Contributor
A quick tip is to highlight your code then hit the # button above, to format it in a more readable manner.

I think the problem is with the line:

[LEFT]var featureLayer = new esri.layers.FeatureLayer("http://karthikpc:8399/arcgis/rest/services/Carriage_Mercantor/FeatureServer", {
mode: esri.layers.FeatureLayer.MODE_ONDEMAND, infoTemplate: infoTemplate, outFields: ["*"] });[/LEFT]


You are missing the layer ID from the end. It should be something like

http://karthikpc:8399/arcgis/rest/services/Carriage_Mercantor/FeatureServer/0

S
ee the Feature Layer sample for further info.


Steve
0 Kudos
karthik_BharadwajT
Emerging Contributor
Hi,

Thank you very much for your reply.

I had corrected the code by adding the layer id and i was able to verify the featurelayer has been loaded using an onLoad event. Would the feature layer be visible,like the normal layer?


var featureLayer = new esri.layers.FeatureLayer("http://karthikpc:8399/arcgis/rest/services/Carriage_Mercantor/FeatureServer/0", {
            mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
            infoTemplate: infoTemplate,
            outFields: ["*"]
        });


When i added an onclick event with the feature Layer it didnt seem to work. My final goal would be given a set of roads on the network , I should be able to highlight them, I thought using the feature Layer would prove useful, correct me if i was wrong.
0 Kudos