dojo.require("esri.tasks.query"); function init() { var queryTask = new esri.tasks.QueryTask("http://sampleserver5.arcgisonline.com/ArcGIS/rest/services/Energy/Geology/MapServer/1"); var query = new esri.tasks.Query(); query.objectIds = [1]; query.outFields = ["*"]; queryTask.execute(query, function(featureSet) { var domains = []; var requestHandle = esri.request({ url: "http://sampleserver5.arcgisonline.com/ArcGIS/rest/services/Energy/Geology/FeatureServer/1", content: {f:"json"}, callbackParamName:"callback", load: function(res){ dojo.forEach(res.fields,function(f){ if (f.domain != null) { domains[f.name] = f.domain.codedValues; } }); dojo.forEach(featureSet.features,function(f) { for(attr in f.attributes) { if (attr in domains) { dojo.forEach(domains[attr],function(d) { if (d.code == f.attributes[attr]) f.attributes[attr] = d.name; }); } } }); console.log(featureSet.features); }, error: function(res){ console.log(res); } }, {useProxy:false}); },function(err){ console.log(err); }); } dojo.addOnLoad(init);
Looking forward to see what you come up with. This service has several layers with coded value domains: http://sampleserver5.arcgisonline.com/ArcGIS/rest/services/Energy/Geology/MapServer
org.mymanatee.common.util.getAliasDomainFormat=function(layerdesc, fieldName, field_val){ dojo.forEach(layerdesc.fields, dojo.hitch(this, function(ldf){ if(ldf.name==fieldName){ //replace with aliases fieldName = ldf.alias; // alert(ldf.name+" : "+ldf.type); if(ldf.type=="esriFieldTypeDate"){ // alert(ldf.type); field_val= dojo.date.locale.format(new Date(field_val), {datePattern: "MM/dd/yyyy"}); // alert(field_val); } if(ldf.type=="esriFieldTypeDouble"){ // alert(ldf.type); field_val= dojo.number.format(field_val,{places: 2 }); // alert(field_val); } if(ldf.domain){ dojo.forEach(ldf.domain.codedValues, dojo.hitch(this, function(domain){ if(field_val==domain.code){ field_val=domain.name; } })); } } })); return [fieldName,field_val]; }
org.mymanatee.common.util.getLayerDesc=function(url){ var desc; var layerurl= ""+url.replace("http://home.intranet","")+"/?f=json"; layerurl= ""+layerurl.replace("http://www.mymanatee.org",""); var params = { url: layerurl, handleAs: "json", sync: true }; var deferred =dojo.xhrGet(params); desc= deferred.results[0]; return desc; }
The general workflow would be:use esri.request() to get your layer's metadatakeep track of fields with domainsbuild an object for each field with a domain to map coded values to actual valuesexecute a querywhen processing the query results, map the coded values from the attributes to actual values
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.