AnsweredAssumed Answered

null extent for dynamically generated polygon geometry from KMLLayer

Question asked by murdoch on Apr 27, 2012
Latest reply on May 2, 2012 by DSwingley-esristaff
I get this error when attempting to use the FeatureLayer selectFeatures method using a dynamically generated polygon geometry:

In "?v=2.8 [dynamic]":
Microsoft JScript runtime error: 'xmin' is null or not an object (Ln 48, Col 41494, Ch 41494)

Ultimately, I want to use the actual geometry in a KML Layer to query another FeatureLayer, rather than use the Extent object of the KML geometries.  I'm trying to create a new geometry object that contains all of the KML Layer geometries.  There may be a better way to do this...

When evaluating breakpoints I can tell that the code fails on this line:
   targetLayer.selectFeatures(query);

Looking closer, I can see that the extent property is null for the new Geometry object after this line:
                           geom.addRing(graphic.geometry);
The graphic.geometry has a valid extent property (and presumably a valid geometry), but the geom object has an invalid extent after this line. 

Any thoughts or suggestions for me?

Thanks for your help!
Andrew




I'm using JavaScript API v2.8

Where kmlLayer = an esri KMLLayer object that contains a polygon for the state of Wyoming (http://dl.dropbox.com/u/2654618/kml/Wyoming.kml) and targetLayer = an esri FeatureLayer object:

function selectByLoadedLayer() {       if (kmlLayer) {         var geom;          var layers = kmlLayer.getLayers();         dojo.forEach(layers, function (lyr) {             if (lyr.graphics && lyr.graphics.length > 0) {                  if (lyr.declaredClass == "esri.layers.FeatureLayer") {                     if (lyr.geometryType == "esriGeometryPoint") {                         geom = new esri.geometry.Multipoint(map.spatialReference);                         dojo.forEach(lyr.graphics, function (graphic) {                             geom.addPoint(graphic.geometry);                         });                      } else if (lyr.geometryType == "esriGeometryPolygon") {                         geom = new esri.geometry.Polygon(map.spatialReference);                         dojo.forEach(lyr.graphics, function (graphic) {                             geom.addRing(graphic.geometry);                         });                      } else if (lyr.geometryType == "esriGeometryPolyline") {                         geom = new esri.geometry.PolyLine(map.spatialReference);                         dojo.forEach(lyr.graphics, function (graphic) {                             geom.addPath(graphic.geometry);                         });                     }                 } else {                     alert("KML layer contains a non-FeatureLayer layer object");                 }              }          });     } else {         alert("Please load an uploaded file or a network link first.");     }      //initialize & execute query     var query = new esri.tasks.Query();     query.geometry = geom;     query.returnGeometry = true;          targetLayer.selectFeatures(query);        }

Outcomes