I found the LayerList to be a pretty good tool for toggling map layers on and off. It handles sub layer visibility for those dynamic map services where you don’t want to show EVERYTHING in the beginning. It also integrates opacity sliders when you want to see what’s underneath. Everything displays and collapses nicely, so there’s not much clutter on the screen. I really liked this user control: so much so that I wanted to…
That’s when I found an issue. I had added the LayerList to one of our web applications, in place of a custom control I had made before, and a client mentioned that they couldn’t see the name of the base layer in the list. I checked it out, and found the client was right. Their latest aerial photography wasn’t visible in the LayerList control.
After a bit of trial and error, I found that the LayerList only shows the operational layers for any web map created through ArcGIS Online. Perhaps they felt that the base map should always be on, since it provides a context you the user can relate to. Or perhaps they had integration problems with it and the Basemap Gallery. I don’t know. All I knew was that the LayerList didn’t show the basemap, and I didn’t know how our client would take it if I told them to wait until ESRI released a fix for it.
While putting together the example, I realized something. A web application is like the movie Inception. With enough know-how, you can totally bend it to your will. So, I analyzed how the user interface was created, and mocked up an extension to the LayerList. What I eventually came up with was the following.
It’s still a little rough, but I was surprised how well it worked. Not only could I get an ArcGIS Online basemap to show in the list, but I could toggle it on and off with the control. Now, I didn’t go so far as to integrate base map opacity or any other cool features. I’ll leave that to somebody else with more time and money. But I’ve published the gist above, and provided a use case in a CodePen below, which expands upon the previous one from my issue.
So, what I have learned from this? I’ve learned it’s so much easier to contribute directly to open source. I learned the different channels to communicate issues with software companies, and why I’d rather spend the time to hack together my own fix. Finally, I learned that I have a super power.
I run into edge cases so quickly, it should be considered a superpower. #CodeBreaker
— Ken Doman (@raykendo) March 18, 2016
After going back and forth with one of the Product Engineers at ESRI, we came up with a more non-invasive method to add the ArcGIS Online Basemap layers to the LayerList. It involves packaging the basemap layers with the operational layers in a list, then creating the LayerList with those layers assigned. Code and examples will be posted soon.