清除地图缩放和要素图层的几何形状
clear map zoom and geometries of feature layer
我已经从组合框中选择了特征(特征层)并缩放到特征。现在我想清除组合框选择和地图。并将地图缩放到默认缩放。
//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>
但我收到错误 "Cannot read property 'geometry' of undefined"
嗯,"Cannot read property 'geometry' of undefined"错误的原因可能有很多。
发生这种情况是因为您正在访问 "undefined" 元素的 "geometry" 属性。
您在代码中的某处添加了 xyz.geometry
。 "xyz"可以是任何js对象。
以下是几个类似问题的link。
https://geonet.esri.com/thread/186541-uncaught-typeerror-cannot-read-property-geometry-of-undefined
希望以上提示能帮助您解决问题。
为避免错误,您可以先检查特征,然后再获取几何图形。
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
你需要寻找其他东西,以防找不到任何功能。
希望对您有所帮助:)
我已经从组合框中选择了特征(特征层)并缩放到特征。现在我想清除组合框选择和地图。并将地图缩放到默认缩放。
//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>
但我收到错误 "Cannot read property 'geometry' of undefined"
嗯,"Cannot read property 'geometry' of undefined"错误的原因可能有很多。
发生这种情况是因为您正在访问 "undefined" 元素的 "geometry" 属性。
您在代码中的某处添加了 xyz.geometry
。 "xyz"可以是任何js对象。
以下是几个类似问题的link。
https://geonet.esri.com/thread/186541-uncaught-typeerror-cannot-read-property-geometry-of-undefined
希望以上提示能帮助您解决问题。
为避免错误,您可以先检查特征,然后再获取几何图形。
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
你需要寻找其他东西,以防找不到任何功能。
希望对您有所帮助:)