How to render feature layer from Feature collection with feature set

3029
7
12-15-2016 05:44 AM
ganeshsrinivasan
New Contributor II

Hi,

How to create feature collection object using multiple Featureset (queried from multiple arcgis rest service URL) to render to map (smart map) as feature layer

Need help in layerdefinition to accomplish the same

7 Replies
RobertScheitlin__GISP
MVP Emeritus

Ganesh,

   What have you tried? Have you looked at the FeatureCollection sample?

Feature collection | ArcGIS API for JavaScript 3.18 

0 Kudos
ganeshsrinivasan
New Contributor II
Hi Robert Scheitlin,
 
Thanks for the reply,
objective: Render multiple query task results (Rest API URL output) to the map as a smart map
 
We had progress with the help of following code which does
1. Create Two Feature set using Tow different Query Task (Map server)
2.Binding two feature set to Feature collection-We are able to find the expected number of results in feature collection with graphics
3.Create feature layer using feature collection along with info template and also able to add feature layer to the map
Issues
1.As a result we able to visualize only the first querytask output on the map, we confirmed this by viewing the pop up. doesn't contain the variables from the second querytask
2.layer rendering to map along with color,extent
Help on
1. Approach
2. why feature layer does't contain both feature set detail(verified number of graphics in feature layer)?
3.provide with any code snippets for the same
 
 Our Code Snippet
var queryTask = new QueryTask("https://xxxxxxx.arcgis.com/arcgis/rest/services/xxxxxxx/MapServer/xx/query?token="+accessTokenForSmartMap);
  var query = new Query();
  query.where = "1 > 0";
  query.outSpatialReference = {wkid:3857}; 
  query.returnGeometry = true;
  query.outFields = ["RTSALESTOT","OBJECTID"];
  promiseCallReturnForRetail = queryTask.execute(query);
 
  var queryTask1 = new QueryTask("https://xxxxxx.arcgis.com/arcgis/rest/servicesxxxxxxxx/MapServer/xx/query?token="+accessTokenForSmartMap);
  var query1 = new Query();
  query1.where = "1 > 0";
  query1.outSpatialReference = {wkid:3857}; 
  query1.returnGeometry = true;
  query1.outFields = ["TOTPOP_CY","OBJECTID"];
  promiseCallReturnForPopulation = queryTask1.execute(query1);
  promises = all([promiseCallReturnForPopulation,promiseCallReturnForRetail]);
        promises.then(outputOfTwoLayers);
function outputOfTwoLayers(results){
        
            var allFeatureSet = [];
        
        arrayUtils.forEach(results,function(value,key){
       
arrayUtils.forEach(results[key].features,function(value,key){
allFeatureSet.push(value);
});
});
     
        var featureCollection = {
          "layerDefinition": null,
          "featureSet": {
          "features" : allFeatureSet,
          "geometryType": "esriGeometryPolygon"
         
          }
        };
        
        featureCollection.layerDefinition = {
          "geometryType": "esriGeometryPolygon",
          "objectIdField": "OBJECTID",
          "fields": [{
          "name": "OBJECTID",
            "alias": "OBJECTID",
            "type": "esriFieldTypeOID"
          },
          {
          "name": "TOTPOP_CY",
            "alias": "2016 Total Population (Esri)",
            "type": "esriFieldTypeInteger"
          },
          {
          "name": "RTSALESTOT",
            "alias": "2016 Total Retail Sales (including Food/Drink Sales)",
            "type": "esriFieldTypeDouble"
          },
          {
      "name": "title",
      "alias": "Title",
      "type": "esriFieldTypeString"
     }]
          };
        
        console.log(featureCollection);
        
        var featureLayer3 = new FeatureLayer(featureCollection,{
        showAttribution : true,
        mode : FeatureLayer.SELECTION_ADD,
        id : "smartMap",
            "infoTemplate": {
            title:"Smart Map Data",
            content: "<b>TOTPOP_CY : </b> ${TOTPOP_CY} <br><b>RTSALESTOT : </b> ${RTSALESTOT} <br>"}
        });
console.log(featureLayer3);
console.log(mapObj);
var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,255,255,1.0]), 1),new dojo.Color([125,125,125,0.35]));  
      
featureLayer3.setRenderer(new esri.renderer.SimpleRenderer(symbol));  
  
mapObj.addLayer(featureLayer3); 
       
        };
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ganesh,

   So you want the geometries and attributes from two different layer queries to be combined into on FeatureLayer? Will the geometries overlap? 

0 Kudos
ganeshsrinivasan
New Contributor II

Robert Scheitlin,

Yes, we need to achieve the concept which you mentioned

we need to use overlay layers to achieve ?its same set of geometry data of polygon(feature set) to be shown in the map( can it be overlapped?)

else how to achieve this?

thanks

ganesh

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ganesh,

its same set of geometry data of polygon(feature set) to be shown in the map( can it be overlapped?)

So if I am interpreting this correctly the geometries are identical but have different attributes? 

0 Kudos
ganeshsrinivasan
New Contributor II

Hi Robert Scheitlin,

Thanks for response

Your interpretation is correct , can you please provide your inputs on the approach that we are following.

if so our approach is correct, can you please help us out with any help links or code snippets

Thanks

Ganesh

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ganesh,

  Your scenario is quite unique so I have not done this before or have any samples for you on this subject. The best I can do is provide some general guidance.  I would create a FeatureLayer (FL) using the fields combined from both sets of attributes that way you can add both of the results to the one FL. When you click on the feature to get a popup you will get a popup containing a record selector for those geometries that are duplicated.

0 Kudos