N00b question: How am I triggering a TypeError within the API?

684
9
09-20-2012 11:24 AM
DonRea
by
New Contributor III
Raw beginner here, trying to figure this out. I am attempting to create a FeatureLayer object; at this point, simply creating it and adding it to a map object is all I'm shooting for. Here's my whole script:


<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.1"></script>

<script type="text/javascript">

dojo.require("esri.map");
dojo.require("esri.layers.FeatureLayer");

function init ( )
{
 var startExtent = new esri.geometry.Extent
 (
  -460735.08683161414 // bottom x
  ,109870.9884550733 // left y
  ,605952.1265091426 // top x
  ,521356.80020335224 // right y
  ,new esri.SpatialReference ({wkt : "GRS_1980"})
 );

 var map = new esri.Map ("map", {extent : startExtent, fitExtent : true});

 var features = new esri.layers.FeatureLayer
 (
  "http://gis-app.bucknell.edu:6080/arcgis/rest/services/Pilot_FeatureAccess/MapServer"
  ,{mode : esri.layers.FeatureLayer.MODE_SNAPSHOT, outFields : ["*"]}
 );
 map.addLayers ([features]);
}

dojo.addOnLoad (init);

</script>


When I load the page, the console is showing two TypeErrors being thrown within the API. I don't even know where to begin looking for the problem at my level of inexperience.
0 Kudos
9 Replies
derekswingley1
Frequent Contributor
Two things:
�??is that a valid wkt for a spatial reference? what spatial reference are you trying to use?
�??you have to add a dynamic or tiled map service to a map before you can add a feature layer
0 Kudos
DonRea
by
New Contributor III
I got the spatial reference name, as well as the extent parameters, from the map information. I've tried several that all seem to be referred to there. Here's what I see:

PROJCS["Albers_PA",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["Longitude_Of_Origin",-78.0],PARAMETER["Standard_Parallel_1",40.0],PARAMETER["Standard_Parallel_2",42.0],PARAMETER["Latitude_Of_Origin",39.0],UNIT["Meter",1.0]]

I honestly have no idea what any of that means or what I'm looking at. It looks like several nested spatial references to me, if I had to guess. Is there any doc that explains this stuff?
0 Kudos
derekswingley1
Frequent Contributor
This is helpful in explaining WKT:  http://webhelp.esri.com/arcgisserver/9.3/java/index.htm#geodatabases/the_ogc-607957855.htm

What about my second bullet point? What happens when you add a dynamic map service layer to your map before attempting to add a feature layer?
0 Kudos
DonRea
by
New Contributor III
I see the dynamic layer okay, but I'm still getting the TypeErrors attributed to serverapi.arcgisonline.com:15. Looking at that file, it seems that all of the scripting is on line 15, so that doesn't really narrow it down much.
0 Kudos
derekswingley1
Frequent Contributor
What do you see in the firebug console?

If you could post a complete, simple page that would be helpful.
0 Kudos
DonRea
by
New Contributor III
The TypeErrors are what I'm seeing in the console. Here's the page I'm testing with:
http://www-test-old.bucknell.edu/script/test/rea/map.html
0 Kudos
StephenLead
Regular Contributor III
    var features = new esri.layers.FeatureLayer
    (
        "http://gis-app.bucknell.edu:6080/arcgis/rest/services/Pilot_FeatureAccess/MapServer"
        ,{mode : esri.layers.FeatureLayer.MODE_SNAPSHOT, outFields : ["*"]}
    );
     



When you reference a feature layer, you need to include the layer's ID on the end of the URL. See the Feature Layer sample, which lists the URL as:

var featureLayer = new esri.layers.FeatureLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Hydrography/Watershed173811/MapServer/1"


note the "1" on the end.

Steve
0 Kudos
__Rich_
Occasional Contributor III
When you reference a feature layer, you need to include the layer's ID on the end of the URL.

Just to add, the reason for this is given in the reference documentation:


The feature layer inherits from the graphics layer and can be used to display features from a single layer in either a Map Service or Feature Service.


Perhaps the documentation could be improved to be a little bit more explicit/obvious?

For example the definition of the url parameter passed to the constructor reads:


URL to the ArcGIS Server REST resource that represents a feature service

Perhaps that's a good place to state that it should be a URL to single layer within a service etc.
0 Kudos
DonRea
by
New Contributor III
Thanks for the information - all of it was useful - but this specific problem turned out to be my lack of understanding of the map services themselves. I was trying to load a raster layer into a esri.featureLayer, not knowing that there even was such a thing as a feature layer in a map.
0 Kudos