2017-05-09 41 views
1

我已經從組合框中選擇要素(要素圖層),並縮放到要素圖層。現在我想清除組合框選擇和地圖。並將地圖縮放到其默認縮放。清晰的地圖縮放和要素圖層的幾何圖形

//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> 

,但我得到錯誤「無法讀取屬性‘幾何’的未定義」

回答

3

爲避免出現錯誤,您可以在獲取幾何圖形之前先檢查該特徵。

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); 
      } 
     }); 

注: -這將停止拋出錯誤但它會阻塞程度設置功能也。所以到setExtent你需要找到別的功能找不到功能。

希望這將幫助你:)

+0

setExtent在clearall函數中?是的,我已經設置了範圍 –

+0

oook ... coooool –

0

嘛,可能有很多原因「無法讀取未定義的特性「幾何」錯誤。

發生這種情況是因爲您正在訪問「未定義」元素的「幾何」屬性。

您代碼中的某處已添加xyz.geometry。 「xyz」可以是任何js對象。

下面是幾個類似問題的鏈接。

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

希望能上面的提示將幫助你解決這個問題。

+0

如果你看一下我的代碼ü可能看到thepoly =功能[0] .gemtry。這是問題。要素圖層將清除,但不知何故此數組不清楚。 –

+0

是的,這是一個項目 –

+0

我已經在這裏更新了我的代碼https://gis.stackexchange.com/questions/239693/clear-map-zoom-and-geometries-of-feature-layer?noredirect=1#comment374272_239693 –