Skip to content Skip to sidebar Skip to footer

Clear Map Zoom And Geometries Of Feature Layer

i have selected feature(feature layer) from combobox and it zoom to the feature . now i want to clear combobox slection and map . and zoom map to its default zoom. //combobox selec

Solution 1:

To avoid the error you can simply check the feature first, before getting the geometry.

A1_layer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (features) {
        if(features && features[0] && features[0].geometry){
             thePoly = features[0].geometry;
             theExtent = thePoly.getExtent().expand(2); //Zoom out slightly from the polygon's extent
             map.setExtent(theExtent);
          }
        });

Note:- this will stop throwing error however it will block the extent set function also. So to setExtent you need to find something else incase of no feature found.

Hoping this will help you :)

Solution 2:

Well, there may be many reasons for "Cannot read property 'geometry' of undefined" error.

This is happening because you are accessing "geometry" attribute of a "undefined" element.

somewhere in your code you have added xyz.geometry. "xyz" can be any js object.

Below are the link of few similar issues.

https://geonet.esri.com/thread/186541-uncaught-typeerror-cannot-read-property-geometry-of-undefined

https://gis.stackexchange.com/questions/182364/uncaught-typeerror-cannot-read-property-on-of-undefined

Hoping above hint will help you to resolve the issue.

Post a Comment for "Clear Map Zoom And Geometries Of Feature Layer"