Select to view content in your preferred language

Identify features in NavMenu

1336
12
08-02-2010 11:58 PM
ManuelFrias
Regular Contributor
Hi,

From the code Robert shared some time ago (http://gis.calhouncounty.org/SFVDemo) I am using the NavMenu which provides a shortcut to the navigation buttons.

I would like to add a new button which would mimic the IdentifyWidget. I added a new public static const to SiteContainer.mxml

  public static const WIDGET_SHOW_INFO:String    ="widgetShowInfo";


which will then call the  public static const SHOW_INFOWINDOW in AppEvent.as

What I find tricky  is how to make the infoData object.

var infoData:Object =
         *       {
         *          icon: icon,              //a Image object
         *          title: "a title string",
         *          content: "a string",
         *          link: "http://a.url.com",
         *          point: point,            //a Point object
         *          geometry: geom           //a Geometry object
         *       };


I looked at IdentifyWidget.mxml and thought I would try to replicate everything in there.

Is there an easier way or should I just go on?

Thanks,
Manolo
Tags (2)
0 Kudos
12 Replies
RobertScheitlin__GISP
MVP Emeritus
Manolo,

   I think that you are on the right path. Do you need any specific help?
0 Kudos
ManuelFrias
Regular Contributor
Hi Robert,

yes, I would need some help (see attached file).

I think my problem is that when I define the variable map:

private var map:Map;


map doesn't get all the layers and I get the error "Cannot access a property or method of a null object reference" here:

map.addLayer(graphicsLayer);


If I initialize the variable (private var map:Map = new Map) the error disappears but map doesn't get any layers.

I've been looking what IdentifyWidget does and there there is no map definition since it gets it from BaseWidget.as. But how does it add all the layers? I don't find it.

Manolo
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Manolo,

  If it is just the map then just do this

private var map:Map = SiteContainer.getInstance().controller.map;
0 Kudos
ManuelFrias
Regular Contributor
Hi,

I still get  "Cannot access a property or method of a null object reference." because map is null, I guess.

Manolo
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Manolo,

Attach your updated code so I can see what might be going wrong.
0 Kudos
ManuelFrias
Regular Contributor
Hi Robert,

here you are the code with your suggestion.

Manolo
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Manolo,

  Here you go the issue was that the mapmanager had not created the map yet when we were calling for it.
0 Kudos
ManuelFrias
Regular Contributor
Thanks Robert!

I could hardly have figured out myself.

I wonder if you know where I can get the visible layers? I tried to get the LayerIds property of identifyParams and then assign the visibleLayers

identifyParams.layerIds = dynamicLayer.visibleLayers.source;


but that doesn't work (see attached code). I did something similar in my IdentifyWirdget.mxml and worked out fine.

Manolo
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Manolo,

   Try this:

private function identifyFeatures():void
   {
    var identifyParams:IdentifyParameters = new IdentifyParameters();
    identifyParams.returnGeometry = false;
    identifyParams.tolerance = identifyTolerance;
    identifyParams.geometry = identifyPoint;
    identifyParams.width = map.width;
    identifyParams.height = map.height;
    identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;
    identifyParams.mapExtent = map.extent;
    
    for (var i:Number = map.layerIds.length -1; i >= 0; i--)
    {
     identifyParams.layerIds = null;
     var layer:Layer = map.getLayer(map.layerIds);
     var url:String;
     if (layer.visible)
     {
      if (layer is ArcGISDynamicMapServiceLayer)
      {
       var dynamicLayer:ArcGISDynamicMapServiceLayer = layer as ArcGISDynamicMapServiceLayer;
       url = dynamicLayer.url;
       if(identifyLayerOption == "visible")
                     {
                      identifyParams.layerIds = dynamicLayer.visibleLayers.source;
                      identifyParams.layerOption = "all";
                      if(dynamicLayer.visible == false)
                       url="";
                     }
       
      }
      else if (layer is ArcGISTiledMapServiceLayer)
      {
       var tiledLayer:ArcGISTiledMapServiceLayer = layer as ArcGISTiledMapServiceLayer;
                     url = tiledLayer.url;
                     if(identifyLayerOption == "visible")
                     {
                      if(tiledLayer.visible == false)
                       url="";
                     }
      }
      if (url)
      {
       var identifyTask:IdentifyTask = new IdentifyTask(url);
       identifyTask.addEventListener(IdentifyEvent.IDENTIFY_COMPLETE, onResult);
       identifyTask.addEventListener(FaultEvent.FAULT, onFault);
       identifyTask.execute(identifyParams);
      }
     }
    }
   }
0 Kudos