清除要素图层的地图缩放和几何 [英] clear map zoom and geometries of feature layer

查看:117
本文介绍了清除要素图层的地图缩放和几何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从组合框中选择了要素(要素层),并且将其缩放到要素.现在我想清除组合框选择和地图.并缩放到其默认缩放比例.

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

但是我收到错误消息无法读取未定义的属性'geometry'"

but i got error "Cannot read property 'geometry' of undefined"

推荐答案

为避免该错误,您可以在获取几何图形之前先简单地检查特征.

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

注意:-,这将停止引发错误,但同时也会阻塞范围设置功能.因此,对于setExtent,您需要在找不到功能的情况下找到其他内容.

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.

希望这对您有帮助:)

这篇关于清除要素图层的地图缩放和几何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆