Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My ultimate goal is a map which can toggle the visibility of layers on an ArcGIS map. However the data I need to use is not available as a feature service, I have to build it programatically from feature collections. I want to make AMD modules that will return FeatureLayers to a script that is in control of the map. I also want the FeatureLayers to contain events.

Does anyone have any advice on how to accomplish this? Can I setup the events and map markers without access to the map object? Maybe pass the map object to the FeatureLayer constructor? Any advice is greatly appreciated.

EDIT: This is what the code that calls my modules looks like.

require(["dojo/parser", "dojo/_base/array", "dojo/request", "dojox/layout/TableContainer", "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/layout/AccordionContainer", "esri/map", "esri/layers/FeatureLayer",
             "esri/dijit/Popup", "esri/tasks/query", "dgrid/Grid", "dojo/json", "js/cbibsModule", "dojo/domReady!"],

              function (parser, array, request, TableContainer, BorderContainer, ContentPane, AccordionContainer, map, FeatureLayer, Popup, query, Grid, JSON, cbibsModule) {
                function init(){
                    _map = new map("mapDiv", {
                      basemap: "oceans",
                      center: [-77.0357, 38.7877],
                      zoom: 7
                    var cbibs = new cbibsModule();
                    var fl = cbibs.requestCBIBS(_map);

cbibs.requestCBIBS(_map) should not only return a Feature Layer object, but should also pass the _map variable by reference so the Feature Layer can attach events to it. This is not working. I don't get any errors but the map does not display.

UPDATE: This is my updated code but my markers are still not drawing on the map, nor am I getting any errors. I build the Graphic objects in a module and return them in an array. I then add them to the Graphics Layer and add it to the Map (at least I think that's what's going on). Any suggestions??

          function (parser, ready, array, request, TableContainer, BorderContainer, ContentPane, AccordionContainer, map, GraphicsLayer, Popup, query, Grid, JSON, cbibsGfxModule, crwoModule) {
            var Map, gfxLayer;
            function init(){
                Map = new map("mapDiv", {
                  basemap: "oceans",
                  center: [-77.0357, 38.7877],
                  zoom: 7
                dojo.connect(Map, "onLoad", addGraphics);

            function addGraphics(){
                gfxLayer = new esri.layers.GraphicsLayer();
                var gfxContainer = []; // Store array returned by cbibsGfxModule.getAllCurrentReadings()
                var cbibs = new cbibsGfxModule();
                gfxContainer = cbibs.getAllCurrentReadings();
                array.forEach (gfxContainer, function (item, i) {
share|improve this question
Maybe I'm missing something, But why aren't you using a graphics layer? – Devdatta Tengshe Jul 19 '13 at 18:59
I'm not sure, I'm still new to this. Could you please tell me why I should be using a graphics layer? – oborden2 Jul 19 '13 at 19:07
up vote 1 down vote accepted

As far as I have understood, you want two things:

  • You want all your features in one layer which you can switch on and off
  • This Layer needs to have certain Events.

What you are looking for, is called a Graphics Layer. It consists of Graphics, which are basically an array of Features.

You should look at this Document: Working with graphics

You should instantiate a new Graphics Layer, add your features to it, and then add the graphics layer to the map.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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