Select to view content in your preferred language

Feature layer onclick and Layer on top of it

2560
7
02-10-2014 05:06 AM
vinayb
by
Deactivated User
HI All,

I am using feature-layer on-click in my application instead of map on-click in order to boost performance of the map. Since i am using snapshot mode and all graphics are loaded in the client i don't want to hit server again hence i thought of using feature-layer on-click functionality as when i tried to use map on-click things dint work as expected hence i started using feature layer on-click.My on click method is an below i am trying read some attribute of the graphic object clicked.

dojo.connect(featureLayer, "onClick", function(e){
       someMethod(e);
          });

function someMethod(evt){
        var graphic = evt.graphic;
        var countryName = graphic.attributes.CNTRY_NAME;
}



    WE need day night functionality in our application hence i used Day Night example which draws some polygon's on the map .The problem i am facing when i click on the map since i am using evt.graphic instead of getting featureLayer graphic object which as the attribute i think i am getting the ploygon which is drawn on the map.Hence i get below issue  
  attributes.CNTRY_NAME is not defined

Can anybody let me know how can i over come this scenario.
0 Kudos
7 Replies
JeffPace
MVP Alum
FeatureLayer is a graphicsLayer, and my guess is your graphics are being drawn on top of FeatureLayer.

Controlling the order of these is difficult. 

Does your click work in areas without the overlayed Layer?
0 Kudos
vinayb
by
Deactivated User
Yes it works
0 Kudos
JeffPace
MVP Alum
You might want to output your layerids to verify that things are stacked in the order you think they should be. My guess is your feature layer is not on top and there is another graphicslayer on top of it
0 Kudos
vinayb
by
Deactivated User
The layer on top of a feature layer is not actually any other feature layer it is set of polygon drawn so how can i make this not disturb my feature layer.
0 Kudos
JeffPace
MVP Alum
Ahhh that is exactly the problem.  Since Feature layers and Graphics are both GraphicLayers, your graphics are on top of your feature layer.

from the API

Each map contains a GraphicsLayer by default, accessible using the Map.Graphics property. Beginning with v1.4, you can create your own graphics layers and add them to the map. Graphics layers can be reordered within the group of graphics layers. However, the graphics layer in Map.Graphics is always on top


So that is why your map graphics are always on top.

So what you will have to do is create a graphicsLayer, and add your polygons to THAT (instead of map.graphics).  This will allow the featureLayer (which IS in map.graphics) to ride on top of your polygons
0 Kudos
JeffPace
MVP Alum
I am not sure if you can draw the polygons on top but not have them interfere with onclick.  I just realize that is what you might be trying to do

If that is the case, you might want to switch from onClick to a query type event where you can specify the layer
0 Kudos
vinayb
by
Deactivated User
Thanks for your suggestion , as you told i added all my polygon to one layer and added that layer before my feature layer so that my feature layer is  always on top now onClick is working fine.
    But map looks little ugly it would be great if ploygon sit on feature layer , can you please explain me about query event .When i click on the map (when polygon layer is on top of my feature layer ) how will get the graphic object of feature layer since i am dependent of graphic object attribute (CNTRY_NAME).
0 Kudos