Permanently change the order in layer list widget

1403
8
Jump to solution
01-09-2018 08:36 AM
MarkCooper5
Occasional Contributor II

Hi

My users have asked me to display the layers in the layer list in alphabetical order as there are over 50 layers in the map and it is hard to find the one that they want.

I really don't want to have to change the drawing order as this needs to be maintained with polygons first, then line and points to enable the data to be shown clearly. Whilst there is a way of allowing layers to be moved up and down when using the widget, I cannot see away to permanently change this. Is it possible at all to do this in the code?

Thanks

Mark

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

Mark,

   All I can provide is coding suggestions for this but in the LayerList widget folder there is a LayerListView.js refresh function. In that refresh function they get the maps operational layers using this.operLayerInfos.getLayerInfoArray() you can try and sort that array.

View solution in original post

0 Kudos
8 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Mark,

   All I can provide is coding suggestions for this but in the LayerList widget folder there is a LayerListView.js refresh function. In that refresh function they get the maps operational layers using this.operLayerInfos.getLayerInfoArray() you can try and sort that array.

0 Kudos
MarkCooper5
Occasional Contributor II

Hi Robert

One of our developers has had a quick look and updated the JS as follows:

refresh: function() {
this._removeLayerNodes();
var sortedLayerArray = this.operLayerInfos.getLayerInfoArray()
sortedLayerArray = sortedLayerArray.sort()

// must be the array - this.operLayerInfos.getLayerInfoArray() - need to sort this
array.forEach(sortedLayerArray, function(layerInfo) {
this.drawListNode(layerInfo, 0, this.layerListTable);
}, this);

Looks like it hasn't worked, unless it will only sort the services and not the layers within it:

Don't suppose you have any clues?

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Mark,

   Yes the sort will only work at the first level the services. it will not sort the sublayers.

0 Kudos
MarkCooper5
Occasional Contributor II

I thought it may be. If there no way of sorting sublayers, I guess the alternative would be to  publish each layer as a service. The problem with that is with 50+ layers just on this map, I would kill the server!

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Mark,

   Sometimes it is your job as the GIS Professional to tell the users that what they want is not practical. That is the case here items in a layerlist or TOC are always organized in the order in which they are displayed in the map. 

0 Kudos
MarkCooper5
Occasional Contributor II

I agree, we need to manage their expectations and let them know if their request is downright daft (of which we have had plenty!) or, after a certain amount of effort, not practical. However, in just in this case I happen to agree with the customer in that it will be easier to find layers if they were in alphabetical order. Whilst layers need to be drawn in a certain order to ensure the best possible cartographic representation, I see no cartographic reason that that is the order they have to be displayed on on the layer list, only limits to the technology.

I actually think, after much googling, I have managed to work out a way round this too! Instead of creating a new service for each layer, just add each layer from the service to AGOL separately using the layer id from the REST endpoint. That way the code to sort the array should work perfectly. I hope!!

Thanks again for your help. Don't think we would have got anywhere near the map we have if it wasn't for your input.

0 Kudos
MarkCooper5
Occasional Contributor II

That looks promising, thanks. I will see if any of the developers in the IT department would know how to add this sort function

0 Kudos
BrianDudek
Occasional Contributor

The alphabetical possibility is a good thing to know.  I was curious on about the ability to move a layer or two to the top of the layer list but not affect the display order in the web map?   The layer list widget once added to the application allows for you to move up and down layers, but doesn't allow you to save those moved changes prior to launching, but even if it did, I think that would affect the display order as that is what the move up and move down commands do in the launched web application

This was possible in the prior Flex-based applications of years ago.

0 Kudos