1

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);
 console.log(_map);
 }
 dojo.ready(init);
 }
 )

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) {
 gfxLayer.graphics.push(item); 
 }); 
 Map.addLayer(gfxLayer);
 console.log(Map);
 };
 dojo.ready(init);
 }
asked Jul 19, 2013 at 16:54
2
  • 1
    Maybe I'm missing something, But why aren't you using a graphics layer? Commented Jul 19, 2013 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? Commented Jul 19, 2013 at 19:07

1 Answer 1

1

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.

answered Jul 20, 2013 at 5:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.