Select to view content in your preferred language

Reorder TiledMapServiceLayer and FeatureLayer

2914
8
Jump to solution
02-26-2014 07:53 AM
DanielTrone
Deactivated User
I have a fairly basic use case; I need a basemap in the background, a feature layer in the middle, and the basemap reference layer with labels on top.

For some reason, I'm having a lot of trouble implementing it.  map.reorderLayer is not working.  Adding the second parameter to map.addLayer is not working.  I'm at a loss.  I'm using Feature Services created with AGOL for my Feature Layers.  I'm guessing that reordering different types of layers is the problem.  Is there any workaround?

See my jsFiddle for a very basic example:
http://jsfiddle.net/DanielTrone/s8ksF/

Thanks for any help.
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
I believe this issue is caused by the fact that a FeatureLayer is based on a GraphicLayer, which will always display at the top. This works correctly when using an ArcGISDynamicMapServiceLayer, according to this modification to your Fiddle: http://jsfiddle.net/s8ksF/1/

View solution in original post

0 Kudos
8 Replies
KenBuja
MVP Esteemed Contributor
I believe this issue is caused by the fact that a FeatureLayer is based on a GraphicLayer, which will always display at the top. This works correctly when using an ArcGISDynamicMapServiceLayer, according to this modification to your Fiddle: http://jsfiddle.net/s8ksF/1/
0 Kudos
DanielTrone
Deactivated User
Thanks for diagnosing the problem Ken - that graphics layers are always drawn on top (despite attempts to change that with map.reorderLayer).

Are there any workarounds that will allow me to use my FeatureLayers sandwiched between the basemap and reference layers?
0 Kudos
KenBuja
MVP Esteemed Contributor
Unfortunately, I don't. I haven't figured out a way to set the reference layer as a GraphicLayer also.
0 Kudos
BenFousek
Deactivated User
Daniel,
It is possible to move an overlay layer above graphics layers, however it is accomplished outside of the jsapi, and requires some advanced knowledge of the dom and dojo to accomplish it. Unfortunately doing so will cause several problems.

Here's an image of the map's dom node from your fiddle. As you can see graphic/feature layers exist in a dom node at the same level as overlay (dynamic, tiled, web tiled, wms, etc) layers. When you reorder layers, if it's an overlay layer it's reordered with the other overlay layers. If it's a graphic/feature layer it's reordered within the graphics dom node.
[ATTACH=CONFIG]31789[/ATTACH]

You can use dojo (or pure js) to move an overlay above (it's reversed in the dom - top most dom node is the lowest layer) the dom node containing all the graphic/feature layers. HOWEVER, doing so will "cover up" the graphics layers and you WILL NOT be able to interact with them, such as clicking, which in necessary to show the popup for example. And if you try to reorder any layer with the api's reorderLayer() after having done so, the map will crash.

Hopefully, that explains what's going on and why you shouldn't do it. As one solution to your problem, take Ken's example and simply add a click event to the map to identify, highlight (with map.graphics) and show popup using your layer.
0 Kudos
JeffPace
MVP Alum
Sorry to be short, but this is one (of the many) reasons we do NOT use FeatureLayers unless we absolutely have to (i.e. editing). 

If you want layer control, use dynamic layers
0 Kudos
DanielTrone
Deactivated User
Ben,

I'd use Ken's example, but my layer is a FeatureLayer while his example shows a ArcGISDynamicMapServiceLayer.  Is there a way to convert one to the other?  I am using AGOL rather than ArcGIS Server.  I'm guessing that ArcGISDynamicMapServiceLayer's are produced by Server.

Jeff,

Noted.  I've had trouble with Feature Layers in the past, but have gotten around most of the issues until now.
0 Kudos
JeffPace
MVP Alum
To use it as dynamic you would have to change the service that has been added to AGOL
0 Kudos
BenFousek
Deactivated User
I'd use Ken's example, but my layer is a FeatureLayer while his example shows a ArcGISDynamicMapServiceLayer.  Is there a way to convert one to the other?  I am using AGOL rather than ArcGIS Server.  I'm guessing that ArcGISDynamicMapServiceLayer's are produced by Server.


Your service doesn't have a corresponding MapServer endpoint like AGS. I'm not sure how AGO works, but someone here can help you out.

Good Luck!
0 Kudos