Is it possible to define operationalLayer as feature (or anything else?) dynamically from json?

We have API on our server which generates JSON as a query result from database (acting as a middleware), I can modify JSON through PHP and I would like to add this to cmv operationalLayers so I can toggle the layer on/off through layerControl. Then I need info popup on this layer and custom symbology based on categories.

I don't know how should I approach this - create KML? But the server is not accessible from internet, so it didn't work out. Create CSV and use csvLayer? Well, it works somehow, but I don't know how to style the layer based on attribute unique values. It looks like featureLayer is the best approach. According to this example it works on JS API, but I don't know how to implement it in CSV.

up vote 0 down vote accepted

The CSV Layer, Feature Layer and even the GeoJSON layer referenced in your link all are based on the Graphics Layer. If you already have something working with the CSV layer I would consider using that.

In any case, the customized styling of the features is up to you. You will have to set the renderer after the layer has been added to the map. There are numerous examples demonstrating how to set different kinds of renderers. Not knowing your data, I can't say which is best for your situation. The typical approach with CMV is to create a custom widget that would set the renderer. The widget could add the layer too. Here is a relatively simple widget that adds a FeatureLayer and sets the renderer for a heatmap. The contributed Drag and Drop widget has examples of how to set a custom renderer.

The current develop branch of CMV supports adding new layer(s) to the layerControl widget if they are not in your original operationalLayers array. Here's the basic code to do that:

var layerControlInfo = { controlOptions: { expanded: false, noLegend: true, metadataUrl: false, swipe: false }, layer: layer, title: 'Search Results', type: 'feature' }; topic.publish('layerControl/addLayerControls', [layerControlInfo]);

  • Thank you very much for your response. The csvLayer was a kind of workaround, I would prefer to add the layer (even as a graphic layer) directly from JSON but I can generate CSV aswell. I will look in to the custom widget you posted, and th adding feature in develop branch will help me aswell. Thank you once more. – Little Dec 8 '16 at 6:18
  • Using JSON instead of CSV would be my preferred option as well. I would suggest using standard geojson with the esri geojson layer. You should be able to use that layer unmodified in the develop branch of CMV as a custom layer type. You can then create your own widget to build and set the renderer. – tmcgee Dec 9 '16 at 8:12

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.