Javascript 清除要素图层的地图缩放和几何图形

Javascript 清除要素图层的地图缩放和几何图形,javascript,arcgis-js-api,esri-maps,Javascript,Arcgis Js Api,Esri Maps,我从组合框中选择了要素(要素图层),并将其缩放到要素。现在我想清除组合框slection和map。并将贴图缩放到其默认缩放 //combobox selection clear dijit.byId("A1").reset(); dijit.byId("A2").reset(); dijit.byId("A3").reset(); dijit.byId("A4").reset(); dijit.byId("A5").reset(); //laye

我从组合框中选择了要素(要素图层),并将其缩放到要素。现在我想清除组合框slection和map。并将贴图缩放到其默认缩放

//combobox selection clear
    dijit.byId("A1").reset();
    dijit.byId("A2").reset();
    dijit.byId("A3").reset();
    dijit.byId("A4").reset();
    dijit.byId("A5").reset();

    //layer selection clear
     document.getElementById('A1_layer').clearSelection();
      document.getElementById('A2_layerC').clearSelection();
      document.getElementById('A3_layerC').clearSelection();
      document.getElementById('A4_layerC').clearSelection();
      document.getElementById('A5_layerC').clearSelection();



app = {
    zoomRow: function(id, which){

      var query = new Query();
      //var thePoly, theExtent;
      if(which == "Land"){
        query.where = "Name='" + (id).toString() + "'";
        console.info(query.where);
        query.returnGeometry = true;
        A1_layer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (features) {
          thePoly = features[0].geometry;
          theExtent = thePoly.getExtent().expand(2); //Zoom out slightly from the polygon's extent
          map.setExtent(theExtent);
        });
        esriRequest({
          url: "http://localhost:6080/arcgis/rest/services/........",
          content:{
            f:'json'
          },
          handleAs:'json',
          callbackParamName:'callback',
          timeout:15000
        }).then(lang.hitch(this,function(response){
          var store2 = new Memory({data:[]});
          dijit.byId("A2").set('store',store2);
          var data = array.map(response.features,lang.hitch(this,function(feat, index){
            var name = feat.attributes.nam;
            var dataItem = {
              id:index,
              name:name
            };
            return dataItem;
          }));
          store2 = new Memory({data:data});
          dijit.byId("A2").set('store',store2);
          document.getElementById('A2').value = "Select Room";
        }));
      }
<input id="A1" data-dojo-type="dijit/form/ComboBox" value="Select landing" onchange="app.zoomRow(document.getElementById('A1').value, 'Land');" data-dojo-props="maxHeight: 200" style="overflow:auto; width:200px; background-color: #E7FCCA "/ ><br></br>
  <input id="A2" data-dojo-type="dijit/form/ComboBox" value="Select room onchange="app.zoomRow(document.getElementById('A2').value, 'Room');"style="overflow:auto; width:200px ;background-color: #E7FCCA" /> <br></br>
//清除组合框选择
dijit.byId(“A1”).reset();
dijit.byId(“A2”).reset();
dijit.byId(“A3”).reset();
dijit.byId(“A4”).reset();
dijit.byId(“A5”).reset();
//图层选择清除
document.getElementById('A1_层').clearSelection();
document.getElementById('A2_layerC').clearSelection();
document.getElementById('A3_layerC').clearSelection();
document.getElementById('A4_layerC').clearSelection();
document.getElementById('A5_layerC').clearSelection();
应用={
zoomRow:函数(id,which){
var query=新查询();
//变量thePoly,范围;
如果(其中=“土地”){
query.where=“Name=”+(id).toString()+“”;
console.info(query.where);
query.returnGeometry=true;
A1\u图层。选择功能(查询、功能图层。选择\u新建、功能(功能){
多边形=特征[0]。几何体;
theExtent=thePoly.getExtent().expand(2);//稍微缩小多边形的范围
地图设置范围(范围);
});
电子请求({
url:“http://localhost:6080/arcgis/rest/services/........",
内容:{
f:‘json’
},
handleAs:'json',
callbackParamName:'callback',
超时:15000
}).然后(lang.hitch)(此,函数(响应){
var store2=新内存({data:[]});
dijit.byId(“A2”).set(“存储”,存储2);
var data=array.map(response.features,lang.hitch)(这个,函数(feat,index){
var name=feat.attributes.nam;
var数据项={
id:索引,
姓名:姓名
};
返回数据项;
}));
store2=新内存({data:data});
dijit.byId(“A2”).set(“存储”,存储2);
document.getElementById('A2').value=“选择房间”;
}));
}



“无法读取未定义的属性‘几何体’”错误可能有很多原因

这是因为您正在访问“未定义”元素的“几何体”属性

在代码的某个地方添加了
xyz.geometry
“xyz”可以是任何js对象

下面是几个类似问题的链接


希望以上提示能帮助您解决问题。

为了避免错误,您只需在获取几何图形之前先检查特征即可

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);
          }
        });
注意:-这将停止抛出错误,但它也会阻止区段集函数。因此,要
设置区段
,您需要在未找到任何功能的情况下查找其他内容


希望这能对您有所帮助:)

如果您查看我的代码,您可能会看到thepoly=feature[0]。gemtry。问题就在这里。功能层将被清除,但不知怎的,这个数组不被清除。我已在clearall函数中更新了我的代码setExtent?是的,我已将Extent设置为OK…Cooool