Error in executing labelPoints method of geometry service

2130
9
07-15-2010 01:00 PM
NeelMallepally
New Contributor
I am trying to use the labelPoints method using ESRI's geometry service.

[HTML] var geometryService = new esri.tasks.GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); 
     var poly = new esri.geometry.Polygon(new esri.SpatialReference({ wkid: 4269 }));
     poly.addRing(parish.geometry.rings);    
     try {
         geometryService.labelPoints(poly, OnLabelPointsComplete, onError);
     } catch (Error) {
     alert(Error);
     }[/HTML]

But something is wrong. I am getting 'TypeError: _b44[0] is undefined' error in try..catch block.
Any ideas?

Thanks.
0 Kudos
9 Replies
derekswingley1
Frequent Contributor
What is parish.geometry.rings? Is that a single ring or an array of rings? I don't think addRing() can handle an array of rings...
0 Kudos
NeelMallepally
New Contributor
What is parish.geometry.rings? Is that a single ring or an array of rings? I don't think addRing() can handle an array of rings...


That's a single ring (may be I am wrong).
parish={"geometry":{ "rings":[[
[-93.342379335, 33.0183192760001], 
            [-93.2386607509999, 33.0175064210001], 
            [-93.2377443679999, 32.715973435], 
            [-93.186697908, 32.716227121], 
            [-93.186091692, 32.6729424970001], 
            [-93.1777359559999, 32.6722301020001], 
            [-93.182898703, 32.6657050920001], 
            [-93.1777075959999, 32.6648898650001]
]]  }};

I tried to construct the polygon in the following way but no luck.
var polygonJson = { "rings": parish.geometry.rings, "spatialReference": { "wkid": 4269} };
var polygon = new esri.geometry.Polygon(polygonJson); 



I also tried to use simplify method which produced a different error - "TypeError:_b06[0].geometry is undefined.



I guess I am doing something wrong in constructing the parameter(polygon) to gemotryService methods.
0 Kudos
derekswingley1
Frequent Contributor
Just remembered that the geometry service functions take Geometry[], not just Geometry. What happens if you pass in [poly] instead of just poly to labelPoints()?
0 Kudos
derekswingley1
Frequent Contributor
Also, are you using a proxy page? If you're sending a geometry that is more than a few points you'll want to have a proxy page configured.

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/ags_proxy.htm
0 Kudos
NeelMallepally
New Contributor
Also, are you using a proxy page? If you're sending a geometry that is more than a few points you'll want to have a proxy page configured.

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/ags_proxy.htm


Sorry, I tried that way ([ploy] too.

here is the code that I used
function init() {         
            //identify proxy page to use if the toJson payload to the geometry service is greater than 2000 characters.
             //If this null or not available the project and lengths operation will not work. Otherwise it will do a http post to the proxy.
             esriConfig.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";
             esriConfig.defaults.io.alwaysUseProxy = false; 

            //create map
            map = new esri.Map("mapDiv", { slider: false });
            dojo.connect(map, "onLoad", initFunctionality);
            //create and add new layer
           
            var layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://maps.lsuagcenter.com/ArcGIS/rest/services/LAFloods/LAFloodMaps/MapServer");
            map.addLayer(layer);
}

function initFunctionality(){
//code to add graphics - I have not included here
showpopUp(obj); 
}

function showpopUp(obj){
var obj;
     var parishFIPS = obj.value;
     var graphic;
     var graphics = map.graphics.graphics;
     for (var i = 0; i < graphics.length; i++) {
         if (parishFIPS == graphics.attributes.FIPS) {
             graphic = graphics;
             break;
         }
     }
     var geometryService = new esri.tasks.GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
     var geometry = graphic.geometry;
    // geometry.setSpatialReference(new esri.SpatialReference({"wkid":4269}));

     try {
         
         geometryService.labelPoints([geometry], function(labelPoints) {
                 dojo.forEach(labelPoints, function(labelPoint) {
                     var x;
                 });
             });
           

     } catch (Error) {
     alert(Error);
     } 
}   

The error caught by try catch block was _b44[0].geometry is undefined.
I used proxypage code same as in ESRI' labelPoints sample .

Does it matter if proxyPage code is used in other function where esri.Map object defined?

Thanks for your help.
0 Kudos
NeelMallepally
New Contributor
Attached is the source code.
0 Kudos
derekswingley1
Frequent Contributor
You're mixing versions...you're using v1.4 of the JS API but hitting a ArcGIS Server 10 geometry service. If you update your ref to the JS API to 2.0, your code works.  Use these links:
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.0/js/dojo/dijit/themes/tundra/tundra.css">
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0"  ></script>


Also, use esri.config as opposed to esriConfig:  http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp/inside_defaults.htm

Note: "esri.config" is a replacement to "esriConfig" as of version 1.3. If you are using version 1.2 or lower, you should refer to Default API configurations for v1.2 and lower. For version 1.3 or higher, you use "esri.config" in place of "esriConfig". Although "esriConfig" will continue to work with version 1.3, you should update your applications to use "esri.config" instead.
0 Kudos
NeelMallepally
New Contributor
The try catch error gone after changing the version 2 and changed esriConfig to esri.config ( I wonder sample in version 2.0 is using esriConfig).
Nothing is happening when I use labelPoints method. So, I used simply method first and then passed the result of simply method to labelPoints method.

In simplify method OnError function returning the below error:

[HTML]Error: Deferred Cancelled: [Exception..."Access to restrited URI denied" code: :1012: nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location:"http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0 Line 16"][/HTML]

looks like something wrong the way I am using proxy?
0 Kudos
derekswingley1
Frequent Contributor
Double check that you're correctly referencing your proxy page. You should see a POST request like this in Firebug's Net tab: 
http://localhost/proxy.ashx?http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/labelPoints
0 Kudos