BearPanther.com

Create a Feature Layer from JSON

Introduction

user

bear


LATEST POSTS

Using jsformat with Sublime Text 26th July, 2014

There are many d3 demos like this but this one is mine 08th June, 2014

Blog

Create a Feature Layer from JSON

Posted on .

One of my favorite features of the feature layer is that you can create one from a feature collection. There’s a sample showing how to do this. I don’t know if many people realize you can do this…so that’s one of the reasons I’ve decided to blog about it.

An example I published for the MLB Layer shows off creating a feature layer from a feature collection. The code to create a feature layer is simple:

app.fl = new esri.layers.FeatureLayer(flJson);

The key is in the flJson variable. That’s created in the fl.js file which defines a single variable from a JSON string. That variable is passed to the feature layer constructor and some JS API magic takes care of creating the feature layer.

Why would you want to do this? Well, if you have some static data (like the states in the MLB Layer example linked above), then there’s no reason to make ArcGIS Server do the work to return your features. If you’re data doesn’t change, why not just load it from a text file? If you don’t have a good answer to that question, load your feature layer up, call featureLayer.toJson, save the result to a file and serve that file as your feature layer.

There are no comments.

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

View Comments (0) ...