Adding a Graphic Layer to the LayerList widget

3922
3
11-10-2014 07:02 AM
NEvatt
by
New Contributor III

Hello,

I am working on a widget that adds geocoded points from an RSS Feed to a GraphicsLayer and then adds that GraphicsLayer to the map using code similar to this:

hGraphics = new esri.layers.GraphicsLayer({ "id": "highlights","displayOnPan": true,"opacity": "1.0", "title":"RSS Feed" });

  this.map.addLayer(hGraphics)...

(for each point)

...var symbol = new esri.symbol.PictureMarkerSymbol("widgets/RSSFeed/images/RSS-logo_25.png", 25, 25);

    var x = node[0][1];

    var y = node[0][0];

    var graphic = new Graphic(new Point(x, y), symbol, attr, infoTemplate);

    hGraphics.add(graphic);

The points get added to the map correctly, the only problem is that since the layer is a GraphicsLayer, the LayerList widget does not automatically add the newly GraphicsLayer to the list of layers which can be toggled.

Inside the Widget.js file of the LayerList widget, there is a function called "_onLayerInfosChanged" which updates the layers list when different type of layer like the ArcGISDynamicMapServiceLayer gets added to the map. This function is not called when my GraphicsLayer is added.

From what figure there are two options: either create a different type of layer and add the points to it, like a FeatureLayer OR configure the LayerList widget to treat a GraphicsLayer as a normal layer.  I am yet to get either of these options working.

Any Ideas?

Thanks,

Nat

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Nat,

   I would definitely go with adding your results to the map as a FeatureLayer. Modifying the LayerList widget to allow for GraphicsLayers to be added will likely lead to other issue beside you having to maintain your code changes as the widget gets updated by esri. You can find an example of add results as a FeatureLayer in the QueryWidget if you are looking for code examples to go by.

NEvatt
by
New Contributor III

Hi Robert,

Thanks for the quick response, I was indeed able to create an empty FeatureLayer, add the points to it, and when I added the layer to the map the LayerList widget picked it up no problem.  In the end I modelled the FeatureLayer after this comment left on this forum post: http://gis.stackexchange.com/questions/8791/featurelayer-creating-in-javascript-arcgis-api (just in case anyone wanted to do something similar).

Thanks Robert,

Nat

0 Kudos
AndrewBiggins
New Contributor III

I have added an idea to add support for graphics layers in the LayerList widget:

https://community.esri.com/ideas/12239

0 Kudos