Select to view content in your preferred language

esri.layers.FeatureLayer is not a constructor error

7323
9
06-27-2011 08:47 AM
BenReilly
Emerging Contributor
I'm trying to add a layer to a javascript map, but I keep getting an error that esri.layers.FeatureLayer is not a constructor. I can only find one post about this, where that person was not using dojo.addOnLoad. I've included my code- what is causing this?

<head>
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.3" type="text/javascript"></script>
<link href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.3/js/dojo/dijit/themes/claro/claro.css" rel="stylesheet" type="text/css" >

<script type="text/javascript">
  dojo.require("esri.map");
  dojo.require("esri.layers.FeatureLayer");
  var map;
  var campus;
function init() {
  map = new esri.Map("mapDiv");
  var spatialRef = new esri.SpatialReference({wkid:4326});
  var startExtent = new esri.geometry.Extent();
  startExtent.xmin = -88.7491;
  startExtent.ymin = 42.8345;
  startExtent.xmax = -88.7368;
  startExtent.ymax = 42.8433;
  startExtent.SpatialReference = spatialRef;


  map.setExtent(startExtent);
  var mapServiceURL = "http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer";
  map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer(mapServiceURL));
  
  campus = new esri.layers.FeatureLayer("http://[SERVER]/ArcGIS/rest/services/campusjava1/MapServer/0");


}


  dojo.addOnLoad(init);
  
</script>
</head>
<body OnLoad="init()" class="claro">
  <div id="mapDiv" style="width:1000px; height:800px; border:1px solid #000;"></div>
</body>
0 Kudos
9 Replies
derekswingley1
Deactivated User
Remove the "OnLoad="init()"" from your body tag.
BenReilly
Emerging Contributor
I took that bit out, but my layer still isn't showing up.
0 Kudos
derekswingley1
Deactivated User
Still getting the same error?
0 Kudos
BenReilly
Emerging Contributor
The constructor error went away. I guess it might be a problem with our server, since no other errors are showing up. Thanks for the quick help!
0 Kudos
derekswingley1
Deactivated User
It's working now? Glad to help!
0 Kudos
BenReilly
Emerging Contributor
It's working now? Glad to help!


No, it's still not showing up, but the original error went away.
0 Kudos
derekswingley1
Deactivated User
You'll also want to add your feature layer to the map after you create it:
map.addLayer(campus);
0 Kudos
BenReilly
Emerging Contributor
You'll also want to add your feature layer to the map after you create it:
map.addLayer(campus);


That's got it showing up! Thank you again, I appreciate it!
0 Kudos
derekswingley1
Deactivated User
You're welcome!
0 Kudos